source: trunk/LMDZ.MARS/libf/phymars/dyn1d/read_profile_mod.F90 @ 2505

Last change on this file since 2505 was 2355, checked in by cmathe, 4 years ago

MARS GCM: improvement in the reading of input profile for 1D simulation

File size: 7.9 KB
Line 
1module read_profile_mod
2
3implicit none
4
5contains
6!=====================================================================================================================!
7! SUBROUTINE: read_profile ===========================================================================================!
8!=====================================================================================================================!
9! Author: Christophe Mathe
10! Date: 09/06/2020
11!---------------------------------------------------------------------------------------------------------------------!
12! Subject:
13!---------
14!   Read input profile of tracers listed in traceur.def
15!---------------------------------------------------------------------------------------------------------------------!
16! Comments:
17!----------
18!     - If no input profile found, q(traceur) and qsurf(traceur) set to 0, except:
19!          - q(co2) = 0.95
20!          - q(hdo) = q(h2o)*2*155.76e-6*5
21!
22!     - igcm is not available at this part of the code
23!
24!     - To ensure that major isotopologue input profile is read before compute minor isotopologue profile, the
25!       calculation is performed at the end of the subroutine
26!---------------------------------------------------------------------------------------------------------------------!
27! Algorithm:
28!-----------
29!   1. Initialization of q and qsurf to 0
30!   2. Get indices of some tracers
31!   3. Main
32!     3.1. Try to open the input profile
33!       3.1.1. Succeed
34!       3.1.2. Fail
35!         3.1.2.a. Some cases require a special initialization
36!   4. Traitment for minor isotopologue if the major isotopologue input profile does not exist
37!=====================================================================================================================!
38  subroutine read_profile(nb_tracer, nb_layer, qsurf, q)
39
40  use infotrac, only: tname
41
42  implicit none
43!---------------------------------------------------------------------------------------------------------------------!
44! VARIABLE DECLARATION
45!---------------------------------------------------------------------------------------------------------------------!
46!  Input arguments:
47!------------------
48  integer, intent(in) :: &
49     nb_layer, & ! number of layer
50     nb_tracer  ! number of traceur read from traceur.def
51!---------------------------------------------------------------------------------------------------------------------!
52!  Output arguments:
53!-------------------
54  real, intent(out) :: &
55     qsurf(nb_tracer), &    ! kg/m2
56     q(nb_layer, nb_tracer) ! kg/kg of atmosphere
57!---------------------------------------------------------------------------------------------------------------------!
58!  Local:
59!--------
60  integer :: &
61     iq,             & ! loop over nb_tracer
62     ilayer,         & ! loop over nb_layer
63     ierr,           & ! open file iostat
64     indice_h2o_vap, & ! indice of h2o_vap tracer
65     indice_h2o_ice, & ! indice of h2o_ice tracer
66     indice_hdo_vap, & ! indice of hdo_vap tracer
67     indice_hdo_ice    ! indice of hdo_ice tracer
68
69  character(len=80), dimension(nb_tracer) :: &
70     name_tracer ! array of all tracers already read in traceur.def
71
72  logical :: &
73     hdo_vap = .false., & ! used to compute hdo_vap profile if its input profile is missing (= .true)
74     hdo_ice = .false.    ! used to compute hdo_ice profile if its input profile is missing (= .true)
75!=====================================================================================================================!
76!=== BEGIN                                                                                                            !
77!=====================================================================================================================!
78! 1. Initialization of q and qsurf to 0
79!---------------------------------------------------------------------------------------------------------------------!
80  q(1:nb_layer,1:nb_tracer) = 0.
81  qsurf(1:nb_tracer) = 0.
82  name_tracer(1:nb_tracer) = ""
83!---------------------------------------------------------------------------------------------------------------------!
84! 2. Get indices of some tracers: igcm is not available at this part of the code
85!---------------------------------------------------------------------------------------------------------------------!
86  do iq = 1, nb_tracer
87    write(name_tracer(iq),"(a)") tname(iq)
88    if (trim(name_tracer(iq)) == 'h2o_vap') then
89      indice_h2o_vap = iq
90    else if (trim(name_tracer(iq)) == 'h2o_ice') then
91      indice_h2o_ice = iq
92    else if (trim(name_tracer(iq)) == 'hdo_vap') then
93      indice_hdo_vap = iq
94    else if (trim(name_tracer(iq)) == 'hdo_ice') then
95      indice_hdo_ice = iq
96    end if
97  end do
98!---------------------------------------------------------------------------------------------------------------------!
99! 3. Main
100!---------------------------------------------------------------------------------------------------------------------!
101  do iq = 1, nb_tracer
102    write(*,*)"  tracer:",trim(name_tracer(iq))
103!---------------------------------------------------------------------------------------------------------------------!
104! 3.1. Try to open the input profile
105!---------------------------------------------------------------------------------------------------------------------!
106    open(91,file='profile_'//trim(name_tracer(iq)), status='old', form='formatted', iostat=ierr)
107!---------------------------------------------------------------------------------------------------------------------!
108! 3.1.1. Succeed: the input file exists
109!---------------------------------------------------------------------------------------------------------------------!
110    if (ierr.eq.0) then
111      read(91,*)qsurf(iq)
112      do ilayer = 1, nb_layer
113        read(91,*)q(ilayer,iq)
114      end do
115!---------------------------------------------------------------------------------------------------------------------!
116! 3.1.2. Fail: the input file does not exist
117!---------------------------------------------------------------------------------------------------------------------!
118    else
119      write(*,*)"File profile_"//trim(name_tracer(iq))//" not found!"
120!---------------------------------------------------------------------------------------------------------------------!
121! 3.1.2.a. Some cases require a special initialization
122!---------------------------------------------------------------------------------------------------------------------!
123      select case(trim(name_tracer(iq)))
124        case("co2")
125          q(1:nb_layer, iq) = 0.95
126
127        case("hdo_vap")
128          hdo_vap = .true.
129
130        case("hdo_ice")
131          hdo_ice = .true.
132
133       end select
134    end if
135    close(91)
136  end do ! of do iq = 1, nq
137!---------------------------------------------------------------------------------------------------------------------!
138! 4. Traitment for minor isotopologue if the major isotopologue input profile does not exist. At this part, ensure that
139!    the main isotopologue profile is already read before minors isotopologues
140!---------------------------------------------------------------------------------------------------------------------!
141  if (hdo_vap.eqv..true. .and. indice_h2o_vap.ne.0) then
142    do ilayer = 1, nb_layer
143      q(ilayer, indice_hdo_vap) = q(ilayer, indice_h2o_vap)*2*155.76e-6*5
144    end do
145  end if
146
147  if (hdo_ice.eqv..true. .and. indice_h2o_ice.ne.0) then
148    qsurf(indice_hdo_ice) = qsurf(indice_h2o_ice) * 2*155.76e-6*5
149    do ilayer = 1, nb_layer
150      q(ilayer, indice_hdo_ice) = q(ilayer, indice_h2o_ice) * 2*155.76e-6*5
151    end do
152  end if
153!=====================================================================================================================!
154!=== END                                                                                                              !
155!=====================================================================================================================!
156  end subroutine read_profile
157end module read_profile_mod
158
Note: See TracBrowser for help on using the repository browser.