[3096] | 1 | MODULE info_PEM_mod |
---|
[3076] | 2 | |
---|
| 3 | implicit none |
---|
| 4 | |
---|
[3349] | 5 | integer :: iPCM, iPEM, nPCM, nPCM_ini ! Data about the chained simulation of PCM/PEM runs |
---|
| 6 | |
---|
[3076] | 7 | !======================================================================= |
---|
| 8 | contains |
---|
| 9 | !======================================================================= |
---|
| 10 | |
---|
[3498] | 11 | SUBROUTINE info_PEM(i_myear_leg,stopPEM,i_myear,n_myear) |
---|
[2886] | 12 | |
---|
[2980] | 13 | !======================================================================= |
---|
| 14 | ! |
---|
[3096] | 15 | ! Purpose: Update the first line of "info_PEM.txt" to count the number of simulated Martian years |
---|
| 16 | ! Write in "info_PEM.txt" the reason why the PEM stopped and the number of simulated years |
---|
[2980] | 17 | ! |
---|
[3039] | 18 | ! Author: RV, JBC |
---|
[2980] | 19 | !======================================================================= |
---|
| 20 | |
---|
[3173] | 21 | use time_evol_mod, only: convert_years, year_bp_ini |
---|
[2886] | 22 | |
---|
[3076] | 23 | implicit none |
---|
[2886] | 24 | |
---|
[3076] | 25 | !----- Arguments |
---|
[3498] | 26 | integer, intent(in) :: stopPEM ! Reason to stop |
---|
| 27 | real, intent(in) :: i_myear_leg ! # of years |
---|
| 28 | real, intent(in) :: i_myear, n_myear ! Current simulated Martian year and maximum number of Martian years to be simulated |
---|
[2886] | 29 | |
---|
[3076] | 30 | !----- Local variables |
---|
[3096] | 31 | logical :: ok |
---|
| 32 | integer :: cstat |
---|
[3533] | 33 | character(20) :: fch1, fch2, fch3 |
---|
[2886] | 34 | |
---|
[3076] | 35 | !----- Code |
---|
[3387] | 36 | inquire(file = 'info_PEM.txt',exist = ok) |
---|
[3039] | 37 | if (ok) then |
---|
[3512] | 38 | write(fch1,'(f'//int2str(nb_digits(i_myear) + 5)//'.4)') i_myear |
---|
| 39 | write(fch2,'(f'//int2str(nb_digits(n_myear) + 5)//'.4)') n_myear |
---|
| 40 | 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" |
---|
[3533] | 41 | call execute_command_line('sed -i "1s/.*/'//trim(fch1)//' '//trim(fch2)//' '//trim(fch3)//' '//int2str(iPCM)//' '//int2str(iPEM + 1)//' '//int2str(nPCM)//' '//int2str(nPCM_ini)//'/" info_PEM.txt',cmdstat = cstat) |
---|
[3096] | 42 | if (cstat > 0) then |
---|
[3297] | 43 | error stop 'info_PEM: command execution failed!' |
---|
[3096] | 44 | else if (cstat < 0) then |
---|
| 45 | error stop 'info_PEM: command execution not supported!' |
---|
| 46 | endif |
---|
| 47 | open(1,file = 'info_PEM.txt',status = "old",position = "append",action = "write") |
---|
[3173] | 48 | ! 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 |
---|
| 49 | ! The conversion ratio from Planetary years to Earth years is given in the header of the file |
---|
[3533] | 50 | write(1,'(f20.4,f20.4,f20.4,i20)') year_bp_ini + i_myear, i_myear_leg, i_myear, stopPEM |
---|
[3096] | 51 | close(1) |
---|
[3039] | 52 | else |
---|
[3096] | 53 | error stop 'The file ''info_PEM.txt'' does not exist and cannot be updated!' |
---|
[3039] | 54 | endif |
---|
| 55 | |
---|
[3096] | 56 | END SUBROUTINE info_PEM |
---|
[3039] | 57 | |
---|
[3512] | 58 | !======================================================================= |
---|
| 59 | |
---|
| 60 | FUNCTION int2str(i) RESULT(str) |
---|
| 61 | ! Function to convert an integer into a string |
---|
| 62 | |
---|
[3533] | 63 | integer, intent(in) :: i |
---|
| 64 | character(20) :: str_tmp |
---|
| 65 | character(:), allocatable :: str |
---|
[3512] | 66 | |
---|
[3533] | 67 | if (nb_digits(real(i)) > len(str_tmp)) error stop 'int2str [info_PEM_mod]: invalid integer for conversion!' |
---|
| 68 | write(str_tmp,'(i0)') i |
---|
| 69 | str = trim(adjustl(str_tmp)) |
---|
[3512] | 70 | |
---|
| 71 | END FUNCTION int2str |
---|
| 72 | |
---|
| 73 | !======================================================================= |
---|
| 74 | |
---|
| 75 | FUNCTION nb_digits(x) RESULT(idigits) |
---|
| 76 | ! Function to give the number of digits for the integer part of a real number |
---|
| 77 | |
---|
| 78 | real, intent(in) :: x |
---|
| 79 | integer :: idigits |
---|
| 80 | |
---|
| 81 | idigits = 1 |
---|
| 82 | ! If x /= 0 then: |
---|
| 83 | if (abs(x) > 1.e-10) idigits = int(log10(abs(x))) + 1 |
---|
| 84 | |
---|
| 85 | END FUNCTION nb_digits |
---|
| 86 | |
---|
[3096] | 87 | END MODULE info_PEM_mod |
---|