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

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

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


Revision 1.2 - (show annotations) (download)
Fri Mar 24 22:58:25 2006 UTC (18 years, 1 month ago) by heimbach
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
o package cost profiles routines to better modularize them.

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

  ViewVC Help
Powered by ViewVC 1.1.22