source: LMDZ6/trunk/libf/dyn3d/dynredem.F90 @ 5258

Last change on this file since 5258 was 5084, checked in by Laurent Fairhead, 4 months ago

Reverting to r4065. Updating fortran standard broke too much stuff. Will do it by smaller chunks
AB, LF

File size: 9.9 KB
Line 
1SUBROUTINE dynredem0(fichnom,iday_end,phis)
2!
3!-------------------------------------------------------------------------------
4! Write the NetCDF restart file (initialization).
5!-------------------------------------------------------------------------------
6#ifdef CPP_IOIPSL
7  USE IOIPSL
8#endif
9  USE strings_mod, ONLY: maxlen
10  USE infotrac, ONLY: nqtot, tracers
11  USE netcdf, ONLY: NF90_CREATE, NF90_DEF_DIM, NF90_INQ_VARID, NF90_GLOBAL,    &
12                    NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER,   &
13                    NF90_64BIT_OFFSET
14  USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
15  USE comvert_mod,  ONLY: ap, bp, presnivs, pa, preff, nivsig, nivsigs
16  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
17  USE logic_mod, ONLY: fxyhypb, ysinus
18  USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy, &
19                              taux,tauy
20  USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, 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 "comgeom2.h"
27  include "description.h"
28  include "iniprint.h"
29!===============================================================================
30! Arguments:
31  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
32  INTEGER,          INTENT(IN) :: iday_end         !---
33  REAL,             INTENT(IN) :: phis(iip1, jjp1) !--- GROUND GEOPOTENTIAL
34!===============================================================================
35! Local variables:
36  INTEGER :: iq
37  INTEGER, PARAMETER :: length=100
38  REAL    :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
39!   For NetCDF:
40  CHARACTER(LEN=maxlen) :: unites
41  INTEGER :: indexID
42  INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
43  INTEGER :: sID, sigID, nID, timID
44  INTEGER :: yyears0, jjour0, mmois0
45  REAL    :: zjulian, hours
46!===============================================================================
47  modname='dynredem0'; fil=fichnom
48#ifdef CPP_IOIPSL
49  CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
50  CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
51#else
52! set yyears0, mmois0, jjour0 to 0,1,1 (hours is not used)
53  yyears0=0
54  mmois0=1
55  jjour0=1
56#endif       
57
58  tab_cntrl(:)  = 0.
59  tab_cntrl(1)  = REAL(iim)
60  tab_cntrl(2)  = REAL(jjm)
61  tab_cntrl(3)  = REAL(llm)
62  tab_cntrl(4)  = REAL(day_ref)
63  tab_cntrl(5)  = REAL(annee_ref)
64  tab_cntrl(6)  = rad
65  tab_cntrl(7)  = omeg
66  tab_cntrl(8)  = g
67  tab_cntrl(9)  = cpp
68  tab_cntrl(10) = kappa
69  tab_cntrl(11) = daysec
70  tab_cntrl(12) = dtvr
71  tab_cntrl(13) = etot0
72  tab_cntrl(14) = ptot0
73  tab_cntrl(15) = ztot0
74  tab_cntrl(16) = stot0
75  tab_cntrl(17) = ang0
76  tab_cntrl(18) = pa
77  tab_cntrl(19) = preff
78
79!    .....    parameters for zoom    ......   
80  tab_cntrl(20) = clon
81  tab_cntrl(21) = clat
82  tab_cntrl(22) = grossismx
83  tab_cntrl(23) = grossismy
84!
85  IF ( fxyhypb )   THEN
86    tab_cntrl(24) = 1.
87    tab_cntrl(25) = dzoomx
88    tab_cntrl(26) = dzoomy
89    tab_cntrl(27) = 0.
90    tab_cntrl(28) = taux
91    tab_cntrl(29) = tauy
92  ELSE
93    tab_cntrl(24) = 0.
94    tab_cntrl(25) = dzoomx
95    tab_cntrl(26) = dzoomy
96    tab_cntrl(27) = 0.
97    tab_cntrl(28) = 0.
98    tab_cntrl(29) = 0.
99    IF( ysinus )  tab_cntrl(27) = 1.
100  END IF
101  tab_cntrl(30) = REAL(iday_end)
102  tab_cntrl(31) = REAL(itau_dyn + itaufin)
103! start_time: start_time of simulation (not necessarily 0.)
104  tab_cntrl(32) = start_time
105
106!--- File creation
107  CALL err(NF90_CREATE(fichnom,IOR(NF90_CLOBBER,NF90_64BIT_OFFSET),nid))
108
109!--- Some global attributes
110  CALL err(NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier demarrage dynamique"))
111
112!--- Dimensions
113  CALL err(NF90_DEF_DIM(nid,"index", length, indexID))
114  CALL err(NF90_DEF_DIM(nid,"rlonu", iip1,   rlonuID))
115  CALL err(NF90_DEF_DIM(nid,"rlatu", jjp1,   rlatuID))
116  CALL err(NF90_DEF_DIM(nid,"rlonv", iip1,   rlonvID))
117  CALL err(NF90_DEF_DIM(nid,"rlatv", jjm,    rlatvID))
118  CALL err(NF90_DEF_DIM(nid,"sigs",  llm,        sID))
119  CALL err(NF90_DEF_DIM(nid,"sig",   llmp1,    sigID))
120  CALL err(NF90_DEF_DIM(nid,"temps", NF90_UNLIMITED, timID))
121
122!--- Define and save invariant fields
123  CALL put_var1(nid,"controle","Parametres de controle" ,[indexID],tab_cntrl)
124  CALL put_var1(nid,"rlonu"   ,"Longitudes des points U",[rlonuID],rlonu)
125  CALL put_var1(nid,"rlatu"   ,"Latitudes des points U" ,[rlatuID],rlatu)
126  CALL put_var1(nid,"rlonv"   ,"Longitudes des points V",[rlonvID],rlonv)
127  CALL put_var1(nid,"rlatv"   ,"Latitudes des points V" ,[rlatvID],rlatv)
128  CALL put_var1(nid,"nivsigs" ,"Numero naturel des couches s"    ,[sID]  ,nivsigs)
129  CALL put_var1(nid,"nivsig"  ,"Numero naturel des couches sigma",[sigID],nivsig)
130  CALL put_var1(nid,"ap"      ,"Coefficient A pour hybride"      ,[sigID],ap)
131  CALL put_var1(nid,"bp"      ,"Coefficient B pour hybride"      ,[sigID],bp)
132  CALL put_var1(nid,"presnivs",""                                ,[sID]  ,presnivs)
133! covariant <-> contravariant <-> natural conversion coefficients
134  CALL put_var2(nid,"cu","Coefficient de passage pour U",[rlonuID,rlatuID],cu)
135  CALL put_var2(nid,"cv","Coefficient de passage pour V",[rlonvID,rlatvID],cv)
136  CALL put_var2(nid,"aire","Aires de chaque maille"     ,[rlonvID,rlatuID],aire)
137  CALL put_var2(nid,"phisinit","Geopotentiel au sol"    ,[rlonvID,rlatuID],phis)
138
139!--- Define fields saved later
140  WRITE(unites,"('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')") &
141               yyears0,mmois0,jjour0
142  CALL cre_var(nid,"temps","Temps de simulation",[timID],unites)
143  CALL cre_var(nid,"ucov" ,"Vitesse U"  ,[rlonuID,rlatuID,sID,timID])
144  CALL cre_var(nid,"vcov" ,"Vitesse V"  ,[rlonvID,rlatvID,sID,timID])
145  CALL cre_var(nid,"teta" ,"Temperature",[rlonvID,rlatuID,sID,timID])
146  DO iq=1,nqtot
147    CALL cre_var(nid,tracers(iq)%name,tracers(iq)%longName,[rlonvID,rlatuID,sID,timID])
148  END DO
149  CALL cre_var(nid,"masse","Masse d air"    ,[rlonvID,rlatuID,sID,timID])
150  CALL cre_var(nid,"ps"   ,"Pression au sol",[rlonvID,rlatuID    ,timID])
151  CALL err(NF90_CLOSE (nid))
152
153  WRITE(lunout,*)TRIM(modname)//': iim,jjm,llm,iday_end',iim,jjm,llm,iday_end
154  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
155
156END SUBROUTINE dynredem0
157!
158!-------------------------------------------------------------------------------
159
160
161!-------------------------------------------------------------------------------
162!
163SUBROUTINE dynredem1(fichnom,time,vcov,ucov,teta,q,masse,ps)
164!
165!-------------------------------------------------------------------------------
166! Purpose: Write the NetCDF restart file (append).
167!-------------------------------------------------------------------------------
168  USE strings_mod, ONLY: maxlen
169  USE infotrac, ONLY: nqtot, tracers, type_trac
170  USE control_mod
171  USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
172                      NF90_CLOSE, NF90_WRITE,   NF90_PUT_VAR, NF90_NoErr
173  USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
174                          err, modname, fil, msg
175  USE temps_mod, ONLY: itau_dyn, itaufin
176 
177  IMPLICIT NONE
178  include "dimensions.h"
179  include "paramet.h"
180  include "description.h"
181  include "comgeom.h"
182  include "iniprint.h"
183!===============================================================================
184! Arguments:
185  CHARACTER(LEN=*), INTENT(IN) :: fichnom              !-- FILE NAME
186  REAL, INTENT(IN)    ::  time                         !-- TIME
187  REAL, INTENT(IN)    ::  vcov(iip1,jjm, llm)          !-- V COVARIANT WIND
188  REAL, INTENT(IN)    ::  ucov(iip1,jjp1,llm)          !-- U COVARIANT WIND
189  REAL, INTENT(IN)    ::  teta(iip1,jjp1,llm)          !-- POTENTIAL TEMPERATURE
190  REAL, INTENT(INOUT) ::     q(iip1,jjp1,llm,nqtot)    !-- TRACERS
191  REAL, INTENT(IN)    :: masse(iip1,jjp1,llm)          !-- MASS PER CELL
192  REAL, INTENT(IN)    ::    ps(iip1,jjp1)              !-- GROUND PRESSURE
193!===============================================================================
194! Local variables:
195  INTEGER :: iq, nid, vID, ierr, nid_trac, vID_trac
196  INTEGER, SAVE :: nb=0
197  INTEGER, PARAMETER :: length=100
198  REAL               :: tab_cntrl(length) ! tableau des parametres du run
199  CHARACTER(LEN=maxlen) :: var, dum
200  LOGICAL            :: lread_inca
201!===============================================================================
202
203  modname='dynredem1'; fil=fichnom
204  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
205
206!--- Write/extend time coordinate
207  nb = nb + 1
208  var="temps"
209  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
210  CALL err(NF90_PUT_VAR(nid,vID,[time]),"put",var)
211  WRITE(lunout,*)TRIM(modname)//": Saving for ", nb, time
212
213!--- Rewrite control table (itaufin undefined in dynredem0)
214  var="controle"
215  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
216  CALL err(NF90_GET_VAR(nid,vID,tab_cntrl),"get",var)
217  tab_cntrl(31)=DBLE(itau_dyn + itaufin)
218  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
219  CALL err(NF90_PUT_VAR(nid,vID,tab_cntrl),"put",var)
220
221!--- Save fields
222  CALL dynredem_write_u(nid,"ucov" ,ucov ,llm)
223  CALL dynredem_write_v(nid,"vcov" ,vcov ,llm)
224  CALL dynredem_write_u(nid,"teta" ,teta ,llm)
225  CALL dynredem_write_u(nid,"masse",masse,llm)
226  CALL dynredem_write_u(nid,"ps"   ,ps   ,1)
227
228!--- Tracers in file "start_trac.nc" (added by Anne)
229  lread_inca=.FALSE.; fil="start_trac.nc"
230  IF(ANY(type_trac == ['inca','inco'])) INQUIRE(FILE=fil,EXIST=lread_inca)
231  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
232
233!--- Save tracers
234  DO iq=1,nqtot; var=TRIM(tracers(iq)%name); ierr=-1
235    IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
236      fil="start_trac.nc"
237      ierr=NF90_INQ_VARID(nid_trac,var,vID_trac)
238      dum='inq'; IF(ierr==NF90_NoErr) dum='fnd'
239      WRITE(lunout,*)msg(dum,var)
240
241
242      IF(ierr==NF90_NoErr) CALL dynredem_read_u(nid_trac,var,q(:,:,:,iq),llm)
243    END IF
244    fil=fichnom
245    CALL dynredem_write_u(nid,var,q(:,:,:,iq),llm)
246  END DO
247  CALL err(NF90_CLOSE(nid),"close")
248  fil="start_trac.nc"
249  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
250
251END SUBROUTINE dynredem1
252
Note: See TracBrowser for help on using the repository browser.