source: LMDZ6/branches/Amaury_dev/libf/dyn3d/dynetat0.F90 @ 5136

Last change on this file since 5136 was 5136, checked in by abarral, 3 months ago

Put comgeom.h, comgeom2.h into modules

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