source: LMDZ6/trunk/libf/dyn3dmem/dynetat0_loc.F90 @ 5214

Last change on this file since 5214 was 5214, checked in by dcugnet, 7 weeks ago

The fortran parameters file "iso_params_mod.F90" is introduced so that "tnat" and "alpha_ideal" are defined in a single place but used in several.
The "getKey" routine is only used in "infotrac" and "infotrac_phy" routines, but could be used outside this scope to get tracers parameters (read from "tracer.def") or isotopic parameters (read from "isotopes_params.def" - disabled for now).

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