source: LMDZ6/branches/cirrus/libf/dyn3d/dynetat0.F90 @ 5232

Last change on this file since 5232 was 5203, checked in by Laurent Fairhead, 8 weeks ago

Merge with trunk revision 5202 before reintegration to trunk

File size: 10.1 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, getKey
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
27  IMPLICIT NONE
28  include "dimensions.h"
29  include "paramet.h"
30  include "comgeom2.h"
31  include "description.h"
32  include "iniprint.h"
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
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.
136#ifdef REPROBUS
137  ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr                                 !--- DETECT OLD REPRO start.nc FILE
138#endif
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"
144#ifdef REPROBUS
145    ix = strIdx(newHNO3, var); IF(ix /= 0) oldVar = oldHNO3(ix)                          !--- REPROBUS HNO3 exceptions
146#endif
147#ifdef INCA
148    IF(var == 'O3') oldVar = 'OX'                                                        !--- DEAL WITH INCA OZONE EXCEPTION
149#endif
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          IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) &
169            CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1)
170         END IF
171         CALL msg('Missing tracer <'//TRIM(var)//'> => initialized with a simplified Rayleigh distillation law.', modname)
172         q(:,:,:,iq) = q(:,:,:,iqParent)*tnat*(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal-1.)
173      ELSE
174         CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to its parent isotope concentration.', modname)
175         ! Camille 9 mars 2023: attention!! seuls les tags qui correspondent à
176         ! izone=izone_init (définie dans isotrac_mod) sont initialisés comme
177         ! les parents. Sinon, c'est nul.
178         ! j'ai fait ça en attendant, mais il faudrait initialiser proprement en
179         ! remplacant 1 par izone_init dans la ligne qui suit.
180         IF(tracers(iq)%iso_iZone == 1) THEN
181           q(:,:,:,iq) = q(:,:,:,iqIsoPha(iName,iPhase))
182         ELSE
183           q(:,:,:,iq) = 0.
184         END IF
185      END IF
186    !--------------------------------------------------------------------------------------------------------------------------
187    ELSE                                                                                 !=== MISSING: SET TO 0
188      CALL msg('Missing tracer <'//TRIM(var)//'> => initialized to zero', modname)
189      q(:,:,:,iq)=0.
190    !--------------------------------------------------------------------------------------------------------------------------
191    END IF
192  END DO
193
194  CALL err(NF90_CLOSE(fID),"close",fichnom)
195  day_ini=day_ini+INT(time)
196  time=time-INT(time)
197
198
199  CONTAINS
200
201
202SUBROUTINE check_dim(n1,n2,str1,str2)
203  INTEGER,          INTENT(IN) :: n1, n2
204  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
205  CHARACTER(LEN=maxlen) :: s1, s2
206  IF(n1/=n2) CALL abort_gcm(TRIM(modname), 'value of "'//TRIM(str1)//'" = '//TRIM(int2str(n1))// &
207   ' read in starting file differs from gcm value of "'//TRIM(str2)//'" = '//TRIM(int2str(n2)), 1)
208END SUBROUTINE check_dim
209
210
211SUBROUTINE get_var1(var,v)
212  CHARACTER(LEN=*), INTENT(IN)  :: var
213  REAL,             INTENT(OUT) :: v(:)
214  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
215  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
216END SUBROUTINE get_var1
217
218
219SUBROUTINE get_var2(var,v)
220  CHARACTER(LEN=*), INTENT(IN)  :: var
221  REAL,             INTENT(OUT) :: v(:,:)
222  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
223  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
224END SUBROUTINE get_var2
225
226
227SUBROUTINE get_var3(var,v)
228  CHARACTER(LEN=*), INTENT(IN)  :: var
229  REAL,             INTENT(OUT) :: v(:,:,:)
230  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
231  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
232END SUBROUTINE get_var3
233
234
235SUBROUTINE err(ierr,typ,nam)
236  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
237  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
238  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
239  IF(ierr==NF90_NoERR) RETURN
240  SELECT CASE(typ)
241    CASE('inq');   mesg="Field <"//TRIM(nam)//"> is missing"
242    CASE('get');   mesg="Reading failed for <"//TRIM(nam)//">"
243    CASE('open');  mesg="File opening failed for <"//TRIM(nam)//">"
244    CASE('close'); mesg="File closing failed for <"//TRIM(nam)//">"
245  END SELECT
246  CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr)
247END SUBROUTINE err
248
249END SUBROUTINE dynetat0
Note: See TracBrowser for help on using the repository browser.