source: trunk/LMDZ.MARS/libf/phymars/iniwritesoil.F90 @ 1047

Last change on this file since 1047 was 1047, checked in by emillour, 11 years ago

Mars GCM:

  • IMPORTANT CHANGE: Removed all reference/use of ngridmx (dimphys.h) in routines (necessary prerequisite to using parallel dynamics); in most cases this just means adding 'ngrid' as routine argument, and making local saved variables allocatable (and allocated at first call). In the process, had to convert many *.h files to equivalent modules: yomaer.h => yomaer_h.F90 , surfdat.h => surfdat_h.F90 , comsaison.h => comsaison_h.F90 , yomlw.h => yomlw_h.F90 , comdiurn.h => comdiurn_h.F90 , dimradmars.h => dimradmars_mod.F90 , comgeomfi.h => comgeomfi_h.F90, comsoil.h => comsoil_h.F90 , slope.h => slope_mod.F90
  • Also updated EOF routines, everything is now in eofdump_mod.F90
  • Removed unused routine lectfux.F (in dyn3d)

EM

File size: 7.7 KB
Line 
1subroutine iniwritesoil(nid,ngrid)
2
3! initialization routine for 'writediagoil'. Here we create/define
4! dimensions (longitude, latitude, depth and time) and other fixed
5! (time-independent) parameters.
6
7use comsoil_h, only: mlayer, inertiedat, nsoilmx
8
9implicit none
10
11#include"dimensions.h"
12!#include"dimphys.h"
13#include"paramet.h"
14#include"comcstfi.h"
15#include"comgeom.h"
16!#include"comsoil.h"
17#include"netcdf.inc"
18
19! Arguments:
20integer,intent(in) :: ngrid
21integer,intent(in) :: nid ! NetCDF output file ID
22
23! Local variables:
24
25! NetCDF stuff:
26integer :: ierr ! NetCDF routines return code
27integer :: idim_rlatu ! ID of the 'latitude' dimension
28integer :: idim_rlonv ! ID of the 'longitude' dimension
29integer :: idim_depth ! ID of the 'depth' dimension
30integer :: idim_time  ! ID of the 'time' dimension
31integer :: varid ! to store NetCDF ID of a variable
32integer,dimension(3) :: dimids ! to store IDs of dimensions of a variable
33character(len=60) :: text ! to store some text
34real,dimension(iip1,jjp1,nsoilmx) :: data3 ! to store 3D data
35integer :: i,j,l,ig0
36
37! 1. Define the dimensions
38! Switch to NetCDF define mode
39ierr=NF_REDEF(nid)
40
41! Define the dimensions
42ierr=NF_DEF_DIM(nid,"longitude",iip1,idim_rlonv)
43! iip1 known from paramet.h
44if (ierr.ne.NF_NOERR) then
45  write(*,*)"iniwritesoil: Error, could not define longitude dimension"
46endif
47ierr=NF_DEF_DIM(nid,"latitude",jjp1,idim_rlatu)
48! jjp1 known from paramet.h
49if (ierr.ne.NF_NOERR) then
50  write(*,*)"iniwritesoil: Error, could not define latitude dimension"
51endif
52ierr=NF_DEF_DIM(nid,"depth",nsoilmx,idim_depth)
53! nsoilmx known from dimphys.h
54if (ierr.ne.NF_NOERR) then
55  write(*,*)"iniwritesoil: Error, could not define depth dimension"
56endif
57ierr=NF_DEF_DIM(nid,"time",NF_UNLIMITED,idim_time)
58if (ierr.ne.NF_NOERR) then
59  write(*,*)"iniwritesoil: Error, could not define time dimension"
60endif
61
62! Switch out of NetCDF define mode
63ierr=NF_ENDDEF(nid)
64
65! 2. Define (as variables) and write dimensions, as well as their attributes
66! 2.1. Longitude
67ierr=NF_REDEF(nid) ! switch to NetCDF define mode
68
69! Define the variable
70#ifdef NC_DOUBLE
71ierr=NF_DEF_VAR(nid,"longitude",NF_DOUBLE,1,idim_rlonv,varid)
72#else
73ierr=NF_DEF_VAR(nid,"longitude",NF_FLOAT,1,idim_rlonv,varid)
74#endif
75if (ierr.ne.NF_NOERR) then
76  write(*,*)"iniwritesoil: Error, could not define longitude variable"
77endif
78
79! Longitude attributes
80text="East longitude"
81ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
82text="degrees_east"
83ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
84
85! Write longitude to file
86ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
87! Write
88#ifdef NC_DOUBLE
89ierr=NF_PUT_VAR_DOUBLE(nid,varid,rlonv*(180./pi))
90#else
91ierr=NF_PUT_VAR_REAL(nid,varid,rlonv*(180./pi))
92#endif
93! Note: rlonv is known from comgeom.h and pi from comcstfi.h
94if (ierr.ne.NF_NOERR) then
95  write(*,*)"iniwritesoil: Error, could not write longitude variable"
96endif
97
98! 2.2. Latitude
99ierr=NF_REDEF(nid) ! switch to NetCDF define mode
100
101! Define the variable
102#ifdef NC_DOUBLE
103ierr=NF_DEF_VAR(nid,"latitude",NF_DOUBLE,1,idim_rlatu,varid)
104#else
105ierr=NF_DEF_VAR(nid,"latitude",NF_FLOAT,1,idim_rlatu,varid)
106#endif
107if (ierr.ne.NF_NOERR) then
108  write(*,*)"iniwritesoil: Error, could not define latitude variable"
109endif
110
111! Latitude attributes
112text="North latitude"
113ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
114text="degrees_north"
115ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
116
117! Write latitude to file
118ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
119! Write
120#ifdef NC_DOUBLE
121ierr=NF_PUT_VAR_DOUBLE(nid,varid,rlatu*(180./pi))
122#else
123ierr=NF_PUT_VAR_REAL(nid,varid,rlatu*(180./pi))
124#endif
125! Note: rlatu is known from comgeom.h and pi from comcstfi.h
126if (ierr.ne.NF_NOERR) then
127  write(*,*)"iniwritesoil: Error, could not write longitude variable"
128endif
129
130! 2.3. Depth
131ierr=NF_REDEF(nid) ! switch to NetCDF define mode
132
133! Define the variable
134#ifdef NC_DOUBLE
135ierr=NF_DEF_VAR(nid,"depth",NF_DOUBLE,1,idim_depth,varid)
136#else
137ierr=NF_DEF_VAR(nid,"depth",NF_FLOAT,1,idim_depth,varid)
138#endif
139if (ierr.ne.NF_NOERR) then
140  write(*,*)"iniwritesoil: Error, could not define depth variable"
141endif
142
143! Depth attributes
144text="Soil mid-layer depth"
145ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
146text="m"
147ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
148text="down"
149ierr=NF_PUT_ATT_TEXT(nid,varid,"positive",len_trim(text),text)
150
151! Write depth to file
152ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
153! Write
154#ifdef NC_DOUBLE
155ierr=NF_PUT_VAR_DOUBLE(nid,varid,mlayer)
156#else
157ierr=NF_PUT_VAR_REAL(nid,varid,mlayer)
158#endif
159! Note mlayer(0:nsoilmx-1) known from comsoil_h
160if (ierr.ne.NF_NOERR) then
161  write(*,*)"iniwritesoil: Error, could not write depth variable"
162endif
163
164! 2.4. Time
165ierr=NF_REDEF(nid) ! switch to NetCDF define mode
166
167! Define the variable
168#ifdef NC_DOUBLE
169ierr=NF_DEF_VAR(nid,"time",NF_DOUBLE,1,idim_time,varid)
170#else
171ierr=NF_DEF_VAR(nid,"time",NF_FLOAT,1,idim_time,varid)
172#endif
173if (ierr.ne.NF_NOERR) then
174  write(*,*)"iniwritesoil: Error, could not define depth variable"
175endif
176
177! time attributes
178text="Time"
179ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
180text="days since 0000-01-01 00:00:00"
181ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
182
183ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
184! Note no need to write time variable here; it is done in writediagsoil.
185
186! 3. Other variables to be included
187
188! 3.1 mesh area surrounding each horizontal point
189ierr=NF_REDEF(nid) ! switch to NetCDF define mode
190
191! Define the variable
192dimids(1)=idim_rlonv ! ID of the 'longitude' dimension
193dimids(2)=idim_rlatu ! ID of the 'latitude' dimension
194#ifdef NC_DOUBLE
195ierr=NF_DEF_VAR(nid,"area",NF_DOUBLE,2,dimids,varid)
196#else
197ierr=NF_DEF_VAR(nid,"area",NF_FLOAT,2,dimids,varid)
198#endif
199if (ierr.ne.NF_NOERR) then
200  write(*,*)"iniwritesoil: Error, could not define area variable"
201endif
202
203! Area attributes
204text="Mesh area"
205ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
206text="m2"
207ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
208
209! Write area to file
210ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
211! Write
212#ifdef NC_DOUBLE
213ierr=NF_PUT_VAR_DOUBLE(nid,varid,aire)
214#else
215ierr=NF_PUT_VAR_REAL(nid,varid,aire)
216#endif
217! Note: aire is known from comgeom.h
218if (ierr.ne.NF_NOERR) then
219  write(*,*)"iniwritesoil: Error, could not write area variable"
220endif
221
222! 3.2 Thermal inertia
223ierr=NF_REDEF(nid) ! switch to NetCDF define mode
224
225! Define the variable
226dimids(1)=idim_rlonv ! ID of the 'longitude' dimension
227dimids(2)=idim_rlatu ! ID of the 'latitude' dimension
228dimids(3)=idim_depth ! ID of the 'depth' dimension
229#ifdef NC_DOUBLE
230ierr=NF_DEF_VAR(nid,"th_inertia",NF_DOUBLE,3,dimids,varid)
231#else
232ierr=NF_DEF_VAR(nid,"th_inertia",NF_FLOAT,3,dimids,varid)
233#endif
234if (ierr.ne.NF_NOERR) then
235  write(*,*)"iniwritesoil: Error, could not define th_inertia variable"
236endif
237
238! Attributes
239text="Thermal inertia"
240ierr=NF_PUT_ATT_TEXT(nid,varid,"long_name",len_trim(text),text)
241text="J.s-1/2.m-2.K-1"
242ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text)
243
244! Recast data along 'dynamics' grid
245! Note: inertiedat is known from comsoil_h
246
247do l=1,nsoilmx
248  ! handle the poles
249  do i=1,iip1
250    data3(i,1,l)=inertiedat(1,l)
251    data3(i,jjp1,l)=inertiedat(ngrid,l)
252  enddo
253  ! rest of the grid
254  do j=2,jjm
255    ig0=1+(j-2)*iim
256    do i=1,iim
257      data3(i,j,l)=inertiedat(ig0+i,l)
258    enddo
259    data3(iip1,j,l)=data3(1,j,l) ! extra (modulo) longitude
260  enddo
261enddo ! of do l=1,nsoilmx
262
263! Write data2 to file
264ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode
265! Write
266#ifdef NC_DOUBLE
267ierr=NF_PUT_VAR_DOUBLE(nid,varid,data3)
268#else
269ierr=NF_PUT_VAR_REAL(nid,varid,data3)
270#endif
271if (ierr.ne.NF_NOERR) then
272  write(*,*)"iniwritesoil: Error, could not write th_inertia variable"
273endif
274
275end subroutine iniwritesoil
Note: See TracBrowser for help on using the repository browser.