source: trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F @ 848

Last change on this file since 848 was 787, checked in by aslmd, 12 years ago

LMDZ.GENERIC. (Sorry for long text but this is a quite major commit)

Paving the path for parallel computations. And moving towards a more flexible code.

Automatic allocation is used within all routines in phystd. No further mention to ngridmx and nqmx.

  1. ngridmx and nqmx are still used in LMDZ.GENERIC in the dyn3d part
  2. if the LMDZ4/LMDZ5 dynamical core is used, there is no more fixed dimensions ngridmx and nqmx --> a fully flexible parallel implementation is now possible (e.g. no need to recompile when changing numbers of processors)

The important stuff :

  • Compilation checked with ifort. OK with and without debug mode. No errors. Checked for: gcm, newstart, rcm1d, kcm1d
  • RUN GCM: Running an Earth test case. Comparison with previous revision --> debug mode : perfect match. bit by bit (diff command). checked with plots --> O1 mode : close match (checked with plots) --> O2 mode : sometimes up to 0.5 K departure.... BUT in this new version O2 and O1 are quite close while in previous version O1 and O2 differed by about, well, typically 0.5 K (pictures available on request)
  • RUN NEWSTART : perfect match (bit-by-bit) in either debug or normal mode.
  • RUN RCM1D : perfect match in normal mode.
  • RUN KCM1D : not tested (I don't know what is the use of kcm1d)

List of main changes :

  • Additional arguments to some subroutines (ngrid and nq)
  • F77 include strategy is obsolete and replaced by F90 module strategy In this new strategy arrays are allocatable and allocated once at first use This has to be done for all common featuring arrays defined with ngridmx or nqmx

surfdat.h >> surfdat_h.F90
tracer.h >> tracer_h.F90
comsaison.h >> comsaison_h.F90
comgeomfi.h >> comgeomfi_h.F90
comsoil.h >> comsoil_h.F90
comdiurn.h >> comdiurn_h.F90
fisice.h >> DELETED. was not used. probably a fossil.
watercap.h >> DELETED. variable put in surfdat_h.F90

  • F77 'save' strategy is obsolete and replaced by F90 'allocatable save' strategy (see previous point and e.g. new version of physiq.F90)
  • Suppressing any mention to advtrac.h which is a common in the dynamics and needs nqmx This was easily solved by adding an argument with tracer names, coming from the dynamics This is probably not a definitive solution, ... but this allows for generic physics to work easily with either LMDZ.GENERIC or LMDZ dynamical cores
  • Removing consistency tests between nq and nqmx ; and ngrid and ngridmx. No use now!
  • Adaptation of rcm1d, kcm1d, newstart given above-mentioned changes

A note on phyetat0 and soil_setting:

  • Now written so that a slice of horizontal size 'ngrid' starting at grid point 'cursor' is read in startfi.nc 'cursor' is defined in dimphys.h and initialized by inifis (or in newstart) this is useful for parallel computations. default behavior is the usual one : sequential runs, cursor is 1, size ngrid is the whole global domain

A note on an additional change :

  • nueffrad is now an argument to callcorrk as is the case for reffrad both are saved in physiq this is for consistency and lisibility (previously nueffrad was saved in callcorrk) ... but there is a call to a function which modifies nueffrad in physiq ... previously this was not modifying nueffrad (although it was quite cumbersome to detect this) ... to be conservative I kept this behaviour and highlighted it with an array nueffrad_dummy ... I added a comment because someone might want to change this
File size: 8.9 KB
Line 
1      subroutine writediagspecVI(ngrid,nom,titre,unite,dim,px)
2
3!  Ecriture de variables diagnostiques au choix dans la physique
4!  dans un fichier NetCDF nomme  'diagfi'. Ces variables peuvent etre
5!  3d (ex : temperature), 2d (ex : temperature de surface), ou
6!  0d (pour un scalaire qui ne depend que du temps : ex : la longitude
7!  solaire)
8!  Dans la version 2000, la periode d'ecriture est celle de
9!  "ecritphy " regle dans le fichier de controle de run :  run.def
10!
11!    writediagfi peut etre appele de n'importe quelle subroutine
12!    de la physique, plusieurs fois. L'initialisation et la creation du
13!    fichier se fait au tout premier appel.
14!
15! WARNING : les variables dynamique (u,v,t,q,ps)
16!  sauvees par writediagfi avec une
17! date donnee sont legerement differentes que dans le fichier histoire car
18! on ne leur a pas encore ajoute de la dissipation et de la physique !!!
19! IL est  RECOMMANDE d'ajouter les tendance physique a ces variables
20! avant l'ecriture dans diagfi (cf. physiq.F)
21
22!
23!  parametres (input) :
24!  ----------
25!      ngrid : nombres de point ou est calcule la physique
26!                (ngrid = 2+(jjm-1)*iim - 1/jjm)
27!                 (= nlon ou klon dans la physique terrestre)
28!     
29!      unit : unite logique du fichier de sortie (toujours la meme)
30!      nom  : nom de la variable a sortir (chaine de caracteres)
31!      titre: titre de la variable (chaine de caracteres)
32!      unite : unite de la variable (chaine de caracteres)
33!      px : variable a sortir (real 0, 2, ou 3d)
34!      dim : dimension de px : 0, 2, ou 3 dimensions
35!
36!=================================================================
37!
38!      This is a modified version that accepts spectrally varying input
39!      RW (2010)
40!
41!=================================================================
42 
43! Addition by RW (2010) to allow OSR to be saved in .nc format
44      use radinc_h, only : L_NSPECTV
45      USE surfdat_h
46
47      implicit none
48
49! Commons
50#include "dimensions.h"
51#include "dimphys.h"
52#include "paramet.h"
53#include "control.h"
54#include "comvert.h"
55#include "comgeom.h"
56#include "description.h"
57#include "netcdf.inc"
58#include "temps.h"
59#include "callkeys.h"
60
61! Arguments on input:
62      integer ngrid
63      character (len=*) :: nom,titre,unite
64      integer dim
65      real px(ngrid,L_NSPECTV)
66
67! Local variables:
68
69!      real dx3(iip1,jjp1,llm) ! to store a 3D data set
70!      real dx2(iip1,jjp1)     ! to store a 2D (surface) data set
71!      real dx0
72
73      real date
74
75      REAL phis(ip1jmp1)
76
77      integer irythme
78      integer ierr
79      integer iq
80      integer i,j,l,zmax , ig0
81
82      integer zitau
83      character firstnom*20
84      SAVE firstnom
85      SAVE zitau
86      SAVE date
87      data firstnom /'1234567890'/
88      data zitau /0/
89
90! Ajouts
91      integer, save :: ntime=0
92      integer :: idim,varid
93      integer :: nid
94      character (len =50):: fichnom
95      integer, dimension(4) :: id
96      integer, dimension(4) :: edges,corner
97
98! added by RDW for OSR output
99       real dx3(iip1,jjp1,L_NSPECTV) ! to store the data set
100
101
102!***************************************************************
103!Sortie des variables au rythme voulu
104
105      irythme = int(ecritphy)*iradia ! sortie au rythme de ecritphy
106!EM+JL if the spetra need to be output more frequently, need to define a ecritSpec...
107!     irythme = iphysiq  ! sortie a tous les pas physique
108
109!***************************************************************
110
111! The following test is here to enforce that writediagfi is not used with the
112! 1D version of the GCM
113!not anymore (JL12)
114      if (ngrid.eq.-1) return
115     
116c     nom=trim((nom))
117c     unite=trim((unite))
118c     titre=trim((titre))
119
120! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file
121! ------------------------------------------------------------------------
122! (Au tout premier appel de la subroutine durant le run.)
123
124      fichnom="diagspecVI.nc"
125
126      if (firstnom.eq.'1234567890') then ! .true. for the very first call
127      !  to this subroutine; now set 'firstnom'
128         firstnom = nom
129         ! just to be sure, check that firstnom is large enough to hold nom
130         if (len_trim(firstnom).lt.len_trim(nom)) then
131           write(*,*) "writediagfi: Error !!!"
132           write(*,*) "   firstnom string not long enough!!"
133           write(*,*) "   increase its size to at least ",len_trim(nom)
134           stop
135         endif
136
137         ! Create the NetCDF file
138         ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
139         ! Define the 'Time' dimension
140         ierr = nf_def_dim(nid,"Time",NF_UNLIMITED,idim)
141         ! Define the 'Time' variable
142#ifdef NC_DOUBLE
143         ierr = NF_DEF_VAR (nid, "Time", NF_DOUBLE, 1, idim,varid)
144#else
145         ierr = NF_DEF_VAR (nid, "Time", NF_FLOAT, 1, idim,varid)
146#endif
147         ! Add a long_name attribute
148         ierr = NF_PUT_ATT_TEXT (nid, varid, "long_name",
149     .          4,"Time")
150         ! Add a units attribute
151         ierr = NF_PUT_ATT_TEXT(nid, varid,'units',29,
152     .          "days since 0000-00-0 00:00:00")
153         ! Switch out of NetCDF Define mode
154         ierr = NF_ENDDEF(nid)
155
156         ! write "header" of file (longitudes, latitudes, geopotential, ...)
157         call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)
158!         call iniwrite(nid,day_ini,phis)
159         call iniwrite_specVI(nid,day_ini,phis)
160
161         zitau = -1 ! initialize zitau
162      else
163         ! Open the NetCDF file
164         ierr = NF_OPEN(fichnom,NF_WRITE,nid)
165      endif ! if (firstnom.eq.'1234567890')
166
167! Increment time index 'zitau' if it is the "firstcall" (at given time level)
168! to writediagfi
169!------------------------------------------------------------------------
170      if (nom.eq.firstnom) then
171          zitau = zitau + iphysiq
172      end if
173
174!--------------------------------------------------------
175! Write the variables to output file if it's time to do so
176!--------------------------------------------------------
177
178      if ( MOD(zitau+1,irythme) .eq.0.) then
179
180! Compute/write/extend 'Time' coordinate (date given in days)
181! (done every "first call" (at given time level) to writediagfi)
182! Note: date is incremented as 1 step ahead of physics time
183!       (like the 'histoire' outputs)
184!--------------------------------------------------------
185
186        if (nom.eq.firstnom) then
187
188        ! We have identified a "first call" (at given date)
189           ntime=ntime+1 ! increment # of stored time steps
190           ! compute corresponding date (in days and fractions thereof)
191           date= float (zitau +1)/float (day_step)
192           ! Get NetCDF ID of 'Time' variable
193           ierr= NF_INQ_VARID(nid,"Time",varid)
194
195           !print*,'in writediagfi_spec.F, time=',varid
196
197           ! Write (append) the new date to the 'Time' array
198#ifdef NC_DOUBLE
199           ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
200#else
201           ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
202#endif
203           if (ierr.ne.NF_NOERR) then
204              write(*,*) "***** PUT_VAR matter in writediagspec_nc"
205              write(*,*) "***** with time"
206              write(*,*) 'ierr=', ierr   
207c             call abort
208           endif
209
210           write(6,*)'WRITEDIAGSPEC: date= ', date
211        end if ! of if (nom.eq.firstnom)
212
213
214 
215!Case of a 3D variable
216!---------------------
217        if (dim.eq.3) then
218
219!         recast (copy) variable from physics grid to dynamics grid
220           DO l=1,L_NSPECTV
221             DO i=1,iip1
222                dx3(i,1,l)=px(1,l)
223                dx3(i,jjp1,l)=px(ngrid,l)
224             ENDDO
225             DO j=2,jjm
226                ig0= 1+(j-2)*iim
227                DO i=1,iim
228                   dx3(i,j,l)=px(ig0+i,l)
229                ENDDO
230                dx3(iip1,j,l)=dx3(1,j,l)
231             ENDDO
232           ENDDO
233
234! name of the variable
235           ierr= NF_INQ_VARID(nid,nom,varid)
236           if (ierr /= NF_NOERR) then
237! corresponding dimensions
238              ierr= NF_INQ_DIMID(nid,"longitude",id(1))
239              ierr= NF_INQ_DIMID(nid,"latitude",id(2))
240              ierr= NF_INQ_DIMID(nid,"VI Wavenumber",id(3))
241              ierr= NF_INQ_DIMID(nid,"Time",id(4))
242
243! Create the variable if it doesn't exist yet
244
245              write (*,*) "=========================="
246              write (*,*) "DIAGSPEC: creating variable ",nom
247              call def_var(nid,nom,titre,unite,4,id,varid,ierr)
248
249           endif
250
251           corner(1)=1
252           corner(2)=1
253           corner(3)=1
254           corner(4)=ntime
255
256           edges(1)=iip1
257           edges(2)=jjp1
258           edges(3)=L_NSPECTV
259           edges(4)=1
260#ifdef NC_DOUBLE
261           ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3)
262#else
263           ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3)
264#endif
265
266           if (ierr.ne.NF_NOERR) then
267              write(*,*) "***** PUT_VAR problem in writediagspec"
268              write(*,*) "***** with ",nom
269              write(*,*) 'ierr=', ierr
270             call abort
271           endif
272
273        endif ! of if (dim.eq.3) elseif(dim.eq.2)...
274
275      endif ! of if ( MOD(zitau+1,irythme) .eq.0.)
276
277      ierr= NF_CLOSE(nid)
278
279      end
Note: See TracBrowser for help on using the repository browser.