| 1 | MODULE metamorphism |
|---|
| 2 | |
|---|
| 3 | implicit none |
|---|
| 4 | |
|---|
| 5 | ! Different types of frost |
|---|
| 6 | type :: frost |
|---|
| 7 | real :: h2o |
|---|
| 8 | real :: co2 |
|---|
| 9 | end type frost |
|---|
| 10 | |
|---|
| 11 | ! Frost retained by the PEM to give back to the PCM at the end |
|---|
| 12 | type(frost), dimension(:,:), allocatable :: frost4PCM |
|---|
| 13 | |
|---|
| 14 | ! Indices for frost taken from the PCM |
|---|
| 15 | integer :: iPCM_h2ofrost, iPCM_co2frost |
|---|
| 16 | |
|---|
| 17 | !======================================================================= |
|---|
| 18 | contains |
|---|
| 19 | !======================================================================= |
|---|
| 20 | |
|---|
| 21 | SUBROUTINE ini_frost_id(nqtot,noms) |
|---|
| 22 | |
|---|
| 23 | implicit none |
|---|
| 24 | |
|---|
| 25 | ! Arguments |
|---|
| 26 | !---------- |
|---|
| 27 | integer, intent(in) :: nqtot |
|---|
| 28 | character(*), dimension(nqtot), intent(in) :: noms |
|---|
| 29 | |
|---|
| 30 | ! Local variables |
|---|
| 31 | !---------------- |
|---|
| 32 | integer :: i |
|---|
| 33 | |
|---|
| 34 | ! Code |
|---|
| 35 | !----- |
|---|
| 36 | ! Initialization |
|---|
| 37 | iPCM_h2ofrost = -1 |
|---|
| 38 | iPCM_co2frost = -1 |
|---|
| 39 | |
|---|
| 40 | ! Getting the index |
|---|
| 41 | do i = 1,nqtot |
|---|
| 42 | if (trim(noms(i)) == "h2o_ice") iPCM_h2ofrost = i |
|---|
| 43 | if (trim(noms(i)) == "co2") iPCM_co2frost = i |
|---|
| 44 | enddo |
|---|
| 45 | |
|---|
| 46 | ! Checking if everything has been found |
|---|
| 47 | if (iPCM_h2ofrost < 0) error stop 'ini_frost_id: H2O frost index not found!' |
|---|
| 48 | if (iPCM_co2frost < 0) error stop 'ini_frost_id: CO2 frost index not found!' |
|---|
| 49 | |
|---|
| 50 | END SUBROUTINE ini_frost_id |
|---|
| 51 | !======================================================================= |
|---|
| 52 | |
|---|
| 53 | SUBROUTINE compute_frost(ngrid,nslope,h2ofrost_PCM,min_h2ofrost,co2frost_PCM,min_co2frost) |
|---|
| 54 | |
|---|
| 55 | implicit none |
|---|
| 56 | |
|---|
| 57 | ! Arguments |
|---|
| 58 | !---------- |
|---|
| 59 | integer, intent(in) :: ngrid, nslope |
|---|
| 60 | real, dimension(ngrid,nslope), intent(in) :: h2ofrost_PCM, min_h2ofrost, co2frost_PCM, min_co2frost |
|---|
| 61 | |
|---|
| 62 | ! Local variables |
|---|
| 63 | !---------------- |
|---|
| 64 | |
|---|
| 65 | ! Code |
|---|
| 66 | !----- |
|---|
| 67 | write(*,*) '> Computing frost to give back to the PCM' |
|---|
| 68 | |
|---|
| 69 | ! Allocation |
|---|
| 70 | call ini_frost(ngrid,nslope) |
|---|
| 71 | |
|---|
| 72 | ! Initialization |
|---|
| 73 | frost4PCM(:,:)%h2o = 0. |
|---|
| 74 | frost4PCM(:,:)%co2 = 0. |
|---|
| 75 | |
|---|
| 76 | ! Computation: frost for the PEM is the extra part of the PCM frost above the yearly minimum |
|---|
| 77 | where (h2ofrost_PCM(:,:) > 0.) frost4PCM(:,:)%h2o = h2ofrost_PCM(:,:) - min_h2ofrost(:,:) |
|---|
| 78 | where (co2frost_PCM(:,:) > 0.) frost4PCM(:,:)%co2 = co2frost_PCM(:,:) - min_co2frost(:,:) |
|---|
| 79 | |
|---|
| 80 | END SUBROUTINE compute_frost |
|---|
| 81 | !======================================================================= |
|---|
| 82 | |
|---|
| 83 | SUBROUTINE set_frost4PCM(PCMfrost) |
|---|
| 84 | |
|---|
| 85 | implicit none |
|---|
| 86 | |
|---|
| 87 | ! Arguments |
|---|
| 88 | !---------- |
|---|
| 89 | real, dimension(:,:,:), intent(inout) :: PCMfrost |
|---|
| 90 | |
|---|
| 91 | ! Local variables |
|---|
| 92 | !---------------- |
|---|
| 93 | |
|---|
| 94 | ! Code |
|---|
| 95 | !----- |
|---|
| 96 | write(*,*) '> Reconstructing frost for the PCM' |
|---|
| 97 | PCMfrost(:,iPCM_h2ofrost,:) = frost4PCM(:,:)%h2o |
|---|
| 98 | PCMfrost(:,iPCM_co2frost,:) = frost4PCM(:,:)%co2 |
|---|
| 99 | |
|---|
| 100 | ! Deallocation |
|---|
| 101 | call end_frost() |
|---|
| 102 | |
|---|
| 103 | END SUBROUTINE set_frost4PCM |
|---|
| 104 | !======================================================================= |
|---|
| 105 | |
|---|
| 106 | SUBROUTINE ini_frost(ngrid,nslope) |
|---|
| 107 | |
|---|
| 108 | implicit none |
|---|
| 109 | |
|---|
| 110 | ! Arguments |
|---|
| 111 | !---------- |
|---|
| 112 | integer, intent(in) :: ngrid, nslope |
|---|
| 113 | |
|---|
| 114 | ! Local variables |
|---|
| 115 | !---------------- |
|---|
| 116 | |
|---|
| 117 | ! Code |
|---|
| 118 | !----- |
|---|
| 119 | if (.not. allocated(frost4PCM)) allocate(frost4PCM(ngrid,nslope)) |
|---|
| 120 | |
|---|
| 121 | END SUBROUTINE ini_frost |
|---|
| 122 | !======================================================================= |
|---|
| 123 | |
|---|
| 124 | SUBROUTINE end_frost() |
|---|
| 125 | |
|---|
| 126 | implicit none |
|---|
| 127 | |
|---|
| 128 | ! Arguments |
|---|
| 129 | !---------- |
|---|
| 130 | |
|---|
| 131 | ! Local variables |
|---|
| 132 | !---------------- |
|---|
| 133 | |
|---|
| 134 | ! Code |
|---|
| 135 | !----- |
|---|
| 136 | if (allocated(frost4PCM)) deallocate(frost4PCM) |
|---|
| 137 | |
|---|
| 138 | END SUBROUTINE end_frost |
|---|
| 139 | |
|---|
| 140 | END MODULE metamorphism |
|---|