1 | SUBROUTINE dynetat0_loc(fichnom,vcov,ucov,teta,q,masse,ps,phis,time) |
---|
2 | ! |
---|
3 | !------------------------------------------------------------------------------- |
---|
4 | ! Authors: P. Le Van , L.Fairhead |
---|
5 | !------------------------------------------------------------------------------- |
---|
6 | ! Purpose: Initial state reading. |
---|
7 | !------------------------------------------------------------------------------- |
---|
8 | USE parallel_lmdz |
---|
9 | USE infotrac, ONLY: nqtot, tracers, niso, iqIsoPha, iH2O, isoName, & |
---|
10 | new2oldH2O, newHNO3, oldHNO3, getKey |
---|
11 | USE strings_mod, ONLY: maxlen, msg, strStack, real2str, int2str, strIdx |
---|
12 | USE netcdf, ONLY: NF90_OPEN, NF90_NOWRITE, NF90_INQUIRE_DIMENSION, NF90_INQ_VARID, & |
---|
13 | NF90_CLOSE, NF90_GET_VAR, NF90_INQUIRE_VARIABLE, NF90_NoErr |
---|
14 | USE control_mod, ONLY: planet_type |
---|
15 | USE assert_eq_m, ONLY: assert_eq |
---|
16 | USE comvert_mod, ONLY: pa,preff |
---|
17 | USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad |
---|
18 | USE logic_mod, ONLY: fxyhypb, ysinus |
---|
19 | USE serre_mod, ONLY: clon, clat, grossismx, grossismy |
---|
20 | USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time |
---|
21 | USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0 |
---|
22 | #ifdef CPP_IOIPSL |
---|
23 | USE IOIPSL, ONLY: getin |
---|
24 | #else |
---|
25 | USE ioipsl_getincom, ONLY: getin |
---|
26 | #endif |
---|
27 | |
---|
28 | IMPLICIT NONE |
---|
29 | include "dimensions.h" |
---|
30 | include "paramet.h" |
---|
31 | include "comgeom.h" |
---|
32 | include "description.h" |
---|
33 | include "iniprint.h" |
---|
34 | !=============================================================================== |
---|
35 | ! Arguments: |
---|
36 | CHARACTER(LEN=*), INTENT(IN) :: fichnom !--- FILE NAME |
---|
37 | REAL, INTENT(OUT) :: vcov(ijb_v:ije_v,llm) !--- V COVARIANT WIND |
---|
38 | REAL, INTENT(OUT) :: ucov(ijb_u:ije_u,llm) !--- U COVARIANT WIND |
---|
39 | REAL, INTENT(OUT) :: teta(ijb_u:ije_u,llm) !--- POTENTIAL TEMP. |
---|
40 | REAL, INTENT(OUT) :: q(ijb_u:ije_u,llm,nqtot)!--- TRACERS |
---|
41 | REAL, INTENT(OUT) :: masse(ijb_u:ije_u,llm) !--- MASS PER CELL |
---|
42 | REAL, INTENT(OUT) :: ps(ijb_u:ije_u) !--- GROUND PRESSURE |
---|
43 | REAL, INTENT(OUT) :: phis(ijb_u:ije_u) !--- GEOPOTENTIAL |
---|
44 | !=============================================================================== |
---|
45 | ! Local variables: |
---|
46 | CHARACTER(LEN=maxlen) :: mesg, var, modname, oldVar |
---|
47 | INTEGER, PARAMETER :: length=100 |
---|
48 | INTEGER :: iq, fID, vID, idecal, ierr, iqParent, iName, iZone, iPhase, ix |
---|
49 | REAL :: time,tab_cntrl(length) !--- RUN PARAMS TABLE |
---|
50 | REAL :: tnat, alpha_ideal |
---|
51 | REAL, ALLOCATABLE :: vcov_glo(:,:),masse_glo(:,:), ps_glo(:) |
---|
52 | REAL, ALLOCATABLE :: ucov_glo(:,:), q_glo(:,:), phis_glo(:) |
---|
53 | REAL, ALLOCATABLE :: teta_glo(:,:) |
---|
54 | LOGICAL :: lSkip, ll, ltnat1 |
---|
55 | !------------------------------------------------------------------------------- |
---|
56 | modname="dynetat0_loc" |
---|
57 | |
---|
58 | !--- Initial state file opening |
---|
59 | var=fichnom |
---|
60 | CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var) |
---|
61 | CALL get_var1("controle",tab_cntrl) |
---|
62 | |
---|
63 | !!! AS: idecal is a hack to be able to read planeto starts... |
---|
64 | !!! .... while keeping everything OK for LMDZ EARTH |
---|
65 | IF(planet_type=="generic") THEN |
---|
66 | CALL msg('NOTE NOTE NOTE : Planeto-like start files', modname) |
---|
67 | idecal = 4 |
---|
68 | annee_ref = 2000 |
---|
69 | ELSE |
---|
70 | CALL msg('NOTE NOTE NOTE : Earth-like start files', modname) |
---|
71 | idecal = 5 |
---|
72 | annee_ref = tab_cntrl(5) |
---|
73 | END IF |
---|
74 | im = tab_cntrl(1) |
---|
75 | jm = tab_cntrl(2) |
---|
76 | lllm = tab_cntrl(3) |
---|
77 | day_ref = tab_cntrl(4) |
---|
78 | rad = tab_cntrl(idecal+1) |
---|
79 | omeg = tab_cntrl(idecal+2) |
---|
80 | g = tab_cntrl(idecal+3) |
---|
81 | cpp = tab_cntrl(idecal+4) |
---|
82 | kappa = tab_cntrl(idecal+5) |
---|
83 | daysec = tab_cntrl(idecal+6) |
---|
84 | dtvr = tab_cntrl(idecal+7) |
---|
85 | etot0 = tab_cntrl(idecal+8) |
---|
86 | ptot0 = tab_cntrl(idecal+9) |
---|
87 | ztot0 = tab_cntrl(idecal+10) |
---|
88 | stot0 = tab_cntrl(idecal+11) |
---|
89 | ang0 = tab_cntrl(idecal+12) |
---|
90 | pa = tab_cntrl(idecal+13) |
---|
91 | preff = tab_cntrl(idecal+14) |
---|
92 | ! |
---|
93 | clon = tab_cntrl(idecal+15) |
---|
94 | clat = tab_cntrl(idecal+16) |
---|
95 | grossismx = tab_cntrl(idecal+17) |
---|
96 | grossismy = tab_cntrl(idecal+18) |
---|
97 | ! |
---|
98 | IF ( tab_cntrl(idecal+19)==1. ) THEN |
---|
99 | fxyhypb = .TRUE. |
---|
100 | ! dzoomx = tab_cntrl(25) |
---|
101 | ! dzoomy = tab_cntrl(26) |
---|
102 | ! taux = tab_cntrl(28) |
---|
103 | ! tauy = tab_cntrl(29) |
---|
104 | ELSE |
---|
105 | fxyhypb = .FALSE. |
---|
106 | ysinus = tab_cntrl(idecal+22)==1. |
---|
107 | END IF |
---|
108 | |
---|
109 | day_ini = tab_cntrl(30) |
---|
110 | itau_dyn = tab_cntrl(31) |
---|
111 | start_time = tab_cntrl(32) |
---|
112 | |
---|
113 | !------------------------------------------------------------------------------- |
---|
114 | CALL msg('rad, omeg, g, cpp, kappa = '//TRIM(strStack(real2str([rad,omeg,g,cpp,kappa]))), modname) |
---|
115 | CALL check_dim(im,iim,'im','im') |
---|
116 | CALL check_dim(jm,jjm,'jm','jm') |
---|
117 | CALL check_dim(lllm,llm,'lm','lllm') |
---|
118 | CALL get_var1("rlonu",rlonu) |
---|
119 | CALL get_var1("rlatu",rlatu) |
---|
120 | CALL get_var1("rlonv",rlonv) |
---|
121 | CALL get_var1("rlatv",rlatv) |
---|
122 | CALL get_var1("cu" ,cu) |
---|
123 | CALL get_var1("cv" ,cv) |
---|
124 | CALL get_var1("aire",aire) |
---|
125 | |
---|
126 | var="temps" |
---|
127 | IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN |
---|
128 | CALL msg('missing field <temps> ; trying with <Time>', modname) |
---|
129 | var="Time" |
---|
130 | CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var) |
---|
131 | END IF |
---|
132 | CALL err(NF90_GET_VAR(fID,vID,time),"get",var) |
---|
133 | |
---|
134 | ALLOCATE(phis_glo(ip1jmp1)) |
---|
135 | CALL get_var1("phisinit",phis_glo) |
---|
136 | phis (ijb_u:ije_u) =phis_glo(ijb_u:ije_u); DEALLOCATE(phis_glo) |
---|
137 | |
---|
138 | ALLOCATE(ucov_glo(ip1jmp1,llm)) |
---|
139 | CALL get_var2("ucov",ucov_glo) |
---|
140 | ucov (ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:); DEALLOCATE(ucov_glo) |
---|
141 | |
---|
142 | ALLOCATE(vcov_glo(ip1jm,llm)) |
---|
143 | CALL get_var2("vcov",vcov_glo) |
---|
144 | vcov (ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:); DEALLOCATE(vcov_glo) |
---|
145 | |
---|
146 | ALLOCATE(teta_glo(ip1jmp1,llm)) |
---|
147 | CALL get_var2("teta",teta_glo) |
---|
148 | teta (ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:); DEALLOCATE(teta_glo) |
---|
149 | |
---|
150 | ALLOCATE(masse_glo(ip1jmp1,llm)) |
---|
151 | CALL get_var2("masse",masse_glo) |
---|
152 | masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:); DEALLOCATE(masse_glo) |
---|
153 | |
---|
154 | ALLOCATE(ps_glo(ip1jmp1)) |
---|
155 | CALL get_var1("ps",ps_glo) |
---|
156 | ps (ijb_u:ije_u) = ps_glo(ijb_u:ije_u); DEALLOCATE(ps_glo) |
---|
157 | |
---|
158 | !--- Tracers |
---|
159 | ALLOCATE(q_glo(ip1jmp1,llm)) |
---|
160 | ll = .FALSE. |
---|
161 | #ifdef REPROBUS |
---|
162 | ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr !--- DETECT OLD REPRO start.nc FILE |
---|
163 | #endif |
---|
164 | ltnat1 = .TRUE.; CALL getin('tnateq1', ltnat1) |
---|
165 | DO iq=1,nqtot |
---|
166 | var = tracers(iq)%name |
---|
167 | oldVar = new2oldH2O(var) |
---|
168 | lSkip = ll .AND. var == 'HNO3' !--- FORCE "HNO3_g" READING FOR "HNO3" |
---|
169 | #ifdef REPROBUS |
---|
170 | ix = strIdx(newHNO3, var); IF(ix /= 0) oldVar = oldHNO3(ix) !--- REPROBUS HNO3 exceptions |
---|
171 | #endif |
---|
172 | #ifdef INCA |
---|
173 | IF(var == 'O3') oldVar = 'OX' !--- DEAL WITH INCA OZONE EXCEPTION |
---|
174 | #endif |
---|
175 | !-------------------------------------------------------------------------------------------------------------------------- |
---|
176 | IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr .AND. .NOT.lSkip) THEN !=== REGULAR CASE: AVAILABLE VARIABLE |
---|
177 | CALL get_var2(var,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:) |
---|
178 | !-------------------------------------------------------------------------------------------------------------------------- |
---|
179 | ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN !=== TRY WITH ALTERNATE NAME |
---|
180 | CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to <'//TRIM(oldVar)//'>', modname) |
---|
181 | CALL get_var2(oldVar, q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:) |
---|
182 | !-------------------------------------------------------------------------------------------------------------------------- |
---|
183 | ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN !=== WATER ISOTOPES |
---|
184 | iName = tracers(iq)%iso_iName |
---|
185 | iPhase = tracers(iq)%iso_iPhase |
---|
186 | iqParent = tracers(iq)%iqParent |
---|
187 | IF(tracers(iq)%iso_iZone == 0) THEN |
---|
188 | IF(ltnat1) THEN |
---|
189 | tnat = 1.0 |
---|
190 | alpha_ideal = 1.0 |
---|
191 | CALL msg(' !!! Beware: alpha_ideal put to 1 !!!', modname) |
---|
192 | ELSE |
---|
193 | IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) & |
---|
194 | CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1) |
---|
195 | END IF |
---|
196 | CALL msg('Missing tracer <'//TRIM(var)//'> => initialized with a simplified Rayleigh distillation law.', modname) |
---|
197 | q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqParent)*tnat*(q(ijb_u:ije_u,:,iqParent)/30.e-3)**(alpha_ideal-1.) |
---|
198 | ! Camille 9 mars 2023: point de vigilence: initialisation incohérente |
---|
199 | ! avec celle de xt_ancien dans la physiq. |
---|
200 | ELSE |
---|
201 | CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to its parent isotope concentration.', modname) |
---|
202 | ! Camille 9 mars 2023: attention!! seuls les tags qui correspondent à |
---|
203 | ! izone=izone_init (définie dans isotrac_mod) sont initialisés comme |
---|
204 | ! les parents. Sinon, c'est nul. |
---|
205 | ! j'ai fait ça en attendant, mais il faudrait initialiser proprement en |
---|
206 | ! remplacant 1 par izone_init dans la ligne qui suit. |
---|
207 | IF(tracers(iq)%iso_iZone == 1) THEN |
---|
208 | q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqIsoPha(iName,iPhase)) |
---|
209 | ELSE |
---|
210 | q(ijb_u:ije_u,:,iq) = 0. |
---|
211 | ENDIF |
---|
212 | END IF |
---|
213 | !-------------------------------------------------------------------------------------------------------------------------- |
---|
214 | ELSE !=== MISSING: SET TO 0 |
---|
215 | CALL msg('missing tracer <'//TRIM(var)//'> => initialized to zero', modname) |
---|
216 | q(ijb_u:ije_u,:,iq)=0. |
---|
217 | !-------------------------------------------------------------------------------------------------------------------------- |
---|
218 | END IF |
---|
219 | END DO |
---|
220 | DEALLOCATE(q_glo) |
---|
221 | CALL err(NF90_CLOSE(fID),"close",fichnom) |
---|
222 | day_ini=day_ini+INT(time) |
---|
223 | time=time-INT(time) |
---|
224 | |
---|
225 | |
---|
226 | CONTAINS |
---|
227 | |
---|
228 | |
---|
229 | SUBROUTINE check_dim(n1,n2,str1,str2) |
---|
230 | INTEGER, INTENT(IN) :: n1, n2 |
---|
231 | CHARACTER(LEN=*), INTENT(IN) :: str1, str2 |
---|
232 | CHARACTER(LEN=maxlen) :: s1, s2 |
---|
233 | IF(n1/=n2) CALL abort_gcm(TRIM(modname), 'value of "'//TRIM(str1)//'" = '//TRIM(int2str(n1))// & |
---|
234 | ' read in starting file differs from gcm value of "'//TRIM(str2)//'" = '//TRIM(int2str(n2)), 1) |
---|
235 | END SUBROUTINE check_dim |
---|
236 | |
---|
237 | |
---|
238 | SUBROUTINE get_var1(var,v) |
---|
239 | CHARACTER(LEN=*), INTENT(IN) :: var |
---|
240 | REAL, INTENT(OUT) :: v(:) |
---|
241 | REAL, ALLOCATABLE :: w2(:,:), w3(:,:,:) |
---|
242 | INTEGER :: nn(3), dids(3), k, nd, ntot |
---|
243 | |
---|
244 | CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var) |
---|
245 | ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd) |
---|
246 | IF(nd==1) THEN |
---|
247 | CALL err(NF90_GET_VAR(fID,vID,v),"get",var); RETURN |
---|
248 | END IF |
---|
249 | ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids) |
---|
250 | DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO |
---|
251 | ntot=PRODUCT(nn(1:nd)) |
---|
252 | SELECT CASE(nd) |
---|
253 | CASE(2); ALLOCATE(w2(nn(1),nn(2))) |
---|
254 | CALL err(NF90_GET_VAR(fID,vID,w2),"get",var) |
---|
255 | v=RESHAPE(w2,[ntot]); DEALLOCATE(w2) |
---|
256 | CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3))) |
---|
257 | CALL err(NF90_GET_VAR(fID,vID,w3),"get",var) |
---|
258 | v=RESHAPE(w3,[ntot]); DEALLOCATE(w3) |
---|
259 | END SELECT |
---|
260 | END SUBROUTINE get_var1 |
---|
261 | |
---|
262 | SUBROUTINE get_var2(var,v) |
---|
263 | CHARACTER(LEN=*), INTENT(IN) :: var |
---|
264 | REAL, INTENT(OUT) :: v(:,:) |
---|
265 | REAL, ALLOCATABLE :: w4(:,:,:,:), w3(:,:,:) |
---|
266 | INTEGER :: nn(4), dids(4), k, nd |
---|
267 | |
---|
268 | |
---|
269 | CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var) |
---|
270 | ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd) |
---|
271 | |
---|
272 | IF(nd==1) THEN |
---|
273 | CALL err(NF90_GET_VAR(fID,vID,v),"get",var); RETURN |
---|
274 | END IF |
---|
275 | ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids) |
---|
276 | |
---|
277 | DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO |
---|
278 | |
---|
279 | SELECT CASE(nd) |
---|
280 | CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3))) |
---|
281 | CALL err(NF90_GET_VAR(fID,vID,w3),"get",var) |
---|
282 | v=RESHAPE(w3,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w3) |
---|
283 | CASE(4); ALLOCATE(w4(nn(1),nn(2),nn(3),nn(4))) |
---|
284 | CALL err(NF90_GET_VAR(fID,vID,w4),"get",var) |
---|
285 | v=RESHAPE(w4,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w4) |
---|
286 | END SELECT |
---|
287 | END SUBROUTINE get_var2 |
---|
288 | |
---|
289 | |
---|
290 | SUBROUTINE err(ierr,typ,nam) |
---|
291 | INTEGER, INTENT(IN) :: ierr !--- NetCDF ERROR CODE |
---|
292 | CHARACTER(LEN=*), INTENT(IN) :: typ !--- TYPE OF OPERATION |
---|
293 | CHARACTER(LEN=*), INTENT(IN) :: nam !--- FIELD/FILE NAME |
---|
294 | IF(ierr==NF90_NoERR) RETURN |
---|
295 | SELECT CASE(typ) |
---|
296 | CASE('inq'); mesg="Field <"//TRIM(nam)//"> is missing" |
---|
297 | CASE('get'); mesg="Reading failed for <"//TRIM(nam)//">" |
---|
298 | CASE('open'); mesg="File opening failed for <"//TRIM(nam)//">" |
---|
299 | CASE('close'); mesg="File closing failed for <"//TRIM(nam)//">" |
---|
300 | END SELECT |
---|
301 | CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr) |
---|
302 | END SUBROUTINE err |
---|
303 | |
---|
304 | END SUBROUTINE dynetat0_loc |
---|