/[MITgcm]/MITgcm/pkg/profiles/profiles_init_fixed.F
ViewVC logotype

Contents of /MITgcm/pkg/profiles/profiles_init_fixed.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download)
Sat May 6 14:33:53 2006 UTC (18 years ago) by heimbach
Branch: MAIN
Changes since 1.2: +9 -6 lines
Make pkg/profile fully independent of ecco,cost, etc. stuff
to be able to use it in pure forward.

1 C $Header: $
2 C $Name: $
3
4 #include "PROFILES_OPTIONS.h"
5
6 C o==========================================================o
7 C | subroutine profiles_init_fixed |
8 C | o initialization for netcdf profiles data |
9 C | started: Gael Forget 15-March-2006 |
10 C o==========================================================o
11
12 SUBROUTINE profiles_init_fixed( myThid )
13
14 implicit none
15
16 C ==================== Global Variables ===========================
17 #include "SIZE.h"
18 #include "EEPARAMS.h"
19 #include "PARAMS.h"
20 #include "GRID.h"
21 #include "DYNVARS.h"
22 #include "cal.h"
23 cph#include "ecco_cost.h"
24 cph#include "ctrl.h"
25 cph#include "ctrl_dummy.h"
26 cph#include "optim.h"
27 #ifdef ALLOW_PROFILES
28 # include "profiles.h"
29 # include "netcdf.inc"
30 #endif
31 C ==================== Routine Variables ==========================
32
33 integer k,l,m,bi,bj,iG,jG, myThid,num_file,length_for_tile
34 integer fid, dimid, varid1, varid1a, varid1b
35 integer varid2,varid3
36 _RL tmpyymmdd(1000),tmphhmmss(1000),diffsecs
37 integer tmpdate(4),tmpdiff(4)
38 _RL tmp_lon, tmp_lon2(1000), tmp_lat2(1000)
39 integer vec_start(2), vec_count(2), profno_div1000, kk
40 character*(80) profilesfile, fnamedatanc
41 character*(80) fnameequinc, adfnameequinc
42 integer IL, err
43 logical exst
44
45 #ifdef ALLOW_PROFILES_CONTRIBUTION
46
47 c == external functions ==
48 integer ILNBLNK
49
50 c-- == end of interface ==
51
52 prof_names(1)='prof_T'
53 prof_names(2)='prof_S'
54 prof_names(3)='prof_U'
55 prof_names(4)='prof_V'
56 prof_namesmask(1)='prof_Tmask'
57 prof_namesmask(2)='prof_Smask'
58 prof_namesmask(3)='prof_Umask'
59 prof_namesmask(4)='prof_Vmask'
60 prof_namesweight(1)='prof_Tweight'
61 prof_namesweight(2)='prof_Sweight'
62 prof_namesweight(3)='prof_Uweight'
63 prof_namesweight(4)='prof_Vweight'
64 profiles_curfile_buff=0
65 profilesfile_equi_type=2
66
67 do m=1,NLEVELMAX
68 do l=1,1000
69 do k=1,4
70 profiles_data_buff(m,l,k)=0
71 profiles_weight_buff(m,l,k)=0
72 enddo
73 enddo
74 enddo
75
76 c remplacer par une boucle ensuite :
77 do num_file=1,NFILESPROFMAX
78
79 IL = ILNBLNK( profilesfiles(num_file) )
80 if (IL.NE.0) then
81 write(profilesfile(1:80),'(1a)') profilesfiles(num_file)(1:IL)
82 else
83 write(profilesfile(1:80),'(1a)') ' '
84 endif
85
86 IL = ILNBLNK( profilesfile )
87 if (IL.NE.0) then
88
89 C===========================================================
90 c open data files and read the position vectors
91 C===========================================================
92
93 write(fnamedatanc(1:80),'(2a)') profilesfile(1:IL),'.nc'
94 err = NF_OPEN(fnamedatanc, 0, fiddata(num_file))
95
96 c1) read the number of profiles :
97 cgf err = NF_OPEN(filename, 0, fid)
98 fid=fiddata(num_file)
99 err = NF_INQ_DIMID(fid,'iPROF', dimid )
100 err = NF_INQ_DIMLEN(fid, dimid, ProfNo(num_file) )
101 err = NF_INQ_DIMID(fid,'iDEPTH', dimid )
102 if (err.NE.NF_NOERR) then
103 err = NF_INQ_DIMID(fid,'Z', dimid )
104 endif
105 err = NF_INQ_DIMLEN(fid, dimid, ProfDepthNo(num_file) )
106 print*,"fid num_file ProfNo(num_file) ProfDepthNo(num_file)",
107 &fid,num_file,ProfNo(num_file),ProfDepthNo(num_file)
108
109 c2) read the dates and positions :
110 err = NF_INQ_VARID(fid,'depth', varid1a )
111 do k=1,ProfDepthNo(num_file)
112 err = NF_GET_VAR1_DOUBLE(fid,varid1a,k,
113 & prof_depth(num_file,k))
114 enddo
115
116 err = NF_INQ_VARID(fid,'prof_YYYYMMDD', varid1a )
117 err = NF_INQ_VARID(fid,'prof_HHMMSS', varid1b )
118 err = NF_INQ_VARID(fid,'prof_lon', varid2 )
119 err = NF_INQ_VARID(fid,'prof_lat', varid3 )
120
121 DO bi = myBxLo(myThid), myBxHi(myThid)
122 DO bj = myByLo(myThid), myByHi(myThid)
123
124 do k=1,NOBSGLOB
125 prof_time(num_file,k)=-999
126 prof_lon(num_file,k)=-999
127 prof_lat(num_file,k)=-999
128 prof_ind_glob(num_file,k)=-999
129 enddo
130
131
132 length_for_tile=0
133 profno_div1000=max(0,int(profno(num_file)/1000))
134
135 do kk=1,profno_div1000+1
136
137 if (min(ProfNo(num_file), 1000*kk).GE.
138 & 1+1000*(kk-1)) then
139
140 vec_start(1)=1
141 vec_start(2)=1+1000*(kk-1)
142 vec_count(1)=1
143 vec_count(2)=min(1000,ProfNo(num_file)-1000*(kk-1))
144
145 if ( (vec_count(2).LE.0).OR.(vec_count(2).GT.1000).OR.
146 & (vec_start(2).LE.0).OR.
147 & (vec_count(2)+vec_start(2)-1.GT.ProfNo(num_file)) )
148 & then
149 print*,"stop 1",vec_start, vec_count
150 stop
151 endif
152
153 err = NF_GET_VARA_DOUBLE(fid,varid1a,vec_start(2),
154 & vec_count(2), tmpyymmdd)
155 err = NF_GET_VARA_DOUBLE(fid,varid1b,vec_start(2),
156 & vec_count(2), tmphhmmss)
157 err = NF_GET_VARA_DOUBLE(fid,varid2,vec_start(2),
158 & vec_count(2), tmp_lon2)
159 err = NF_GET_VARA_DOUBLE(fid,varid3,vec_start(2),
160 & vec_count(2), tmp_lat2)
161
162 if (err.NE.NF_NOERR) then
163 print*,"stop 2",vec_start(2),vec_count(2),
164 & kk,min(1000,ProfNo(num_file)-1000*(kk-1))
165 stop
166 endif
167
168 do k=1,min(1000,ProfNo(num_file)-1000*(kk-1))
169
170 call cal_FullDate( int(tmpyymmdd(k)),int(tmphhmmss(k)),
171 & tmpdate,mythid )
172 call cal_TimePassed( modelstartdate,tmpdate,tmpdiff,mythid )
173 call cal_ToSeconds (tmpdiff,diffsecs,mythid)
174 diffsecs=diffsecs+nIter0*deltaTclock
175
176 if (xC(sNx+1,1,bi,bj).LT.xC(1,1,bi,bj)) then
177 tmp_lon=xC(sNx+1,1,bi,bj)+360
178 else
179 tmp_lon=xC(sNx+1,1,bi,bj)
180 endif
181 if ((xC(1,1,bi,bj).LE.tmp_lon2(k)).AND.
182 & (tmp_lon.GT.tmp_lon2(k)).AND.
183 & (yC(1,1,bi,bj).LE.tmp_lat2(k)).AND.
184 & (yC(1,sNy+1,bi,bj).GT.tmp_lat2(k))
185 & ) then
186 length_for_tile=length_for_tile+1
187 prof_time(num_file,length_for_tile)=diffsecs
188 prof_lon(num_file,length_for_tile)=tmp_lon2(k)
189 prof_lat(num_file,length_for_tile)=tmp_lat2(k)
190 prof_ind_glob(num_file,length_for_tile)=k+1000*(kk-1)
191 if (length_for_tile.GT.NOBSGLOB) then
192 print*,"too much profiles: need to increase NOBSGLOB,"
193 print*," or split the data file (less memory cost)"
194 stop
195 endif
196 elseif (xC(sNx+1,1,bi,bj).LT.xC(1,1,bi,bj)) then
197 if ((xC(1,1,bi,bj).LE.tmp_lon2(k)+360).AND.
198 & (tmp_lon.GT.tmp_lon2(k)+360).AND.
199 & (yC(1,1,bi,bj).LE.tmp_lat2(k)).AND.
200 & (yC(1,sNy+1,bi,bj).GT.tmp_lat2(k))
201 & ) then
202 length_for_tile=length_for_tile+1
203 prof_time(num_file,length_for_tile)=diffsecs
204 prof_lon(num_file,length_for_tile)=tmp_lon2(k)+360
205 prof_lat(num_file,length_for_tile)=tmp_lat2(k)
206 prof_ind_glob(num_file,length_for_tile)=k+1000*(kk-1)
207 if (length_for_tile.GT.NOBSGLOB) then
208 print*,"too much profiles: need to increase NOBSGLOB,"
209 print*," or split the data file (less memory cost)"
210 stop
211 endif
212 endif
213 endif
214 enddo
215 endif
216 enddo
217
218 ProfNo(num_file)=length_for_tile
219 print*,"fid dimid ProfNo(num_file)",fid, dimid,
220 & num_file, ProfNo(num_file)
221
222 do k=1,4
223 prof_num_var_cur(num_file,k)=0
224 enddo
225 prof_num_var_tot(num_file)=0
226
227 c3) detect available data types
228 err = NF_INQ_VARID(fid,'prof_T', varid1 )
229 if (err.EQ.NF_NOERR) then
230 vec_quantities(num_file,1)=.TRUE.
231 prof_num_var_tot(num_file)=prof_num_var_tot(num_file)+1
232 prof_num_var_cur(num_file,1)=prof_num_var_tot(num_file)
233 else
234 vec_quantities(num_file,1)=.FALSE.
235 endif
236 err = NF_INQ_VARID(fid,'prof_S', varid1 )
237 if (err.EQ.NF_NOERR) then
238 vec_quantities(num_file,2)=.TRUE.
239 prof_num_var_tot(num_file)=prof_num_var_tot(num_file)+1
240 prof_num_var_cur(num_file,2)=prof_num_var_tot(num_file)
241 else
242 vec_quantities(num_file,2)=.FALSE.
243 endif
244 err = NF_INQ_VARID(fid,'prof_U', varid1 )
245 if (err.EQ.NF_NOERR) then
246 vec_quantities(num_file,3)=.TRUE.
247 prof_num_var_tot(num_file)=prof_num_var_tot(num_file)+1
248 prof_num_var_cur(num_file,3)=prof_num_var_tot(num_file)
249 else
250 vec_quantities(num_file,3)=.FALSE.
251 endif
252 err = NF_INQ_VARID(fid,'prof_V', varid1 )
253 if (err.EQ.NF_NOERR) then
254 vec_quantities(num_file,4)=.TRUE.
255 prof_num_var_tot(num_file)=prof_num_var_tot(num_file)+1
256 prof_num_var_cur(num_file,4)=prof_num_var_tot(num_file)
257 else
258 vec_quantities(num_file,4)=.FALSE.
259 endif
260
261
262 C===========================================================
263 c create files for model counterparts to observations
264 C===========================================================
265
266 if (profno(num_file).GT.0) then
267 iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
268 jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
269
270 if (profilesfile_equi_type.EQ.1) then
271
272 write(fnameequinc(1:80),'(2a,i3.3,a,i3.3,a)')
273 & profilesfile(1:IL),'.',iG,'.',jG,'.equi.nc'
274 write(adfnameequinc(1:80),'(3a,i3.3,a,i3.3,a)') 'ad',
275 & profilesfile(1:IL),'.',iG,'.',jG,'.equi.nc'
276
277 inquire( file=fnameequinc, exist=exst )
278 if (.NOT.exst) then
279 call profiles_init_ncfile(num_file,fiddata(num_file),fnameequinc,
280 & fidforward(num_file),profno(num_file),profdepthno(num_file),
281 & myThid)
282 call profiles_init_ncfile(num_file,fiddata(num_file),
283 & adfnameequinc, fidadjoint(num_file),profno(num_file),
284 & profdepthno(num_file), myThid)
285 else
286 err = NF_OPEN(fnameequinc , NF_WRITE , fidforward(num_file) )
287 err = NF_OPEN(adfnameequinc , NF_WRITE , fidadjoint(num_file) )
288 endif
289
290 else
291
292 write(fnameequinc(1:80),'(2a,i3.3,a,i3.3,a)')
293 & profilesfile(1:IL),'.',iG,'.',jG,'.equi.bin'
294 write(adfnameequinc(1:80),'(3a,i3.3,a,i3.3,a)') 'ad',
295 & profilesfile(1:IL),'.',iG,'.',jG,'.equi.bin'
296
297 inquire( file=fnameequinc, exist=exst )
298 if (.NOT.exst) then
299 call profiles_init_ncfile(num_file,fiddata(num_file),fnameequinc,
300 & fidforward(num_file),profno(num_file),profdepthno(num_file),
301 & myThid)
302 call profiles_init_ncfile(num_file,fiddata(num_file),
303 & adfnameequinc, fidadjoint(num_file),profno(num_file),
304 & profdepthno(num_file), myThid)
305 else
306 call MDSFINDUNIT( fidforward(num_file) , mythid )
307 open( fidforward(num_file),file=fnameequinc,
308 & form ='unformatted',status='unknown', access='direct',
309 & recl= (profdepthno(num_file)+1)*WORDLENGTH*2 )
310 call MDSFINDUNIT( fidadjoint(num_file) , mythid )
311 open( fidadjoint(num_file),file=adfnameequinc,
312 & form ='unformatted',status='unknown', access='direct',
313 & recl= (profdepthno(num_file)+1)*WORDLENGTH*2 )
314 endif
315
316 endif
317
318 endif
319
320 ENDDO
321 ENDDO
322
323
324 C===========================================================
325 else
326 ProfNo(num_file)=0
327 do k=1,4
328 prof_num_var_cur(num_file,k)=0
329 vec_quantities(num_file,k)=.FALSE.
330 enddo
331 prof_num_var_tot(num_file)=0
332 do k=1,NOBSGLOB
333 prof_time(num_file,k)=-999
334 prof_lon(num_file,k)=-999
335 prof_lat(num_file,k)=-999
336 prof_ind_glob(num_file,k)=-999
337 enddo
338
339 endif !if (IL.NE.0) then
340 enddo ! do num_file=1,NFILESPROFMAX
341 C===========================================================
342
343 #endif
344
345 END
346

  ViewVC Help
Powered by ViewVC 1.1.22