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

Last change on this file since 2609 was 2565, checked in by emillour, 4 years ago

Mars GCM:
Some follow-up of commit r2562; update newstart, start2archive and
testphys1d accordingly.
EM

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