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

Last change on this file since 2790 was 2630, checked in by abierjon, 4 years ago

Mars GCM:
Fix ticket #93. start2archive now correctly stores the variable albedo from
startfi.nc in the output file start_archive.nc, and newstart reads the variable
albedo in start_archive.nc before outputing it in restartfi.nc

AB+LL

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