source: trunk/LMDZ.GENERIC/libf/phystd/mkstat.F90 @ 1145

Last change on this file since 1145 was 965, checked in by emillour, 12 years ago

Common dynamics and generic/universal GCM:

  • LMDZ.COMMON: minor bug fix on the computation of physics mesh area in gcm.F
  • LMDZ.UNIVERSAL: missing clean initialization of tab_cntrl(:) array in phyredem.F90
  • LMDZ.GENERIC: minor bug fix in hydrol.F90, only output runoff if it is used. Update output routines so that all outputs files (stats, diagfi.nc, diagsoil.nc, diagspecIR.nc and diagspecVI.nc) can be generated when running LMDZ.UNIVERSAL in MPI mode.

EM

File size: 4.8 KB
Line 
1subroutine mkstats(ierr)
2 
3!
4!  This program writes a stats.nc file from sums and sums of squares
5!  to means and standard deviations and also writes netcdf style
6!  file so that the data can be viewed easily.  The data file is
7!  overwritten in place. 
8!  SRL  21 May 1996
9!  Yann W. july 2003
10
11#ifdef CPP_PARA
12use mod_phys_lmdz_para, only : is_master
13#endif
14
15implicit none
16
17#include "dimensions.h"
18#include "statto.h"
19#include "netcdf.inc"
20
21integer,parameter :: iip1=iim+1
22integer,parameter :: jjp1=jjm+1
23integer :: ierr,nid,nbvar,i,ndims,lt,nvarid
24integer, dimension(4) :: id,varid,start,size
25integer, dimension(5) :: dimids
26character (len=50) :: name,nameout,units,title
27real, dimension(iip1,jjp1,llm) :: sum3d,square3d,mean3d,sd3d
28real, dimension(iip1,jjp1) :: sum2d,square2d,mean2d,sd2d
29real, dimension(istime) :: time
30real, dimension(jjp1) :: lat
31real, dimension(iip1) :: lon
32real, dimension(llm) :: alt
33logical :: lcopy=.true.
34!integer :: latid,lonid,altid,timeid
35integer :: meanid,sdid
36!integer, dimension(4) :: dimout
37#ifndef CPP_PARA
38logical,parameter :: is_master=.true.
39#endif
40
41! Incrementation of count for the last step, which is not done in wstats
42count(istime)=count(istime)+1
43
44if (is_master) then
45! only the master needs do this
46
47ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
48
49! We catch the id of dimensions of the stats file
50
51ierr= NF_INQ_DIMID(nid,"latitude",id(1))
52ierr= NF_INQ_DIMID(nid,"longitude",id(2))
53ierr= NF_INQ_DIMID(nid,"altitude",id(3))
54ierr= NF_INQ_DIMID(nid,"Time",id(4))
55
56ierr= NF_INQ_VARID(nid,"latitude",varid(1))
57ierr= NF_INQ_VARID(nid,"longitude",varid(2))
58ierr= NF_INQ_VARID(nid,"altitude",varid(3))
59ierr= NF_INQ_VARID(nid,"Time",varid(4))
60
61! Time initialisation
62
63do i=1,istime
64   time(i)=i*24./istime
65#ifdef NC_DOUBLE
66   ierr= NF_PUT_VARA_DOUBLE(nid,varid(4),i,1,time(i))
67#else
68   ierr= NF_PUT_VARA_REAL(nid,varid(4),i,1,time(i))
69#endif
70enddo
71
72! We catche the values of the variables
73
74#ifdef NC_DOUBLE
75         ierr = NF_GET_VAR_DOUBLE(nid,varid(1),lat)
76         ierr = NF_GET_VAR_DOUBLE(nid,varid(2),lon)
77         ierr = NF_GET_VAR_DOUBLE(nid,varid(3),alt)
78#else
79         ierr = NF_GET_VAR_REAL(nid,varid(1),lat)
80         ierr = NF_GET_VAR_REAL(nid,varid(2),lon)
81         ierr = NF_GET_VAR_REAL(nid,varid(3),alt)
82#endif
83
84! We catch the number of variables in the stats file
85ierr = NF_INQ_NVARS(nid,nbvar)
86
87! to catche the "real" number of variables (without the "additionnal variables")
88nbvar=(nbvar-4)/2
89
90do i=1,nbvar
91   varid=(i-1)*2+5
92
93   ! What's the variable's name?
94   ierr=NF_INQ_VARNAME(nid,varid,name)
95   write(*,*) "OK variable ",name
96   ! Its units?
97   units=" "
98   ierr=NF_GET_ATT_TEXT(nid,varid,"units",units)
99   ! Its title?
100   title=" "
101   ierr=NF_GET_ATT_TEXT(nid,varid,"title",title)
102   ! Its number of dimensions?   
103   ierr=NF_INQ_VARNDIMS(nid,varid,ndims)
104   ! Its values?
105
106   if(ndims==4) then ! lat, lon, alt & time
107
108!      dimout(1)=lonid
109!      dimout(2)=latid
110!      dimout(3)=altid
111!      dimout(4)=timeid
112
113      size=(/iip1,jjp1,llm,1/)
114      do lt=1,istime
115         start=(/1,1,1,lt/)
116         ! Extraction of the "source" variables
117#ifdef NC_DOUBLE
118         ierr = NF_GET_VARA_DOUBLE(nid,varid,start,size,sum3d)
119         ierr = NF_GET_VARA_DOUBLE(nid,varid+1,start,size,square3d)
120#else
121         ierr = NF_GET_VARA_REAL(nid,varid,start,size,sum3d)
122         ierr = NF_GET_VARA_REAL(nid,varid+1,start,size,square3d)
123#endif
124         ! Calculation of these variables
125         mean3d=sum3d/count(lt)
126         sd3d=sqrt(max(0.,square3d/count(lt)-mean3d**2))
127         ! Writing of the variables
128#ifdef NC_DOUBLE
129         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,mean3d)
130         ierr = NF_PUT_VARA_DOUBLE(nid,varid+1,start,size,sd3d)
131#else
132         ierr = NF_PUT_VARA_REAL(nid,varid,start,size,mean3d)
133         ierr = NF_PUT_VARA_REAL(nid,varid+1,start,size,sd3d)
134#endif
135      enddo
136
137    else if (ndims.eq.3) then
138
139!      dimout(1)=lonid
140!      dimout(2)=latid
141!      dimout(3)=timeid
142
143      size=(/iip1,jjp1,1,0/)
144      do lt=1,istime
145         start=(/1,1,lt,0/)
146         ! Extraction of the "source" variables
147#ifdef NC_DOUBLE
148         ierr = NF_GET_VARA_DOUBLE(nid,varid,start,size,sum2d)
149         ierr = NF_GET_VARA_DOUBLE(nid,varid+1,start,size,square2d)
150#else
151         ierr = NF_GET_VARA_REAL(nid,varid,start,size,sum2d)
152         ierr = NF_GET_VARA_REAL(nid,varid+1,start,size,square2d)
153#endif
154         ! Calculation of these variables
155         mean2d=sum2d/count(lt)
156         sd2d=sqrt(max(0.,square2d/count(lt)-mean2d**2))
157         ! Writing of the variables
158#ifdef NC_DOUBLE
159         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,mean2d)
160         ierr = NF_PUT_VARA_DOUBLE(nid,varid+1,start,size,sd2d)
161#else
162         ierr = NF_PUT_VARA_REAL(nid,varid,start,size,mean2d)
163         ierr = NF_PUT_VARA_REAL(nid,varid+1,start,size,sd2d)
164#endif
165      enddo
166
167    endif
168enddo
169
170ierr= NF_CLOSE(nid)
171
172endif ! of if (is_master)
173
174end
Note: See TracBrowser for help on using the repository browser.