source: LMDZ6/trunk/libf/dyn3dmem/dynetat0_loc.F90 @ 4175

Last change on this file since 4175 was 4143, checked in by dcugnet, 2 years ago
  • Some variables are renamed or replaced by direct equivalents:
    • iso_indnum -> tracers(:)%iso_iName
    • niso_possibles -> niso
    • iqiso -> iqIsoPha ; index_trac -> itZonIso
    • ok_iso_verif -> isoCheck
    • ntraceurs_zone -> nzone ; ntraciso -> ntiso
    • qperemin -> min_qparent ; masseqmin -> min_qmass ; ratiomin -> min_ratio
  • Some renamed variables are only aliased with the older name (using USE <module>, ONLY: <oldName> => <newName>) in routines where they are repeated many times.
  • Few hard-coded indexes are now computed (examples: ilic, iso, ivap, irneb, iq_vap, iq_liq, iso_H2O, iso_HDO, iso_HTO, iso_O17, iso_O18).
  • The IF(isoCheck) test is now embedded in the check_isotopes_seq and check_isotopes_loc routines (lighter calling).
  • 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: 11.1 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, tnat, alpha_ideal, iH2O
10  USE strings_mod, ONLY: maxlen, msg, strStack, real2str
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 readTracFiles_mod, ONLY: new2oldName
14  USE control_mod, ONLY: planet_type
15  USE assert_eq_m, 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
23  IMPLICIT NONE
24  include "dimensions.h"
25  include "paramet.h"
26  include "comgeom.h"
27  include "description.h"
28  include "iniprint.h"
29!===============================================================================
30! Arguments:
31  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
32  REAL, INTENT(OUT) ::  vcov(ijb_v:ije_v,llm)      !--- V COVARIANT WIND
33  REAL, INTENT(OUT) ::  ucov(ijb_u:ije_u,llm)      !--- U COVARIANT WIND
34  REAL, INTENT(OUT) ::  teta(ijb_u:ije_u,llm)      !--- POTENTIAL TEMP.
35  REAL, INTENT(OUT) ::     q(ijb_u:ije_u,llm,nqtot)!--- TRACERS
36  REAL, INTENT(OUT) :: masse(ijb_u:ije_u,llm)      !--- MASS PER CELL
37  REAL, INTENT(OUT) ::    ps(ijb_u:ije_u)          !--- GROUND PRESSURE
38  REAL, INTENT(OUT) ::  phis(ijb_u:ije_u)          !--- GEOPOTENTIAL
39!===============================================================================
40! Local variables:
41  CHARACTER(LEN=maxlen) :: mesg, var, modname, oldVar
42  INTEGER, PARAMETER :: length=100
43  INTEGER :: iq, fID, vID, idecal, ierr, iqParent, iName, iZone, iPhase
44  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
45  REAL,             ALLOCATABLE :: vcov_glo(:,:),masse_glo(:,:),   ps_glo(:)
46  REAL,             ALLOCATABLE :: ucov_glo(:,:),    q_glo(:,:), phis_glo(:)
47  REAL,             ALLOCATABLE :: teta_glo(:,:)
48!-------------------------------------------------------------------------------
49  modname="dynetat0_loc"
50
51!--- Initial state file opening
52  var=fichnom
53  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
54  CALL get_var1("controle",tab_cntrl)
55
56!!! AS: idecal is a hack to be able to read planeto starts...
57!!!     .... while keeping everything OK for LMDZ EARTH
58  IF(planet_type=="generic") THEN
59    CALL msg('NOTE NOTE NOTE : Planeto-like start files', modname)
60    idecal = 4
61    annee_ref  = 2000
62  ELSE
63    CALL msg('NOTE NOTE NOTE : Earth-like start files', modname)
64    idecal = 5
65    annee_ref  = tab_cntrl(5)
66  END IF
67  im         = tab_cntrl(1)
68  jm         = tab_cntrl(2)
69  lllm       = tab_cntrl(3)
70  day_ref    = tab_cntrl(4)
71  rad        = tab_cntrl(idecal+1)
72  omeg       = tab_cntrl(idecal+2)
73  g          = tab_cntrl(idecal+3)
74  cpp        = tab_cntrl(idecal+4)
75  kappa      = tab_cntrl(idecal+5)
76  daysec     = tab_cntrl(idecal+6)
77  dtvr       = tab_cntrl(idecal+7)
78  etot0      = tab_cntrl(idecal+8)
79  ptot0      = tab_cntrl(idecal+9)
80  ztot0      = tab_cntrl(idecal+10)
81  stot0      = tab_cntrl(idecal+11)
82  ang0       = tab_cntrl(idecal+12)
83  pa         = tab_cntrl(idecal+13)
84  preff      = tab_cntrl(idecal+14)
85!
86  clon       = tab_cntrl(idecal+15)
87  clat       = tab_cntrl(idecal+16)
88  grossismx  = tab_cntrl(idecal+17)
89  grossismy  = tab_cntrl(idecal+18)
90!
91  IF ( tab_cntrl(idecal+19)==1. )  THEN
92    fxyhypb  = .TRUE.
93!   dzoomx   = tab_cntrl(25)
94!   dzoomy   = tab_cntrl(26)
95!   taux     = tab_cntrl(28)
96!   tauy     = tab_cntrl(29)
97  ELSE
98    fxyhypb = .FALSE.
99    ysinus  = tab_cntrl(idecal+22)==1.
100  END IF
101
102  day_ini    = tab_cntrl(30)
103  itau_dyn   = tab_cntrl(31)
104  start_time = tab_cntrl(32)
105
106!-------------------------------------------------------------------------------
107  CALL msg('rad, omeg, g, cpp, kappa = '//TRIM(strStack(real2str([rad,omeg,g,cpp,kappa]))), modname)
108  CALL check_dim(im,iim,'im','im')
109  CALL check_dim(jm,jjm,'jm','jm')
110  CALL check_dim(lllm,llm,'lm','lllm')
111  CALL get_var1("rlonu",rlonu)
112  CALL get_var1("rlatu",rlatu)
113  CALL get_var1("rlonv",rlonv)
114  CALL get_var1("rlatv",rlatv)
115  CALL get_var1("cu"  ,cu)
116  CALL get_var1("cv"  ,cv)
117  CALL get_var1("aire",aire)
118
119  var="temps"
120  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
121    CALL msg('missing field <temps> ; trying with <Time>', modname)
122    var="Time"
123    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
124  END IF
125  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
126
127  ALLOCATE(phis_glo(ip1jmp1))
128  CALL get_var1("phisinit",phis_glo)
129  phis (ijb_u:ije_u)  =phis_glo(ijb_u:ije_u);    DEALLOCATE(phis_glo)
130
131  ALLOCATE(ucov_glo(ip1jmp1,llm))
132  CALL get_var2("ucov",ucov_glo)
133  ucov (ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:);  DEALLOCATE(ucov_glo)
134
135  ALLOCATE(vcov_glo(ip1jm,llm))
136  CALL get_var2("vcov",vcov_glo)
137  vcov (ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:);  DEALLOCATE(vcov_glo)
138
139  ALLOCATE(teta_glo(ip1jmp1,llm))
140  CALL get_var2("teta",teta_glo)
141  teta (ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:);  DEALLOCATE(teta_glo)
142
143  ALLOCATE(masse_glo(ip1jmp1,llm))
144  CALL get_var2("masse",masse_glo)
145  masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:); DEALLOCATE(masse_glo)
146 
147  ALLOCATE(ps_glo(ip1jmp1))
148  CALL get_var1("ps",ps_glo)
149  ps   (ijb_u:ije_u)  =   ps_glo(ijb_u:ije_u);   DEALLOCATE(ps_glo)
150
151!--- Tracers
152  ALLOCATE(q_glo(ip1jmp1,llm))
153  DO iq=1,nqtot
154    var = tracers(iq)%name
155    oldVar = new2oldName(var)
156    !--------------------------------------------------------------------------------------------------------------------------
157    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN                                 !=== REGULAR CASE
158      CALL get_var2(var,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
159    !--------------------------------------------------------------------------------------------------------------------------
160    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== OLD NAME
161      CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to <'//TRIM(oldVar)//'>', modname)
162      CALL get_var2(oldVar, q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
163    !--------------------------------------------------------------------------------------------------------------------------
164#ifdef INCA
165    ELSE IF(NF90_INQ_VARID(fID, 'OX',   vID) == NF90_NoErr .AND. var == 'O3') THEN       !=== INCA: OX INSTEAD OF O3
166      CALL msg('Tracer <O3> is missing => initialized to <OX>', modname)
167      CALL get_var2( 'OX' , q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
168    !--------------------------------------------------------------------------------------------------------------------------
169#endif
170    ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
171      iName    = tracers(iq)%iso_iName
172      iPhase   = tracers(iq)%iso_iPhase
173      iqParent = tracers(iq)%iqParent
174      IF(tracers(iq)%iso_iZone == 0) THEN
175         CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized with a simplified Rayleigh distillation law.', modname)
176         q(ijb_u:ije_u,:,iq)= q(ijb_u:ije_u,:,iqParent)*tnat(iName)*(q(ijb_u:ije_u,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
177      ELSE
178         CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to its parent isotope concentration.', modname)
179         q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqIsoPha(iName,iPhase))
180      END IF
181    !--------------------------------------------------------------------------------------------------------------------------
182    ELSE                                                                                 !=== MISSING: SET TO 0
183      CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to zero', modname)
184      q(ijb_u:ije_u,:,iq)=0.
185    !--------------------------------------------------------------------------------------------------------------------------
186    END IF
187  END DO
188  DEALLOCATE(q_glo)
189  CALL err(NF90_CLOSE(fID),"close",fichnom)
190  day_ini=day_ini+INT(time)
191  time=time-INT(time)
192
193
194  CONTAINS
195
196
197SUBROUTINE check_dim(n1,n2,str1,str2)
198  INTEGER,          INTENT(IN) :: n1, n2
199  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
200  CHARACTER(LEN=maxlen) :: s1, s2
201  IF(n1/=n2) THEN
202    s1='value of '//TRIM(str1)//' ='
203    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
204    WRITE(mesg,'(10x,a,i4,2x,a,i4)')TRIM(ADJUSTL(s1)),n1,TRIM(ADJUSTL(s2)),n2
205    CALL ABORT_gcm(TRIM(modname),TRIM(mesg),1)
206  END IF
207END SUBROUTINE check_dim
208
209
210SUBROUTINE get_var1(var,v)
211  CHARACTER(LEN=*), INTENT(IN)  :: var
212  REAL,             INTENT(OUT) :: v(:)
213  REAL,             ALLOCATABLE :: w2(:,:), w3(:,:,:)
214  INTEGER :: nn(3), dids(3), k, nd, ntot
215
216  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
217  ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd)
218  IF(nd==1) THEN
219    CALL err(NF90_GET_VAR(fID,vID,v),"get",var); RETURN
220  END IF
221  ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids)
222  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
223  ntot=PRODUCT(nn(1:nd))
224  SELECT CASE(nd)
225    CASE(2); ALLOCATE(w2(nn(1),nn(2)))
226      CALL err(NF90_GET_VAR(fID,vID,w2),"get",var)
227      v=RESHAPE(w2,[ntot]); DEALLOCATE(w2)
228    CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3)))
229      CALL err(NF90_GET_VAR(fID,vID,w3),"get",var)
230      v=RESHAPE(w3,[ntot]); DEALLOCATE(w3)
231  END SELECT
232END SUBROUTINE get_var1
233
234SUBROUTINE get_var2(var,v)
235  CHARACTER(LEN=*), INTENT(IN)  :: var
236  REAL,             INTENT(OUT) :: v(:,:)
237  REAL,             ALLOCATABLE :: w4(:,:,:,:), w3(:,:,:)
238  INTEGER :: nn(4), dids(4), k, nd
239
240
241  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
242  ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd)
243
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
249  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
250
251  SELECT CASE(nd)
252  CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3)))
253     CALL err(NF90_GET_VAR(fID,vID,w3),"get",var)
254     v=RESHAPE(w3,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w3)
255  CASE(4);  ALLOCATE(w4(nn(1),nn(2),nn(3),nn(4)))
256     CALL err(NF90_GET_VAR(fID,vID,w4),"get",var)
257     v=RESHAPE(w4,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w4)
258  END SELECT
259END SUBROUTINE get_var2
260
261
262SUBROUTINE err(ierr,typ,nam)
263  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
264  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
265  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
266  IF(ierr==NF90_NoERR) RETURN
267  SELECT CASE(typ)
268    CASE('inq');   mesg="Field <"//TRIM(nam)//"> is missing"
269    CASE('get');   mesg="Reading failed for <"//TRIM(nam)//">"
270    CASE('open');  mesg="File opening failed for <"//TRIM(nam)//">"
271    CASE('close'); mesg="File closing failed for <"//TRIM(nam)//">"
272  END SELECT
273  CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr)
274END SUBROUTINE err
275
276END SUBROUTINE dynetat0_loc
Note: See TracBrowser for help on using the repository browser.