source: LMDZ6/branches/Ocean_skin/libf/dyn3d/dynetat0.F90 @ 5453

Last change on this file since 5453 was 4368, checked in by lguez, 2 years ago

Sync latest trunk changes to Ocean_skin

File size: 9.4 KB
RevLine 
[2293]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!-------------------------------------------------------------------------------
[4325]8  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, iH2O, isoName
[4193]9  USE strings_mod, ONLY: maxlen, msg, strStack, real2str, int2str
[4120]10  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, &
11                         NF90_CLOSE, NF90_GET_VAR, NF90_NoErr
[4325]12  USE readTracFiles_mod, ONLY: new2oldH2O, newHNO3, oldHNO3, getKey
[2293]13  USE control_mod, ONLY: planet_type
14  USE assert_eq_m, ONLY: assert_eq
[2600]15  USE comvert_mod, ONLY: pa,preff
[2597]16  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
[2603]17  USE logic_mod, ONLY: fxyhypb, ysinus
[2598]18  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
[2601]19  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
[2622]20  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
[2600]21
[2293]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:
[4120]40  CHARACTER(LEN=maxlen) :: mesg, var, modname, oldVar
[2293]41  INTEGER, PARAMETER :: length=100
[4050]42  INTEGER :: iq, fID, vID, idecal, iqParent, iName, iZone, iPhase
[4325]43  REAL    :: time, tnat, alpha_ideal, tab_cntrl(length)    !--- RUN PARAMS TABLE
[4301]44  LOGICAL :: lSkip, ll
[2293]45!-------------------------------------------------------------------------------
46  modname="dynetat0"
47
48!--- Initial state file opening
49  var=fichnom
50  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
51  CALL get_var1("controle",tab_cntrl)
52
53!!! AS: idecal is a hack to be able to read planeto starts...
54!!!     .... while keeping everything OK for LMDZ EARTH
55  IF(planet_type=="generic") THEN
[4120]56    CALL msg('NOTE NOTE NOTE : Planeto-like start files', modname)
[2293]57    idecal = 4
58    annee_ref  = 2000
59  ELSE
[4120]60    CALL msg('NOTE NOTE NOTE : Earth-like start files', modname)
[2293]61    idecal = 5
62    annee_ref  = tab_cntrl(5)
63  END IF
64  im         = tab_cntrl(1)
65  jm         = tab_cntrl(2)
66  lllm       = tab_cntrl(3)
67  day_ref    = tab_cntrl(4)
68  rad        = tab_cntrl(idecal+1)
69  omeg       = tab_cntrl(idecal+2)
70  g          = tab_cntrl(idecal+3)
71  cpp        = tab_cntrl(idecal+4)
72  kappa      = tab_cntrl(idecal+5)
73  daysec     = tab_cntrl(idecal+6)
74  dtvr       = tab_cntrl(idecal+7)
75  etot0      = tab_cntrl(idecal+8)
76  ptot0      = tab_cntrl(idecal+9)
77  ztot0      = tab_cntrl(idecal+10)
78  stot0      = tab_cntrl(idecal+11)
79  ang0       = tab_cntrl(idecal+12)
80  pa         = tab_cntrl(idecal+13)
81  preff      = tab_cntrl(idecal+14)
82!
83  clon       = tab_cntrl(idecal+15)
84  clat       = tab_cntrl(idecal+16)
85  grossismx  = tab_cntrl(idecal+17)
86  grossismy  = tab_cntrl(idecal+18)
87!
88  IF ( tab_cntrl(idecal+19)==1. )  THEN
89    fxyhypb  = .TRUE.
90!   dzoomx   = tab_cntrl(25)
91!   dzoomy   = tab_cntrl(26)
92!   taux     = tab_cntrl(28)
93!   tauy     = tab_cntrl(29)
94  ELSE
95    fxyhypb = .FALSE.
96    ysinus  = tab_cntrl(idecal+22)==1.
97  END IF
98
99  day_ini    = tab_cntrl(30)
100  itau_dyn   = tab_cntrl(31)
101  start_time = tab_cntrl(32)
102
103!-------------------------------------------------------------------------------
[4120]104  CALL msg('rad, omeg, g, cpp, kappa = '//TRIM(strStack(real2str([rad,omeg,g,cpp,kappa]))), modname)
[2293]105  CALL check_dim(im,iim,'im','im')
106  CALL check_dim(jm,jjm,'jm','jm')
107  CALL check_dim(lllm,llm,'lm','lllm')
108  CALL get_var1("rlonu",rlonu)
109  CALL get_var1("rlatu",rlatu)
110  CALL get_var1("rlonv",rlonv)
111  CALL get_var1("rlatv",rlatv)
112  CALL get_var2("cu"   ,cu)
113  CALL get_var2("cv"   ,cv)
114  CALL get_var2("aire" ,aire)
115  var="temps"
116  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
[4120]117    CALL msg('missing field <temps> ; trying with <Time>', modname)
118    var="Time"
[2293]119    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
120  END IF
121  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
[2299]122  CALL get_var2("phisinit",phis)
[2293]123  CALL get_var3("ucov",ucov)
124  CALL get_var3("vcov",vcov)
125  CALL get_var3("teta",teta)
126  CALL get_var3("masse",masse)
127  CALL get_var2("ps",ps)
128
129!--- Tracers
[4268]130  ll=.FALSE.
[4265]131#ifdef REPROBUS
[4301]132  ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr                                 !--- DETECT OLD REPRO start.nc FILE
[4265]133#endif
[2293]134  DO iq=1,nqtot
[4120]135    var = tracers(iq)%name
[4301]136    oldVar = new2oldH2O(var)
137    lSkip = ll .AND. var == 'HNO3'                                                       !--- FORCE "HNO3_g" READING FOR "HNO3"
138#ifdef REPROBUS
139    ix = strIdx(newHNO3, var); IF(ix /= 0) oldVar = oldHNO3(ix)                          !--- REPROBUS HNO3 exceptions
140#endif
141#ifdef INCA
142    IF(var == 'O3') oldVar = 'OX'                                                        !--- DEAL WITH INCA OZONE EXCEPTION
143#endif
[4120]144    !--------------------------------------------------------------------------------------------------------------------------
[4301]145    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr .AND. .NOT.lSkip) THEN                !=== REGULAR CASE: AVAILABLE VARIABLE
[4120]146      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var)
147    !--------------------------------------------------------------------------------------------------------------------------
[4301]148    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== TRY WITH ALTERNATE NAME
[4120]149      CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to <'//TRIM(oldVar)//'>', modname)
150      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",oldVar)
151    !--------------------------------------------------------------------------------------------------------------------------
152    ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
[4143]153      iName    = tracers(iq)%iso_iName
[4120]154      iPhase   = tracers(iq)%iso_iPhase
155      iqParent = tracers(iq)%iqParent
156      IF(tracers(iq)%iso_iZone == 0) THEN
[4325]157         IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) &
158            CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1)
[4120]159         CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized with a simplified Rayleigh distillation law.', modname)
[4325]160         q(:,:,:,iq) = q(:,:,:,iqParent)*tnat*(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal-1.)
[4120]161      ELSE
162         CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to its parent isotope concentration.', modname)
[4143]163         q(:,:,:,iq) = q(:,:,:,iqIsoPha(iName,iPhase))
[4120]164      END IF
165    !--------------------------------------------------------------------------------------------------------------------------
166    ELSE                                                                                 !=== MISSING: SET TO 0
167      CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to zero', modname)
168      q(:,:,:,iq)=0.
169    !--------------------------------------------------------------------------------------------------------------------------
[2293]170    END IF
171  END DO
172
173  CALL err(NF90_CLOSE(fID),"close",fichnom)
174  day_ini=day_ini+INT(time)
175  time=time-INT(time)
176
177
178  CONTAINS
179
180
181SUBROUTINE check_dim(n1,n2,str1,str2)
182  INTEGER,          INTENT(IN) :: n1, n2
183  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
[4046]184  CHARACTER(LEN=maxlen) :: s1, s2
[4193]185  IF(n1/=n2) CALL abort_gcm(TRIM(modname), 'value of "'//TRIM(str1)//'" = '//TRIM(int2str(n1))// &
186   ' read in starting file differs from gcm value of "'//TRIM(str2)//'" = '//TRIM(int2str(n2)), 1)
[2293]187END SUBROUTINE check_dim
188
189
190SUBROUTINE get_var1(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_var1
196
197
198SUBROUTINE get_var2(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_var2
204
205
206SUBROUTINE get_var3(var,v)
207  CHARACTER(LEN=*), INTENT(IN)  :: var
208  REAL,             INTENT(OUT) :: v(:,:,:)
209  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
210  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
211END SUBROUTINE get_var3
212
213
214SUBROUTINE err(ierr,typ,nam)
215  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
216  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
217  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
218  IF(ierr==NF90_NoERR) RETURN
219  SELECT CASE(typ)
[4120]220    CASE('inq');   mesg="Field <"//TRIM(nam)//"> is missing"
221    CASE('get');   mesg="Reading failed for <"//TRIM(nam)//">"
222    CASE('open');  mesg="File opening failed for <"//TRIM(nam)//">"
223    CASE('close'); mesg="File closing failed for <"//TRIM(nam)//">"
[2293]224  END SELECT
[4120]225  CALL ABORT_gcm(TRIM(modname),TRIM(mesg),ierr)
[2293]226END SUBROUTINE err
227
228END SUBROUTINE dynetat0
Note: See TracBrowser for help on using the repository browser.