source: trunk/LMDZ.GENERIC/libf/dyn3d/newstart.F @ 671

Last change on this file since 671 was 649, checked in by jleconte, 13 years ago
  • Correction a huge bug in newstart: rcp and cpp can now be changed in start.nc files and are the same as in startfi.nc;

Even when starting from start and startfi files.

  • rcp, cpp and mugaz can now be computed using gases.def in newstart
  • Correction of a bug arising in gcm.F when the solar days are long (thanks Melanie V.)
File size: 65.2 KB
Line 
1C======================================================================
2      PROGRAM newstart
3c=======================================================================
4c
5c
6c   Auteur:   Christophe Hourdin/Francois Forget/Yann Wanherdrick
7c   ------
8c             Derniere modif : 12/03
9c
10c
11c   Objet:  Create or modify the initial state for the LMD Mars GCM
12c   -----           (fichiers NetCDF start et startfi)
13c
14c
15c=======================================================================
16
17      implicit none
18
19#include "dimensions.h"
20#include "dimphys.h"
21#include "surfdat.h"
22#include "comsoil.h"
23#include "planete.h"
24#include "paramet.h"
25#include "comconst.h"
26#include "comvert.h"
27#include "comgeom2.h"
28#include "control.h"
29#include "logic.h"
30#include "description.h"
31#include "ener.h"
32#include "temps.h"
33#include "lmdstd.h"
34#include "comdissnew.h"
35#include "clesph0.h"
36#include "serre.h"
37#include "netcdf.inc"
38#include "advtrac.h"
39#include "tracer.h"
40c=======================================================================
41c   Declarations
42c=======================================================================
43
44c Variables dimension du fichier "start_archive"
45c------------------------------------
46      CHARACTER relief*3
47
48
49c Variables pour les lectures NetCDF des fichiers "start_archive"
50c--------------------------------------------------
51      INTEGER nid_dyn, nid_fi,nid,nvarid
52      INTEGER length
53      parameter (length = 100)
54      INTEGER tab0
55      INTEGER   NB_ETATMAX
56      parameter (NB_ETATMAX = 100)
57
58      REAL  date
59      REAL p_rad,p_omeg,p_g,p_cpp,p_mugaz,p_daysec
60
61c Variable histoire
62c------------------
63      REAL vcov(iip1,jjm,llm),ucov(iip1,jjp1,llm) ! vents covariants
64      REAL phis(iip1,jjp1)
65      REAL q(iip1,jjp1,llm,nqmx)               ! champs advectes
66
67c autre variables dynamique nouvelle grille
68c------------------------------------------
69      REAL pks(iip1,jjp1)
70      REAL w(iip1,jjp1,llm+1)
71      REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
72!      REAL dv(ip1jm,llm),du(ip1jmp1,llm)
73!      REAL dh(ip1jmp1,llm),dp(ip1jmp1)
74      REAL phi(iip1,jjp1,llm)
75
76      integer klatdat,klongdat
77      PARAMETER (klatdat=180,klongdat=360)
78
79c Physique sur grille scalaire
80c----------------------------
81      real zmeaS(iip1,jjp1),zstdS(iip1,jjp1)
82      real zsigS(iip1,jjp1),zgamS(iip1,jjp1),ztheS(iip1,jjp1)
83
84c variable physique
85c------------------
86      REAL tsurf(ngridmx)       ! surface temperature
87      REAL tsoil(ngridmx,nsoilmx) ! soil temperature
88!      REAL co2ice(ngridmx)     ! CO2 ice layer
89      REAL emis(ngridmx)        ! surface emissivity
90      real emisread             ! added by RW
91      REAL qsurf(ngridmx,nqmx)
92      REAL q2(ngridmx,nlayermx+1)
93!      REAL rnaturfi(ngridmx)
94      real alb(iip1,jjp1),albfi(ngridmx) ! albedos
95      real ith(iip1,jjp1,nsoilmx),ithfi(ngridmx,nsoilmx) ! thermal inertia (3D)
96      real surfith(iip1,jjp1),surfithfi(ngridmx) ! surface thermal inertia (2D)
97      REAL latfi(ngridmx),lonfi(ngridmx),airefi(ngridmx)
98
99      INTEGER i,j,l,isoil,ig,idum
100      real mugaz ! molar mass of the atmosphere
101
102      integer ierr
103
104c Variables on the new grid along scalar points
105c------------------------------------------------------
106!      REAL p(iip1,jjp1)
107      REAL t(iip1,jjp1,llm)
108      REAL tset(iip1,jjp1,llm)
109      real phisold_newgrid(iip1,jjp1)
110      REAL :: teta(iip1, jjp1, llm)
111      REAL :: pk(iip1,jjp1,llm)
112      REAL :: pkf(iip1,jjp1,llm)
113      REAL :: ps(iip1, jjp1)
114      REAL :: masse(iip1,jjp1,llm)
115      REAL :: xpn,xps,xppn(iim),xpps(iim)
116      REAL :: p3d(iip1, jjp1, llm+1)
117      REAL :: beta(iip1,jjp1,llm)
118!      REAL dteta(ip1jmp1,llm)
119
120c Variable de l'ancienne grille
121c------------------------------
122      real time
123      real tab_cntrl(100)
124      real tab_cntrl_bis(100)
125
126c variables diverses
127c-------------------
128      real choix_1,pp
129      character*80      fichnom
130      integer Lmodif,iq,thermo
131      character modif*20
132      real z_reel(iip1,jjp1)
133      real tsud,albsud,alb_bb,ith_bb,Tiso,Tabove
134      real ptoto,pcap,patm,airetot,ptotn,patmn,psea
135!      real ssum
136      character*1 yes
137      logical :: flagtset=.false. ,  flagps0=.false.
138      real val, val2, val3 ! to store temporary variables
139      real :: iceith=2000 ! thermal inertia of subterranean ice
140      integer iref,jref
141
142      INTEGER :: itau
143     
144      INTEGER :: nq,numvanle
145      character(len=20) :: txt ! to store some text
146      integer :: count
147
148! MONS data:
149      real :: MONS_Hdn(iip1,jjp1) ! Hdn: %WEH=Mass fraction of H2O
150      real :: MONS_d21(iip1,jjp1) ! ice table "depth" (in kg/m2)
151      ! coefficient to apply to convert d21 to 'true' depth (m)
152      real :: MONS_coeff
153      real :: MONS_coeffS ! coeff for southern hemisphere
154      real :: MONS_coeffN ! coeff for northern hemisphere
155!      real,parameter :: icedepthmin=1.e-3 ! Ice begins at most at that depth
156
157!     added by RW for test
158      real pmean, phi0
159
160!     added by BC for equilibrium temperature startup
161      real teque
162
163!     added by BC for cloud fraction setup
164      REAL hice(ngridmx),cloudfrac(ngridmx,nlayermx)
165      REAL totalfrac(ngridmx)
166
167!     added by RW for nuketharsis
168      real fact1
169      real fact2
170
171
172c sortie visu pour les champs dynamiques
173c---------------------------------------
174!      INTEGER :: visuid
175!      real :: time_step,t_ops,t_wrt
176!      CHARACTER*80 :: visu_file
177
178      cpp    = 0.
179      preff  = 0.
180      pa     = 0. ! to ensure disaster rather than minor error if we don`t
181                  ! make deliberate choice of these values elsewhere.
182
183c=======================================================================
184c   Choice of the start file(s) to use
185c=======================================================================
186
187      write(*,*) 'From which kind of files do you want to create new',
188     .  'start and startfi files'
189      write(*,*) '    0 - from a file start_archive'
190      write(*,*) '    1 - from files start and startfi'
191 
192c-----------------------------------------------------------------------
193c   Open file(s) to modify (start or start_archive)
194c-----------------------------------------------------------------------
195
196      DO
197         read(*,*,iostat=ierr) choix_1
198         if ((choix_1 /= 0).OR.(choix_1 /=1)) EXIT
199      ENDDO
200
201c     Open start_archive
202c     ~~~~~~~~~~~~~~~~~~~~~~~~~~
203      if (choix_1.eq.0) then
204
205        write(*,*) 'Creating start files from:'
206        write(*,*) './start_archive.nc'
207        write(*,*)
208        fichnom = 'start_archive.nc'
209        ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
210        IF (ierr.NE.NF_NOERR) THEN
211          write(6,*)' Problem opening file:',fichnom
212          write(6,*)' ierr = ', ierr
213          CALL ABORT
214        ENDIF
215        tab0 = 50
216        Lmodif = 1
217
218c     OR open start and startfi files
219c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220      else
221        write(*,*) 'Creating start files from:'
222        write(*,*) './start.nc and ./startfi.nc'
223        write(*,*)
224        fichnom = 'start.nc'
225        ierr = NF_OPEN (fichnom, NF_NOWRITE,nid_dyn)
226        IF (ierr.NE.NF_NOERR) THEN
227          write(6,*)' Problem opening file:',fichnom
228          write(6,*)' ierr = ', ierr
229          CALL ABORT
230        ENDIF
231 
232        fichnom = 'startfi.nc'
233        ierr = NF_OPEN (fichnom, NF_NOWRITE,nid_fi)
234        IF (ierr.NE.NF_NOERR) THEN
235          write(6,*)' Problem opening file:',fichnom
236          write(6,*)' ierr = ', ierr
237          CALL ABORT
238        ENDIF
239
240        tab0 = 0
241        Lmodif = 0
242
243      endif
244
245
246c=======================================================================
247c  INITIALISATIONS DIVERSES
248c=======================================================================
249! Load tracer names:
250      call iniadvtrac(nq,numvanle)
251      ! tnom(:) now contains tracer names
252! JL12 we will need the tracer names to read start in dyneta0
253
254c-----------------------------------------------------------------------
255c Lecture du tableau des parametres du run (pour la dynamique)
256c-----------------------------------------------------------------------
257
258      if (choix_1.eq.0) then
259
260        write(*,*) 'reading tab_cntrl START_ARCHIVE'
261c
262        ierr = NF_INQ_VARID (nid, "controle", nvarid)
263#ifdef NC_DOUBLE
264        ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tab_cntrl)
265#else
266        ierr = NF_GET_VAR_REAL(nid, nvarid, tab_cntrl)
267#endif
268c
269      else if (choix_1.eq.1) then
270
271        write(*,*) 'reading tab_cntrl START'
272c
273        ierr = NF_INQ_VARID (nid_dyn, "controle", nvarid)
274#ifdef NC_DOUBLE
275        ierr = NF_GET_VAR_DOUBLE(nid_dyn, nvarid, tab_cntrl)
276#else
277        ierr = NF_GET_VAR_REAL(nid_dyn, nvarid, tab_cntrl)
278#endif
279c
280        write(*,*) 'reading tab_cntrl STARTFI'
281c
282        ierr = NF_INQ_VARID (nid_fi, "controle", nvarid)
283#ifdef NC_DOUBLE
284        ierr = NF_GET_VAR_DOUBLE(nid_fi, nvarid, tab_cntrl_bis)
285#else
286        ierr = NF_GET_VAR_REAL(nid_fi, nvarid, tab_cntrl_bis)
287#endif
288c
289        do i=1,50
290          tab_cntrl(i+50)=tab_cntrl_bis(i)
291        enddo
292        write(*,*) 'printing tab_cntrl', tab_cntrl
293        do i=1,100
294          write(*,*) i,tab_cntrl(i)
295        enddo
296       
297        ! Lmodif set to 0 to disable modifications possibility in phyeta0                           
298        write(*,*) 'Reading file START'
299        fichnom = 'start.nc'
300        CALL dynetat0(fichnom,nqmx,vcov,ucov,teta,q,masse,
301     .       ps,phis,time)
302
303        write(*,*) 'Reading file STARTFI'
304        fichnom = 'startfi.nc'
305        CALL phyetat0 (fichnom,tab0,Lmodif,nsoilmx,nqmx,
306     .        day_ini,time,
307     .        tsurf,tsoil,emis,q2,qsurf,   !) ! temporary modif by RDW
308     .        cloudfrac,totalfrac,hice)
309
310        ! copy albedo and soil thermal inertia
311        do i=1,ngridmx
312          albfi(i) = albedodat(i)
313          do j=1,nsoilmx
314           ithfi(i,j) = inertiedat(i,j)
315          enddo
316        ! build a surfithfi(:) using 1st layer of ithfi(:), which might
317        ! be neede later on if reinitializing soil thermal inertia
318          surfithfi(i)=ithfi(i,1)
319        enddo
320
321     
322      endif
323c-----------------------------------------------------------------------
324c               Initialisation des constantes dynamique
325c-----------------------------------------------------------------------
326
327      kappa = tab_cntrl(9)
328      etot0 = tab_cntrl(12)
329      ptot0 = tab_cntrl(13)
330      ztot0 = tab_cntrl(14)
331      stot0 = tab_cntrl(15)
332      ang0 = tab_cntrl(16)
333      write(*,*) "Newstart: kappa,etot0,ptot0,ztot0,stot0,ang0"
334      write(*,*) kappa,etot0,ptot0,ztot0,stot0,ang0
335
336      ! for vertical coordinate
337      preff=tab_cntrl(18) ! reference surface pressure
338      pa=tab_cntrl(17)  ! reference pressure at which coord is purely pressure
339      !NB: in start_archive files tab_cntrl(17)=tab_cntrl(18)=0
340      write(*,*) "Newstart: preff=",preff," pa=",pa
341      yes=' '
342      do while ((yes.ne.'y').and.(yes.ne.'n'))
343        write(*,*) "Change the values of preff and pa? (y/n)"
344        read(*,fmt='(a)') yes
345      end do
346      if (yes.eq.'y') then
347        write(*,*)"New value of reference surface pressure preff?"
348        write(*,*)"   (for Mars, typically preff=610)"
349        read(*,*) preff
350        write(*,*)"New value of reference pressure pa for purely"
351        write(*,*)"pressure levels (for hybrid coordinates)?"
352        write(*,*)"   (for Mars, typically pa=20)"
353        read(*,*) pa
354      endif
355c-----------------------------------------------------------------------
356c   Lecture du tab_cntrl et initialisation des constantes physiques
357c  - pour start:  Lmodif = 0 => pas de modifications possibles
358c                  (modif dans le tabfi de readfi + loin)
359c  - pour start_archive:  Lmodif = 1 => modifications possibles
360c-----------------------------------------------------------------------
361      if (choix_1.eq.0) then
362         call tabfi (nid,Lmodif,tab0,day_ini,lllm,p_rad,
363     .            p_omeg,p_g,p_cpp,p_mugaz,p_daysec,time)
364      else if (choix_1.eq.1) then
365         Lmodif=1 ! Lmodif set to 1 to allow modifications in phyeta0                           
366         call tabfi (nid_fi,Lmodif,tab0,day_ini,lllm,p_rad,
367     .            p_omeg,p_g,p_cpp,p_mugaz,p_daysec,time)
368      endif
369
370      rad = p_rad
371      omeg = p_omeg
372      g = p_g
373      cpp = p_cpp
374      mugaz = p_mugaz
375      daysec = p_daysec
376
377      kappa = 8.314*1000./(p_mugaz*p_cpp) ! added by RDW
378
379
380c=======================================================================
381c  INITIALISATIONS DIVERSES
382c=======================================================================
383! Initialize global tracer indexes (stored in tracer.h)
384      call initracer()
385! Load parameters from run.def file
386      CALL defrun_new( 99, .TRUE. )
387      CALL iniconst
388      CALL inigeom
389      idum=-1
390      idum=0
391
392c Initialisation coordonnees /aires
393c -------------------------------
394! Note: rlatu(:) and rlonv(:) are commons defined in "comgeom.h"
395!       rlatu() and rlonv() are given in radians
396      latfi(1)=rlatu(1)
397      lonfi(1)=0.
398      DO j=2,jjm
399         DO i=1,iim
400            latfi((j-2)*iim+1+i)=rlatu(j)
401            lonfi((j-2)*iim+1+i)=rlonv(i)
402         ENDDO
403      ENDDO
404      latfi(ngridmx)=rlatu(jjp1)
405      lonfi(ngridmx)=0.
406      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
407
408c=======================================================================
409c   lecture topographie, albedo, inertie thermique, relief sous-maille
410c=======================================================================
411
412      if (choix_1.ne.1) then  ! pour ne pas avoir besoin du fichier
413                              ! surface.dat dans le cas des start
414
415c do while((relief(1:3).ne.'mol').AND.(relief(1:3).ne.'pla'))
416c       write(*,*)
417c       write(*,*) 'choix du relief (mola,pla)'
418c       write(*,*) '(Topographie MGS MOLA, plat)'
419c       read(*,fmt='(a3)') relief
420        relief="mola"
421c     enddo
422
423      CALL datareadnc(relief,phis,alb,surfith,zmeaS,zstdS,zsigS,zgamS,
424     .          ztheS)
425
426      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
427      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,surfith,surfithfi)
428      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
429      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,zmeaS,zmea)
430      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,zstdS,zstd)
431      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,zsigS,zsig)
432      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,zgamS,zgam)
433      CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,ztheS,zthe)
434
435      endif ! of if (choix_1.ne.1)
436
437
438c=======================================================================
439c  Lecture des fichiers (start ou start_archive)
440c=======================================================================
441
442      if (choix_1.eq.0) then
443
444        write(*,*) 'Reading file START_ARCHIVE'
445        CALL lect_start_archive(date,tsurf,tsoil,emis,q2,
446     .   t,ucov,vcov,ps,teta,phisold_newgrid,q,qsurf,
447     &   surfith,nid)
448        write(*,*) "OK, read start_archive file"
449        ! copy soil thermal inertia
450        ithfi(:,:)=inertiedat(:,:)
451       
452        ierr= NF_CLOSE(nid)
453
454      else if (choix_1.eq.1) then
455         !do nothing, start and startfi have already been read
456      else
457        CALL exit(1)
458      endif
459
460      dtvr   = daysec/FLOAT(day_step)
461      dtphys   = dtvr * FLOAT(iphysiq)
462
463c=======================================================================
464c
465c=======================================================================
466
467      do ! infinite loop on list of changes
468
469      write(*,*)
470      write(*,*)
471      write(*,*) 'List of possible changes :'
472      write(*,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
473      write(*,*)
474      write(*,*) 'flat : no topography ("aquaplanet")'
475      write(*,*) 'nuketharsis : no Tharsis bulge'
476      write(*,*) 'bilball : uniform albedo and thermal inertia'
477      write(*,*) 'coldspole : cold subsurface and high albedo at S.pole'
478      write(*,*) 'qname : change tracer name'
479      write(*,*) 'q=0 : ALL tracer =zero'
480      write(*,*) 'q=x : give a specific uniform value to one tracer'
481      write(*,*) 'ini_q : tracers initialisation for chemistry, water an
482     $d ice   '
483      write(*,*) 'ini_q-H2O : tracers initialisation for chemistry and
484     $ice '
485      write(*,*) 'ini_q-iceH2O : tracers initialisation for chemistry on
486     $ly '
487      write(*,*) 'noglacier : Remove tropical H2O ice if |lat|<45'
488      write(*,*) 'watercapn : H20 ice on permanent N polar cap '
489      write(*,*) 'watercaps : H20 ice on permanent S polar cap '
490      write(*,*) 'noacglac  : H2O ice across Noachis Terra'
491      write(*,*) 'oborealis : H2O ice across Vastitas Borealis'
492      write(*,*) 'iceball   : Thick ice layer all over surface'
493      write(*,*) 'wetstart  : start with a wet atmosphere'
494      write(*,*) 'isotherm  : Isothermal Temperatures, wind set to zero'
495      write(*,*) 'radequi   : Earth-like radiative equilibrium temperature
496     $ profile (lat-alt) and winds set to zero'
497      write(*,*) 'coldstart : Start X K above the CO2 frost point and
498     $set wind to zero (assumes 100% CO2)'
499      write(*,*) 'co2ice=0 : remove CO2 polar cap'
500      write(*,*) 'ptot : change total pressure'
501      write(*,*) 'emis : change surface emissivity'
502      write(*,*) 'therm_ini_s : Set soil thermal inertia to reference sur
503     &face values'
504!      write(*,*) 'subsoilice_n : Put deep underground ice layer in northe
505!     &rn hemisphere'
506!      write(*,*) 'subsoilice_s : Put deep underground ice layer in southe
507!     &rn hemisphere'
508!      write(*,*) 'mons_ice : Put underground ice layer according to MONS-
509!     &derived data'
510
511        write(*,*)
512        write(*,*) 'Change to perform ?'
513        write(*,*) '   (enter keyword or return to end)'
514        write(*,*)
515
516        read(*,fmt='(a20)') modif
517        if (modif(1:1) .eq. ' ') exit ! exit loop on changes
518
519        write(*,*)
520        write(*,*) trim(modif) , ' : '
521
522c       'flat : no topography ("aquaplanet")'
523c       -------------------------------------
524        if (modif(1:len_trim(modif)) .eq. 'flat') then
525c         set topo to zero
526          CALL initial0(ip1jmp1,z_reel)
527          CALL multscal(ip1jmp1,z_reel,g,phis)
528          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
529          write(*,*) 'topography set to zero.'
530          write(*,*) 'WARNING : the subgrid topography parameters',
531     &    ' were not set to zero ! => set calllott to F'                   
532
533c        Choice of surface pressure
534         yes=' '
535         do while ((yes.ne.'y').and.(yes.ne.'n'))
536            write(*,*) 'Do you wish to choose homogeneous surface',
537     &                 'pressure (y) or let newstart interpolate ',
538     &                 ' the previous field  (n)?'
539             read(*,fmt='(a)') yes
540         end do
541         if (yes.eq.'y') then
542           flagps0=.true.
543           write(*,*) 'New value for ps (Pa) ?'
544 201       read(*,*,iostat=ierr) patm
545            if(ierr.ne.0) goto 201
546             write(*,*)
547             write(*,*) ' new ps everywhere (Pa) = ', patm
548             write(*,*)
549             do j=1,jjp1
550               do i=1,iip1
551                 ps(i,j)=patm
552               enddo
553             enddo
554         end if
555
556c       'nuketharsis : no tharsis bulge for Early Mars'
557c       ---------------------------------------------
558        else if (modif(1:len_trim(modif)) .eq. 'nuketharsis') then
559
560           DO j=1,jjp1       
561              DO i=1,iim
562                 ig=1+(j-2)*iim +i
563                 if(j.eq.1) ig=1
564                 if(j.eq.jjp1) ig=ngridmx
565
566                 fact1=(((rlonv(i)*180./pi)+100)**2 +
567     &                (rlatu(j)*180./pi)**2)/65**2
568                 fact2=exp( -fact1**2.5 )
569
570                 phis(i,j) = phis(i,j) - (phis(i,j)+4000.*g)*fact2
571
572!                 if(phis(i,j).gt.2500.*g)then
573!                    if(rlatu(j)*180./pi.gt.-80.)then ! avoid chopping south polar cap
574!                       phis(i,j)=2500.*g
575!                    endif
576!                 endif
577
578              ENDDO
579           ENDDO
580          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
581
582
583c       bilball : uniform albedo, thermal inertia
584c       -----------------------------------------
585        else if (modif(1:len_trim(modif)) .eq. 'bilball') then
586          write(*,*) 'constante albedo and iner.therm:'
587          write(*,*) 'New value for albedo (ex: 0.25) ?'
588 101      read(*,*,iostat=ierr) alb_bb
589          if(ierr.ne.0) goto 101
590          write(*,*)
591          write(*,*) ' uniform albedo (new value):',alb_bb
592          write(*,*)
593
594          write(*,*) 'New value for thermal inertia (eg: 247) ?'
595 102      read(*,*,iostat=ierr) ith_bb
596          if(ierr.ne.0) goto 102
597          write(*,*) 'uniform thermal inertia (new value):',ith_bb
598          DO j=1,jjp1
599             DO i=1,iip1
600                alb(i,j) = alb_bb       ! albedo
601                do isoil=1,nsoilmx
602                  ith(i,j,isoil) = ith_bb       ! thermal inertia
603                enddo
604             END DO
605          END DO
606!          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,ith,ithfi)
607          CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
608          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
609
610c       coldspole : sous-sol de la calotte sud toujours froid
611c       -----------------------------------------------------
612        else if (modif(1:len_trim(modif)) .eq. 'coldspole') then
613          write(*,*)'new value for the subsurface temperature',
614     &   ' beneath the permanent southern polar cap ? (eg: 141 K)'
615 103      read(*,*,iostat=ierr) tsud
616          if(ierr.ne.0) goto 103
617          write(*,*)
618          write(*,*) ' new value of the subsurface temperature:',tsud
619c         nouvelle temperature sous la calotte permanente
620          do l=2,nsoilmx
621               tsoil(ngridmx,l) =  tsud
622          end do
623
624
625          write(*,*)'new value for the albedo',
626     &   'of the permanent southern polar cap ? (eg: 0.75)'
627 104      read(*,*,iostat=ierr) albsud
628          if(ierr.ne.0) goto 104
629          write(*,*)
630
631c         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
632c         Option 1:  only the albedo of the pole is modified :   
633          albfi(ngridmx)=albsud
634          write(*,*) 'ig=',ngridmx,'   albedo perennial cap ',
635     &    albfi(ngridmx)
636
637c         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
638c          Option 2 A haute resolution : coordonnee de la vrai calotte ~   
639c           DO j=1,jjp1
640c             DO i=1,iip1
641c                ig=1+(j-2)*iim +i
642c                if(j.eq.1) ig=1
643c                if(j.eq.jjp1) ig=ngridmx
644c                if ((rlatu(j)*180./pi.lt.-84.).and.
645c     &            (rlatu(j)*180./pi.gt.-91.).and.
646c     &            (rlonv(i)*180./pi.gt.-91.).and.
647c     &            (rlonv(i)*180./pi.lt.0.))         then
648cc    albedo de la calotte permanente fixe a albsud
649c                   alb(i,j)=albsud
650c                   write(*,*) 'lat=',rlatu(j)*180./pi,
651c     &                      ' lon=',rlonv(i)*180./pi
652cc     fin de la condition sur les limites de la calotte permanente
653c                end if
654c             ENDDO
655c          ENDDO
656c      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
657
658c         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
659
660
661c       ptot : Modification of the total pressure: ice + current atmosphere
662c       -------------------------------------------------------------------
663        else if (modif(1:len_trim(modif)).eq.'ptot') then
664
665          ! check if we have a co2_ice surface tracer:
666          if (igcm_co2_ice.eq.0) then
667            write(*,*) " No surface CO2 ice !"
668            write(*,*) " only atmospheric pressure will be considered!"
669          endif
670c         calcul de la pression totale glace + atm actuelle
671          patm=0.
672          airetot=0.
673          pcap=0.
674          DO j=1,jjp1
675             DO i=1,iim
676                ig=1+(j-2)*iim +i
677                if(j.eq.1) ig=1
678                if(j.eq.jjp1) ig=ngridmx
679                patm = patm + ps(i,j)*aire(i,j)
680                airetot= airetot + aire(i,j)
681                if (igcm_co2_ice.ne.0) then
682                  !pcap = pcap + aire(i,j)*co2ice(ig)*g
683                  pcap = pcap + aire(i,j)*qsurf(ig,igcm_co2_ice)*g
684                endif
685             ENDDO
686          ENDDO
687          ptoto = pcap + patm
688
689          print*,'Current total pressure at surface (co2 ice + atm) ',
690     &       ptoto/airetot
691
692          print*,'new value?'
693          read(*,*) ptotn
694          ptotn=ptotn*airetot
695          patmn=ptotn-pcap
696          print*,'ptoto,patm,ptotn,patmn'
697          print*,ptoto,patm,ptotn,patmn
698          print*,'Mult. factor for pressure (atm only)', patmn/patm
699          do j=1,jjp1
700             do i=1,iip1
701                ps(i,j)=ps(i,j)*patmn/patm
702             enddo
703          enddo
704
705
706
707c        Correction pour la conservation des traceurs
708         yes=' '
709         do while ((yes.ne.'y').and.(yes.ne.'n'))
710            write(*,*) 'Do you wish to conserve tracer total mass (y)',
711     &              ' or tracer mixing ratio (n) ?'
712             read(*,fmt='(a)') yes
713         end do
714
715         if (yes.eq.'y') then
716           write(*,*) 'OK : conservation of tracer total mass'
717           DO iq =1, nqmx
718             DO l=1,llm
719               DO j=1,jjp1
720                  DO i=1,iip1
721                    q(i,j,l,iq)=q(i,j,l,iq)*patm/patmn
722                  ENDDO
723               ENDDO
724             ENDDO
725           ENDDO
726          else
727            write(*,*) 'OK : conservation of tracer mixing ratio'
728          end if
729
730c        Correction pour la pression au niveau de la mer
731         yes=' '
732         do while ((yes.ne.'y').and.(yes.ne.'n'))
733            write(*,*) 'Do you wish fix pressure at sea level (y)',
734     &              ' or not (n) ?'
735             read(*,fmt='(a)') yes
736         end do
737
738         if (yes.eq.'y') then
739           write(*,*) 'Value?'
740                read(*,*,iostat=ierr) psea
741             DO i=1,iip1
742               DO j=1,jjp1
743                    ps(i,j)=psea
744
745                  ENDDO
746               ENDDO
747                write(*,*) 'psea=',psea
748          else
749            write(*,*) 'no'
750          end if
751
752
753c       emis : change surface emissivity (added by RW)
754c       ----------------------------------------------
755        else if (trim(modif).eq.'emis') then
756
757           print*,'new value?'
758           read(*,*) emisread
759
760           do i=1,ngridmx
761              emis(i)=emisread
762           enddo
763
764c       qname : change tracer name
765c       --------------------------
766        else if (trim(modif).eq.'qname') then
767         yes='y'
768         do while (yes.eq.'y')
769          write(*,*) 'Which tracer name do you want to change ?'
770          do iq=1,nqmx
771            write(*,'(i3,a3,a20)')iq,' : ',trim(tnom(iq))
772          enddo
773          write(*,'(a35,i3)')
774     &            '(enter tracer number; between 1 and ',nqmx
775          write(*,*)' or any other value to quit this option)'
776          read(*,*) iq
777          if ((iq.ge.1).and.(iq.le.nqmx)) then
778            write(*,*)'Change tracer name ',trim(tnom(iq)),' to ?'
779            read(*,*) txt
780            tnom(iq)=txt
781            write(*,*)'Do you want to change another tracer name (y/n)?'
782            read(*,'(a)') yes
783          else
784! inapropiate value of iq; quit this option
785            yes='n'
786          endif ! of if ((iq.ge.1).and.(iq.le.nqmx))
787         enddo ! of do while (yes.ne.'y')
788
789c       q=0 : set tracers to zero
790c       -------------------------
791        else if (modif(1:len_trim(modif)).eq.'q=0') then
792c          mise a 0 des q (traceurs)
793          write(*,*) 'Tracers set to 0 (1.E-30 in fact)'
794           DO iq =1, nqmx
795             DO l=1,llm
796               DO j=1,jjp1
797                  DO i=1,iip1
798                    q(i,j,l,iq)=1.e-30
799                  ENDDO
800               ENDDO
801             ENDDO
802           ENDDO
803
804c          set surface tracers to zero
805           DO iq =1, nqmx
806             DO ig=1,ngridmx
807                 qsurf(ig,iq)=0.
808             ENDDO
809           ENDDO
810
811c       q=x : initialise tracer manually
812c       --------------------------------
813        else if (modif(1:len_trim(modif)).eq.'q=x') then
814             write(*,*) 'Which tracer do you want to modify ?'
815             do iq=1,nqmx
816               write(*,*)iq,' : ',trim(tnom(iq))
817             enddo
818             write(*,*) '(choose between 1 and ',nqmx,')'
819             read(*,*) iq
820             write(*,*)'mixing ratio of tracer ',trim(tnom(iq)),
821     &                 ' ? (kg/kg)'
822             read(*,*) val
823             DO l=1,llm
824               DO j=1,jjp1
825                  DO i=1,iip1
826                    q(i,j,l,iq)=val
827                  ENDDO
828               ENDDO
829             ENDDO
830             write(*,*) 'SURFACE value of tracer ',trim(tnom(iq)),
831     &                   ' ? (kg/m2)'
832             read(*,*) val
833             DO ig=1,ngridmx
834                 qsurf(ig,iq)=val
835             ENDDO
836
837c       ini_q : Initialize tracers for chemistry
838c       -----------------------------------------------
839        else if (modif(1:len_trim(modif)) .eq. 'ini_q') then
840c         For more than 32 layers, possible to initiate thermosphere only     
841          thermo=0
842          yes=' '
843          if (llm.gt.32) then
844            do while ((yes.ne.'y').and.(yes.ne.'n'))
845            write(*,*)'',
846     &     'initialisation for thermosphere only? (y/n)'
847            read(*,fmt='(a)') yes
848            if (yes.eq.'y') then
849            thermo=1
850            else
851            thermo=0
852            endif
853            enddo 
854          endif
855         
856c             call inichim_newstart(q,ps,sig,nqmx,latfi,lonfi,airefi,
857c    $   thermo,qsurf)
858          write(*,*) 'Chemical species initialized'
859
860        if (thermo.eq.0) then
861c          mise a 0 des qsurf (traceurs a la surface)
862           DO iq =1, nqmx
863             DO ig=1,ngridmx
864                 qsurf(ig,iq)=0.
865             ENDDO
866           ENDDO
867        endif   
868
869c       ini_q-H2O : as above except for the water vapour tracer
870c       ------------------------------------------------------
871        else if (modif(1:len_trim(modif)) .eq. 'ini_q-H2O') then
872          ! for more than 32 layers, possible to initiate thermosphere only     
873          thermo=0
874          yes=' '
875          if(llm.gt.32) then
876            do while ((yes.ne.'y').and.(yes.ne.'n'))
877            write(*,*)'',
878     &      'initialisation for thermosphere only? (y/n)'
879            read(*,fmt='(a)') yes
880            if (yes.eq.'y') then
881            thermo=1
882            else
883            thermo=0
884            endif
885            enddo
886          endif
887c             call inichim_newstart(q,ps,sig,nqmx-1,latfi,lonfi,airefi,
888c    $   thermo,qsurf)
889c         write(*,*) 'Initialized chem. species exept last (H2O)'
890
891        if (thermo.eq.0) then
892c          set surface tracers to zero, except water ice
893           DO iq =1, nqmx
894            if (iq.ne.igcm_h2o_ice) then
895             DO ig=1,ngridmx
896                 qsurf(ig,iq)=0.
897             ENDDO
898            endif
899           ENDDO
900        endif
901
902c       ini_q-iceH2O : as above exept for ice et H2O
903c       -----------------------------------------------
904        else if (modif(1:len_trim(modif)) .eq. 'ini_q-iceH2O') then
905c         For more than 32 layers, possible to initiate thermosphere only     
906          thermo=0
907          yes=' '
908          if(llm.gt.32) then
909            do while ((yes.ne.'y').and.(yes.ne.'n'))
910            write(*,*)'',
911     &      'initialisation for thermosphere only? (y/n)'
912            read(*,fmt='(a)') yes
913            if (yes.eq.'y') then
914            thermo=1
915            else
916            thermo=0
917            endif
918            enddo
919          endif
920     
921c        call inichim_newstart(q,ps,sig,nqmx-2,latfi,lonfi,airefi,
922c    $   thermo,qsurf)
923c         write(*,*) 'Initialized chem. species exept ice and H2O'
924
925        if (thermo.eq.0) then
926c          set surface tracers to zero, except water ice
927           DO iq =1, nqmx
928            if (iq.ne.igcm_h2o_ice) then
929             DO ig=1,ngridmx
930                 qsurf(ig,iq)=0.
931             ENDDO
932            endif
933           ENDDO
934        endif
935
936c      wetstart : wet atmosphere with a north to south gradient
937c      --------------------------------------------------------
938       else if (modif(1:len_trim(modif)) .eq. 'wetstart') then
939        ! check that there is indeed a water vapor tracer
940        if (igcm_h2o_vap.eq.0) then
941          write(*,*) "No water vapour tracer! Can't use this option"
942          stop
943        endif
944          DO l=1,llm
945            DO j=1,jjp1
946              DO i=1,iip1
947                q(i,j,l,igcm_h2o_vap)=150.e-6 * (rlatu(j)+pi/2.) / pi
948              ENDDO
949            ENDDO
950          ENDDO
951
952         write(*,*) 'Water mass mixing ratio at north pole='
953     *               ,q(1,1,1,igcm_h2o_vap)
954         write(*,*) '---------------------------south pole='
955     *               ,q(1,jjp1,1,igcm_h2o_vap)
956
957c      noglacier : remove tropical water ice (to initialize high res sim)
958c      --------------------------------------------------
959        else if (modif(1:len_trim(modif)) .eq. 'noglacier') then
960           if (igcm_h2o_ice.eq.0) then
961             write(*,*) "No water ice tracer! Can't use this option"
962             stop
963           endif
964           do ig=1,ngridmx
965             j=(ig-2)/iim +2
966              if(ig.eq.1) j=1
967              write(*,*) 'OK: remove surface ice for |lat|<45'
968              if (abs(rlatu(j)*180./pi).lt.45.) then
969                   qsurf(ig,igcm_h2o_ice)=0.
970              end if
971           end do
972
973
974c      watercapn : H20 ice on permanent northern cap
975c      --------------------------------------------------
976        else if (modif(1:len_trim(modif)) .eq. 'watercapn') then
977           if (igcm_h2o_ice.eq.0) then
978             write(*,*) "No water ice tracer! Can't use this option"
979             stop
980           endif
981
982           DO j=1,jjp1       
983              DO i=1,iim
984                 ig=1+(j-2)*iim +i
985                 if(j.eq.1) ig=1
986                 if(j.eq.jjp1) ig=ngridmx
987
988                 if (rlatu(j)*180./pi.gt.80.) then
989                    qsurf(ig,igcm_h2o_ice)=3.4e3
990                    !do isoil=1,nsoilmx
991                    !   ith(i,j,isoil) = 18000. ! thermal inertia
992                    !enddo
993                   write(*,*)'     ==> Ice mesh North boundary (deg)= ',
994     &                   rlatv(j-1)*180./pi
995                 end if
996              ENDDO
997           ENDDO
998           CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
999
1000c$$$           do ig=1,ngridmx
1001c$$$             j=(ig-2)/iim +2
1002c$$$              if(ig.eq.1) j=1
1003c$$$              if (rlatu(j)*180./pi.gt.80.) then
1004c$$$
1005c$$$                   qsurf(ig,igcm_h2o_ice)=1.e5
1006c$$$                   qsurf(ig,igcm_h2o_vap)=0.0!1.e5
1007c$$$
1008c$$$                   write(*,*) 'ig=',ig,'    H2O ice mass (kg/m2)= ',
1009c$$$     &              qsurf(ig,igcm_h2o_ice)
1010c$$$
1011c$$$                   write(*,*)'     ==> Ice mesh South boundary (deg)= ',
1012c$$$     &              rlatv(j)*180./pi
1013c$$$                end if
1014c$$$           enddo
1015
1016c      watercaps : H20 ice on permanent southern cap
1017c      -------------------------------------------------
1018        else if (modif(1:len_trim(modif)) .eq. 'watercaps') then
1019           if (igcm_h2o_ice.eq.0) then
1020              write(*,*) "No water ice tracer! Can't use this option"
1021              stop
1022           endif
1023
1024           DO j=1,jjp1       
1025              DO i=1,iim
1026                 ig=1+(j-2)*iim +i
1027                 if(j.eq.1) ig=1
1028                 if(j.eq.jjp1) ig=ngridmx
1029
1030                 if (rlatu(j)*180./pi.lt.-80.) then
1031                    qsurf(ig,igcm_h2o_ice)=3.4e3
1032                    !do isoil=1,nsoilmx
1033                    !   ith(i,j,isoil) = 18000. ! thermal inertia
1034                    !enddo
1035                   write(*,*)'     ==> Ice mesh South boundary (deg)= ',
1036     &                   rlatv(j-1)*180./pi
1037                 end if
1038              ENDDO
1039           ENDDO
1040           CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1041
1042c$$$           do ig=1,ngridmx
1043c$$$               j=(ig-2)/iim +2
1044c$$$               if(ig.eq.1) j=1
1045c$$$               if (rlatu(j)*180./pi.lt.-80.) then
1046c$$$                  qsurf(ig,igcm_h2o_ice)=1.e5
1047c$$$                  qsurf(ig,igcm_h2o_vap)=0.0 !1.e5
1048c$$$
1049c$$$                  write(*,*) 'ig=',ig,'   H2O ice mass (kg/m2)= ',
1050c$$$     &                 qsurf(ig,igcm_h2o_ice)
1051c$$$                  write(*,*)'     ==> Ice mesh North boundary (deg)= ',
1052c$$$     &                 rlatv(j-1)*180./pi
1053c$$$               end if
1054c$$$           enddo
1055
1056
1057c       noacglac : H2O ice across highest terrain
1058c       --------------------------------------------
1059        else if (modif(1:len_trim(modif)) .eq. 'noacglac') then
1060           if (igcm_h2o_ice.eq.0) then
1061             write(*,*) "No water ice tracer! Can't use this option"
1062             stop
1063           endif
1064          DO j=1,jjp1       
1065             DO i=1,iim
1066                ig=1+(j-2)*iim +i
1067                if(j.eq.1) ig=1
1068                if(j.eq.jjp1) ig=ngridmx
1069
1070                if(phis(i,j).gt.1000.*g)then
1071                    alb(i,j) = 0.5 ! snow value
1072                    do isoil=1,nsoilmx
1073                       ith(i,j,isoil) = 18000. ! thermal inertia
1074                       ! this leads to rnat set to 'ocean' in physiq.F90
1075                       ! actually no, because it is soil not surface
1076                    enddo
1077                endif
1078             ENDDO
1079          ENDDO
1080          CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1081          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
1082          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
1083
1084
1085
1086c       oborealis : H2O oceans across Vastitas Borealis
1087c       -----------------------------------------------
1088        else if (modif(1:len_trim(modif)) .eq. 'oborealis') then
1089           if (igcm_h2o_ice.eq.0) then
1090             write(*,*) "No water ice tracer! Can't use this option"
1091             stop
1092           endif
1093          DO j=1,jjp1       
1094             DO i=1,iim
1095                ig=1+(j-2)*iim +i
1096                if(j.eq.1) ig=1
1097                if(j.eq.jjp1) ig=ngridmx
1098
1099                if(phis(i,j).lt.-4000.*g)then
1100!                if( (phis(i,j).lt.-4000.*g)
1101!     &               .and. (rlatu(j)*180./pi.lt.0.) )then ! south hemisphere only
1102!                    phis(i,j)=-8000.0*g ! proper ocean
1103                    phis(i,j)=-4000.0*g ! scanty ocean
1104
1105                    alb(i,j) = 0.07 ! oceanic value
1106                    do isoil=1,nsoilmx
1107                       ith(i,j,isoil) = 18000. ! thermal inertia
1108                       ! this leads to rnat set to 'ocean' in physiq.F90
1109                       ! actually no, because it is soil not surface
1110                    enddo
1111                endif
1112             ENDDO
1113          ENDDO
1114          CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1115          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
1116          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
1117
1118c       iborealis : H2O ice in Northern plains
1119c       --------------------------------------
1120        else if (modif(1:len_trim(modif)) .eq. 'iborealis') then
1121           if (igcm_h2o_ice.eq.0) then
1122             write(*,*) "No water ice tracer! Can't use this option"
1123             stop
1124           endif
1125          DO j=1,jjp1       
1126             DO i=1,iim
1127                ig=1+(j-2)*iim +i
1128                if(j.eq.1) ig=1
1129                if(j.eq.jjp1) ig=ngridmx
1130
1131                if(phis(i,j).lt.-4000.*g)then
1132                   !qsurf(ig,igcm_h2o_ice)=1.e3
1133                   qsurf(ig,igcm_h2o_ice)=241.4 ! to make total 33 kg m^-2
1134                endif
1135             ENDDO
1136          ENDDO
1137          CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1138          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
1139          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
1140
1141
1142c       oceanball : H2O liquid everywhere
1143c       ----------------------------
1144        else if (modif(1:len_trim(modif)) .eq. 'oceanball') then
1145           if (igcm_h2o_ice.eq.0) then
1146             write(*,*) "No water ice tracer! Can't use this option"
1147             stop
1148           endif
1149          DO j=1,jjp1       
1150             DO i=1,iim
1151                ig=1+(j-2)*iim +i
1152                if(j.eq.1) ig=1
1153                if(j.eq.jjp1) ig=ngridmx
1154
1155                qsurf(ig,igcm_h2o_vap)=0.0    ! for ocean, this is infinite source
1156                qsurf(ig,igcm_h2o_ice)=0.0
1157                alb(i,j) = 0.07 ! ocean value
1158
1159                do isoil=1,nsoilmx
1160                   ith(i,j,isoil) = 18000. ! thermal inertia
1161                   !ith(i,j,isoil) = 50. ! extremely low for test
1162                   ! this leads to rnat set to 'ocean' in physiq.F90
1163                enddo
1164
1165             ENDDO
1166          ENDDO
1167          CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1168          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
1169          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,phis,phisfi)
1170
1171c       iceball : H2O ice everywhere
1172c       ----------------------------
1173        else if (modif(1:len_trim(modif)) .eq. 'iceball') then
1174           if (igcm_h2o_ice.eq.0) then
1175             write(*,*) "No water ice tracer! Can't use this option"
1176             stop
1177           endif
1178          DO j=1,jjp1       
1179             DO i=1,iim
1180                ig=1+(j-2)*iim +i
1181                if(j.eq.1) ig=1
1182                if(j.eq.jjp1) ig=ngridmx
1183
1184                qsurf(ig,igcm_h2o_vap)=-50.    ! for ocean, this is infinite source
1185                qsurf(ig,igcm_h2o_ice)=50.     ! == to 0.05 m of oceanic ice
1186                alb(i,j) = 0.6 ! ice albedo value
1187
1188                do isoil=1,nsoilmx
1189                   !ith(i,j,isoil) = 18000. ! thermal inertia
1190                   ! this leads to rnat set to 'ocean' in physiq.F90
1191                enddo
1192
1193             ENDDO
1194          ENDDO
1195          CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1196          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,alb,albfi)
1197
1198c       isotherm : Isothermal temperatures and no winds
1199c       -----------------------------------------------
1200        else if (modif(1:len_trim(modif)) .eq. 'isotherm') then
1201
1202          write(*,*)'Isothermal temperature of the atmosphere,
1203     &           surface and subsurface'
1204          write(*,*) 'Value of this temperature ? :'
1205 203      read(*,*,iostat=ierr) Tiso
1206          if(ierr.ne.0) goto 203
1207
1208          do ig=1, ngridmx
1209            tsurf(ig) = Tiso
1210          end do
1211          do l=2,nsoilmx
1212            do ig=1, ngridmx
1213              tsoil(ig,l) = Tiso
1214            end do
1215          end do
1216          DO j=1,jjp1
1217           DO i=1,iim
1218            Do l=1,llm
1219               Tset(i,j,l)=Tiso
1220            end do
1221           end do
1222          end do
1223          flagtset=.true.
1224          call initial0(llm*ip1jmp1,ucov)
1225          call initial0(llm*ip1jm,vcov)
1226          call initial0(ngridmx*(llm+1),q2)
1227
1228c       radequi : Radiative equilibrium profile of temperatures and no winds
1229c       --------------------------------------------------------------------
1230        else if (modif(1:len_trim(modif)) .eq. 'radequi') then
1231
1232          write(*,*)'radiative equilibrium temperature profile'       
1233
1234          do ig=1, ngridmx
1235             teque= 335.0-60.0*sin(latfi(ig))*sin(latfi(ig))-
1236     &            10.0*cos(latfi(ig))*cos(latfi(ig))
1237             tsurf(ig) = MAX(220.0,teque)
1238          end do
1239          do l=2,nsoilmx
1240             do ig=1, ngridmx
1241                tsoil(ig,l) = tsurf(ig)
1242             end do
1243          end do
1244          DO j=1,jjp1
1245             DO i=1,iim
1246                Do l=1,llm
1247                   teque=335.-60.0*sin(rlatu(j))*sin(rlatu(j))-
1248     &                  10.0*cos(rlatu(j))*cos(rlatu(j))
1249                   Tset(i,j,l)=MAX(220.0,teque)
1250                end do
1251             end do
1252          end do
1253          flagtset=.true.
1254          call initial0(llm*ip1jmp1,ucov)
1255          call initial0(llm*ip1jm,vcov)
1256          call initial0(ngridmx*(llm+1),q2)
1257
1258c       coldstart : T set 1K above CO2 frost point and no winds
1259c       ------------------------------------------------
1260        else if (modif(1:len_trim(modif)) .eq. 'coldstart') then
1261
1262          write(*,*)'set temperature of the atmosphere,'
1263     &,'surface and subsurface how many degrees above CO2 frost point?'
1264 204      read(*,*,iostat=ierr) Tabove
1265          if(ierr.ne.0) goto 204
1266
1267            DO j=1,jjp1
1268             DO i=1,iim
1269                ig=1+(j-2)*iim +i
1270                if(j.eq.1) ig=1
1271                if(j.eq.jjp1) ig=ngridmx
1272            tsurf(ig) = (-3167.8)/(log(.01*ps(i,j))-23.23)+Tabove
1273             END DO
1274            END DO
1275          do l=1,nsoilmx
1276            do ig=1, ngridmx
1277              tsoil(ig,l) = tsurf(ig)
1278            end do
1279          end do
1280          DO j=1,jjp1
1281           DO i=1,iim
1282            Do l=1,llm
1283               pp = aps(l) +bps(l)*ps(i,j)
1284               Tset(i,j,l)=(-3167.8)/(log(.01*pp)-23.23)+Tabove
1285            end do
1286           end do
1287          end do
1288
1289          flagtset=.true.
1290          call initial0(llm*ip1jmp1,ucov)
1291          call initial0(llm*ip1jm,vcov)
1292          call initial0(ngridmx*(llm+1),q2)
1293
1294
1295c       co2ice=0 : remove CO2 polar ice caps'
1296c       ------------------------------------------------
1297        else if (modif(1:len_trim(modif)) .eq. 'co2ice=0') then
1298         ! check that there is indeed a co2_ice tracer ...
1299          if (igcm_co2_ice.ne.0) then
1300           do ig=1,ngridmx
1301              !co2ice(ig)=0
1302              qsurf(ig,igcm_co2_ice)=0
1303              emis(ig)=emis(ngridmx/2)
1304           end do
1305          else
1306            write(*,*) "Can't remove CO2 ice!! (no co2_ice tracer)"
1307          endif
1308       
1309!       therm_ini_s: (re)-set soil thermal inertia to reference surface values
1310!       ----------------------------------------------------------------------
1311
1312        else if (modif(1:len_trim(modif)).eq.'therm_ini_s') then
1313!          write(*,*)"surfithfi(1):",surfithfi(1)
1314          do isoil=1,nsoilmx
1315            inertiedat(1:ngridmx,isoil)=surfithfi(1:ngridmx)
1316          enddo
1317          write(*,*)'OK: Soil thermal inertia has been reset to referenc
1318     &e surface values'
1319!         write(*,*)"inertiedat(1,1):",inertiedat(1,1)
1320          ithfi(:,:)=inertiedat(:,:)
1321         ! recast ithfi() onto ith()
1322         call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,ithfi,ith)
1323! Check:
1324!         do i=1,iip1
1325!           do j=1,jjp1
1326!             do isoil=1,nsoilmx
1327!               write(77,*) i,j,isoil,"  ",ith(i,j,isoil)
1328!             enddo
1329!           enddo
1330!        enddo
1331
1332
1333
1334
1335c$$$!       subsoilice_n: Put deep ice layer in northern hemisphere soil
1336c$$$!       ------------------------------------------------------------
1337c$$$
1338c$$$    else if (modif(1:len_trim(modif)).eq.'subsoilice_n') then
1339c$$$
1340c$$$         write(*,*)'From which latitude (in deg.), up to the north pole,
1341c$$$     &should we put subterranean ice?'
1342c$$$     ierr=1
1343c$$$     do while (ierr.ne.0)
1344c$$$      read(*,*,iostat=ierr) val
1345c$$$      if (ierr.eq.0) then ! got a value
1346c$$$        ! do a sanity check
1347c$$$        if((val.lt.0.).or.(val.gt.90)) then
1348c$$$          write(*,*)'Latitude should be between 0 and 90 deg. !!!'
1349c$$$          ierr=1
1350c$$$        else ! find corresponding jref (nearest latitude)
1351c$$$          ! note: rlatu(:) contains decreasing values of latitude
1352c$$$          !       starting from PI/2 to -PI/2
1353c$$$          do j=1,jjp1
1354c$$$            if ((rlatu(j)*180./pi.ge.val).and.
1355c$$$     &              (rlatu(j+1)*180./pi.le.val)) then
1356c$$$              ! find which grid point is nearest to val:
1357c$$$              if (abs(rlatu(j)*180./pi-val).le.
1358c$$$     &                abs((rlatu(j+1)*180./pi-val))) then
1359c$$$               jref=j
1360c$$$              else
1361c$$$               jref=j+1
1362c$$$              endif
1363c$$$             
1364c$$$             write(*,*)'Will use nearest grid latitude which is:',
1365c$$$     &                     rlatu(jref)*180./pi
1366c$$$            endif
1367c$$$          enddo ! of do j=1,jjp1
1368c$$$        endif ! of if((val.lt.0.).or.(val.gt.90))
1369c$$$      endif !of if (ierr.eq.0)
1370c$$$     enddo ! of do while
1371c$$$
1372c$$$         ! Build layers() (as in soil_settings.F)
1373c$$$     val2=sqrt(mlayer(0)*mlayer(1))
1374c$$$     val3=mlayer(1)/mlayer(0)
1375c$$$     do isoil=1,nsoilmx
1376c$$$       layer(isoil)=val2*(val3**(isoil-1))
1377c$$$     enddo
1378c$$$
1379c$$$         write(*,*)'At which depth (in m.) does the ice layer begin?'
1380c$$$         write(*,*)'(currently, the deepest soil layer extends down to:'
1381c$$$     &              ,layer(nsoilmx),')'
1382c$$$     ierr=1
1383c$$$     do while (ierr.ne.0)
1384c$$$      read(*,*,iostat=ierr) val2
1385c$$$!     write(*,*)'val2:',val2,'ierr=',ierr
1386c$$$      if (ierr.eq.0) then ! got a value, but do a sanity check
1387c$$$        if(val2.gt.layer(nsoilmx)) then
1388c$$$          write(*,*)'Depth should be less than ',layer(nsoilmx)
1389c$$$          ierr=1
1390c$$$        endif
1391c$$$        if(val2.lt.layer(1)) then
1392c$$$          write(*,*)'Depth should be more than ',layer(1)
1393c$$$          ierr=1
1394c$$$        endif
1395c$$$      endif
1396c$$$         enddo ! of do while
1397c$$$     
1398c$$$     ! find the reference index iref the depth corresponds to
1399c$$$!    if (val2.lt.layer(1)) then
1400c$$$!     iref=1
1401c$$$!    else
1402c$$$      do isoil=1,nsoilmx-1
1403c$$$       if((val2.gt.layer(isoil)).and.(val2.lt.layer(isoil+1)))
1404c$$$     &       then
1405c$$$         iref=isoil
1406c$$$         exit
1407c$$$       endif
1408c$$$      enddo
1409c$$$!    endif
1410c$$$     
1411c$$$!    write(*,*)'iref:',iref,'  jref:',jref
1412c$$$!    write(*,*)'layer',layer
1413c$$$!    write(*,*)'mlayer',mlayer
1414c$$$         
1415c$$$     ! thermal inertia of the ice:
1416c$$$     ierr=1
1417c$$$     do while (ierr.ne.0)
1418c$$$          write(*,*)'What is the value of subterranean ice thermal inert
1419c$$$     &ia? (e.g.: 2000)'
1420c$$$          read(*,*,iostat=ierr)iceith
1421c$$$     enddo ! of do while
1422c$$$     
1423c$$$     ! recast ithfi() onto ith()
1424c$$$     call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,ithfi,ith)
1425c$$$     
1426c$$$     do j=1,jref
1427c$$$!       write(*,*)'j:',j,'rlatu(j)*180./pi:',rlatu(j)*180./pi
1428c$$$        do i=1,iip1 ! loop on longitudes
1429c$$$         ! Build "equivalent" thermal inertia for the mixed layer
1430c$$$         ith(i,j,iref+1)=sqrt((layer(iref+1)-layer(iref))/
1431c$$$     &                     (((val2-layer(iref))/(ith(i,j,iref)**2))+
1432c$$$     &                      ((layer(iref+1)-val2)/(iceith)**2)))
1433c$$$         ! Set thermal inertia of lower layers
1434c$$$         do isoil=iref+2,nsoilmx
1435c$$$          ith(i,j,isoil)=iceith ! ice
1436c$$$         enddo
1437c$$$        enddo ! of do i=1,iip1
1438c$$$     enddo ! of do j=1,jjp1
1439c$$$     
1440c$$$
1441c$$$     CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1442c$$$
1443c$$$!         do i=1,nsoilmx
1444c$$$!     write(*,*)'i:',i,'ithfi(1,i):',ithfi(1,i)
1445c$$$!    enddo
1446
1447       
1448c$$$!       subsoilice_s: Put deep ice layer in southern hemisphere soil
1449c$$$!       ------------------------------------------------------------
1450c$$$
1451c$$$    else if (modif(1:len_trim(modif)).eq.'subsoilice_s') then
1452c$$$
1453c$$$         write(*,*)'From which latitude (in deg.), down to the south pol
1454c$$$     &e, should we put subterranean ice?'
1455c$$$     ierr=1
1456c$$$     do while (ierr.ne.0)
1457c$$$      read(*,*,iostat=ierr) val
1458c$$$      if (ierr.eq.0) then ! got a value
1459c$$$        ! do a sanity check
1460c$$$        if((val.gt.0.).or.(val.lt.-90)) then
1461c$$$          write(*,*)'Latitude should be between 0 and -90 deg. !!!'
1462c$$$          ierr=1
1463c$$$        else ! find corresponding jref (nearest latitude)
1464c$$$          ! note: rlatu(:) contains decreasing values of latitude
1465c$$$          !       starting from PI/2 to -PI/2
1466c$$$          do j=1,jjp1
1467c$$$            if ((rlatu(j)*180./pi.ge.val).and.
1468c$$$     &              (rlatu(j+1)*180./pi.le.val)) then
1469c$$$              ! find which grid point is nearest to val:
1470c$$$              if (abs(rlatu(j)*180./pi-val).le.
1471c$$$     &                abs((rlatu(j+1)*180./pi-val))) then
1472c$$$               jref=j
1473c$$$              else
1474c$$$               jref=j+1
1475c$$$              endif
1476c$$$             
1477c$$$             write(*,*)'Will use nearest grid latitude which is:',
1478c$$$     &                     rlatu(jref)*180./pi
1479c$$$            endif
1480c$$$          enddo ! of do j=1,jjp1
1481c$$$        endif ! of if((val.lt.0.).or.(val.gt.90))
1482c$$$      endif !of if (ierr.eq.0)
1483c$$$     enddo ! of do while
1484c$$$
1485c$$$         ! Build layers() (as in soil_settings.F)
1486c$$$     val2=sqrt(mlayer(0)*mlayer(1))
1487c$$$     val3=mlayer(1)/mlayer(0)
1488c$$$     do isoil=1,nsoilmx
1489c$$$       layer(isoil)=val2*(val3**(isoil-1))
1490c$$$     enddo
1491c$$$
1492c$$$         write(*,*)'At which depth (in m.) does the ice layer begin?'
1493c$$$         write(*,*)'(currently, the deepest soil layer extends down to:'
1494c$$$     &              ,layer(nsoilmx),')'
1495c$$$     ierr=1
1496c$$$     do while (ierr.ne.0)
1497c$$$      read(*,*,iostat=ierr) val2
1498c$$$!     write(*,*)'val2:',val2,'ierr=',ierr
1499c$$$      if (ierr.eq.0) then ! got a value, but do a sanity check
1500c$$$        if(val2.gt.layer(nsoilmx)) then
1501c$$$          write(*,*)'Depth should be less than ',layer(nsoilmx)
1502c$$$          ierr=1
1503c$$$        endif
1504c$$$        if(val2.lt.layer(1)) then
1505c$$$          write(*,*)'Depth should be more than ',layer(1)
1506c$$$          ierr=1
1507c$$$        endif
1508c$$$      endif
1509c$$$         enddo ! of do while
1510c$$$     
1511c$$$     ! find the reference index iref the depth corresponds to
1512c$$$      do isoil=1,nsoilmx-1
1513c$$$       if((val2.gt.layer(isoil)).and.(val2.lt.layer(isoil+1)))
1514c$$$     &       then
1515c$$$         iref=isoil
1516c$$$         exit
1517c$$$       endif
1518c$$$      enddo
1519c$$$     
1520c$$$!    write(*,*)'iref:',iref,'  jref:',jref
1521c$$$         
1522c$$$     ! thermal inertia of the ice:
1523c$$$     ierr=1
1524c$$$     do while (ierr.ne.0)
1525c$$$          write(*,*)'What is the value of subterranean ice thermal inert
1526c$$$     &ia? (e.g.: 2000)'
1527c$$$          read(*,*,iostat=ierr)iceith
1528c$$$     enddo ! of do while
1529c$$$     
1530c$$$     ! recast ithfi() onto ith()
1531c$$$     call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,ithfi,ith)
1532c$$$     
1533c$$$     do j=jref,jjp1
1534c$$$!       write(*,*)'j:',j,'rlatu(j)*180./pi:',rlatu(j)*180./pi
1535c$$$        do i=1,iip1 ! loop on longitudes
1536c$$$         ! Build "equivalent" thermal inertia for the mixed layer
1537c$$$         ith(i,j,iref+1)=sqrt((layer(iref+1)-layer(iref))/
1538c$$$     &                     (((val2-layer(iref))/(ith(i,j,iref)**2))+
1539c$$$     &                      ((layer(iref+1)-val2)/(iceith)**2)))
1540c$$$         ! Set thermal inertia of lower layers
1541c$$$         do isoil=iref+2,nsoilmx
1542c$$$          ith(i,j,isoil)=iceith ! ice
1543c$$$         enddo
1544c$$$        enddo ! of do i=1,iip1
1545c$$$     enddo ! of do j=jref,jjp1
1546c$$$     
1547c$$$
1548c$$$     CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1549
1550
1551c$$$c       'mons_ice' : use MONS data to build subsurface ice table
1552c$$$c       --------------------------------------------------------
1553c$$$        else if (modif(1:len_trim(modif)).eq.'mons_ice') then
1554c$$$       
1555c$$$       ! 1. Load MONS data
1556c$$$        call load_MONS_data(MONS_Hdn,MONS_d21)
1557c$$$       
1558c$$$        ! 2. Get parameters from user
1559c$$$        ierr=1
1560c$$$    do while (ierr.ne.0)
1561c$$$          write(*,*) "Coefficient to apply to MONS 'depth' in Northern",
1562c$$$     &               " Hemisphere?"
1563c$$$          write(*,*) " (should be somewhere between 3.2e-4 and 1.3e-3)"
1564c$$$          read(*,*,iostat=ierr) MONS_coeffN
1565c$$$        enddo
1566c$$$        ierr=1
1567c$$$    do while (ierr.ne.0)
1568c$$$          write(*,*) "Coefficient to apply to MONS 'depth' in Southern",
1569c$$$     &               " Hemisphere?"
1570c$$$          write(*,*) " (should be somewhere between 3.2e-4 and 1.3e-3)"
1571c$$$          read(*,*,iostat=ierr) MONS_coeffS
1572c$$$        enddo
1573c$$$        ierr=1
1574c$$$        do while (ierr.ne.0)
1575c$$$          write(*,*) "Value of subterranean ice thermal inertia?"
1576c$$$          write(*,*) " (e.g.: 2000, or perhaps 2290)"
1577c$$$          read(*,*,iostat=ierr) iceith
1578c$$$        enddo
1579c$$$       
1580c$$$        ! 3. Build subterranean thermal inertia
1581c$$$       
1582c$$$        ! initialise subsurface inertia with reference surface values
1583c$$$        do isoil=1,nsoilmx
1584c$$$          ithfi(1:ngridmx,isoil)=surfithfi(1:ngridmx)
1585c$$$        enddo
1586c$$$        ! recast ithfi() onto ith()
1587c$$$    call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,ithfi,ith)
1588c$$$       
1589c$$$        do i=1,iip1 ! loop on longitudes
1590c$$$          do j=1,jjp1 ! loop on latitudes
1591c$$$            ! set MONS_coeff
1592c$$$            if (rlatu(j).ge.0) then ! northern hemisphere
1593c$$$              ! N.B: rlatu(:) contains decreasing values of latitude
1594c$$$          !       starting from PI/2 to -PI/2
1595c$$$              MONS_coeff=MONS_coeffN
1596c$$$            else ! southern hemisphere
1597c$$$              MONS_coeff=MONS_coeffS
1598c$$$            endif
1599c$$$            ! check if we should put subterranean ice
1600c$$$            if (MONS_Hdn(i,j).ge.14.0) then ! no ice if Hdn<14%
1601c$$$              ! compute depth at which ice lies:
1602c$$$              val=MONS_d21(i,j)*MONS_coeff
1603c$$$              ! compute val2= the diurnal skin depth of surface inertia
1604c$$$              ! assuming a volumetric heat cap. of C=1.e6 J.m-3.K-1
1605c$$$              val2=ith(i,j,1)*1.e-6*sqrt(88775./3.14159)
1606c$$$              if (val.lt.val2) then
1607c$$$                ! ice must be below the (surface inertia) diurnal skin depth
1608c$$$                val=val2
1609c$$$              endif
1610c$$$              if (val.lt.layer(nsoilmx)) then ! subterranean ice
1611c$$$                ! find the reference index iref that depth corresponds to
1612c$$$                iref=0
1613c$$$                do isoil=1,nsoilmx-1
1614c$$$                 if ((val.ge.layer(isoil)).and.(val.lt.layer(isoil+1)))
1615c$$$     &             then
1616c$$$               iref=isoil
1617c$$$               exit
1618c$$$             endif
1619c$$$                enddo
1620c$$$                ! Build "equivalent" thermal inertia for the mixed layer
1621c$$$                ith(i,j,iref+1)=sqrt((layer(iref+1)-layer(iref))/
1622c$$$     &                     (((val-layer(iref))/(ith(i,j,iref+1)**2))+
1623c$$$     &                      ((layer(iref+1)-val)/(iceith)**2)))
1624c$$$            ! Set thermal inertia of lower layers
1625c$$$                do isoil=iref+2,nsoilmx
1626c$$$                  ith(i,j,isoil)=iceith
1627c$$$                enddo
1628c$$$              endif ! of if (val.lt.layer(nsoilmx))
1629c$$$            endif ! of if (MONS_Hdn(i,j).lt.14.0)
1630c$$$          enddo ! do j=1,jjp1
1631c$$$        enddo ! do i=1,iip1
1632c$$$       
1633c$$$! Check:
1634c$$$!         do i=1,iip1
1635c$$$!           do j=1,jjp1
1636c$$$!             do isoil=1,nsoilmx
1637c$$$!               write(77,*) i,j,isoil,"  ",ith(i,j,isoil)
1638c$$$!             enddo
1639c$$$!           enddo
1640c$$$!    enddo
1641c$$$
1642c$$$        ! recast ith() into ithfi()
1643c$$$        CALL gr_dyn_fi(nsoilmx,iip1,jjp1,ngridmx,ith,ithfi)
1644c$$$       
1645c$$$    else
1646c$$$          write(*,*) '       Unknown (misspelled?) option!!!'
1647        end if ! of if (modif(1:len_trim(modif)) .eq. '...') elseif ...
1648       
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659       enddo ! of do ! infinite loop on liste of changes
1660
1661 999  continue
1662
1663 
1664c=======================================================================
1665c   Initialisation for cloud fraction and oceanic ice (added by BC 2010)
1666c=======================================================================
1667      DO ig=1, ngridmx
1668         totalfrac(ig)=0.5
1669         DO l=1,llm
1670            cloudfrac(ig,l)=0.5
1671         ENDDO
1672! Ehouarn, march 2012: also add some initialisation for hice
1673         hice(ig)=0.0
1674      ENDDO
1675     
1676c========================================================
1677
1678!      DO ig=1,ngridmx
1679!         IF(tsurf(ig) .LT. 273.16-1.8) THEN
1680!            hice(ig)=(273.16-1.8-tsurf(ig))/(273.16-1.8-240)*1.
1681!            hice(ig)=min(hice(ig),1.0)
1682!         ENDIF
1683!      ENDDO
1684
1685c=======================================================================
1686c   Correct pressure on the new grid (menu 0)
1687c=======================================================================
1688
1689
1690      if ((choix_1.eq.0).and.(.not.flagps0)) then
1691        r = 1000.*8.31/mugaz
1692
1693        do j=1,jjp1
1694          do i=1,iip1
1695             ps(i,j) = ps(i,j) *
1696     .            exp((phisold_newgrid(i,j)-phis(i,j)) /
1697     .                                  (t(i,j,1) * r))
1698          end do
1699        end do
1700
1701c periodicite de ps en longitude
1702        do j=1,jjp1
1703          ps(1,j) = ps(iip1,j)
1704        end do
1705      end if
1706
1707         
1708c=======================================================================
1709c=======================================================================
1710
1711c=======================================================================
1712c    Initialisation de la physique / ecriture de newstartfi :
1713c=======================================================================
1714
1715
1716      CALL inifilr
1717      CALL pression(ip1jmp1, ap, bp, ps, p3d)
1718
1719c-----------------------------------------------------------------------
1720c   Initialisation  pks:
1721c-----------------------------------------------------------------------
1722
1723      CALL exner_hyb(ip1jmp1, ps, p3d, beta, pks, pk, pkf)
1724! Calcul de la temperature potentielle teta
1725
1726      if (flagtset) then
1727          DO l=1,llm
1728             DO j=1,jjp1
1729                DO i=1,iim
1730                   teta(i,j,l) = Tset(i,j,l) * cpp/pk(i,j,l)
1731                ENDDO
1732                teta (iip1,j,l)= teta (1,j,l)
1733             ENDDO
1734          ENDDO
1735      else if (choix_1.eq.0) then
1736         DO l=1,llm
1737            DO j=1,jjp1
1738               DO i=1,iim
1739                  teta(i,j,l) = t(i,j,l) * cpp/pk(i,j,l)
1740               ENDDO
1741               teta (iip1,j,l)= teta (1,j,l)
1742            ENDDO
1743         ENDDO
1744      endif
1745
1746C Calcul intermediaire
1747c
1748      if (choix_1.eq.0) then
1749         CALL massdair( p3d, masse  )
1750c
1751         print *,' ALPHAX ',alphax
1752
1753         DO  l = 1, llm
1754           DO  i    = 1, iim
1755             xppn(i) = aire( i, 1   ) * masse(  i     ,  1   , l )
1756             xpps(i) = aire( i,jjp1 ) * masse(  i     , jjp1 , l )
1757           ENDDO
1758             xpn      = SUM(xppn)/apoln
1759             xps      = SUM(xpps)/apols
1760           DO i   = 1, iip1
1761             masse(   i   ,   1     ,  l )   = xpn
1762             masse(   i   ,   jjp1  ,  l )   = xps
1763           ENDDO
1764         ENDDO
1765      endif
1766      phis(iip1,:) = phis(1,:)
1767
1768      CALL inidissip ( lstardis, nitergdiv, nitergrot, niterh,
1769     *                tetagdiv, tetagrot , tetatemp  )
1770      itau=0
1771      if (choix_1.eq.0) then
1772         day_ini=int(date)
1773      endif
1774c
1775      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
1776
1777      CALL caldyn0( itau,ucov,vcov,teta,ps,masse,pk,phis ,
1778     *                phi,w, pbaru,pbarv,day_ini+time )
1779
1780         
1781      CALL dynredem0("restart.nc",day_ini,anneeref,phis,nqmx)
1782      CALL dynredem1("restart.nc",0.0,vcov,ucov,teta,q,nqmx,masse,ps)
1783C
1784C Ecriture etat initial physique
1785C
1786
1787!      do ig=1,ngridmx
1788!         print*,'surface ice in newstart=',qsurf(ig,igcm_h2o_ice)
1789!         print*,'surface liq in newstart=',qsurf(ig,igcm_h2o_vap)
1790!      enddo
1791!      stop
1792
1793
1794      call physdem1("restartfi.nc",lonfi,latfi,nsoilmx,nqmx,
1795     .              dtphys,float(day_ini),
1796     .              time,tsurf,tsoil,emis,q2,qsurf,
1797     .              airefi,albfi,ithfi,zmea,zstd,zsig,zgam,zthe,
1798     .              cloudfrac,totalfrac,hice)
1799
1800c=======================================================================
1801c       Formats
1802c=======================================================================
1803
1804   1  FORMAT(//10x,'la valeur de im =',i4,2x,'lue sur le fichier de dema
1805     *rrage est differente de la valeur parametree iim =',i4//)
1806   2  FORMAT(//10x,'la valeur de jm =',i4,2x,'lue sur le fichier de dema
1807     *rrage est differente de la valeur parametree jjm =',i4//)
1808   3  FORMAT(//10x,'la valeur de lllm =',i4,2x,'lue sur le fichier demar
1809     *rage est differente de la valeur parametree llm =',i4//)
1810
1811      end
1812
1813!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1814      subroutine load_MONS_data(MONS_Hdn,MONS_d21)
1815      use datafile_mod, only: datadir
1816      implicit none
1817      ! routine to load Benedicte Diez MONS dataset, fill in date in southern
1818      ! polar region, and interpolate the result onto the GCM grid
1819#include"dimensions.h"
1820#include"paramet.h"
1821#include"comgeom.h"
1822      ! arguments:
1823      real,intent(out) :: MONS_Hdn(iip1,jjp1) ! Hdn: %WEH=Mass fraction of H2O
1824      real,intent(out) :: MONS_d21(iip1,jjp1) ! ice table "depth" (in kg/m2)
1825      ! N.B MONS datasets should be of dimension (iip1,jjp1)
1826      ! local variables:
1827      character(len=88) :: filename="results_MONS_lat_lon_H_depth.txt"
1828      character(len=88) :: txt ! to store some text
1829      integer :: ierr,i,j
1830      integer,parameter :: nblon=180 ! number of longitudes of MONS datasets
1831      integer,parameter :: nblat=90 ! number of latitudes of MONS datasets
1832      real :: pi
1833      real :: longitudes(nblon) ! MONS dataset longitudes
1834      real :: latitudes(nblat)  ! MONS dataset latitudes
1835      ! MONS dataset: mass fraction of H2O where H is assumed to be in H2O
1836      real :: Hdn(nblon,nblat)
1837      real :: d21(nblon,nblat)! MONS dataset "depth" (g/cm2)
1838
1839      ! Extended MONS dataset (for interp_horiz)
1840      real :: Hdnx(nblon+1,nblat)
1841      real :: d21x(nblon+1,nblat)
1842      real :: lon_bound(nblon+1) ! longitude boundaries
1843      real :: lat_bound(nblat-1) ! latitude boundaries
1844
1845      ! 1. Initializations:
1846
1847      write(*,*) "Loading MONS data"
1848
1849      ! Open MONS datafile:
1850      open(42,file=trim(datadir)//"/"//trim(filename),
1851     &     status="old",iostat=ierr)
1852      if (ierr/=0) then
1853        write(*,*) "Error in load_MONS_data:"
1854        write(*,*) "Failed opening file ",
1855     &             trim(datadir)//"/"//trim(filename)
1856        write(*,*)'Check that your path to datagcm:',trim(datadir)
1857        write(*,*)' is correct. You can change it in callphys.def with:'
1858        write(*,*)' datadir = /absolute/path/to/datagcm'
1859        write(*,*)'If necessary ',trim(filename),
1860     &                 ' (and other datafiles)'
1861        write(*,*)'   can be obtained online at:'
1862        write(*,*)' http://www.lmd.jussieu.fr/~forget/datagcm/datafile'
1863        CALL ABORT
1864      else ! skip first line of file (dummy read)
1865         read(42,*) txt
1866      endif
1867
1868      pi=2.*asin(1.)
1869     
1870      !2. Load MONS data (on MONS grid)
1871      do j=1,nblat
1872        do i=1,nblon
1873        ! swap latitude index so latitudes go from north pole to south pole:
1874          read(42,*) latitudes(nblat-j+1),longitudes(i),
1875     &               Hdn(i,nblat-j+1),d21(i,nblat-j+1)
1876        ! multiply d21 by 10 to convert from g/cm2 to kg/m2
1877          d21(i,nblat-j+1)=d21(i,nblat-j+1)*10.0
1878        enddo
1879      enddo
1880      close(42)
1881     
1882      ! there is unfortunately no d21 data for latitudes -77 to -90
1883      ! so we build some by linear interpolation between values at -75
1884      ! and assuming d21=0 at the pole
1885      do j=84,90 ! latitudes(84)=-77 ; latitudes(83)=-75
1886        do i=1,nblon
1887          d21(i,j)=d21(i,83)*((latitudes(j)+90)/15.0)
1888        enddo
1889      enddo
1890
1891      ! 3. Build extended MONS dataset & boundaries (for interp_horiz)
1892      ! longitude boundaries (in radians):
1893      do i=1,nblon
1894        ! NB: MONS data is every 2 degrees in longitude
1895        lon_bound(i)=(longitudes(i)+1.0)*pi/180.0
1896      enddo
1897      ! extra 'modulo' value
1898      lon_bound(nblon+1)=lon_bound(1)+2.0*pi
1899     
1900      ! latitude boundaries (in radians):
1901      do j=1,nblat-1
1902        ! NB: Mons data is every 2 degrees in latitude
1903        lat_bound(j)=(latitudes(j)-1.0)*pi/180.0
1904      enddo
1905     
1906      ! MONS datasets:
1907      do j=1,nblat
1908        Hdnx(1:nblon,j)=Hdn(1:nblon,j)
1909        Hdnx(nblon+1,j)=Hdnx(1,j)
1910        d21x(1:nblon,j)=d21(1:nblon,j)
1911        d21x(nblon+1,j)=d21x(1,j)
1912      enddo
1913     
1914      ! Interpolate onto GCM grid
1915      call interp_horiz(Hdnx,MONS_Hdn,nblon,nblat-1,iim,jjm,1,
1916     &                  lon_bound,lat_bound,rlonu,rlatv)
1917      call interp_horiz(d21x,MONS_d21,nblon,nblat-1,iim,jjm,1,
1918     &                  lon_bound,lat_bound,rlonu,rlatv)
1919     
1920      end subroutine
Note: See TracBrowser for help on using the repository browser.