[2355] | 1 | module read_profile_mod |
---|
| 2 | |
---|
| 3 | implicit none |
---|
| 4 | |
---|
| 5 | contains |
---|
| 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 |
---|
[2878] | 41 | use tracer_mod, only: igcm_co2 |
---|
[2355] | 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) |
---|
[2878] | 112 | if (trim(name_tracer(iq)) == 'co2') then |
---|
| 113 | igcm_co2 = iq |
---|
[2827] | 114 | endif |
---|
[2355] | 115 | do ilayer = 1, nb_layer |
---|
| 116 | read(91,*)q(ilayer,iq) |
---|
| 117 | end do |
---|
| 118 | !---------------------------------------------------------------------------------------------------------------------! |
---|
| 119 | ! 3.1.2. Fail: the input file does not exist |
---|
| 120 | !---------------------------------------------------------------------------------------------------------------------! |
---|
| 121 | else |
---|
| 122 | write(*,*)"File profile_"//trim(name_tracer(iq))//" not found!" |
---|
| 123 | !---------------------------------------------------------------------------------------------------------------------! |
---|
| 124 | ! 3.1.2.a. Some cases require a special initialization |
---|
| 125 | !---------------------------------------------------------------------------------------------------------------------! |
---|
| 126 | select case(trim(name_tracer(iq))) |
---|
| 127 | case("co2") |
---|
| 128 | q(1:nb_layer, iq) = 0.95 |
---|
| 129 | |
---|
| 130 | case("hdo_vap") |
---|
| 131 | hdo_vap = .true. |
---|
| 132 | |
---|
| 133 | case("hdo_ice") |
---|
| 134 | hdo_ice = .true. |
---|
| 135 | |
---|
| 136 | end select |
---|
| 137 | end if |
---|
| 138 | close(91) |
---|
| 139 | end do ! of do iq = 1, nq |
---|
| 140 | !---------------------------------------------------------------------------------------------------------------------! |
---|
| 141 | ! 4. Traitment for minor isotopologue if the major isotopologue input profile does not exist. At this part, ensure that |
---|
| 142 | ! the main isotopologue profile is already read before minors isotopologues |
---|
| 143 | !---------------------------------------------------------------------------------------------------------------------! |
---|
| 144 | if (hdo_vap.eqv..true. .and. indice_h2o_vap.ne.0) then |
---|
| 145 | do ilayer = 1, nb_layer |
---|
| 146 | q(ilayer, indice_hdo_vap) = q(ilayer, indice_h2o_vap)*2*155.76e-6*5 |
---|
| 147 | end do |
---|
| 148 | end if |
---|
| 149 | |
---|
| 150 | if (hdo_ice.eqv..true. .and. indice_h2o_ice.ne.0) then |
---|
| 151 | qsurf(indice_hdo_ice) = qsurf(indice_h2o_ice) * 2*155.76e-6*5 |
---|
| 152 | do ilayer = 1, nb_layer |
---|
| 153 | q(ilayer, indice_hdo_ice) = q(ilayer, indice_h2o_ice) * 2*155.76e-6*5 |
---|
| 154 | end do |
---|
| 155 | end if |
---|
| 156 | !=====================================================================================================================! |
---|
| 157 | !=== END ! |
---|
| 158 | !=====================================================================================================================! |
---|
| 159 | end subroutine read_profile |
---|
| 160 | end module read_profile_mod |
---|
| 161 | |
---|