source: trunk/LMDZ.MARS/libf/phymars/iniwrite.F @ 1009

Last change on this file since 1009 was 999, checked in by tnavarro, 11 years ago

Possibility to store multiple initial states in one start/startfi. This is RETROCOMPATIBLE. New option ecrithist in run.def to write data in start/startfi every ecrithist dynamical timestep. New option timestart in run.def to initialize the GCM with the time timestart stored in start

File size: 10.6 KB
Line 
1      SUBROUTINE iniwrite(nid,idayref,phis)
2      IMPLICIT NONE
3
4c=======================================================================
5c
6c   Auteur:  L. Fairhead  ,  P. Le Van, Y. Wanherdrick, F. Forget
7c   -------
8c
9c   Objet:
10c   ------
11c
12c   'Initialize' the diagfi.nc file: write down dimensions as well
13c   as time-independent fields (e.g: geopotential, mesh area, ...)
14c
15c=======================================================================
16c-----------------------------------------------------------------------
17c   Declarations:
18c   -------------
19
20#include "dimensions.h"
21#include "paramet.h"
22!include "comconst.h"
23#include "comcstfi.h"
24#include "comvert.h"
25#include "comgeom.h"
26#include "temps.h"
27#include "ener.h"
28#include "logic.h"
29#include "netcdf.inc"
30#include "description.h"
31#include "serre.h"
32#include"dimphys.h"
33#include"comsoil.h"
34
35c   Arguments:
36c   ----------
37
38      integer,intent(in) :: nid        ! NetCDF file ID
39      INTEGER*4,intent(in) :: idayref  ! date (initial date for this run)
40      real,intent(in) :: phis(ip1jmp1) ! surface geopotential
41
42c   Local:
43c   ------
44      INTEGER length,l
45      parameter (length = 100)
46      REAL tab_cntrl(length) ! run parameters are stored in this array
47      INTEGER ierr
48
49      integer :: nvarid,idim_index,idim_rlonu,idim_rlonv
50      integer :: idim_rlatu,idim_rlatv,idim_llmp1,idim_llm
51      integer :: idim_nsoilmx ! "subsurface_layers" dimension ID #
52      integer, dimension(2) :: id 
53c-----------------------------------------------------------------------
54
55      DO l=1,length
56         tab_cntrl(l)=0.
57      ENDDO
58      tab_cntrl(1)  = real(iim)
59      tab_cntrl(2)  = real(jjm)
60      tab_cntrl(3)  = real(llm)
61      tab_cntrl(4)  = real(idayref)
62      tab_cntrl(5)  = rad
63      tab_cntrl(6)  = omeg
64      tab_cntrl(7)  = g
65      tab_cntrl(8)  = mugaz
66      tab_cntrl(9)  = rcp
67      tab_cntrl(10) = daysec
68      tab_cntrl(11) = dtphys
69      tab_cntrl(12) = etot0
70      tab_cntrl(13) = ptot0
71      tab_cntrl(14) = ztot0
72      tab_cntrl(15) = stot0
73      tab_cntrl(16) = ang0
74
75      tab_cntrl(27) = hour_ini
76c
77c    ..........    P.Le Van  ( ajout le 8/04/96 )    .........
78c         .....        parametres  pour le zoom          ......   
79      tab_cntrl(17)  = clon
80      tab_cntrl(18)  = clat
81      tab_cntrl(19)  = grossismx
82      tab_cntrl(20)  = grossismy
83c
84c     .....   ajout  le 6/05/97 et le 15/10/97  .......
85c
86      IF ( fxyhypb )   THEN
87        tab_cntrl(21) = 1.
88        tab_cntrl(22) = dzoomx
89        tab_cntrl(23) = dzoomy
90      ELSE
91        tab_cntrl(21) = 0.
92        tab_cntrl(22) = dzoomx
93        tab_cntrl(23) = dzoomy
94        tab_cntrl(24) = 0.
95        IF( ysinus )  tab_cntrl(24) = 1.
96      ENDIF
97
98c    .........................................................
99
100! Define dimensions
101   
102      ierr = NF_REDEF (nid)
103
104      ierr = NF_DEF_DIM (nid, "index", length, idim_index)
105      ierr = NF_DEF_DIM (nid, "rlonu", iip1, idim_rlonu)
106      ierr = NF_DEF_DIM (nid, "latitude", jjp1, idim_rlatu)
107      ierr = NF_DEF_DIM (nid, "longitude", iip1, idim_rlonv)
108      ierr = NF_DEF_DIM (nid, "rlatv", jjm, idim_rlatv)
109      ierr = NF_DEF_DIM (nid, "interlayer", (llm+1), idim_llmp1)
110      ierr = NF_DEF_DIM (nid, "altitude", llm, idim_llm)
111      ierr = NF_DEF_DIM (nid,"subsurface_layers",nsoilmx,idim_nsoilmx)
112c
113      ierr = NF_ENDDEF(nid)
114
115c  Contol parameters for this run
116      ierr = NF_REDEF (nid)
117#ifdef NC_DOUBLE
118      ierr = NF_DEF_VAR (nid, "controle", NF_DOUBLE, 1,
119     .       idim_index,nvarid)
120#else
121      ierr = NF_DEF_VAR (nid, "controle", NF_FLOAT, 1,
122     .       idim_index,nvarid)
123#endif
124      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 18,
125     .                       "Control parameters")
126      ierr = NF_ENDDEF(nid)
127#ifdef NC_DOUBLE
128      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
129#else
130      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
131#endif
132
133c --------------------------
134c  longitudes and latitudes
135      ierr = NF_REDEF (nid)
136#ifdef NC_DOUBLE
137      ierr = NF_DEF_VAR (nid, "rlonu", NF_DOUBLE, 1, idim_rlonu,nvarid)
138#else
139      ierr = NF_DEF_VAR (nid, "rlonu", NF_FLOAT, 1, idim_rlonu,nvarid)
140#endif
141      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 21,
142     .                       "Longitudes at u nodes")
143      ierr = NF_ENDDEF(nid)
144#ifdef NC_DOUBLE
145      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlonu/pi*180)
146#else
147      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlonu/pi*180)
148#endif
149c
150c --------------------------
151      ierr = NF_REDEF (nid)
152#ifdef NC_DOUBLE
153      ierr =NF_DEF_VAR(nid, "latitude", NF_DOUBLE, 1, idim_rlatu,nvarid)
154#else
155      ierr =NF_DEF_VAR (nid, "latitude", NF_FLOAT, 1, idim_rlatu,nvarid)
156#endif
157      ierr =NF_PUT_ATT_TEXT(nid,nvarid,'units',13,"degrees_north")
158      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 14,
159     .      "North latitude")
160      ierr = NF_ENDDEF(nid)
161#ifdef NC_DOUBLE
162      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlatu/pi*180)
163#else
164      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlatu/pi*180)
165#endif
166c
167c --------------------------
168      ierr = NF_REDEF (nid)
169#ifdef NC_DOUBLE
170      ierr =NF_DEF_VAR(nid,"longitude", NF_DOUBLE, 1, idim_rlonv,nvarid)
171#else
172      ierr = NF_DEF_VAR(nid,"longitude", NF_FLOAT, 1, idim_rlonv,nvarid)
173#endif
174      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 14,
175     .      "East longitude")
176      ierr = NF_PUT_ATT_TEXT(nid,nvarid,'units',12,"degrees_east")
177      ierr = NF_ENDDEF(nid)
178#ifdef NC_DOUBLE
179      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlonv/pi*180)
180#else
181      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlonv/pi*180)
182#endif
183c
184c --------------------------
185      ierr = NF_REDEF (nid)
186#ifdef NC_DOUBLE
187      ierr = NF_DEF_VAR (nid, "altitude", NF_DOUBLE, 1,
188     .       idim_llm,nvarid)
189#else
190      ierr = NF_DEF_VAR (nid, "altitude", NF_FLOAT, 1,
191     .       idim_llm,nvarid)
192#endif
193      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name",10,"pseudo-alt")
194      ierr = NF_PUT_ATT_TEXT (nid,nvarid,'units',2,"km")
195      ierr = NF_PUT_ATT_TEXT (nid,nvarid,'positive',2,"up")
196
197      ierr = NF_ENDDEF(nid)
198#ifdef NC_DOUBLE
199      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pseudoalt)
200#else
201      ierr = NF_PUT_VAR_REAL (nid,nvarid,pseudoalt)
202#endif
203c
204c --------------------------
205      ierr = NF_REDEF (nid)
206#ifdef NC_DOUBLE
207      ierr = NF_DEF_VAR (nid, "rlatv", NF_DOUBLE, 1, idim_rlatv,nvarid)
208#else
209      ierr = NF_DEF_VAR (nid, "rlatv", NF_FLOAT, 1, idim_rlatv,nvarid)
210#endif
211      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 20,
212     .                       "Latitudes at v nodes")
213      ierr = NF_ENDDEF(nid)
214#ifdef NC_DOUBLE
215      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlatv/pi*180)
216#else
217      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlatv/pi*180)
218#endif
219c
220c --------------------------
221c  Vertical levels
222      call def_var(nid,"aps","hybrid pressure at midlayers ","Pa",
223     .            1,idim_llm,nvarid,ierr)
224#ifdef NC_DOUBLE
225      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aps)
226#else
227      ierr = NF_PUT_VAR_REAL (nid,nvarid,aps)
228#endif
229
230      call def_var(nid,"bps","hybrid sigma at midlayers"," ",
231     .            1,idim_llm,nvarid,ierr)
232#ifdef NC_DOUBLE
233      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bps)
234#else
235      ierr = NF_PUT_VAR_REAL (nid,nvarid,bps)
236#endif
237
238      call def_var(nid,"ap","hybrid pressure at interlayers","Pa",
239     .            1,idim_llmp1,nvarid,ierr)
240#ifdef NC_DOUBLE
241      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,ap)
242#else
243      ierr = NF_PUT_VAR_REAL (nid,nvarid,ap)
244#endif
245
246      call def_var(nid,"bp","hybrid sigma at interlayers"," ",
247     .            1,idim_llmp1,nvarid,ierr)
248#ifdef NC_DOUBLE
249      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bp)
250#else
251      ierr = NF_PUT_VAR_REAL (nid,nvarid,bp)
252#endif
253
254!-------------------------------
255! (soil) depth variable mlayer() (known from comsoil.h)
256!-------------------------------
257      ierr=NF_REDEF (nid) ! Enter NetCDF (re-)define mode
258      ! define variable
259#ifdef NC_DOUBLE
260      ierr=NF_DEF_VAR(nid,"soildepth",NF_DOUBLE,1,idim_nsoilmx,nvarid)
261#else
262      ierr=NF_DEF_VAR(nid,"soildepth",NF_FLOAT,1,idim_nsoilmx,nvarid)
263#endif
264      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 20,
265     .                        "Soil mid-layer depth")
266      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"units",1,"m")
267      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"positive",4,"down")
268      ierr=NF_ENDDEF(nid) ! Leave NetCDF define mode
269      ! write variable
270#ifdef NC_DOUBLE
271      ierr=NF_PUT_VAR_DOUBLE (nid,nvarid,mlayer)
272#else
273      ierr=NF_PUT_VAR_REAL (nid,nvarid,mlayer)
274#endif
275
276c
277c --------------------------
278c  Mesh area and conversion coefficients cov. <-> contra. <--> natural
279
280      id(1)=idim_rlonu
281      id(2)=idim_rlatu
282c
283      ierr = NF_REDEF (nid)
284#ifdef NC_DOUBLE
285      ierr = NF_DEF_VAR (nid, "cu", NF_DOUBLE, 2, id,nvarid)
286#else
287      ierr = NF_DEF_VAR (nid, "cu", NF_FLOAT, 2, id,nvarid)
288#endif
289      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 40,
290     .             "Conversion coefficients cov <--> natural")
291      ierr = NF_ENDDEF(nid)
292#ifdef NC_DOUBLE
293      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,cu)
294#else
295      ierr = NF_PUT_VAR_REAL (nid,nvarid,cu)
296#endif
297c
298      id(1)=idim_rlonv
299      id(2)=idim_rlatv
300c
301c --------------------------
302      ierr = NF_REDEF (nid)
303#ifdef NC_DOUBLE
304      ierr = NF_DEF_VAR (nid, "cv", NF_DOUBLE, 2, id,nvarid)
305#else
306      ierr = NF_DEF_VAR (nid, "cv", NF_FLOAT, 2, id,nvarid)
307#endif
308      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 40,
309     .             "Conversion coefficients cov <--> natural")
310      ierr = NF_ENDDEF(nid)
311#ifdef NC_DOUBLE
312      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,cv)
313#else
314      ierr = NF_PUT_VAR_REAL (nid,nvarid,cv)
315#endif
316c
317      id(1)=idim_rlonv
318      id(2)=idim_rlatu
319c
320c --------------------------
321      ierr = NF_REDEF (nid)
322#ifdef NC_DOUBLE
323      ierr = NF_DEF_VAR (nid, "aire", NF_DOUBLE, 2, id,nvarid)
324#else
325      ierr = NF_DEF_VAR (nid, "aire", NF_FLOAT, 2, id,nvarid)
326#endif
327      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
328     .                       "Mesh area")
329      ierr = NF_ENDDEF(nid)
330#ifdef NC_DOUBLE
331      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aire)
332#else
333      ierr = NF_PUT_VAR_REAL (nid,nvarid,aire)
334#endif
335c
336c  Surface geopotential
337      id(1)=idim_rlonv
338      id(2)=idim_rlatu
339c
340      ierr = NF_REDEF (nid)
341#ifdef NC_DOUBLE
342      ierr = NF_DEF_VAR (nid, "phisinit", NF_DOUBLE, 2, id,nvarid)
343#else
344      ierr = NF_DEF_VAR (nid, "phisinit", NF_FLOAT, 2, id,nvarid)
345#endif
346      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 27,
347     .                       "Geopotential at the surface")
348      ierr = NF_ENDDEF(nid)
349#ifdef NC_DOUBLE
350      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,phis)
351#else
352      ierr = NF_PUT_VAR_REAL (nid,nvarid,phis)
353#endif
354c
355
356      write(*,*)'iniwrite: iim,jjm,llm,idayref',iim,jjm,llm,idayref
357      write(*,*)'iniwrite: rad,omeg,g,mugaz,rcp',
358     s rad,omeg,g,mugaz,rcp
359      write(*,*)'iniwrite: daysec,dtphys',daysec,dtphys
360
361      END
Note: See TracBrowser for help on using the repository browser.