source: LMDZ6/branches/Amaury_dev/libf/dyn3dmem/dynetat0_loc.F90 @ 5172

Last change on this file since 5172 was 5159, checked in by abarral, 5 months ago

Put dimensions.h and paramet.h into modules

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