GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: dyn3d/dynredem.F90 Lines: 105 117 89.7 %
Date: 2023-06-30 12:56:34 Branches: 59 74 79.7 %

Line Branch Exec Source
1
4
SUBROUTINE 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
1
  modname='dynredem0'; fil=fichnom
48
#ifdef CPP_IOIPSL
49
1
  CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
50
1
  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
1
  tab_cntrl(:)  = 0.
59
1
  tab_cntrl(1)  = REAL(iim)
60
1
  tab_cntrl(2)  = REAL(jjm)
61
1
  tab_cntrl(3)  = REAL(llm)
62
1
  tab_cntrl(4)  = REAL(day_ref)
63
1
  tab_cntrl(5)  = REAL(annee_ref)
64
1
  tab_cntrl(6)  = rad
65
1
  tab_cntrl(7)  = omeg
66
1
  tab_cntrl(8)  = g
67
1
  tab_cntrl(9)  = cpp
68
1
  tab_cntrl(10) = kappa
69
1
  tab_cntrl(11) = daysec
70
1
  tab_cntrl(12) = dtvr
71
1
  tab_cntrl(13) = etot0
72
1
  tab_cntrl(14) = ptot0
73
1
  tab_cntrl(15) = ztot0
74
1
  tab_cntrl(16) = stot0
75
1
  tab_cntrl(17) = ang0
76
1
  tab_cntrl(18) = pa
77
1
  tab_cntrl(19) = preff
78
79
!    .....    parameters for zoom    ......
80
1
  tab_cntrl(20) = clon
81
1
  tab_cntrl(21) = clat
82
1
  tab_cntrl(22) = grossismx
83
1
  tab_cntrl(23) = grossismy
84
!
85
1
  IF ( fxyhypb )   THEN
86
1
    tab_cntrl(24) = 1.
87
1
    tab_cntrl(25) = dzoomx
88
1
    tab_cntrl(26) = dzoomy
89
1
    tab_cntrl(27) = 0.
90
1
    tab_cntrl(28) = taux
91
1
    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
1
  tab_cntrl(30) = REAL(iday_end)
102
1
  tab_cntrl(31) = REAL(itau_dyn + itaufin)
103
! start_time: start_time of simulation (not necessarily 0.)
104
1
  tab_cntrl(32) = start_time
105
106
!--- File creation
107
1
  CALL err(NF90_CREATE(fichnom,IOR(NF90_CLOBBER,NF90_64BIT_OFFSET),nid))
108
109
!--- Some global attributes
110
1
  CALL err(NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier demarrage dynamique"))
111
112
!--- Dimensions
113
1
  CALL err(NF90_DEF_DIM(nid,"index", length, indexID))
114
1
  CALL err(NF90_DEF_DIM(nid,"rlonu", iip1,   rlonuID))
115
1
  CALL err(NF90_DEF_DIM(nid,"rlatu", jjp1,   rlatuID))
116
1
  CALL err(NF90_DEF_DIM(nid,"rlonv", iip1,   rlonvID))
117
1
  CALL err(NF90_DEF_DIM(nid,"rlatv", jjm,    rlatvID))
118
1
  CALL err(NF90_DEF_DIM(nid,"sigs",  llm,        sID))
119
1
  CALL err(NF90_DEF_DIM(nid,"sig",   llmp1,    sigID))
120
1
  CALL err(NF90_DEF_DIM(nid,"temps", NF90_UNLIMITED, timID))
121
122
!--- Define and save invariant fields
123
2
  CALL put_var1(nid,"controle","Parametres de controle" ,[indexID],tab_cntrl)
124
2
  CALL put_var1(nid,"rlonu"   ,"Longitudes des points U",[rlonuID],rlonu)
125
2
  CALL put_var1(nid,"rlatu"   ,"Latitudes des points U" ,[rlatuID],rlatu)
126
2
  CALL put_var1(nid,"rlonv"   ,"Longitudes des points V",[rlonvID],rlonv)
127
2
  CALL put_var1(nid,"rlatv"   ,"Latitudes des points V" ,[rlatvID],rlatv)
128
2
  CALL put_var1(nid,"nivsigs" ,"Numero naturel des couches s"    ,[sID]  ,nivsigs)
129
2
  CALL put_var1(nid,"nivsig"  ,"Numero naturel des couches sigma",[sigID],nivsig)
130
2
  CALL put_var1(nid,"ap"      ,"Coefficient A pour hybride"      ,[sigID],ap)
131
2
  CALL put_var1(nid,"bp"      ,"Coefficient B pour hybride"      ,[sigID],bp)
132
2
  CALL put_var1(nid,"presnivs",""                                ,[sID]  ,presnivs)
133
! covariant <-> contravariant <-> natural conversion coefficients
134
3
  CALL put_var2(nid,"cu","Coefficient de passage pour U",[rlonuID,rlatuID],cu)
135
3
  CALL put_var2(nid,"cv","Coefficient de passage pour V",[rlonvID,rlatvID],cv)
136
3
  CALL put_var2(nid,"aire","Aires de chaque maille"     ,[rlonvID,rlatuID],aire)
137
3
  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
1
               yyears0,mmois0,jjour0
142
2
  CALL cre_var(nid,"temps","Temps de simulation",[timID],unites)
143
5
  CALL cre_var(nid,"ucov" ,"Vitesse U"  ,[rlonuID,rlatuID,sID,timID])
144
5
  CALL cre_var(nid,"vcov" ,"Vitesse V"  ,[rlonvID,rlatvID,sID,timID])
145
5
  CALL cre_var(nid,"teta" ,"Temperature",[rlonvID,rlatuID,sID,timID])
146
6
  DO iq=1,nqtot
147
26
    CALL cre_var(nid,tracers(iq)%name,tracers(iq)%longName,[rlonvID,rlatuID,sID,timID])
148
  END DO
149
5
  CALL cre_var(nid,"masse","Masse d air"    ,[rlonvID,rlatuID,sID,timID])
150
4
  CALL cre_var(nid,"ps"   ,"Pression au sol",[rlonvID,rlatuID    ,timID])
151
1
  CALL err(NF90_CLOSE (nid))
152
153
1
  WRITE(lunout,*)TRIM(modname)//': iim,jjm,llm,iday_end',iim,jjm,llm,iday_end
154
1
  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
155
156
1
END SUBROUTINE dynredem0
157
!
158
!-------------------------------------------------------------------------------
159
160
161
!-------------------------------------------------------------------------------
162
!
163
2
SUBROUTINE 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
1
  modname='dynredem1'; fil=fichnom
204
1
  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
205
206
!--- Write/extend time coordinate
207
1
  nb = nb + 1
208
1
  var="temps"
209
1
  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
210
2
  CALL err(NF90_PUT_VAR(nid,vID,[time]),"put",var)
211
1
  WRITE(lunout,*)TRIM(modname)//": Saving for ", nb, time
212
213
!--- Rewrite control table (itaufin undefined in dynredem0)
214
1
  var="controle"
215
1
  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
216
1
  CALL err(NF90_GET_VAR(nid,vID,tab_cntrl),"get",var)
217
1
  tab_cntrl(31)=DBLE(itau_dyn + itaufin)
218
1
  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
219
1
  CALL err(NF90_PUT_VAR(nid,vID,tab_cntrl),"put",var)
220
221
!--- Save fields
222
1
  CALL dynredem_write_u(nid,"ucov" ,ucov ,llm)
223
1
  CALL dynredem_write_v(nid,"vcov" ,vcov ,llm)
224
1
  CALL dynredem_write_u(nid,"teta" ,teta ,llm)
225
1
  CALL dynredem_write_u(nid,"masse",masse,llm)
226
1
  CALL dynredem_write_u(nid,"ps"   ,ps   ,1)
227
228
!--- Tracers in file "start_trac.nc" (added by Anne)
229
1
  lread_inca=.FALSE.; fil="start_trac.nc"
230

3
  IF(ANY(type_trac == ['inca','inco'])) INQUIRE(FILE=fil,EXIST=lread_inca)
231
1
  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
232
233
!--- Save tracers
234
6
  DO iq=1,nqtot; var=TRIM(tracers(iq)%name); ierr=-1
235
5
    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
5
    fil=fichnom
245
6
    CALL dynredem_write_u(nid,var,q(:,:,:,iq),llm)
246
  END DO
247
1
  CALL err(NF90_CLOSE(nid),"close")
248
1
  fil="start_trac.nc"
249
1
  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
250
251
1
END SUBROUTINE dynredem1
252