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

Last change on this file since 3933 was 3865, checked in by lmdz-users, 4 years ago

Modifications from Thibaut to create an ESM with interactive CO2 + INCA aerosols

File size: 9.8 KB
RevLine 
[2293]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 infotrac
[2299]10  USE netcdf, ONLY: NF90_CREATE, NF90_DEF_DIM, NF90_INQ_VARID, NF90_GLOBAL,    &
[3803]11                    NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER,   &
12                    NF90_64BIT_OFFSET
[2299]13  USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
[2600]14  USE comvert_mod, ONLY: ap,bp,aps,bps,presnivs,pseudoalt,pa,preff, &
15                              nivsig,nivsigs
[2597]16  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
[2603]17  USE logic_mod, ONLY: fxyhypb, ysinus
[2598]18  USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy, &
[2600]19                              taux,tauy
[2601]20  USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, start_time
[2622]21  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
[2601]22 
[2293]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, l
37  INTEGER, PARAMETER :: length=100
38  REAL    :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
39!   For NetCDF:
40  CHARACTER(LEN=30) :: unites
41  INTEGER :: indexID
42  INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
43  INTEGER :: sID, sigID, nID, vID, timID
44  INTEGER :: yyears0, jjour0, mmois0
[2299]45  REAL    :: zan0, zjulian, hours
[2293]46!===============================================================================
[2299]47  modname='dynredem0'; fil=fichnom
[2293]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
[3803]107  CALL err(NF90_CREATE(fichnom,IOR(NF90_CLOBBER,NF90_64BIT_OFFSET),nid))
[2293]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
[2299]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)
[2293]133! covariant <-> contravariant <-> natural conversion coefficients
[2299]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)
[2293]138
139!--- Define fields saved later
140  WRITE(unites,"('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')"),&
141               yyears0,mmois0,jjour0
[2299]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])
[2293]146  DO iq=1,nqtot
[2299]147    CALL cre_var(nid,tname(iq),ttext(iq),[rlonvID,rlatuID,sID,timID])
[2293]148  END DO
[2299]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])
[2293]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 infotrac
169  USE control_mod
[2299]170  USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
171                      NF90_CLOSE, NF90_WRITE,   NF90_PUT_VAR, NF90_NoErr
172  USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
173                          err, modname, fil, msg
[2601]174  USE temps_mod, ONLY: itau_dyn, itaufin
175 
[2293]176  IMPLICIT NONE
[2299]177  include "dimensions.h"
178  include "paramet.h"
179  include "description.h"
180  include "comgeom.h"
181  include "iniprint.h"
[2293]182!===============================================================================
183! Arguments:
[2299]184  CHARACTER(LEN=*), INTENT(IN) :: fichnom              !-- FILE NAME
185  REAL, INTENT(IN)    ::  time                         !-- TIME
186  REAL, INTENT(IN)    ::  vcov(iip1,jjm, llm)          !-- V COVARIANT WIND
187  REAL, INTENT(IN)    ::  ucov(iip1,jjp1,llm)          !-- U COVARIANT WIND
188  REAL, INTENT(IN)    ::  teta(iip1,jjp1,llm)          !-- POTENTIAL TEMPERATURE
189  REAL, INTENT(INOUT) ::     q(iip1,jjp1,llm,nqtot)    !-- TRACERS
190  REAL, INTENT(IN)    :: masse(iip1,jjp1,llm)          !-- MASS PER CELL
191  REAL, INTENT(IN)    ::    ps(iip1,jjp1)              !-- GROUND PRESSURE
[2293]192!===============================================================================
193! Local variables:
[2299]194  INTEGER :: l, iq, nid, vID, ierr, nid_trac, vID_trac
[2293]195  INTEGER, SAVE :: nb=0
196  INTEGER, PARAMETER :: length=100
197  REAL               :: tab_cntrl(length) ! tableau des parametres du run
[2299]198  CHARACTER(LEN=256) :: var, dum
199  LOGICAL            :: lread_inca
[2293]200!===============================================================================
[2299]201
202  modname='dynredem1'; fil=fichnom
[2293]203  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
204
205!--- Write/extend time coordinate
206  nb = nb + 1
[2299]207  var="temps"
208  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
209  CALL err(NF90_PUT_VAR(nid,vID,[time]),"put",var)
[2293]210  WRITE(lunout,*)TRIM(modname)//": Saving for ", nb, time
211
212!--- Rewrite control table (itaufin undefined in dynredem0)
213  var="controle"
214  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
[2299]215  CALL err(NF90_GET_VAR(nid,vID,tab_cntrl),"get",var)
216  tab_cntrl(31)=DBLE(itau_dyn + itaufin)
217  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
218  CALL err(NF90_PUT_VAR(nid,vID,tab_cntrl),"put",var)
[2293]219
220!--- Save fields
[2299]221  CALL dynredem_write_u(nid,"ucov" ,ucov ,llm)
222  CALL dynredem_write_v(nid,"vcov" ,vcov ,llm)
223  CALL dynredem_write_u(nid,"teta" ,teta ,llm)
224  CALL dynredem_write_u(nid,"masse",masse,llm)
225  CALL dynredem_write_u(nid,"ps"   ,ps   ,1)
[2293]226
227!--- Tracers in file "start_trac.nc" (added by Anne)
[2299]228  lread_inca=.FALSE.; fil="start_trac.nc"
[3865]229  IF(type_trac=='inca' .OR. type_trac=='inco') INQUIRE(FILE=fil,EXIST=lread_inca)
[2299]230  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
[2293]231
[2299]232!--- Save tracers
233  DO iq=1,nqtot; var=tname(iq); ierr=-1
234    IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
235      fil="start_trac.nc"
236      ierr=NF90_INQ_VARID(nid_trac,var,vID_trac)
237      dum='inq'; IF(ierr==NF90_NoErr) dum='fnd'
238      WRITE(lunout,*)msg(dum,var)
[2293]239
[2299]240
241      IF(ierr==NF90_NoErr) CALL dynredem_read_u(nid_trac,var,q(:,:,:,iq),llm)
[2293]242    END IF
[2299]243    fil=fichnom
244    CALL dynredem_write_u(nid,var,q(:,:,:,iq),llm)
[2293]245  END DO
[2299]246  CALL err(NF90_CLOSE(nid),"close")
247  fil="start_trac.nc"
248  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
[2293]249
250END SUBROUTINE dynredem1
251
Note: See TracBrowser for help on using the repository browser.