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