| 1 | MODULE info_pem |
|---|
| 2 | !----------------------------------------------------------------------- |
|---|
| 3 | ! NAME |
|---|
| 4 | ! info_pem |
|---|
| 5 | ! |
|---|
| 6 | ! DESCRIPTION |
|---|
| 7 | ! Handles counters for PCM/PEM coupled runs and simulation metadata. |
|---|
| 8 | ! |
|---|
| 9 | ! AUTHORS & DATE |
|---|
| 10 | ! R. Vandemeulebrouck |
|---|
| 11 | ! JB Clement, 2023-2025 |
|---|
| 12 | ! |
|---|
| 13 | ! NOTES |
|---|
| 14 | ! |
|---|
| 15 | !----------------------------------------------------------------------- |
|---|
| 16 | |
|---|
| 17 | ! DECLARATION |
|---|
| 18 | ! ----------- |
|---|
| 19 | implicit none |
|---|
| 20 | |
|---|
| 21 | ! MODULE VARIABLES |
|---|
| 22 | ! ---------------- |
|---|
| 23 | integer :: iPCM, iPEM, nPCM, nPCM_ini ! Data about the chained simulation of PCM/PEM runs |
|---|
| 24 | |
|---|
| 25 | contains |
|---|
| 26 | !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 27 | |
|---|
| 28 | !======================================================================= |
|---|
| 29 | SUBROUTINE update_info(i_myear_leg,stopPEM,i_myear,nyears_tot) |
|---|
| 30 | !----------------------------------------------------------------------- |
|---|
| 31 | ! NAME |
|---|
| 32 | ! update_info |
|---|
| 33 | ! |
|---|
| 34 | ! DESCRIPTION |
|---|
| 35 | ! Update the first line of "launchPEM.info" to count the number of |
|---|
| 36 | ! simulated Martian years. Write in "launchPEM.info" the reason why |
|---|
| 37 | ! the PEM stopped and the number of simulated years. |
|---|
| 38 | ! |
|---|
| 39 | ! AUTHORS & DATE |
|---|
| 40 | ! R. Vandemeulebrouck |
|---|
| 41 | ! JB Clement, 2023-2025 |
|---|
| 42 | ! |
|---|
| 43 | ! NOTES |
|---|
| 44 | ! |
|---|
| 45 | !----------------------------------------------------------------------- |
|---|
| 46 | |
|---|
| 47 | ! DEPENDENCIES |
|---|
| 48 | ! ------------ |
|---|
| 49 | use evolution, only: convert_years, year_bp_ini |
|---|
| 50 | |
|---|
| 51 | ! DECLARATION |
|---|
| 52 | ! ----------- |
|---|
| 53 | implicit none |
|---|
| 54 | |
|---|
| 55 | ! ARGUMENTS |
|---|
| 56 | ! --------- |
|---|
| 57 | integer, intent(in) :: stopPEM ! Reason to stop |
|---|
| 58 | real, intent(in) :: i_myear_leg ! # of years |
|---|
| 59 | real, intent(in) :: i_myear ! Current simulated Martian year |
|---|
| 60 | real, intent(in) :: nyears_tot ! Maximum number of Martian years to be simulated |
|---|
| 61 | |
|---|
| 62 | ! LOCAL VARIABLES |
|---|
| 63 | ! --------------- |
|---|
| 64 | logical :: ok |
|---|
| 65 | integer :: cstat |
|---|
| 66 | character(20) :: fch1, fch2, fch3 |
|---|
| 67 | |
|---|
| 68 | ! CODE |
|---|
| 69 | ! ---- |
|---|
| 70 | inquire(file = 'launchPEM.info',exist = ok) |
|---|
| 71 | if (ok) then |
|---|
| 72 | write(fch1,'(f'//int2str(nb_digits(i_myear) + 5)//'.4)') i_myear |
|---|
| 73 | write(fch2,'(f'//int2str(nb_digits(nyears_tot) + 5)//'.4)') nyears_tot |
|---|
| 74 | write(fch3,'(f6.4)') convert_years ! 4 digits to the right of the decimal point to respect the precision of Martian year in "launch_pem.sh" |
|---|
| 75 | call execute_command_line('sed -i "1s/.*/'//trim(fch1)//' '//trim(fch2)//' '//trim(fch3)//' '//int2str(iPCM)//' '//int2str(iPEM + 1)//' '//int2str(nPCM)//' '//int2str(nPCM_ini)//'/" launchPEM.info',cmdstat = cstat) |
|---|
| 76 | if (cstat > 0) then |
|---|
| 77 | error stop 'update_info: command execution failed!' |
|---|
| 78 | else if (cstat < 0) then |
|---|
| 79 | error stop 'update_info: command execution not supported!' |
|---|
| 80 | endif |
|---|
| 81 | open(1,file = 'launchPEM.info',status = "old",position = "append",action = "write") |
|---|
| 82 | ! Martian date, Number of Martians years done by the PEM run, Number of Martians years done by the chainded simulation, Code of the stopping criterion |
|---|
| 83 | ! The conversion ratio from Planetary years to Earth years is given in the header of the file |
|---|
| 84 | write(1,'(f20.4,f20.4,f20.4,i20)') year_bp_ini + i_myear, i_myear_leg, i_myear, stopPEM |
|---|
| 85 | close(1) |
|---|
| 86 | else |
|---|
| 87 | error stop 'The file ''launchPEM.info'' does not exist and cannot be updated!' |
|---|
| 88 | endif |
|---|
| 89 | |
|---|
| 90 | END SUBROUTINE update_info |
|---|
| 91 | !======================================================================= |
|---|
| 92 | |
|---|
| 93 | !======================================================================= |
|---|
| 94 | FUNCTION int2str(i) RESULT(str) |
|---|
| 95 | !----------------------------------------------------------------------- |
|---|
| 96 | ! NAME |
|---|
| 97 | ! int2str |
|---|
| 98 | ! |
|---|
| 99 | ! DESCRIPTION |
|---|
| 100 | ! Convert an integer into a string. |
|---|
| 101 | ! |
|---|
| 102 | ! AUTHORS & DATE |
|---|
| 103 | ! JB Clement, 2023-2025 |
|---|
| 104 | ! |
|---|
| 105 | ! NOTES |
|---|
| 106 | ! |
|---|
| 107 | !----------------------------------------------------------------------- |
|---|
| 108 | |
|---|
| 109 | ! DECLARATION |
|---|
| 110 | ! ----------- |
|---|
| 111 | implicit none |
|---|
| 112 | |
|---|
| 113 | ! ARGUMENTS |
|---|
| 114 | ! --------- |
|---|
| 115 | integer, intent(in) :: i |
|---|
| 116 | |
|---|
| 117 | ! LOCAL VARIABLES |
|---|
| 118 | ! --------------- |
|---|
| 119 | character(20) :: str_tmp |
|---|
| 120 | character(:), allocatable :: str |
|---|
| 121 | |
|---|
| 122 | ! CODE |
|---|
| 123 | ! ---- |
|---|
| 124 | if (nb_digits(real(i)) > len(str_tmp)) error stop 'int2str [info_pem]: invalid integer for conversion!' |
|---|
| 125 | write(str_tmp,'(i0)') i |
|---|
| 126 | str = trim(adjustl(str_tmp)) |
|---|
| 127 | |
|---|
| 128 | END FUNCTION int2str |
|---|
| 129 | !======================================================================= |
|---|
| 130 | |
|---|
| 131 | !======================================================================= |
|---|
| 132 | FUNCTION nb_digits(x) RESULT(idigits) |
|---|
| 133 | !----------------------------------------------------------------------- |
|---|
| 134 | ! NAME |
|---|
| 135 | ! nb_digits |
|---|
| 136 | ! |
|---|
| 137 | ! DESCRIPTION |
|---|
| 138 | ! Give the number of digits for the integer part of a real number. |
|---|
| 139 | ! |
|---|
| 140 | ! AUTHORS & DATE |
|---|
| 141 | ! JB Clement, 2023-2025 |
|---|
| 142 | ! |
|---|
| 143 | ! NOTES |
|---|
| 144 | ! |
|---|
| 145 | !----------------------------------------------------------------------- |
|---|
| 146 | |
|---|
| 147 | ! DECLARATION |
|---|
| 148 | ! ----------- |
|---|
| 149 | implicit none |
|---|
| 150 | |
|---|
| 151 | ! ARGUMENTS |
|---|
| 152 | ! --------- |
|---|
| 153 | real, intent(in) :: x |
|---|
| 154 | |
|---|
| 155 | ! LOCAL VARIABLES |
|---|
| 156 | ! --------------- |
|---|
| 157 | integer :: idigits |
|---|
| 158 | |
|---|
| 159 | ! CODE |
|---|
| 160 | ! ---- |
|---|
| 161 | idigits = 1 |
|---|
| 162 | ! If x /= 0 then: |
|---|
| 163 | if (abs(x) > 1.e-10) idigits = int(log10(abs(x))) + 1 |
|---|
| 164 | |
|---|
| 165 | END FUNCTION nb_digits |
|---|
| 166 | !======================================================================= |
|---|
| 167 | |
|---|
| 168 | END MODULE info_pem |
|---|