source: trunk/LMDZ.MARS/libf/phymars/start2archive.F @ 1311

Last change on this file since 1311 was 1266, checked in by aslmd, 11 years ago

LMDZ.MARS
IMPORTANT CHANGE

  • Remove all reference/use of nlayermx and dimphys.h
  • Made use of automatic arrays whenever arrays are needed with dimension nlayer
  • Remove lots of obsolete reference to dimensions.h
  • Converted iono.h and param_v4.h into corresponding modules

(with embedded subroutine to allocate arrays)
(no arrays allocated if thermosphere not used)

  • Deleted param.h and put contents into module param_v4_h
  • Adapted testphys1d, newstart, etc...
  • Made DATA arrays in param_read to be initialized by subroutine

fill_data_thermos in module param_v4_h

  • Optimized computations in paramfoto_compact (twice less dlog10 calculations)
  • Checked consistency before/after modification in debug mode
  • Checked performance is not impacted (same as before)
File size: 14.7 KB
Line 
1c=======================================================================
2      PROGRAM start2archive
3c=======================================================================
4c
5c
6c   Date:    01/1997
7c   ----
8c
9c
10c   Objet:   Passage des  fichiers netcdf d'etat initial "start" et
11c   -----    "startfi" a un fichier netcdf unique "start_archive"
12c
13c  "start_archive" est une banque d'etats initiaux:
14c  On peut stocker plusieurs etats initiaux dans un meme fichier "start_archive"
15c    (Veiller dans ce cas avoir un day_ini different pour chacun des start)
16c
17c
18c
19c=======================================================================
20
21      use infotrac, only: iniadvtrac, nqtot, tname
22      use comsoil_h, only: nsoilmx, inertiedat
23      use surfdat_h, only: ini_surfdat_h, qsurf
24      use comsoil_h, only: ini_comsoil_h
25      use comgeomphy, only: initcomgeomphy
26      implicit none
27
28#include "dimensions.h"
29      integer, parameter :: ngridmx = (2+(jjm-1)*iim - 1/jjm)
30#include "paramet.h"
31#include "comconst.h"
32#include "comdissip.h"
33#include "comvert.h"
34#include "comgeom.h"
35#include "logic.h"
36#include "temps.h"
37#include "ener.h"
38#include "description.h"
39#include "netcdf.inc"
40
41c-----------------------------------------------------------------------
42c   Declarations
43c-----------------------------------------------------------------------
44
45c variables dynamiques du GCM
46c -----------------------------
47      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
48      REAL teta(ip1jmp1,llm)                    ! temperature potentielle
49      REAL,ALLOCATABLE :: q(:,:,:)   ! champs advectes
50      REAL pks(ip1jmp1)                      ! exner (f pour filtre)
51      REAL pk(ip1jmp1,llm)
52      REAL pkf(ip1jmp1,llm)
53      REAL beta(iip1,jjp1,llm)
54      REAL phis(ip1jmp1)                     ! geopotentiel au sol
55      REAL masse(ip1jmp1,llm)                ! masse de l'atmosphere
56      REAL ps(ip1jmp1)                       ! pression au sol
57      REAL p3d(iip1, jjp1, llm+1)            ! pression aux interfaces
58     
59c Variable Physiques (grille physique)
60c ------------------------------------
61      REAL tsurf(ngridmx)       ! Surface temperature
62      REAL tsoil(ngridmx,nsoilmx) ! Soil temperature
63      REAL co2ice(ngridmx)      ! CO2 ice layer
64      REAL tauscaling(ngridmx) ! dust conversion factor
65      REAL q2(ngridmx,llm+1)
66      REAL emis(ngridmx)
67      INTEGER start,length
68      PARAMETER (length = 100)
69      REAL tab_cntrl_fi(length) ! tableau des parametres de startfi
70      INTEGER*4 day_ini_fi
71
72c Variable naturelle / grille scalaire
73c ------------------------------------
74      REAL T(ip1jmp1,llm),us(ip1jmp1,llm),vs(ip1jmp1,llm)
75      REAL tsurfS(ip1jmp1)
76      REAL tsoilS(ip1jmp1,nsoilmx)
77      REAL ithS(ip1jmp1,nsoilmx) ! Soil Thermal Inertia
78      REAL co2iceS(ip1jmp1)
79      REAL tauscalingS(ip1jmp1)
80      REAL q2S(ip1jmp1,llm+1)
81      REAL,ALLOCATABLE :: qsurfS(:,:)
82      REAL emisS(ip1jmp1)
83
84c Variables intermediaires : vent naturel, mais pas coord scalaire
85c----------------------------------------------------------------
86      REAL vn(ip1jm,llm),un(ip1jmp1,llm)
87
88c Autres  variables
89c -----------------
90      LOGICAL startdrs
91      INTEGER Lmodif
92
93      REAL ptotal, co2icetotal
94      REAL timedyn,timefi !fraction du jour dans start, startfi
95      REAL date
96
97      CHARACTER*2 str2
98      CHARACTER*80 fichier
99      data  fichier /'startfi'/
100
101      INTEGER ij, l,i,j,isoil,iq
102      character*80      fichnom
103      integer :: ierr,ntime
104      integer :: nq,numvanle
105      character(len=30) :: txt ! to store some text
106
107c Netcdf
108c-------
109      integer varid,dimid,timelen
110      INTEGER nid,nid1
111
112c-----------------------------------------------------------------------
113c   Initialisations
114c-----------------------------------------------------------------------
115
116      CALL defrun_new(99, .TRUE. )
117      grireg   = .TRUE.
118! initialize "serial/parallel" related stuff
119      CALL init_phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
120      call initcomgeomphy
121
122c=======================================================================
123c Lecture des donnees
124c=======================================================================
125! Load tracer number and names:
126      call iniadvtrac(nqtot,numvanle)
127
128! allocate arrays:
129      allocate(q(ip1jmp1,llm,nqtot))
130      allocate(qsurfS(ip1jmp1,nqtot))
131      call ini_surfdat_h(ngridmx,nqtot)
132      call ini_comsoil_h(ngridmx)
133     
134
135      fichnom = 'start.nc'
136      CALL dynetat0(fichnom,nqtot,vcov,ucov,teta,q,masse,
137     .       ps,phis,timedyn)
138
139
140      fichnom = 'startfi.nc'
141      Lmodif=0
142
143      CALL phyetat0 (fichnom,0,Lmodif,nsoilmx,ngridmx,llm,nqtot,
144     &      day_ini_fi,timefi,tsurf,tsoil,emis,q2,qsurf,co2ice,
145     &      tauscaling)
146
147       ierr = NF_OPEN (fichnom, NF_NOWRITE,nid1)
148       IF (ierr.NE.NF_NOERR) THEN
149         write(6,*)' Pb d''ouverture du fichier'//fichnom
150        CALL ABORT
151       ENDIF
152                                               
153      ierr = NF_INQ_VARID (nid1, "controle", varid)
154      IF (ierr .NE. NF_NOERR) THEN
155       PRINT*, "start2archive: Le champ <controle> est absent"
156       CALL abort
157      ENDIF
158#ifdef NC_DOUBLE
159       ierr = NF_GET_VAR_DOUBLE(nid1, varid, tab_cntrl_fi)
160#else
161      ierr = NF_GET_VAR_REAL(nid1, varid, tab_cntrl_fi)
162#endif
163       IF (ierr .NE. NF_NOERR) THEN
164          PRINT*, "start2archive: Lecture echoue pour <controle>"
165          CALL abort
166       ENDIF
167
168      ierr = NF_CLOSE(nid1)
169
170c-----------------------------------------------------------------------
171c Controle de la synchro
172c-----------------------------------------------------------------------
173!mars a voir      if ((day_ini_fi.ne.day_ini).or.(abs(timefi-timedyn).gt.1.e-10))
174      if ((day_ini_fi.ne.day_ini))
175     &  stop ' Probleme de Synchro entre start et startfi !!!'
176
177
178c *****************************************************************
179c    Option : Reinitialisation des dates dans la premieres annees :
180       do while (day_ini.ge.669)
181          day_ini=day_ini-669
182       enddo
183c *****************************************************************
184
185c-----------------------------------------------------------------------
186c   Initialisations
187c-----------------------------------------------------------------------
188
189      CALL defrun_new(99, .FALSE. )
190      call iniconst
191      call inigeom
192      call inifilr
193      CALL pression(ip1jmp1, ap, bp, ps, p3d)
194      call exner_hyb(ip1jmp1, ps, p3d, beta, pks, pk, pkf)
195
196c=======================================================================
197c Transformation EN VARIABLE NATURELLE / GRILLE SCALAIRE si necessaire
198c=======================================================================
199c  Les variables modeles dependent de la resolution. Il faut donc
200c  eliminer les facteurs responsables de cette dependance
201c  (pour utiliser newstart)
202c=======================================================================
203
204c-----------------------------------------------------------------------
205c Vent   (depend de la resolution horizontale)
206c-----------------------------------------------------------------------
207c
208c ucov --> un  et  vcov --> vn
209c un --> us  et   vn --> vs
210c
211c-----------------------------------------------------------------------
212
213      call covnat(llm,ucov, vcov, un, vn)
214      call wind_scal(un,vn,us,vs)
215
216c-----------------------------------------------------------------------
217c Temperature  (depend de la resolution verticale => de "sigma.def")
218c-----------------------------------------------------------------------
219c
220c h --> T
221c
222c-----------------------------------------------------------------------
223
224      DO l=1,llm
225         DO ij=1,ip1jmp1
226            T(ij,l)=teta(ij,l)*pk(ij,l)/cpp !mars deduit de l'equation dans newstart
227         ENDDO
228      ENDDO
229
230c-----------------------------------------------------------------------
231c Variable physique
232c-----------------------------------------------------------------------
233c
234c tsurf --> tsurfS
235c co2ice --> co2iceS
236c tsoil --> tsoilS
237c emis --> emisS
238c q2 --> q2S
239c qsurf --> qsurfS
240c tauscaling --> tauscalingS
241c
242c-----------------------------------------------------------------------
243
244      call gr_fi_dyn(1,ngridmx,iip1,jjp1,tsurf,tsurfS)
245      call gr_fi_dyn(1,ngridmx,iip1,jjp1,co2ice,co2iceS)
246      call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,tsoil,tsoilS)
247      ! Note: thermal inertia "inertiedat" is in comsoil.h
248      call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,inertiedat,ithS)
249      call gr_fi_dyn(1,ngridmx,iip1,jjp1,emis,emisS)
250      call gr_fi_dyn(llm+1,ngridmx,iip1,jjp1,q2,q2S)
251      call gr_fi_dyn(nqtot,ngridmx,iip1,jjp1,qsurf,qsurfS)
252      call gr_fi_dyn(1,ngridmx,iip1,jjp1,tauscaling,tauscalingS)
253
254c=======================================================================
255c Info pour controler
256c=======================================================================
257
258      ptotal =  0.
259      co2icetotal = 0.
260      DO j=1,jjp1
261         DO i=1,iim
262           ptotal=ptotal+aire(i+(iim+1)*(j-1))*ps(i+(iim+1)*(j-1))/g
263           co2icetotal = co2icetotal +
264     &            co2iceS(i+(iim+1)*(j-1))*aire(i+(iim+1)*(j-1))
265         ENDDO
266      ENDDO
267      write(*,*)'Ancienne grille : masse de l''atm :',ptotal
268      write(*,*)'Ancienne grille : masse de la glace CO2 :',co2icetotal
269
270c-----------------------------------------------------------------------
271c Passage de "ptotal" et "co2icetotal" par tab_cntrl_fi
272c-----------------------------------------------------------------------
273
274      tab_cntrl_fi(49) = ptotal
275      tab_cntrl_fi(50) = co2icetotal
276
277c=======================================================================
278c Ecriture dans le fichier  "start_archive"
279c=======================================================================
280
281c-----------------------------------------------------------------------
282c Ouverture de "start_archive"
283c-----------------------------------------------------------------------
284
285      ierr = NF_OPEN ('start_archive.nc', NF_WRITE,nid)
286 
287c-----------------------------------------------------------------------
288c  si "start_archive" n'existe pas:
289c    1_ ouverture
290c    2_ creation de l'entete dynamique ("ini_archive")
291c-----------------------------------------------------------------------
292c ini_archive:
293c On met dans l'entete le tab_cntrl dynamique (1 a 16)
294c  On y ajoute les valeurs du tab_cntrl_fi (a partir de 51)
295c  En plus les deux valeurs ptotal et co2icetotal (99 et 100)
296c-----------------------------------------------------------------------
297
298      if (ierr.ne.NF_NOERR) then
299         write(*,*)'OK, Could not open file "start_archive.nc"'
300         write(*,*)'So let s create a new "start_archive"'
301         ierr = NF_CREATE('start_archive.nc',
302     &  IOR(NF_CLOBBER,NF_64BIT_OFFSET), nid)
303         call ini_archive(nid,day_ini,phis,ithS,tab_cntrl_fi)
304      endif
305
306c-----------------------------------------------------------------------
307c Ecriture de la coordonnee temps (date en jours)
308c-----------------------------------------------------------------------
309
310      date = day_ini + hour_ini
311      ierr= NF_INQ_VARID(nid,"Time",varid)
312      ierr= NF_INQ_DIMID(nid,"Time",dimid)
313      ierr= NF_INQ_DIMLEN(nid,dimid,timelen)
314      ntime=timelen+1
315
316      write(*,*) "******************"
317      write(*,*) "ntime",ntime
318      write(*,*) "******************"
319#ifdef NC_DOUBLE
320      ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
321#else
322      ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
323#endif
324      if (ierr.ne.NF_NOERR) then
325         write(*,*) "time matter ",NF_STRERROR(ierr)
326         stop
327      endif
328
329c-----------------------------------------------------------------------
330c Ecriture des champs  (co2ice,emis,ps,Tsurf,T,u,v,q2,q,qsurf)
331c-----------------------------------------------------------------------
332c ATTENTION: q2 a une couche de plus!!!!
333c    Pour creer un fichier netcdf lisible par grads,
334c    On passe donc une des couches de q2 a part
335c    comme une variable 2D (la couche au sol: "q2surf")
336c    Les lmm autres couches sont nommees "q2atm" (3D)
337c-----------------------------------------------------------------------
338
339      call write_archive(nid,ntime,'co2ice','couche de glace co2',
340     &  'kg/m2',2,co2iceS)
341      call write_archive(nid,ntime,'tauscaling',
342     &  'dust conversion factor',' ',2,tauscalingS)
343      call write_archive(nid,ntime,'emis','grd emis',' ',2,emisS)
344      call write_archive(nid,ntime,'ps','Psurf','Pa',2,ps)
345      call write_archive(nid,ntime,'tsurf','surf T','K',2,tsurfS)
346      call write_archive(nid,ntime,'temp','temperature','K',3,t)
347      call write_archive(nid,ntime,'u','Vent zonal','m.s-1',3,us)
348      call write_archive(nid,ntime,'v','Vent merid','m.s-1',3,vs)
349      call write_archive(nid,ntime,'q2surf','wind variance','m2.s-2',2,
350     .              q2S)
351      call write_archive(nid,ntime,'q2atm','wind variance','m2.s-2',3,
352     .              q2S(1,2))
353
354c-----------------------------------------------------------------------
355c Ecriture du champs  q  ( q[1,nqtot] )
356c-----------------------------------------------------------------------
357      do iq=1,nqtot
358c       write(str2,'(i2.2)') iq
359c        call write_archive(nid,ntime,'q'//str2,'tracer','kg/kg',
360c     .         3,q(1,1,iq))
361        call write_archive(nid,ntime,tname(iq),'tracer','kg/kg',
362     &         3,q(1,1,iq))
363      end do
364c-----------------------------------------------------------------------
365c Ecriture du champs  qsurf  ( qsurf[1,nqtot] )
366c-----------------------------------------------------------------------
367      do iq=1,nqtot
368c       write(str2,'(i2.2)') iq
369c       call write_archive(nid,ntime,'qsurf'//str2,'Tracer on surface',
370c     $  'kg.m-2',2,qsurfS(1,iq))
371        txt=trim(tname(iq))//"_surf"
372        call write_archive(nid,ntime,txt,'Tracer on surface',
373     &  'kg.m-2',2,qsurfS(1,iq))
374      enddo
375
376
377c-----------------------------------------------------------------------
378c Ecriture du champs  tsoil  ( Tg[1,10] )
379c-----------------------------------------------------------------------
380c "tsoil" Temperature au sol definie dans 10 couches dans le sol
381c   Les 10 couches sont lues comme 10 champs
382c  nommees Tg[1,10]
383
384c      do isoil=1,nsoilmx
385c       write(str2,'(i2.2)') isoil
386c       call write_archive(nid,ntime,'Tg'//str2,'Ground Temperature ',
387c     .   'K',2,tsoilS(1,isoil))
388c      enddo
389
390! Write soil temperatures tsoil
391      call write_archive(nid,ntime,'tsoil','Soil temperature',
392     &     'K',-3,tsoilS)
393
394! Write soil thermal inertia
395      call write_archive(nid,ntime,'inertiedat',
396     &     'Soil thermal inertia',
397     &     'J.s-1/2.m-2.K-1',-3,ithS)
398
399! Write (0D) volumetric heat capacity (stored in comsoil.h)
400!      call write_archive(nid,ntime,'volcapa',
401!     &     'Soil volumetric heat capacity',
402!     &     'J.m-3.K-1',0,volcapa)
403! Note: no need to write volcapa, it is stored in "controle" table
404
405      ierr=NF_CLOSE(nid)
406c-----------------------------------------------------------------------
407c Fin
408c-----------------------------------------------------------------------
409
410      write(*,*) "startarchive: all is well that ends well"
411     
412      end
Note: See TracBrowser for help on using the repository browser.