source: LMDZ6/trunk/libf/dyn3d/dynetat0.f90 @ 5401

Last change on this file since 5401 was 5285, checked in by abarral, 7 weeks ago

As discussed internally, remove generic ONLY: ... for new _mod_h modules

File size: 10.6 KB
Line 
1SUBROUTINE dynetat0(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 iniprint_mod_h
9  USE comgeom2_mod_h
10  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, iH2O, isoName, &
11                         new2oldH2O, newHNO3, oldHNO3
12  USE strings_mod, ONLY: maxlen, msg, strStack, real2str, int2str
13  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, &
14                         NF90_CLOSE, NF90_GET_VAR, NF90_NoErr
15  USE control_mod, ONLY: planet_type
16  USE assert_eq_m, ONLY: assert_eq
17  USE comvert_mod, ONLY: pa,preff
18  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
19  USE logic_mod, ONLY: fxyhypb, ysinus
20  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
21  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
22  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
23  USE IOIPSL,   ONLY: getin
24  USE iso_params_mod   ! tnat_* and alpha_ideal_*
25  USE lmdz_cppkeys_wrapper, ONLY: CPPKEY_INCA, CPPKEY_REPROBUS
26  USE strings_mod, ONLY: strIdx
27
28  USE dimensions_mod, ONLY: iim, jjm, llm, ndm
29USE paramet_mod_h
30IMPLICIT NONE
31
32
33  !===============================================================================
34! Arguments:
35  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
36  REAL, INTENT(OUT) ::  vcov(iip1,jjm, llm)        !--- V COVARIANT WIND
37  REAL, INTENT(OUT) ::  ucov(iip1,jjp1,llm)        !--- U COVARIANT WIND
38  REAL, INTENT(OUT) ::  teta(iip1,jjp1,llm)        !--- POTENTIAL TEMP.
39  REAL, INTENT(OUT) ::     q(iip1,jjp1,llm,nqtot)  !--- TRACERS
40  REAL, INTENT(OUT) :: masse(iip1,jjp1,llm)        !--- MASS PER CELL
41  REAL, INTENT(OUT) ::    ps(iip1,jjp1)            !--- GROUND PRESSURE
42  REAL, INTENT(OUT) ::  phis(iip1,jjp1)            !--- GEOPOTENTIAL
43!===============================================================================
44! Local variables:
45  CHARACTER(LEN=maxlen) :: mesg, var, modname, oldVar
46  INTEGER, PARAMETER :: length=100
47  INTEGER :: iq, fID, vID, idecal, iqParent, iName, iZone, iPhase, ix
48  REAL    :: time, tnat, alpha_ideal, tab_cntrl(length)    !--- RUN PARAMS TABLE
49  LOGICAL :: lSkip, ll, ltnat1
50!-------------------------------------------------------------------------------
51  modname="dynetat0"
52
53!--- Initial state file opening
54  var=fichnom
55  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
56  CALL get_var1("controle",tab_cntrl)
57
58!!! AS: idecal is a hack to be able to read planeto starts...
59!!!     .... while keeping everything OK for LMDZ EARTH
60  IF(planet_type=="generic") THEN
61    CALL msg('NOTE NOTE NOTE : Planeto-like start files', modname)
62    idecal = 4
63    annee_ref  = 2000
64  ELSE
65    CALL msg('NOTE NOTE NOTE : Earth-like start files', modname)
66    idecal = 5
67    annee_ref  = tab_cntrl(5)
68  END IF
69  im         = tab_cntrl(1)
70  jm         = tab_cntrl(2)
71  lllm       = tab_cntrl(3)
72  day_ref    = tab_cntrl(4)
73  rad        = tab_cntrl(idecal+1)
74  omeg       = tab_cntrl(idecal+2)
75  g          = tab_cntrl(idecal+3)
76  cpp        = tab_cntrl(idecal+4)
77  kappa      = tab_cntrl(idecal+5)
78  daysec     = tab_cntrl(idecal+6)
79  dtvr       = tab_cntrl(idecal+7)
80  etot0      = tab_cntrl(idecal+8)
81  ptot0      = tab_cntrl(idecal+9)
82  ztot0      = tab_cntrl(idecal+10)
83  stot0      = tab_cntrl(idecal+11)
84  ang0       = tab_cntrl(idecal+12)
85  pa         = tab_cntrl(idecal+13)
86  preff      = tab_cntrl(idecal+14)
87!
88  clon       = tab_cntrl(idecal+15)
89  clat       = tab_cntrl(idecal+16)
90  grossismx  = tab_cntrl(idecal+17)
91  grossismy  = tab_cntrl(idecal+18)
92!
93  IF ( tab_cntrl(idecal+19)==1. )  THEN
94    fxyhypb  = .TRUE.
95!   dzoomx   = tab_cntrl(25)
96!   dzoomy   = tab_cntrl(26)
97!   taux     = tab_cntrl(28)
98!   tauy     = tab_cntrl(29)
99  ELSE
100    fxyhypb = .FALSE.
101    ysinus  = tab_cntrl(idecal+22)==1.
102  END IF
103
104  day_ini    = tab_cntrl(30)
105  itau_dyn   = tab_cntrl(31)
106  start_time = tab_cntrl(32)
107
108!-------------------------------------------------------------------------------
109  CALL msg('rad, omeg, g, cpp, kappa = '//TRIM(strStack(real2str([rad,omeg,g,cpp,kappa]))), modname)
110  CALL check_dim(im,iim,'im','im')
111  CALL check_dim(jm,jjm,'jm','jm')
112  CALL check_dim(lllm,llm,'lm','lllm')
113  CALL get_var1("rlonu",rlonu)
114  CALL get_var1("rlatu",rlatu)
115  CALL get_var1("rlonv",rlonv)
116  CALL get_var1("rlatv",rlatv)
117  CALL get_var2("cu"   ,cu)
118  CALL get_var2("cv"   ,cv)
119  CALL get_var2("aire" ,aire)
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  CALL get_var2("phisinit",phis)
128  CALL get_var3("ucov",ucov)
129  CALL get_var3("vcov",vcov)
130  CALL get_var3("teta",teta)
131  CALL get_var3("masse",masse)
132  CALL get_var2("ps",ps)
133
134!--- Tracers
135  ll=.FALSE.
136IF (CPPKEY_REPROBUS) THEN
137  ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr                                 !--- DETECT OLD REPRO start.nc FILE
138END IF
139  ltnat1 = .TRUE.; CALL getin('tnateq1', ltnat1)
140  DO iq=1,nqtot
141    var = tracers(iq)%name
142    oldVar = new2oldH2O(var)
143    lSkip = ll .AND. var == 'HNO3'                                                       !--- FORCE "HNO3_g" READING FOR "HNO3"
144IF (CPPKEY_REPROBUS) THEN
145    ix = strIdx(newHNO3, var); IF(ix /= 0) oldVar = oldHNO3(ix)                          !--- REPROBUS HNO3 exceptions
146END IF
147IF (CPPKEY_INCA) THEN
148    IF(var == 'O3') oldVar = 'OX'                                                        !--- DEAL WITH INCA OZONE EXCEPTION
149END IF
150    !--------------------------------------------------------------------------------------------------------------------------
151    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr .AND. .NOT.lSkip) THEN                !=== REGULAR CASE: AVAILABLE VARIABLE
152      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var)
153    !--------------------------------------------------------------------------------------------------------------------------
154    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== TRY WITH ALTERNATE NAME
155      CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to <'//TRIM(oldVar)//'>', modname)
156      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",oldVar)
157    !--------------------------------------------------------------------------------------------------------------------------
158    ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
159      iName    = tracers(iq)%iso_iName
160      iPhase   = tracers(iq)%iso_iPhase
161      iqParent = tracers(iq)%iqParent
162      IF(tracers(iq)%iso_iZone == 0) THEN
163         IF(ltnat1) THEN
164            tnat = 1.0
165            alpha_ideal = 1.0
166            CALL msg(' !!!  Beware: alpha_ideal put to 1  !!!', modname)
167         ELSE
168            SELECT CASE(isoName(iName))
169              CASE('H216O'); tnat = tnat_H216O; alpha_ideal = alpha_ideal_H216O
170              CASE('H217O'); tnat = tnat_H217O; alpha_ideal = alpha_ideal_H217O
171              CASE('H218O'); tnat = tnat_H218O; alpha_ideal = alpha_ideal_H218O
172              CASE('HDO');   tnat = tnat_HDO;   alpha_ideal = alpha_ideal_HDO
173              CASE('HTO');   tnat = tnat_HTO;   alpha_ideal = alpha_ideal_HTO
174              CASE DEFAULT; CALL abort_gcm(TRIM(modname),'unknown isotope "'//TRIM(isoName(iName))//'" ; check tracer.def file',1)
175            END SELECT
176         END IF
177         CALL msg('Missing tracer <'//TRIM(var)//'> => initialized with a simplified Rayleigh distillation law.', modname)
178         q(:,:,:,iq) = q(:,:,:,iqParent)*tnat*(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal-1.)
179      ELSE
180         CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to its parent isotope concentration.', modname)
181         ! Camille 9 mars 2023: attention!! seuls les tags qui correspondent à
182         ! izone=izone_init (définie dans isotrac_mod) sont initialisés comme
183         ! les parents. Sinon, c'est nul.
184         ! j'ai fait ça en attendant, mais il faudrait initialiser proprement en
185         ! remplacant 1 par izone_init dans la ligne qui suit.
186         IF(tracers(iq)%iso_iZone == 1) THEN
187           q(:,:,:,iq) = q(:,:,:,iqIsoPha(iName,iPhase))
188         ELSE
189           q(:,:,:,iq) = 0.
190         END IF
191      END IF
192    !--------------------------------------------------------------------------------------------------------------------------
193    ELSE                                                                                 !=== MISSING: SET TO 0
194      CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to zero', modname)
195      q(:,:,:,iq)=0.
196    !--------------------------------------------------------------------------------------------------------------------------
197    END IF
198  END DO
199
200  CALL err(NF90_CLOSE(fID),"close",fichnom)
201  day_ini=day_ini+INT(time)
202  time=time-INT(time)
203
204
205  CONTAINS
206
207
208SUBROUTINE check_dim(n1,n2,str1,str2)
209  INTEGER,          INTENT(IN) :: n1, n2
210  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
211  CHARACTER(LEN=maxlen) :: s1, s2
212  IF(n1/=n2) CALL abort_gcm(TRIM(modname), 'value of "'//TRIM(str1)//'" = '//TRIM(int2str(n1))// &
213   ' read in starting file differs from gcm value of "'//TRIM(str2)//'" = '//TRIM(int2str(n2)), 1)
214END SUBROUTINE check_dim
215
216
217SUBROUTINE get_var1(var,v)
218  CHARACTER(LEN=*), INTENT(IN)  :: var
219  REAL,             INTENT(OUT) :: v(:)
220  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
221  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
222END SUBROUTINE get_var1
223
224
225SUBROUTINE get_var2(var,v)
226  CHARACTER(LEN=*), INTENT(IN)  :: var
227  REAL,             INTENT(OUT) :: v(:,:)
228  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
229  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
230END SUBROUTINE get_var2
231
232
233SUBROUTINE get_var3(var,v)
234  CHARACTER(LEN=*), INTENT(IN)  :: var
235  REAL,             INTENT(OUT) :: v(:,:,:)
236  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
237  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
238END SUBROUTINE get_var3
239
240
241SUBROUTINE err(ierr,typ,nam)
242  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
243  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
244  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
245  IF(ierr==NF90_NoERR) RETURN
246  SELECT CASE(typ)
247    CASE('inq');   mesg="Field <"//TRIM(nam)//"> is missing"
248    CASE('get');   mesg="Reading failed for <"//TRIM(nam)//">"
249    CASE('open');  mesg="File opening failed for <"//TRIM(nam)//">"
250    CASE('close'); mesg="File closing failed for <"//TRIM(nam)//">"
251  END SELECT
252  CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr)
253END SUBROUTINE err
254
255END SUBROUTINE dynetat0
Note: See TracBrowser for help on using the repository browser.