source: trunk/LMDZ.GENERIC/libf/phystd/dyn1d/inichim_1D.F90 @ 2987

Last change on this file since 2987 was 2542, checked in by aslmd, 3 years ago

Generic GCM:

Large update of the chemical modules

  • Read chemical network from input files
  • Init chemistry with ModernTrac?
  • Photolysis online calculation

YJ

  • Property svn:executable set to *
File size: 6.9 KB
Line 
1      subroutine inichim_1D(nlayer, nq, pq, qsurf, play, &
2                                  flagh2o,flagthermo)
3
4      use tracer_h, only: noms, mmol
5      use datafile_mod, only: datadir
6
7      implicit none
8
9!=======================================================================
10!
11!  Purpose:
12!  --------
13!
14!  Initialization of the chemistry for use in the building of a new start file
15!  used by program newstart.F
16!  also used by program testphys1d.F
17!
18!  Authors:
19!  -------
20!  Initial version 11/2002 by Sebastien Lebonnois
21!  Revised 07/2003 by Monica Angelats-i-Coll to use input files
22!  Modified 10/2008 Identify tracers by their names Ehouarn Millour
23!  Modified 11/2011 Addition of methane Franck Lefevre
24!  Rewritten 04/2012 Franck Lefevre
25!  Rewritten 03/2021 Yassin Jaziri (Use of #Moderntrac-v1 to init thanks traceur.def)
26!
27!  Arguments:
28!  ----------
29!
30!  nlayer          Number of atmospheric layers
31!  pq(nlayer,nq)   Advected fields, ie chemical species here
32!  qsurf(nq)       Amount of tracer on the surface (kg/m2)
33!  play(nlayer)    Pressure (Pa)
34!  flagh2o         flag for initialisation of h2o (1: yes / 0: no)
35!  flagthermo      flag for initialisation of thermosphere only (1: yes / 0: no)
36!
37!=======================================================================
38
39
40! inputs :
41
42      integer,intent(in) :: nlayer         ! Number of atmospheric layers.
43      integer,intent(in) :: nq             ! number of tracers
44      real   ,intent(in) :: play(nlayer)   ! Mid-layer pressure (Pa). 
45      integer,intent(in) :: flagh2o        ! flag for h2o initialisation
46      integer,intent(in) :: flagthermo     ! flag for thermosphere initialisation only
47
48! outputs :
49
50      real,intent(out)   :: pq(nlayer,nq)  ! tracers (kg/kg_of_air)
51      real,intent(out)   :: qsurf(nq)      ! surface values (kg/m2) of tracers
52
53! local :
54
55      real, allocatable  :: pf(:)          ! pressure in vmr profile files set in traceur.def
56      real, allocatable  :: qf(:)          ! vmr      in vmr profile files set in traceur.def
57
58      real    :: mmean(nlayer)             ! mean molecular mass (g)
59      real    :: pqx(nlayer,nq)            ! tracers (vmr)
60      real    :: qx(nq)                    ! constant vmr set in traceur.def
61      integer :: iq, ilay, iline, nlines, ierr
62
63      CHARACTER(len=100) :: qxf(nq)        ! vmr profile files set in traceur.def
64      CHARACTER(len=100) :: fil            ! path files
65      character(len=500) :: tracline       ! to store a line of text
66
67      logical :: foundback = .false.
68
69! 1. initialization
70
71      pq(:,:)  = 0.
72      qsurf(:) = 0.
73      pqx(:,:) = 0.
74      qx(:)    = 0.
75      qxf(:)   = 'None'
76
77! 2. load in traceur.def chemistry data for initialization:
78
79      ! Skip nq
80      open(90,file='traceur.def',status='old',form='formatted',iostat=ierr)
81      if (ierr.eq.0) then
82        READ(90,'(A)') tracline
83        IF (trim(tracline).eq.'#ModernTrac-v1') THEN ! Test modern traceur.def
84           DO
85             READ(90,'(A)',iostat=ierr) tracline
86             IF (ierr.eq.0) THEN
87               IF (index(tracline,'#').ne.1) THEN ! Allows arbitary number of comments lines in the header
88                 EXIT
89               ENDIF
90             ELSE ! If pb, or if reached EOF without having found number of tracer
91                write(*,*) "calchim: error reading line of tracers"
92                write(*,*) "   (first lines of traceur.def) "
93                stop
94             ENDIF
95           ENDDO
96        ENDIF ! if modern or standard traceur.def
97      else
98         write(*,*) "calchim: error opening traceur.def in inichim_1D"
99         stop
100      endif
101
102      ! Get data of tracers
103      do iq=1,nq
104         read(90,'(A)') tracline
105         write(*,*)"inichim_1D: iq=",iq,"noms(iq)=",trim(noms(iq))
106         if (index(tracline,'qx='    ) /= 0) then
107            read(tracline(index(tracline,'qx=')+len('qx='):),*) qx(iq)
108            write(*,*) ' Parameter value (traceur.def) : qx=', qx(iq)
109         else
110            write(*,*) ' Parameter value (default)     : qx=', qx(iq)
111         end if
112         if (index(tracline,'qxf='    ) /= 0) then
113            read(tracline(index(tracline,'qxf=')+len('qxf='):),*) qxf(iq)
114            write(*,*) ' Parameter value (traceur.def) : qxf=', qxf(iq)
115         else
116            write(*,*) ' Parameter value (default)     : qxf=', qxf(iq)
117         end if
118      end do
119
120      close(90)
121
122! 3. initialization of tracers
123
124! 3.1 vertical interpolation
125
126      do iq=1,nq
127         if (qx(iq) /= 0.) then
128            pqx(:,iq) = qx(iq)
129         else if (qxf(iq) /= 'None') then
130            ! Opening file
131            fil = trim(datadir)//'/chemical_profiles/'//qxf(iq)
132            print*, 'chemical pofile '//trim(noms(iq))//': ', fil
133            open(UNIT=90,FILE=fil,STATUS='old',iostat=ierr)
134            if (ierr.eq.0) then
135               read(90,*) ! read one header line
136               do         ! get number of lines
137                   read(90,*,iostat=ierr)
138                   if (ierr<0) exit
139                   nlines = nlines + 1
140               end do
141               ! allocate reading variable
142               allocate(pf(nlines))
143               allocate(qf(nlines))
144               ! read file
145               rewind(90) ! restart from the beggining of the file
146               read(90,*) ! read one header line
147               do iline=1,nlines
148                  read(90,*) pf(iline), qf(iline) ! pf [Pa], qf [vmr]
149               end do
150               ! interp in gcm grid
151               do ilay=1,nlayer
152                  call intrplf(log(play(ilay)),pqx(ilay,iq),log(pf),qf,nlines)
153               end do
154               ! deallocate for next tracer
155               deallocate(pf)
156               deallocate(qf)
157            else
158               write(*,*) 'inichim_1D: error opening ', fil
159               stop
160            endif
161            close(90)
162         end if
163      end do
164
165! 3.2 background gas
166
167      do iq=1,nq
168         if (all(pqx(:,iq)==1.)) then
169            pqx(:,iq) = 0.
170            do ilay=1,nlayer
171               pqx(ilay,iq) = 1-sum(pqx(ilay,:))
172               if (pqx(ilay,iq)<=0.) then
173                  write(*,*) 'inichim_1D: vmr tot > 1 not possible'
174                  stop
175               end if
176            end do
177            foundback = .true.
178            exit ! you found the background gas you can skip others
179         end if
180      end do
181      if (.not.foundback) then
182         write(*,*) 'inichim_1D: you need to set a background gas'
183         write(*,*) '            by qx=1. in traceur.def'
184         stop
185      end if
186
187! 3.3 mmean
188      mmean(:) = 0.
189      do ilay=1,nlayer
190         do iq=1,nq
191            mmean(ilay) = mmean(ilay) + pqx(ilay,iq)*mmol(iq)
192         end do
193      end do
194
195! 3.4 convert vmr to mmr
196
197      do ilay=1,nlayer
198         do iq=1,nq
199            pq(ilay,iq) = pqx(ilay,iq)*mmol(iq)/mmean(ilay)
200         end do
201      end do
202
203! 4. Hard coding
204! Do whatever you want here to specify pq and qsurf
205! Or use #ModernTrac-v1 and add another option section 2.
206
207      end
Note: See TracBrowser for help on using the repository browser.