source: LMDZ6/trunk/libf/dyn3d/dynetat0.f90 @ 4119

Last change on this file since 4119 was 4064, checked in by dcugnet, 3 years ago
  • minor fixes (unused variables suppressed, comas after a WRITE() statement, etc.)
  • parser routines taken from version 7 of https://svn.lmd.jussieu.fr/tracers-parser
  • few changes in infotrac, and few fixes of (at least) the sequential version:
    • uadv and vadv were deallocated twice (fix was lost by mistake just before last commit)
    • in [( dum(im), im=1, nm)] implicit loops, ifort evaluates "dum(im)" even if nm==0,

resulting in a crash, "im" being unitialized.

File size: 7.4 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, iqiso, iso_indnum, tnat, alpha_ideal, &
9                         ok_isotopes
10  USE strings_mod, ONLY: maxlen
11  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_NoErr, &
12                         NF90_CLOSE, NF90_GET_VAR
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
22  IMPLICIT NONE
23  include "dimensions.h"
24  include "paramet.h"
25  include "comgeom2.h"
26  include "description.h"
27  include "iniprint.h"
28!===============================================================================
29! Arguments:
30  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
31  REAL, INTENT(OUT) ::  vcov(iip1,jjm, llm)        !--- V COVARIANT WIND
32  REAL, INTENT(OUT) ::  ucov(iip1,jjp1,llm)        !--- U COVARIANT WIND
33  REAL, INTENT(OUT) ::  teta(iip1,jjp1,llm)        !--- POTENTIAL TEMP.
34  REAL, INTENT(OUT) ::     q(iip1,jjp1,llm,nqtot)  !--- TRACERS
35  REAL, INTENT(OUT) :: masse(iip1,jjp1,llm)        !--- MASS PER CELL
36  REAL, INTENT(OUT) ::    ps(iip1,jjp1)            !--- GROUND PRESSURE
37  REAL, INTENT(OUT) ::  phis(iip1,jjp1)            !--- GEOPOTENTIAL
38!===============================================================================
39! Local variables:
40  CHARACTER(LEN=maxlen) :: msg, var, modname
41  INTEGER, PARAMETER :: length=100
42  INTEGER :: iq, fID, vID, idecal, iqParent, iName, iZone, iPhase
43  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
44!-------------------------------------------------------------------------------
45  modname="dynetat0"
46
47!--- Initial state file opening
48  var=fichnom
49  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
50  CALL get_var1("controle",tab_cntrl)
51
52!!! AS: idecal is a hack to be able to read planeto starts...
53!!!     .... while keeping everything OK for LMDZ EARTH
54  IF(planet_type=="generic") THEN
55    WRITE(lunout,*)'NOTE NOTE NOTE : Planeto-like start files'
56    idecal = 4
57    annee_ref  = 2000
58  ELSE
59    WRITE(lunout,*)'NOTE NOTE NOTE : Earth-like start files'
60    idecal = 5
61    annee_ref  = tab_cntrl(5)
62  END IF
63  im         = tab_cntrl(1)
64  jm         = tab_cntrl(2)
65  lllm       = tab_cntrl(3)
66  day_ref    = tab_cntrl(4)
67  rad        = tab_cntrl(idecal+1)
68  omeg       = tab_cntrl(idecal+2)
69  g          = tab_cntrl(idecal+3)
70  cpp        = tab_cntrl(idecal+4)
71  kappa      = tab_cntrl(idecal+5)
72  daysec     = tab_cntrl(idecal+6)
73  dtvr       = tab_cntrl(idecal+7)
74  etot0      = tab_cntrl(idecal+8)
75  ptot0      = tab_cntrl(idecal+9)
76  ztot0      = tab_cntrl(idecal+10)
77  stot0      = tab_cntrl(idecal+11)
78  ang0       = tab_cntrl(idecal+12)
79  pa         = tab_cntrl(idecal+13)
80  preff      = tab_cntrl(idecal+14)
81!
82  clon       = tab_cntrl(idecal+15)
83  clat       = tab_cntrl(idecal+16)
84  grossismx  = tab_cntrl(idecal+17)
85  grossismy  = tab_cntrl(idecal+18)
86!
87  IF ( tab_cntrl(idecal+19)==1. )  THEN
88    fxyhypb  = .TRUE.
89!   dzoomx   = tab_cntrl(25)
90!   dzoomy   = tab_cntrl(26)
91!   taux     = tab_cntrl(28)
92!   tauy     = tab_cntrl(29)
93  ELSE
94    fxyhypb = .FALSE.
95    ysinus  = tab_cntrl(idecal+22)==1.
96  END IF
97
98  day_ini    = tab_cntrl(30)
99  itau_dyn   = tab_cntrl(31)
100  start_time = tab_cntrl(32)
101
102!-------------------------------------------------------------------------------
103  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
104  CALL check_dim(im,iim,'im','im')
105  CALL check_dim(jm,jjm,'jm','jm')
106  CALL check_dim(lllm,llm,'lm','lllm')
107  CALL get_var1("rlonu",rlonu)
108  CALL get_var1("rlatu",rlatu)
109  CALL get_var1("rlonv",rlonv)
110  CALL get_var1("rlatv",rlatv)
111  CALL get_var2("cu"   ,cu)
112  CALL get_var2("cv"   ,cv)
113  CALL get_var2("aire" ,aire)
114  var="temps"
115  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
116    WRITE(lunout,*)TRIM(modname)//": missing field <temps>"
117    WRITE(lunout,*)TRIM(modname)//": trying with <Time>"; var="Time"
118    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
119  END IF
120  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
121  CALL get_var2("phisinit",phis)
122  CALL get_var3("ucov",ucov)
123  CALL get_var3("vcov",vcov)
124  CALL get_var3("teta",teta)
125  CALL get_var3("masse",masse)
126  CALL get_var2("ps",ps)
127
128!--- Tracers
129  DO iq=1,nqtot
130    var=TRIM(tracers(iq)%name)
131    IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
132      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
133    END IF
134    WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
135    WRITE(lunout,*)"         It is hence initialized to zero"
136    q(:,:,:,iq)=0.
137   !--- CRisi: for isotops, theoretical initialization using very simplified
138   !           Rayleigh distillation law.
139    iName = tracers(iq)%iso_iName
140    IF(.NOT.ok_isotopes .OR. iName<=0) CYCLE
141    iZone = tracers(iq)%iso_iZone
142    iPhase= tracers(iq)%iso_iPhase
143    iqParent = tracers(iq)%iqParent
144    IF(iZone==0) q(:,:,:,iq) = q(:,:,:,iqParent)*tnat(iName)    &
145                             *(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
146    IF(iZone==1) q(:,:,:,iq) = q(:,:,:,iqiso(iso_indnum(iq),iPhase))
147  END DO
148
149  CALL err(NF90_CLOSE(fID),"close",fichnom)
150  day_ini=day_ini+INT(time)
151  time=time-INT(time)
152
153
154  CONTAINS
155
156
157SUBROUTINE check_dim(n1,n2,str1,str2)
158  INTEGER,          INTENT(IN) :: n1, n2
159  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
160  CHARACTER(LEN=maxlen) :: s1, s2
161  IF(n1/=n2) THEN
162    s1='value of '//TRIM(str1)//' ='
163    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
164    WRITE(msg,'(10x,a,i4,2x,a,i4)')TRIM(ADJUSTL(s1)),n1,TRIM(ADJUSTL(s2)),n2
165    CALL ABORT_gcm(TRIM(modname),TRIM(msg),1)
166  END IF
167END SUBROUTINE check_dim
168
169
170SUBROUTINE get_var1(var,v)
171  CHARACTER(LEN=*), INTENT(IN)  :: var
172  REAL,             INTENT(OUT) :: v(:)
173  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
174  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
175END SUBROUTINE get_var1
176
177
178SUBROUTINE get_var2(var,v)
179  CHARACTER(LEN=*), INTENT(IN)  :: var
180  REAL,             INTENT(OUT) :: v(:,:)
181  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
182  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
183END SUBROUTINE get_var2
184
185
186SUBROUTINE get_var3(var,v)
187  CHARACTER(LEN=*), INTENT(IN)  :: var
188  REAL,             INTENT(OUT) :: v(:,:,:)
189  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
190  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
191END SUBROUTINE get_var3
192
193
194SUBROUTINE err(ierr,typ,nam)
195  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
196  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
197  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
198  IF(ierr==NF90_NoERR) RETURN
199  SELECT CASE(typ)
200    CASE('inq');   msg="Field <"//TRIM(nam)//"> is missing"
201    CASE('get');   msg="Reading failed for <"//TRIM(nam)//">"
202    CASE('open');  msg="File opening failed for <"//TRIM(nam)//">"
203    CASE('close'); msg="File closing failed for <"//TRIM(nam)//">"
204  END SELECT
205  CALL ABORT_gcm(TRIM(modname),TRIM(msg),1)
206END SUBROUTINE err
207
208END SUBROUTINE dynetat0
Note: See TracBrowser for help on using the repository browser.