source: trunk/LMDZ.MARS/libf/phymars/newstart.F @ 1230

Last change on this file since 1230 was 1226, checked in by aslmd, 12 years ago

LMDZ.MARS : Replaced comcstfi and planete includes by modules.

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