source: LMDZ6/trunk/libf/dyn3d/dynetat0.F90 @ 4226

Last change on this file since 4226 was 4193, checked in by dcugnet, 2 years ago
  • Modifications in readSections to allow a continuation line character "\": in both "tracer.def" and "isotopes_params.def", information for a single tracer or isotope can now be stored on several lines.
  • Modifications in "dispTable" and associated routines to allow too wide tables to be displayed as several shorter sub-tables: each sub-table is at most "nMaxCol" characters wide (typically: number of characters displayable in a tandard screen window) and the first "nHead" columns (typically: name, index, etc.) are duplicated in each sub-table. A default value for nMaxCol, called maxTableWidth (currently = 192) is available in readTracFiles_mod.
  • Subroutine "readIsotopesFile" becomes a function with a boolean returned error value "lerr" used to trigger an external aborting function (no STOP).
File size: 9.0 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, tnat, alpha_ideal, iH2O
9  USE strings_mod, 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 readTracFiles_mod, ONLY: new2oldName
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) :: mesg, var, modname, oldVar
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    CALL msg('NOTE NOTE NOTE : Planeto-like start files', modname)
56    idecal = 4
57    annee_ref  = 2000
58  ELSE
59    CALL msg('NOTE NOTE NOTE : Earth-like start files', modname)
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  CALL msg('rad, omeg, g, cpp, kappa = '//TRIM(strStack(real2str([rad,omeg,g,cpp,kappa]))), modname)
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    CALL msg('missing field <temps> ; trying with <Time>', modname)
117    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 = tracers(iq)%name
131    oldVar = new2oldName(var)
132    !--------------------------------------------------------------------------------------------------------------------------
133    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN                                 !=== REGULAR CASE
134      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var)
135    !--------------------------------------------------------------------------------------------------------------------------
136    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== OLD NAME
137      CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to <'//TRIM(oldVar)//'>', modname)
138      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",oldVar)
139    !--------------------------------------------------------------------------------------------------------------------------
140#ifdef INCA
141    ELSE IF(NF90_INQ_VARID(fID, 'OX',   vID) == NF90_NoErr .AND. var == 'O3') THEN       !=== INCA: OX INSTEAD OF O3
142      CALL msg('Tracer <O3> is missing => initialized to <OX>', modname)
143      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",'OX')
144    !--------------------------------------------------------------------------------------------------------------------------
145#endif
146    ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
147      iName    = tracers(iq)%iso_iName
148      iPhase   = tracers(iq)%iso_iPhase
149      iqParent = tracers(iq)%iqParent
150      IF(tracers(iq)%iso_iZone == 0) THEN
151         CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized with a simplified Rayleigh distillation law.', modname)
152         q(:,:,:,iq) = q(:,:,:,iqParent)*tnat(iName)*(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
153      ELSE
154         CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to its parent isotope concentration.', modname)
155         q(:,:,:,iq) = q(:,:,:,iqIsoPha(iName,iPhase))
156      END IF
157    !--------------------------------------------------------------------------------------------------------------------------
158    ELSE                                                                                 !=== MISSING: SET TO 0
159      CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to zero', modname)
160      q(:,:,:,iq)=0.
161    !--------------------------------------------------------------------------------------------------------------------------
162    END IF
163  END DO
164
165  CALL err(NF90_CLOSE(fID),"close",fichnom)
166  day_ini=day_ini+INT(time)
167  time=time-INT(time)
168
169
170  CONTAINS
171
172
173SUBROUTINE check_dim(n1,n2,str1,str2)
174  INTEGER,          INTENT(IN) :: n1, n2
175  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
176  CHARACTER(LEN=maxlen) :: s1, s2
177  IF(n1/=n2) CALL abort_gcm(TRIM(modname), 'value of "'//TRIM(str1)//'" = '//TRIM(int2str(n1))// &
178   ' read in starting file differs from gcm value of "'//TRIM(str2)//'" = '//TRIM(int2str(n2)), 1)
179END SUBROUTINE check_dim
180
181
182SUBROUTINE get_var1(var,v)
183  CHARACTER(LEN=*), INTENT(IN)  :: var
184  REAL,             INTENT(OUT) :: v(:)
185  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
186  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
187END SUBROUTINE get_var1
188
189
190SUBROUTINE get_var2(var,v)
191  CHARACTER(LEN=*), INTENT(IN)  :: var
192  REAL,             INTENT(OUT) :: v(:,:)
193  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
194  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
195END SUBROUTINE get_var2
196
197
198SUBROUTINE get_var3(var,v)
199  CHARACTER(LEN=*), INTENT(IN)  :: var
200  REAL,             INTENT(OUT) :: v(:,:,:)
201  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
202  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
203END SUBROUTINE get_var3
204
205
206SUBROUTINE err(ierr,typ,nam)
207  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
208  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
209  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
210  IF(ierr==NF90_NoERR) RETURN
211  SELECT CASE(typ)
212    CASE('inq');   mesg="Field <"//TRIM(nam)//"> is missing"
213    CASE('get');   mesg="Reading failed for <"//TRIM(nam)//">"
214    CASE('open');  mesg="File opening failed for <"//TRIM(nam)//">"
215    CASE('close'); mesg="File closing failed for <"//TRIM(nam)//">"
216  END SELECT
217  CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr)
218END SUBROUTINE err
219
220END SUBROUTINE dynetat0
Note: See TracBrowser for help on using the repository browser.