source: LMDZ6/trunk/libf/dyn3d/dynetat0.F90 @ 5258

Last change on this file since 5258 was 5252, checked in by abarral, 5 weeks ago

Wrap uses of cpp key REPROBUS and CPP_STRATAER
Add REPROBUS wrapper

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