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