18 |
SUBROUTINE flinopen_nozoom(iim, jjm, llm, lon, lat, lev, & |
SUBROUTINE flinopen_nozoom(iim, jjm, llm, lon, lat, lev, & |
19 |
ttm, itaus, date0, dt, fid_out) |
ttm, itaus, date0, dt, fid_out) |
20 |
|
|
21 |
!- The routine will open an input file |
! The routine will open an input file |
22 |
!- INPUT |
! INPUT |
23 |
!- There is no test of the content of the file against the input |
! There is no test of the content of the file against the input |
24 |
! from the model |
! from the model |
25 |
|
|
26 |
!- iim : size in the x direction in the file (longitude) |
! iim: size in the x direction in the file (longitude) |
27 |
!- jjm : size in the y direction |
! jjm: size in the y direction |
28 |
!- llm : number of levels |
! llm: number of levels |
29 |
!- (llm = 0 means no axis to be expected) |
! (llm = 0 means no axis to be expected) |
30 |
|
|
31 |
!- WARNING : |
! WARNING: |
32 |
!- It is for the user to check |
! It is for the user to check |
33 |
!- that the dimensions of lon lat and lev are correct when passed to |
! that the dimensions of lon lat and lev are correct when passed to |
34 |
!- flinopen. This can be done after the call when iim and jjm have |
! flinopen. This can be done after the call when iim and jjm have |
35 |
!- been retrieved from the netCDF file. In F90 this problem will |
! been retrieved from the netCDF file. In F90 this problem will |
36 |
!- be solved with an internal assign |
! be solved with an internal assign |
37 |
!- IF iim, jjm, llm or ttm are parameters in the calling program |
! IF iim, jjm, llm or ttm are parameters in the calling program |
38 |
!- it will create a segmentation fault |
! it will create a segmentation fault |
39 |
|
|
40 |
!- ttm : size of time axis |
! ttm: size of time axis |
41 |
|
|
42 |
!- OUTPUT |
! OUTPUT |
43 |
|
|
44 |
!- lon : array of (iim,jjm), |
! lon: array of (iim, jjm), |
45 |
!- that contains the longitude of each point |
! that contains the longitude of each point |
46 |
!- lat : same for latitude |
! lat: same for latitude |
47 |
!- lev : An array of llm for the latitude |
! lev: An array of llm for the latitude |
48 |
!- itaus : Time steps within this file |
! itaus: Time steps within this file |
49 |
!- date0 : Julian date at which itau = 0 |
! date0: Julian date at which itau = 0 |
50 |
!- dt : length of the time steps of the data |
! dt: length of the time steps of the data |
51 |
|
|
52 |
!--------------------------------------------------------------------- |
!--------------------------------------------------------------------- |
53 |
|
|
54 |
USE calendar, ONLY : ymds2ju, ioconf_calendar |
USE calendar, ONLY: ymds2ju, ioconf_calendar |
55 |
USE errioipsl, ONLY : histerr |
USE errioipsl, ONLY: histerr |
56 |
USE netcdf, ONLY : nf90_get_att, nf90_get_var, nf90_global, & |
USE netcdf, ONLY: nf90_get_att, nf90_get_var, nf90_global, & |
57 |
nf90_inquire_variable |
nf90_inquire_variable |
58 |
|
|
|
IMPLICIT NONE |
|
|
|
|
59 |
! ARGUMENTS |
! ARGUMENTS |
60 |
|
|
61 |
INTEGER, intent(in) :: iim, jjm, llm, ttm |
INTEGER, intent(in):: iim, jjm, llm, ttm |
62 |
real, intent(out):: lon(iim,jjm), lat(iim,jjm), lev(llm) |
real, intent(out):: lon(iim, jjm), lat(iim, jjm), lev(llm) |
63 |
INTEGER, intent(out):: itaus(ttm) |
INTEGER, intent(out):: itaus(ttm) |
64 |
REAL, intent(out):: date0, dt |
REAL, intent(out):: date0, dt |
65 |
|
|
68 |
|
|
69 |
! LOCAL |
! LOCAL |
70 |
|
|
71 |
INTEGER :: iret, vid, fid, nbdim, i |
INTEGER:: iret, vid, fid, nbdim, i |
72 |
INTEGER :: gdtt_id, old_id, iv, gdtmaf_id |
INTEGER:: gdtt_id, old_id, iv, gdtmaf_id |
73 |
CHARACTER(LEN=250) :: name |
CHARACTER(LEN=250):: name |
74 |
CHARACTER(LEN=80) :: units, my_calendar |
CHARACTER(LEN=80):: units, my_calendar |
75 |
INTEGER :: year, month, day |
INTEGER:: year, month, day |
76 |
REAL :: r_year, r_month, r_day |
REAL:: r_year, r_month, r_day |
77 |
INTEGER :: year0, month0, day0, hours0, minutes0, seci |
INTEGER:: year0, month0, day0, hours0, minutes0, seci |
78 |
REAL :: sec, sec0 |
REAL:: sec, sec0 |
79 |
CHARACTER :: strc |
CHARACTER:: strc |
80 |
|
|
81 |
REAL,DIMENSION(:),ALLOCATABLE :: vec_tmp |
REAL, DIMENSION(:), ALLOCATABLE:: vec_tmp |
82 |
|
|
83 |
!--------------------------------------------------------------------- |
!--------------------------------------------------------------------- |
84 |
|
|
94 |
stop 1 |
stop 1 |
95 |
end IF |
end IF |
96 |
|
|
97 |
!-- The user has already opened the file |
! The user has already opened the file |
98 |
!-- and we trust that he knows the dimensions |
! and we trust that he knows the dimensions |
99 |
|
|
100 |
fid = ncids(fid_out) |
fid = ncids(fid_out) |
101 |
|
|
102 |
! 2.0 get the sizes and names of the different coordinates |
! 2.0 get the sizes and names of the different coordinates |
103 |
! and do a first set of verification. |
! and do a first set of verification. |
104 |
|
|
105 |
! 3.0 Check if we are realy talking about the same coodinate system |
! 3.0 Check if we are realy talking about the same coodinate system |
106 |
! if not then we get the lon, lat and lev variables from the file |
! if not then we get the lon, lat and lev variables from the file |
107 |
|
|
108 |
|
! 4.0 extracting the coordinates |
109 |
|
|
|
!-- 4.0 extracting the coordinates |
|
|
!--- |
|
110 |
CALL flinfindcood (fid_out, 'lon', vid, nbdim) |
CALL flinfindcood (fid_out, 'lon', vid, nbdim) |
111 |
IF (nbdim == 2) THEN |
IF (nbdim == 2) THEN |
112 |
iret = NF90_GET_VAR (fid, vid, lon, & |
iret = NF90_GET_VAR (fid, vid, lon, & |
115 |
ALLOCATE(vec_tmp(iim)) |
ALLOCATE(vec_tmp(iim)) |
116 |
iret = NF90_GET_VAR (fid, vid, vec_tmp, & |
iret = NF90_GET_VAR (fid, vid, vec_tmp, & |
117 |
start=(/ 1 /), count=(/ iim /)) |
start=(/ 1 /), count=(/ iim /)) |
118 |
DO i=1,jjm |
DO i=1, jjm |
119 |
lon(:,i) = vec_tmp(:) |
lon(:, i) = vec_tmp(:) |
120 |
ENDDO |
ENDDO |
121 |
DEALLOCATE(vec_tmp) |
DEALLOCATE(vec_tmp) |
122 |
ENDIF |
ENDIF |
123 |
!--- |
|
124 |
CALL flinfindcood (fid_out, 'lat', vid, nbdim) |
CALL flinfindcood (fid_out, 'lat', vid, nbdim) |
125 |
IF (nbdim == 2) THEN |
IF (nbdim == 2) THEN |
126 |
iret = NF90_GET_VAR (fid, vid, lat, & |
iret = NF90_GET_VAR (fid, vid, lat, & |
129 |
ALLOCATE(vec_tmp(jjm)) |
ALLOCATE(vec_tmp(jjm)) |
130 |
iret = NF90_GET_VAR (fid, vid, vec_tmp, & |
iret = NF90_GET_VAR (fid, vid, vec_tmp, & |
131 |
start=(/ 1 /), count=(/ jjm /)) |
start=(/ 1 /), count=(/ jjm /)) |
132 |
DO i=1,iim |
DO i=1, iim |
133 |
lat(i,:) = vec_tmp(:) |
lat(i, :) = vec_tmp(:) |
134 |
ENDDO |
ENDDO |
135 |
DEALLOCATE(vec_tmp) |
DEALLOCATE(vec_tmp) |
136 |
ENDIF |
ENDIF |
137 |
!--- |
|
138 |
IF (llm > 0) THEN |
IF (llm > 0) THEN |
139 |
CALL flinfindcood (fid_out, 'lev', vid, nbdim) |
CALL flinfindcood (fid_out, 'lev', vid, nbdim) |
140 |
IF (nbdim == 1) THEN |
IF (nbdim == 1) THEN |
141 |
iret = NF90_GET_VAR (fid, vid, lev, & |
iret = NF90_GET_VAR (fid, vid, lev, & |
142 |
start=(/ 1 /), count=(/ llm /)) |
start=(/ 1 /), count=(/ llm /)) |
143 |
ELSE |
ELSE |
144 |
CALL histerr (3,'flinopen', & |
CALL histerr (3, 'flinopen', & |
145 |
'Can not handle vertical coordinates that have more',& |
'Can not handle vertical coordinates that have more', & |
146 |
'than 1 dimension',' ') |
'than 1 dimension', ' ') |
147 |
ENDIF |
ENDIF |
148 |
ENDIF |
ENDIF |
149 |
|
|
150 |
! 5.0 Get all the details for the time if possible needed |
! 5.0 Get all the details for the time if possible needed |
151 |
|
|
152 |
IF (ttm > 0) THEN |
IF (ttm > 0) THEN |
153 |
!--- |
|
154 |
!-- 5.1 Find the time axis. Prefered method is the 'timestep since' |
! 5.1 Find the time axis. Prefered method is the 'timestep since' |
155 |
!--- |
|
156 |
gdtmaf_id = -1 |
gdtmaf_id = -1 |
157 |
gdtt_id = -1 |
gdtt_id = -1 |
158 |
old_id = -1 |
old_id = -1 |
159 |
DO iv=1,ncnbva(fid_out) |
DO iv=1, ncnbva(fid_out) |
160 |
name='' |
name='' |
161 |
iret = NF90_INQUIRE_VARIABLE (fid, iv, name=name) |
iret = NF90_INQUIRE_VARIABLE (fid, iv, name=name) |
162 |
units='' |
units='' |
163 |
iret = NF90_GET_ATT (fid, iv, 'units', units) |
iret = NF90_GET_ATT (fid, iv, 'units', units) |
164 |
IF (INDEX(units,'seconds since') > 0) gdtmaf_id = iv |
IF (INDEX(units, 'seconds since') > 0) gdtmaf_id = iv |
165 |
IF (INDEX(units,'timesteps since') > 0) gdtt_id = iv |
IF (INDEX(units, 'timesteps since') > 0) gdtt_id = iv |
166 |
IF (INDEX(name, 'tstep') > 0) old_id = iv |
IF (INDEX(name, 'tstep') > 0) old_id = iv |
167 |
ENDDO |
ENDDO |
168 |
!--- |
|
169 |
IF (gdtt_id > 0) THEN |
IF (gdtt_id > 0) THEN |
170 |
vid = gdtt_id |
vid = gdtt_id |
171 |
ELSE IF (gdtmaf_id > 0) THEN |
ELSE IF (gdtmaf_id > 0) THEN |
173 |
ELSE IF (old_id > 0) THEN |
ELSE IF (old_id > 0) THEN |
174 |
vid = old_id |
vid = old_id |
175 |
ELSE |
ELSE |
176 |
CALL histerr (3, 'flinopen', 'No time axis found',' ',' ') |
CALL histerr (3, 'flinopen', 'No time axis found', ' ', ' ') |
177 |
ENDIF |
ENDIF |
178 |
!--- |
|
179 |
ALLOCATE(vec_tmp(ttm)) |
ALLOCATE(vec_tmp(ttm)) |
180 |
iret = NF90_GET_VAR (fid, vid, vec_tmp, & |
iret = NF90_GET_VAR (fid, vid, vec_tmp, & |
181 |
start=(/ 1 /), count=(/ ttm /)) |
start=(/ 1 /), count=(/ ttm /)) |
182 |
itaus(1:ttm) = NINT(vec_tmp(1:ttm)) |
itaus(1:ttm) = NINT(vec_tmp(1:ttm)) |
183 |
DEALLOCATE(vec_tmp) |
DEALLOCATE(vec_tmp) |
184 |
!--- |
|
185 |
!-- Getting all the details for the time axis |
! Getting all the details for the time axis |
186 |
!--- |
|
187 |
!-- Find the calendar |
! Find the calendar |
188 |
my_calendar='XXXX' |
my_calendar='XXXX' |
189 |
iret = NF90_GET_ATT (fid, gdtmaf_id, 'calendar', my_calendar) |
iret = NF90_GET_ATT (fid, gdtmaf_id, 'calendar', my_calendar) |
190 |
IF ( INDEX(my_calendar,'XXXX') < 1 ) THEN |
IF ( INDEX(my_calendar, 'XXXX') < 1 ) THEN |
191 |
CALL ioconf_calendar(my_calendar) |
CALL ioconf_calendar(my_calendar) |
192 |
ENDIF |
ENDIF |
193 |
!-- |
|
194 |
units = '' |
units = '' |
195 |
iret = NF90_GET_ATT (fid, vid, 'units', units) |
iret = NF90_GET_ATT (fid, vid, 'units', units) |
196 |
IF (gdtt_id > 0) THEN |
IF (gdtt_id > 0) THEN |
197 |
units = units(INDEX(units,'since')+6:LEN_TRIM(units)) |
units = units(INDEX(units, 'since')+6:LEN_TRIM(units)) |
198 |
READ (units,'(I4.4,5(a,I2.2))') & |
READ (units, '(I4.4, 5(a, I2.2))') & |
199 |
year0, strc, month0, strc, day0, & |
year0, strc, month0, strc, day0, & |
200 |
strc, hours0, strc, minutes0, strc, seci |
strc, hours0, strc, minutes0, strc, seci |
201 |
sec0 = hours0*3600. + minutes0*60. + seci |
sec0 = hours0*3600. + minutes0*60. + seci |
202 |
CALL ymds2ju (year0, month0, day0, sec0, date0) |
CALL ymds2ju (year0, month0, day0, sec0, date0) |
203 |
iret = NF90_GET_ATT (fid, gdtt_id, 'tstep_sec', dt) |
iret = NF90_GET_ATT (fid, gdtt_id, 'tstep_sec', dt) |
204 |
ELSE IF (gdtmaf_id > 0) THEN |
ELSE IF (gdtmaf_id > 0) THEN |
205 |
units = units(INDEX(units,'since')+6:LEN_TRIM(units)) |
units = units(INDEX(units, 'since')+6:LEN_TRIM(units)) |
206 |
READ (units,'(I4.4,5(a,I2.2))') & |
READ (units, '(I4.4, 5(a, I2.2))') & |
207 |
year0, strc, month0, strc, day0, & |
year0, strc, month0, strc, day0, & |
208 |
strc, hours0, strc, minutes0, strc, seci |
strc, hours0, strc, minutes0, strc, seci |
209 |
sec0 = hours0*3600. + minutes0*60. + seci |
sec0 = hours0*3600. + minutes0*60. + seci |
210 |
CALL ymds2ju (year0, month0, day0, sec0, date0) |
CALL ymds2ju (year0, month0, day0, sec0, date0) |
211 |
!----- |
|
212 |
ELSE IF (old_id > 0) THEN |
ELSE IF (old_id > 0) THEN |
213 |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'delta_tstep_sec', dt) |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'delta_tstep_sec', dt) |
214 |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'day0', r_day) |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'day0', r_day) |
215 |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'sec0', sec) |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'sec0', sec) |
216 |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'year0', r_year) |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'year0', r_year) |
217 |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'month0', r_month) |
iret = NF90_GET_ATT (fid, NF90_GLOBAL, 'month0', r_month) |
218 |
!----- |
|
219 |
day = INT(r_day) |
day = INT(r_day) |
220 |
month = INT(r_month) |
month = INT(r_month) |
221 |
year = INT(r_year) |
year = INT(r_year) |
222 |
!----- |
|
223 |
CALL ymds2ju (year, month, day, sec, date0) |
CALL ymds2ju (year, month, day, sec, date0) |
224 |
ENDIF |
ENDIF |
225 |
ENDIF |
ENDIF |
226 |
|
|
227 |
END SUBROUTINE flinopen_nozoom |
END SUBROUTINE flinopen_nozoom |
228 |
|
|
229 |
!=== |
!*************************************************************** |
230 |
|
|
231 |
SUBROUTINE flininfo (filename, iim, jjm, llm, ttm, fid_out) |
SUBROUTINE flininfo(filename, iim, jjm, llm, ttm, fid_out) |
|
!--------------------------------------------------------------------- |
|
|
!- This subroutine allows to get some information. |
|
|
!- It is usualy done within flinopen but the user may want to call |
|
|
!- it before in order to allocate the space needed to extract the |
|
|
!- data from the file. |
|
|
!--------------------------------------------------------------------- |
|
|
USE strlowercase_m, ONLY : strlowercase |
|
|
USE errioipsl, ONLY : histerr |
|
|
USE netcdf, ONLY : nf90_inquire, nf90_inquire_dimension, nf90_noerr, & |
|
|
nf90_nowrite, nf90_open |
|
232 |
|
|
233 |
IMPLICIT NONE |
! This subroutine allows to get some information. |
234 |
|
! It is usualy done within flinopen but the user may want to call |
235 |
! ARGUMENTS |
! it before in order to allocate the space needed to extract the |
236 |
|
! data from the file. |
237 |
|
|
238 |
|
USE strlowercase_m, ONLY: strlowercase |
239 |
|
USE errioipsl, ONLY: histerr |
240 |
|
USE netcdf, ONLY: nf90_inquire, nf90_inquire_dimension, nf90_noerr, & |
241 |
|
nf90_nowrite |
242 |
|
use netcdf95, only: nf95_open |
243 |
|
|
244 |
CHARACTER(LEN=*), intent(in):: filename |
CHARACTER(LEN=*), intent(in):: filename |
245 |
INTEGER, intent(out):: iim, jjm, llm, ttm, fid_out |
INTEGER, intent(out):: iim, jjm, llm, ttm, fid_out |
246 |
|
|
247 |
! LOCAL |
! LOCAL |
248 |
|
|
249 |
INTEGER, SAVE :: nbfiles = 0 |
INTEGER, SAVE:: nbfiles = 0 |
250 |
INTEGER, SAVE :: ncdims(nbfile_max,4) |
INTEGER, SAVE:: ncdims(nbfile_max, 4) |
251 |
INTEGER :: iret, fid, ndims, nvars, nb_atts, id_unlim |
INTEGER:: iret, fid, ndims, nvars, nb_atts, id_unlim |
252 |
INTEGER :: iv, lll |
INTEGER:: iv, lll |
253 |
CHARACTER(LEN=80) :: name |
CHARACTER(LEN=80):: name |
254 |
CHARACTER(LEN=30) :: axname |
CHARACTER(LEN=30):: axname |
255 |
|
|
|
LOGICAL :: check = .FALSE. |
|
256 |
!--------------------------------------------------------------------- |
!--------------------------------------------------------------------- |
257 |
|
|
258 |
lll = LEN_TRIM(filename) |
lll = LEN_TRIM(filename) |
259 |
IF (filename(lll-2:lll) /= '.nc') THEN |
IF (filename(lll-2:lll) /= '.nc') THEN |
260 |
name = filename(1:lll)//'.nc' |
name = filename(1:lll)//'.nc' |
262 |
name = filename(1:lll) |
name = filename(1:lll) |
263 |
ENDIF |
ENDIF |
264 |
|
|
265 |
iret = NF90_OPEN (name, NF90_NOWRITE, fid) |
call NF95_OPEN(name, NF90_NOWRITE, fid) |
266 |
IF (iret /= NF90_NOERR) THEN |
iret = NF90_INQUIRE(fid, nDimensions=ndims, nVariables=nvars, & |
|
CALL histerr(3, 'flininfo','Could not open file :',TRIM(name),' ') |
|
|
ENDIF |
|
|
|
|
|
iret = NF90_INQUIRE (fid, nDimensions=ndims, nVariables=nvars, & |
|
267 |
nAttributes=nb_atts, unlimitedDimId=id_unlim) |
nAttributes=nb_atts, unlimitedDimId=id_unlim) |
268 |
|
|
269 |
iim = 0; |
iim = 0 |
270 |
jjm = 0; |
jjm = 0 |
271 |
llm = 0; |
llm = 0 |
272 |
ttm = 0; |
ttm = 0 |
273 |
|
|
274 |
DO iv=1,ndims |
DO iv=1, ndims |
275 |
!--- |
iret = NF90_INQUIRE_DIMENSION(fid, iv, name=axname, len=lll) |
276 |
iret = NF90_INQUIRE_DIMENSION (fid, iv, name=axname, len=lll) |
CALL strlowercase(axname) |
|
CALL strlowercase (axname) |
|
277 |
axname = ADJUSTL(axname) |
axname = ADJUSTL(axname) |
278 |
!--- |
|
279 |
IF (check) WRITE(*,*) & |
IF ((INDEX(axname, 'x') == 1) .OR. (INDEX(axname, 'lon') == 1)) THEN |
280 |
'flininfo - getting axname',iv,axname,lll |
iim = lll |
281 |
!--- |
ELSE IF ((INDEX(axname, 'y') == 1) & |
282 |
IF ( (INDEX(axname,'x') == 1) & |
.OR. (INDEX(axname, 'lat') == 1)) THEN |
283 |
.OR.(INDEX(axname,'lon') == 1) ) THEN |
jjm = lll |
284 |
iim = lll; |
ELSE IF ((INDEX(axname, 'lev') == 1) .OR. (INDEX(axname, 'plev') == 1) & |
285 |
ELSE IF ( (INDEX(axname,'y') == 1) & |
.OR. (INDEX(axname, 'z') == 1) & |
286 |
.OR.(INDEX(axname,'lat') == 1) ) THEN |
.OR. (INDEX(axname, 'depth') == 1)) THEN |
287 |
jjm = lll; |
llm = lll |
288 |
ELSE IF ( (INDEX(axname,'lev') == 1) & |
ELSE IF ((INDEX(axname, 'tstep') == 1) & |
289 |
.OR.(INDEX(axname,'plev') == 1) & |
.OR. (INDEX(axname, 'time_counter') == 1)) THEN |
290 |
.OR.(INDEX(axname,'z') == 1) & |
! For the time we certainly need to allow for other names |
291 |
.OR.(INDEX(axname,'depth') == 1) ) THEN |
ttm = lll |
|
llm = lll; |
|
|
ELSE IF ( (INDEX(axname,'tstep') == 1) & |
|
|
.OR.(INDEX(axname,'time_counter') == 1) ) THEN |
|
|
!---- For the time we certainly need to allow for other names |
|
|
ttm = lll; |
|
292 |
ELSE IF (ndims == 1) THEN |
ELSE IF (ndims == 1) THEN |
293 |
!---- Nothing was found and ndims=1 then we have a vector of data |
! Nothing was found and ndims=1 then we have a vector of data |
294 |
iim = lll; |
iim = lll |
295 |
ENDIF |
ENDIF |
|
!--- |
|
296 |
ENDDO |
ENDDO |
297 |
|
|
298 |
! Keep all this information |
! Keep all this information |
300 |
nbfiles = nbfiles+1 |
nbfiles = nbfiles+1 |
301 |
|
|
302 |
IF (nbfiles > nbfile_max) THEN |
IF (nbfiles > nbfile_max) THEN |
303 |
CALL histerr (3,'flininfo', & |
CALL histerr(3, 'flininfo', & |
304 |
'Too many files. Please increase nbfil_max', & |
'Too many files. Please increase nbfil_max', & |
305 |
'in program flincom.F90.',' ') |
'in program flincom.F90.', ' ') |
306 |
ENDIF |
ENDIF |
307 |
|
|
308 |
ncids(nbfiles) = fid |
ncids(nbfiles) = fid |
309 |
ncdims(nbfiles,1:4) = (/ iim, jjm, llm, ttm /) |
ncdims(nbfiles, :) = (/ iim, jjm, llm, ttm /) |
310 |
|
ncnbva(nbfiles) = nvars |
|
ncnbva(nbfiles) = nvars |
|
311 |
ncfileopen(nbfiles) = .TRUE. |
ncfileopen(nbfiles) = .TRUE. |
|
|
|
312 |
fid_out = nbfiles |
fid_out = nbfiles |
313 |
!---------------------- |
|
314 |
END SUBROUTINE flininfo |
END SUBROUTINE flininfo |
315 |
|
|
316 |
!=== |
!*************************************************************** |
317 |
|
|
318 |
SUBROUTINE flinfindcood (fid_in, axtype, vid, ndim) |
SUBROUTINE flinfindcood (fid_in, axtype, vid, ndim) |
|
!--------------------------------------------------------------------- |
|
|
!- This subroutine explores the file in order to find |
|
|
!- the coordinate according to a number of rules |
|
|
!--------------------------------------------------------------------- |
|
|
USE strlowercase_m, ONLY : strlowercase |
|
|
USE errioipsl, ONLY : histerr |
|
|
USE netcdf, ONLY : nf90_get_att, nf90_inquire_dimension, & |
|
|
nf90_inquire_variable, nf90_noerr |
|
319 |
|
|
320 |
IMPLICIT NONE |
! This subroutine explores the file in order to find |
321 |
|
! the coordinate according to a number of rules |
322 |
|
|
323 |
|
USE strlowercase_m, ONLY: strlowercase |
324 |
|
USE errioipsl, ONLY: histerr |
325 |
|
USE netcdf, ONLY: nf90_get_att, nf90_inquire_dimension, & |
326 |
|
nf90_inquire_variable, nf90_noerr |
327 |
|
|
328 |
! ARGUMENTS |
! ARGUMENTS |
329 |
|
|
330 |
INTEGER, intent(in):: fid_in |
INTEGER, intent(in):: fid_in |
331 |
integer vid, ndim |
integer vid, ndim |
332 |
CHARACTER(LEN=3) :: axtype |
CHARACTER(LEN=3):: axtype |
333 |
|
|
334 |
! LOCAL |
! LOCAL |
335 |
|
|
336 |
INTEGER :: iv, iret, dimnb |
INTEGER:: iv, iret, dimnb |
337 |
CHARACTER(LEN=40) :: dimname, dimuni1, dimuni2, dimuni3 |
CHARACTER(LEN=40):: dimname, dimuni1, dimuni2, dimuni3 |
338 |
CHARACTER(LEN=30) :: str1 |
CHARACTER(LEN=30):: str1 |
339 |
LOGICAL :: found_rule = .FALSE. |
LOGICAL:: found_rule = .FALSE. |
340 |
!--------------------------------------------------------------------- |
!--------------------------------------------------------------------- |
341 |
vid = -1 |
vid = -1 |
342 |
|
|
347 |
dimuni2 = '?-?' |
dimuni2 = '?-?' |
348 |
dimuni3 = '?-?' |
dimuni3 = '?-?' |
349 |
|
|
350 |
! First rule : we look for the correct units |
! First rule: we look for the correct units |
351 |
! lon : east |
! lon: east |
352 |
! lat : north |
! lat: north |
353 |
! We make an exact check as it would be too easy to mistake |
! We make an exact check as it would be too easy to mistake |
354 |
! some units by just comparing the substrings. |
! some units by just comparing the substrings. |
355 |
|
|
379 |
iret = NF90_GET_ATT (ncids(fid_in), iv, 'units', str1) |
iret = NF90_GET_ATT (ncids(fid_in), iv, 'units', str1) |
380 |
IF (iret == NF90_NOERR) THEN |
IF (iret == NF90_NOERR) THEN |
381 |
CALL strlowercase (str1) |
CALL strlowercase (str1) |
382 |
IF ( (INDEX(str1, TRIM(dimuni1)) == 1) & |
IF ( (INDEX(str1, TRIM(dimuni1)) == 1) & |
383 |
.OR.(INDEX(str1, TRIM(dimuni2)) == 1) & |
.OR.(INDEX(str1, TRIM(dimuni2)) == 1) & |
384 |
.OR.(INDEX(str1, TRIM(dimuni3)) == 1) ) THEN |
.OR.(INDEX(str1, TRIM(dimuni3)) == 1) ) THEN |
385 |
vid = iv |
vid = iv |
389 |
ENDDO |
ENDDO |
390 |
ENDIF |
ENDIF |
391 |
|
|
392 |
! Second rule : we find specific names : |
! Second rule: we find specific names: |
393 |
! lon : nav_lon |
! lon: nav_lon |
394 |
! lat : nav_lat |
! lat: nav_lat |
395 |
! Here we can check if we find the substring as the |
! Here we can check if we find the substring as the |
396 |
! names are more specific. |
! names are more specific. |
397 |
|
|
416 |
str1='' |
str1='' |
417 |
iret = NF90_INQUIRE_VARIABLE (ncids(fid_in), iv, & |
iret = NF90_INQUIRE_VARIABLE (ncids(fid_in), iv, & |
418 |
name=str1, ndims=ndim) |
name=str1, ndims=ndim) |
419 |
IF (INDEX(dimname,TRIM(str1)) >= 1) THEN |
IF (INDEX(dimname, TRIM(str1)) >= 1) THEN |
420 |
vid = iv |
vid = iv |
421 |
ENDIF |
ENDIF |
422 |
ENDDO |
ENDDO |
423 |
ENDIF |
ENDIF |
424 |
|
|
425 |
! Third rule : we find a variable with the same name as the dimension |
! Third rule: we find a variable with the same name as the dimension |
426 |
! lon = 1 |
! lon = 1 |
427 |
! lat = 2 |
! lat = 2 |
428 |
! lev = 3 |
! lev = 3 |
441 |
CASE DEFAULT |
CASE DEFAULT |
442 |
found_rule = .FALSE. |
found_rule = .FALSE. |
443 |
END SELECT |
END SELECT |
444 |
!--- |
|
445 |
IF (found_rule) THEN |
IF (found_rule) THEN |
446 |
iret = NF90_INQUIRE_DIMENSION (ncids(fid_in), dimnb, name=dimname) |
iret = NF90_INQUIRE_DIMENSION (ncids(fid_in), dimnb, name=dimname) |
447 |
iv = 0 |
iv = 0 |
450 |
str1='' |
str1='' |
451 |
iret = NF90_INQUIRE_VARIABLE (ncids(fid_in), iv, & |
iret = NF90_INQUIRE_VARIABLE (ncids(fid_in), iv, & |
452 |
name=str1, ndims=ndim) |
name=str1, ndims=ndim) |
453 |
IF (INDEX(dimname,TRIM(str1)) == 1) THEN |
IF (INDEX(dimname, TRIM(str1)) == 1) THEN |
454 |
vid = iv |
vid = iv |
455 |
ENDIF |
ENDIF |
456 |
ENDDO |
ENDDO |
460 |
! Stop the program if no coordinate was found |
! Stop the program if no coordinate was found |
461 |
|
|
462 |
IF (vid < 0) THEN |
IF (vid < 0) THEN |
463 |
CALL histerr (3,'flinfindcood', & |
CALL histerr (3, 'flinfindcood', & |
464 |
'No coordinate axis was found in the file', & |
'No coordinate axis was found in the file', & |
465 |
'The data in this file can not be used', axtype) |
'The data in this file can not be used', axtype) |
466 |
ENDIF |
ENDIF |
467 |
!-------------------------- |
|
468 |
END SUBROUTINE flinfindcood |
END SUBROUTINE flinfindcood |
469 |
|
|
470 |
!=== |
!*************************************************************** |
471 |
|
|
472 |
SUBROUTINE flinclo (fid_in) |
SUBROUTINE flinclo (fid_in) |
|
!--------------------------------------------------------------------- |
|
|
USE netcdf, ONLY : nf90_close |
|
|
IMPLICIT NONE |
|
473 |
|
|
474 |
INTEGER :: fid_in |
USE netcdf, ONLY: nf90_close |
475 |
|
|
476 |
|
INTEGER:: fid_in |
477 |
|
|
478 |
|
INTEGER:: iret |
479 |
|
|
|
INTEGER :: iret |
|
480 |
!--------------------------------------------------------------------- |
!--------------------------------------------------------------------- |
481 |
|
|
482 |
iret = NF90_CLOSE (ncids(fid_in)) |
iret = NF90_CLOSE (ncids(fid_in)) |
483 |
ncfileopen(fid_in) = .FALSE. |
ncfileopen(fid_in) = .FALSE. |
484 |
!--------------------- |
|
485 |
END SUBROUTINE flinclo |
END SUBROUTINE flinclo |
486 |
|
|
487 |
END MODULE flincom |
END MODULE flincom |