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 (nxt == 720 .and. nyt == 576) fsrc =
'mx050'
108 if (nxt == 360 .and. nyt == 320) fsrc =
'mx100'
109 if (len_trim(fsrc) == 0)
then
111 write(errmsg,
'(a)')
'FATAL ERROR: source grid dimensions invalid'
115 if (nxr == 1440 .and. nyr == 1080) fdst =
'mx025'
116 if (nxr == 720 .and. nyr == 576) fdst =
'mx050'
117 if (nxr == 360 .and. nyr == 320) fdst =
'mx100'
118 if (nxr == 72 .and. nyr == 35) fdst =
'mx500'
119 if (len_trim(fdst) == 0)
then
121 write(errmsg,
'(a)')
'FATAL ERROR: destination grid dimensions invalid'
125 if (trim(fsrc) .eq. trim(fdst))
then
127 write(errmsg,
'(a)')
'FATAL ERROR: Source and destination grids must differ'
131 if (trim(fdst) ==
'mx500')
then
133 write(errmsg,
'(a)')
'FATAL ERROR: 5deg destination grid is not supported'
138 if (trim(ftype) ==
'ocean')
then
144 input_file = trim(ftype)//
'.nc'
145 inquire (file=trim(input_file), exist=fexist)
146 if (.not. fexist)
then
147 write (errmsg,
'(a)')
'FATAL ERROR: input file '//trim(input_file)//
' does not exist.'
153 open(newunit=logunit, file=trim(ftype)//
'.prep.log',form=
'formatted')
154 if (debug)
write(logunit,
'(a)')
'input file: '//trim(input_file)
157 write(errmsg,
'(a)')
'Namelist successfully read, continue'
170 subroutine readcsv(fname,errmsg,rc,nvalid)
172 character(len=*),
intent(in) :: fname
173 character(len=*),
intent(out) :: errmsg
174 integer,
intent(out) :: rc
175 integer,
intent(out) :: nvalid
178 character(len=100) :: chead
179 character(len= 20) :: c1,c3,c4,c5,c6
180 integer :: i2, idx1,idx2
181 integer :: nn,n,ierr,iounit
187 open(newunit=iounit, file=trim(fname), status=
'old', iostat=ierr)
190 write (errmsg,
'(a)')
'FATAL ERROR: input file '//trim(fname)//
' does not exist.'
197 read(iounit,*,iostat=ierr)c1,i2,c3,c4,c5,c6
198 if (ierr .ne. 0)
exit
199 if (len_trim(c1) > 0)
then
201 outvars(nn)%var_name = trim(c1)
202 outvars(nn)%var_dimen = i2
203 outvars(nn)%var_grid = trim(c3)
204 outvars(nn)%var_remapmethod = trim(c4)
205 outvars(nn)%var_pair = trim(c5)
206 outvars(nn)%var_pair_grid = trim(c6)
214 if (len_trim(outvars(n)%var_pair) > 0 .and. idx1 .eq. 0)
then
220 if (idx1*idx2 > 0)
then
221 if (trim(outvars(idx1)%var_pair) /= trim(outvars(idx2)%var_name))
then
223 write(errmsg,
'(a)')
'FATAL ERROR: vector pair for '//trim(outvars(idx1)%var_name) &
224 //
' is not set correctly'
227 if (trim(outvars(idx2)%var_pair) /= trim(outvars(idx1)%var_name))
then
229 write(errmsg,
'(a)')
'FATAL ERROR: vector pair for '//trim(outvars(idx2)%var_name) &
230 //
' is not set correctly'
235 if (outvars(idx1)%var_name(1:1) ==
'u')
then
236 if ((outvars(idx1)%var_grid(1:2) /=
'Cu') .and. outvars(idx1)%var_grid(1:2) /=
'Bu')
then
238 write(errmsg,
'(a)')
'FATAL ERROR: u-vector has wrong grid '
242 if (outvars(idx2)%var_name(1:1) ==
'v')
then
243 if ((outvars(idx2)%var_grid(1:2) /=
'Cv') .and. outvars(idx2)%var_grid(1:2) /=
'Bu')
then
245 write(errmsg,
'(a)')
'FATAL ERROR: v-vector has wrong grid '
252 write(errmsg,
'(a)')
'CSV successfully read, continue'