source: LMDZ6/branches/Amaury_dev/libf/dyn3d/dynredem.F90 @ 5136

Last change on this file since 5136 was 5136, checked in by abarral, 5 months ago

Put comgeom.h, comgeom2.h into modules

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