-
Notifications
You must be signed in to change notification settings - Fork 3
/
readBioStat.f90
151 lines (121 loc) · 5.42 KB
/
readBioStat.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
subroutine readBioStat
!---------------------------------------------------------------------------
!anna !
! Copyright 2018 Anna Teruzzi, OGS, Trieste !
! !
! This file is part of 3DVarBio.
! 3DVarBio is based on OceanVar (Dobricic, 2006) !
! !
! 3DVarBio is free software: you can redistribute it and/or modify. !
! it under the terms of the GNU General Public License as published by !
! the Free Software Foundation, either version 3 of the License, or !
! (at your option) any later version. !
! !
! 3DVarBio is distributed in the hope that it will be useful, !
! but WITHOUT ANY WARRANTY; without even the implied warranty of !
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !
! GNU General Public License for more details. !
! !
! You should have received a copy of the GNU General Public License !
! along with OceanVar. If not, see <http://www.gnu.org/licenses/>. !
! !
!---------------------------------------------------------------------------
!-----------------------------------------------------------------------
! !
! READ quotas for biological variables !
! !
! Version 1: A. Teruzzi 2018 !
! This routine will have effect only if compiled with netcdf library. !
!-----------------------------------------------------------------------
! use filenames
use da_params
use bio_str
use grd_str
use drv_str
use mpi_str
use pnetcdf
implicit none
INTEGER(i4) :: ncid, VarId, ierr, iVar
INTEGER(i4) :: i,j,k,l,m
CHARACTER(LEN=51) :: RstFileName
CHARACTER(LEN=3) :: MyVarName
REAL(4), ALLOCATABLE :: x3(:,:,:)
ALLOCATE(x3(grd%im, grd%jm, grd%km))
ALLOCATE(bio%InitialChl(grd%im, grd%jm, grd%km)) ; bio%InitialChl(:,:,:) = 0.0
ALLOCATE(bio%pquot( grd%im, grd%jm, grd%km, bio%nphy)) ; bio%pquot(:,:,:,:) = 0.0
ALLOCATE(bio%cquot( grd%im, grd%jm, grd%km, bio%nphy, bio%ncmp)) ; bio%cquot(:,:,:,:,:) = 0.0
x3(:,:,:) = 0.0
do m=1,bio%ncmp
do l=1,bio%nphy
iVar = l + bio%nphy*(m-1)
if(iVar .gt. NBioVar) cycle
MyVarName = DA_VarList(iVar)
RstFileName = 'DA__FREQ_1/RST.'//ShortDate//'.'//MyVarName//'.nc'
if(drv%Verbose .eq. 1) then
if(MyId .eq. 0) &
write(*,*) "Reading ", RstFileName, " date: ", DA_DATE
endif
ierr = nf90mpi_open(Var3DCommunicator, trim(RstFileName), NF90_NOWRITE, MPI_INFO_NULL, ncid)
if (ierr .ne. NF90_NOERR ) call handle_err('nf90mpi_open RST', ierr)
ierr = nf90mpi_inq_varid (ncid, DA_VarList(iVar), VarId)
if (ierr .ne. NF90_NOERR ) call handle_err('nf90mpi_inq_varid', ierr)
ierr = nfmpi_get_vara_real_all (ncid, VarId, MyStart, MyCount, x3)
if (ierr .ne. NF90_NOERR ) call handle_err('nfmpi_get_vara_real_all RST', ierr)
if(m .eq. 1) then
! preparing pquot array
do k=1,grd%km
do j=1,grd%jm
do i=1,grd%im
bio%pquot(i,j,k,l) = x3(i,j,k)
if(x3(i,j,k) .lt. 1.e20) then
bio%InitialChl(i,j,k) = bio%InitialChl(i,j,k) + x3(i,j,k)
else
bio%InitialChl(i,j,k) = x3(i,j,k)
if(grd%msk(i,j,k) .eq. 1) then
write(*,*) "Warning!! Bad mask point in bio structure!"
write(*,*) "i=",i," j=",j," k=",k
write(*,*) "grd%msk(i,j,k)=",grd%msk
write(*,*) "bio%InitialChl(i,j,k)=",bio%InitialChl(i,j,k)
write(*,*) "Aborting.."
call MPI_Abort(Var3DCommunicator, -1, ierr)
endif
endif
enddo
enddo
enddo
endif
do k=1,grd%km
do j=1,grd%jm
do i=1,grd%im
if(bio%pquot(i,j,k,l).ne.0) &
bio%cquot(i,j,k,l,m) = x3(i,j,k) / bio%pquot(i,j,k,l)
enddo
enddo
enddo
ierr = nf90mpi_close(ncid)
if (ierr .ne. NF90_NOERR ) call handle_err('nf90mpi_close RST', ierr)
if(drv%Verbose .eq. 1) then
if(MyId .eq. 0) &
write(*,*) "Restart ", RstFileName, " read"
endif
enddo
enddo
do l=1,bio%nphy
do k=1,grd%km
do j=1,grd%jm
do i=1,grd%im
if( (bio%InitialChl(i,j,k) .lt. 1.e20) .and. (bio%InitialChl(i,j,k) .gt. 0)) then
bio%pquot(i,j,k,l) = bio%pquot(i,j,k,l) / bio%InitialChl(i,j,k)
else
bio%pquot(i,j,k,l) = 0.
endif
enddo
enddo
enddo
enddo
if(MyId .eq. 0) then
write(drv%dia,*)'Number of phytoplankton types is ', bio%nphy
write(drv%dia,*)'Number of phytoplankton components is ', bio%ncmp
endif
DEALLOCATE(x3)
end subroutine readBioStat