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

Last change on this file since 5183 was 5183, checked in by dcugnet, 2 months ago
  • Remove INCA retro-compatibility with "traceur.def" (containing only water tracers but getting chemical species from an internal INCA routine).
  • The "trac_type" derived type internal to "readTracFiles_mod" is removed because a generic "keys_type" is enough: no explicit key ("%" operator) is needed, even %name.
  • The "trac_type" and "isot_type" derived types are now defined locally in "infotrac" and "infotrac_phy" (and more generally in each context: dynamic, lmdz dynamics, lmdz physics, etc.). The "readTracFiles_mod" module is now only used in these two routines:
    • few internal routines/variables (addPhase, delPhase, new2oldH2O, newHNO3, oldHNO3) are made available through "infotrac" and "infotrac_phy".
    • the "getKey" routine is only used in these two routines to define the explicit keys ("%" operator) of the local derived types "trac_type" and "isot_type". It could be in principle used outside this scope to get tracers parameters (read from "tracer.def") or isotopic parameters (read from "isotopes_params.def" - disabled for now).
  • 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. "ltnat1" is no longer hardcoded but defined with the *.def files parameter "tnat1"
  • Few minor changes:
    • use "infotrac_phy" instead of "infotrac" in calfis* because "tracers(:)%isAdvected" is defined in physics only.
    • "isotopes_mod" now ready for several isotopes classes (currently: only H2O)
    • isotopes class name (the name of the parent of the isotopes) is now %name and no longer %parent.
    • improvement of "getKey"
  • 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
RevLine 
[2299]1SUBROUTINE dynetat0_loc(fichnom,vcov,ucov,teta,q,masse,ps,phis,time)
[1632]2!
[2299]3!-------------------------------------------------------------------------------
4! Authors: P. Le Van , L.Fairhead
5!-------------------------------------------------------------------------------
6! Purpose: Initial state reading.
7!-------------------------------------------------------------------------------
8  USE parallel_lmdz
[5183]9  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, iH2O, isoName, &
10                         new2oldH2O, newHNO3, oldHNO3
[4436]11  USE strings_mod, ONLY: maxlen, msg, strStack, real2str, int2str, strIdx
[5084]12  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQUIRE_DIMENSION, NF90_INQ_VARID, &
[4120]13                         NF90_CLOSE, NF90_GET_VAR, NF90_INQUIRE_VARIABLE,  NF90_NoErr
[2299]14  USE control_mod, ONLY: planet_type
15  USE assert_eq_m, ONLY: assert_eq
[2600]16  USE comvert_mod, ONLY: pa,preff
[4120]17  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
[2603]18  USE logic_mod, ONLY: fxyhypb, ysinus
[2598]19  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
[4120]20  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
[2622]21  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
[5183]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_*
[4120]28
[2299]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:
[4120]47  CHARACTER(LEN=maxlen) :: mesg, var, modname, oldVar
[2299]48  INTEGER, PARAMETER :: length=100
[4301]49  INTEGER :: iq, fID, vID, idecal, ierr, iqParent, iName, iZone, iPhase, ix
[4984]50  REAL    :: time,tab_cntrl(length)    !--- RUN PARAMS TABLE
51  REAL    :: tnat, alpha_ideal
[2299]52  REAL,             ALLOCATABLE :: vcov_glo(:,:),masse_glo(:,:),   ps_glo(:)
53  REAL,             ALLOCATABLE :: ucov_glo(:,:),    q_glo(:,:), phis_glo(:)
54  REAL,             ALLOCATABLE :: teta_glo(:,:)
[5183]55  LOGICAL :: lSkip, ll, ltnat1
[2299]56!-------------------------------------------------------------------------------
57  modname="dynetat0_loc"
[1632]58
[2299]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)
[1632]63
[2299]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
[4120]67    CALL msg('NOTE NOTE NOTE : Planeto-like start files', modname)
[2299]68    idecal = 4
69    annee_ref  = 2000
70  ELSE
[4120]71    CALL msg('NOTE NOTE NOTE : Earth-like start files', modname)
[2299]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
[1632]109
[2299]110  day_ini    = tab_cntrl(30)
111  itau_dyn   = tab_cntrl(31)
[2615]112  start_time = tab_cntrl(32)
[1632]113
[2299]114!-------------------------------------------------------------------------------
[4120]115  CALL msg('rad, omeg, g, cpp, kappa = '//TRIM(strStack(real2str([rad,omeg,g,cpp,kappa]))), modname)
[2299]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)
[1632]126
[2299]127  var="temps"
128  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
[4120]129    CALL msg('missing field <temps> ; trying with <Time>', modname)
130    var="Time"
[2299]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)
[1632]134
[2299]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)
[1632]138
[2299]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)
[1673]142
[2299]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)
[1632]146
[2299]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)
[1632]150
[2299]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)
[1632]158
[2299]159!--- Tracers
160  ALLOCATE(q_glo(ip1jmp1,llm))
[4301]161  ll = .FALSE.
[4263]162#ifdef REPROBUS
[4301]163  ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr                                 !--- DETECT OLD REPRO start.nc FILE
[4263]164#endif
[5183]165  ltnat1 = .TRUE.; CALL getin('tnateq1', ltnat1)
[2299]166  DO iq=1,nqtot
[4120]167    var = tracers(iq)%name
[4301]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
[4265]176    !--------------------------------------------------------------------------------------------------------------------------
[4301]177    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr .AND. .NOT.lSkip) THEN                !=== REGULAR CASE: AVAILABLE VARIABLE
[4265]178      CALL get_var2(var,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
179    !--------------------------------------------------------------------------------------------------------------------------
[4301]180    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== TRY WITH ALTERNATE NAME
[5183]181      CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to <'//TRIM(oldVar)//'>', modname)
[4265]182      CALL get_var2(oldVar, q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
183    !--------------------------------------------------------------------------------------------------------------------------
[4120]184    ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
[4143]185      iName    = tracers(iq)%iso_iName
[4120]186      iPhase   = tracers(iq)%iso_iPhase
187      iqParent = tracers(iq)%iqParent
188      IF(tracers(iq)%iso_iZone == 0) THEN
[5183]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)
[4325]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.)
[4490]205         ! Camille 9 mars 2023: point de vigilence: initialisation incohérente
206         ! avec celle de xt_ancien dans la physiq.
[4120]207      ELSE
[5183]208         CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to its parent isotope concentration.', modname)
[4490]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
[4984]215           q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqIsoPha(iName,iPhase))
[4490]216         ELSE
217           q(ijb_u:ije_u,:,iq) =  0.
218         ENDIF
[4120]219      END IF
220    !--------------------------------------------------------------------------------------------------------------------------
221    ELSE                                                                                 !=== MISSING: SET TO 0
[5183]222      CALL msg('missing tracer <'//TRIM(var)//'> => initialized to zero', modname)
[4120]223      q(ijb_u:ije_u,:,iq)=0.
224    !--------------------------------------------------------------------------------------------------------------------------
[2299]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)
[1673]231
232
[2299]233  CONTAINS
[1632]234
235
[2299]236SUBROUTINE check_dim(n1,n2,str1,str2)
237  INTEGER,          INTENT(IN) :: n1, n2
238  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
[4046]239  CHARACTER(LEN=maxlen) :: s1, s2
[4301]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)
[2299]242END SUBROUTINE check_dim
[1632]243
244
[2299]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
[1632]250
[2299]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
[1632]268
[2299]269SUBROUTINE get_var2(var,v)
270  CHARACTER(LEN=*), INTENT(IN)  :: var
271  REAL,             INTENT(OUT) :: v(:,:)
[3967]272  REAL,             ALLOCATABLE :: w4(:,:,:,:), w3(:,:,:)
[2299]273  INTEGER :: nn(4), dids(4), k, nd
[3967]274
275
[2299]276  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
[3967]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
[2299]284  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
[3967]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
[2299]294END SUBROUTINE get_var2
[1632]295
296
[2299]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)
[4120]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)//">"
[2299]307  END SELECT
[4120]308  CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr)
[2299]309END SUBROUTINE err
[1632]310
[2299]311END SUBROUTINE dynetat0_loc
Note: See TracBrowser for help on using the repository browser.