13 integer,
parameter :: maxvars = 60
14 character(len=10) :: maskvar =
'h' 17 character(len= 20) :: var_name
18 character(len=120) :: long_name
19 character(len= 20) :: units
20 character(len= 20) :: var_remapmethod
22 character(len= 4) :: var_grid
23 character(len= 20) :: var_pair
24 character(len= 4) :: var_pair_grid
30 character(len=10) :: ftype
31 character(len=10) :: fsrc
32 character(len=10) :: fdst
33 character(len=120) :: wgtsdir
34 character(len=120) :: griddir
35 character(len=20) :: input_file
56 subroutine readnml(fname,errmsg,rc)
58 character(len=*),
intent(in) :: fname
59 character(len=*),
intent(out) :: errmsg
60 integer,
intent(out) :: rc
64 integer :: ierr, iounit
65 integer :: srcdims(2), dstdims(2)
68 namelist /ocniceprep_nml/ ftype, wgtsdir, griddir, srcdims, dstdims, debug
70 srcdims = 0; dstdims = 0
74 inquire(file=trim(fname), exist=fexist)
75 if (.not. fexist)
then 76 write (errmsg,
'(a)')
'FATAL ERROR: input file '//trim(fname)//
' does not exist.' 81 open (action=
'read', file=trim(fname), iostat=ierr, newunit=iounit)
82 read (nml=ocniceprep_nml, iostat=ierr, unit=iounit)
85 write (errmsg,
'(a)')
'FATAL ERROR: invalid namelist format.' 92 wgtsdir = trim(wgtsdir)//
'/' 93 griddir = trim(griddir)//
'/' 96 if (trim(ftype) /=
'ocean' .and. trim(ftype) /=
'ice')
then 98 write (errmsg,
'(a)')
'FATAL ERROR: ftype must be ocean or ice' 103 nxt = srcdims(1); nyt = srcdims(2)
104 nxr = dstdims(1); nyr = dstdims(2)
105 fsrc =
'' ; fdst =
'' 106 if (nxt == 1440 .and. nyt == 1080) fsrc =
'mx025' 107 if (len_trim(fsrc) == 0)
then 109 write(errmsg,
'(a)')
'FATAL ERROR: source grid dimensions invalid' 113 if (nxr == 720 .and. nyr == 576) fdst =
'mx050' 114 if (nxr == 360 .and. nyr == 320) fdst =
'mx100' 115 if (nxr == 72 .and. nyr == 35) fdst =
'mx500' 116 if (len_trim(fdst) == 0)
then 118 write(errmsg,
'(a)')
'FATAL ERROR: destination grid dimensions invalid' 122 if (trim(fdst) ==
'mx500')
then 124 write(errmsg,
'(a)')
'FATAL ERROR: 5deg destination grid is not supported' 129 if (trim(ftype) ==
'ocean')
then 135 input_file = trim(ftype)//
'.nc' 136 inquire (file=trim(input_file), exist=fexist)
137 if (.not. fexist)
then 138 write (errmsg,
'(a)')
'FATAL ERROR: input file '//trim(input_file)//
' does not exist.' 144 open(newunit=logunit, file=trim(ftype)//
'.prep.log',form=
'formatted')
145 if (debug)
write(logunit,
'(a)')
'input file: '//trim(input_file)
148 write(errmsg,
'(a)')
'Namelist successfully read, continue' 151 end subroutine readnml
161 subroutine readcsv(fname,errmsg,rc,nvalid)
163 character(len=*),
intent(in) :: fname
164 character(len=*),
intent(out) :: errmsg
165 integer,
intent(out) :: rc
166 integer,
intent(out) :: nvalid
169 character(len=100) :: chead
170 character(len= 20) :: c1,c3,c4,c5,c6
171 integer :: i2, idx1,idx2
172 integer :: nn,n,ierr,iounit
178 open(newunit=iounit, file=trim(fname), status=
'old', iostat=ierr)
181 write (errmsg,
'(a)')
'FATAL ERROR: input file '//trim(fname)//
' does not exist.' 188 read(iounit,*,iostat=ierr)c1,i2,c3,c4,c5,c6
189 if (ierr .ne. 0)
exit 190 if (len_trim(c1) > 0)
then 192 outvars(nn)%var_name = trim(c1)
193 outvars(nn)%var_dimen = i2
194 outvars(nn)%var_grid = trim(c3)
195 outvars(nn)%var_remapmethod = trim(c4)
196 outvars(nn)%var_pair = trim(c5)
197 outvars(nn)%var_pair_grid = trim(c6)
206 if (len_trim(outvars(n)%var_pair) > 0 .and. idx1 .eq. 0)
then 212 if (trim(outvars(idx1)%var_pair) /= trim(outvars(idx2)%var_name))
then 214 write(errmsg,
'(a)')
'FATAL ERROR: vector pair for '//trim(outvars(idx1)%var_name) &
215 //
' is not set correctly' 218 if (trim(outvars(idx2)%var_pair) /= trim(outvars(idx1)%var_name))
then 220 write(errmsg,
'(a)')
'FATAL ERROR: vector pair for '//trim(outvars(idx2)%var_name) &
221 //
' is not set correctly' 226 if (outvars(idx1)%var_name(1:1) ==
'u')
then 227 if ((outvars(idx1)%var_grid(1:2) /=
'Cu') .and. outvars(idx1)%var_grid(1:2) /=
'Bu')
then 229 write(errmsg,
'(a)')
'FATAL ERROR: u-vector has wrong grid ' 233 if (outvars(idx2)%var_name(1:1) ==
'v')
then 234 if ((outvars(idx2)%var_grid(1:2) /=
'Cv') .and. outvars(idx2)%var_grid(1:2) /=
'Bu')
then 236 write(errmsg,
'(a)')
'FATAL ERROR: v-vector has wrong grid ' 242 write(errmsg,
'(a)')
'CSV successfully read, continue' 245 end subroutine readcsv