| 1 | MODULE info_PEM_mod |
|---|
| 2 | |
|---|
| 3 | implicit none |
|---|
| 4 | |
|---|
| 5 | integer :: iPCM, iPEM, nPCM, nPCM_ini ! Data about the chained simulation of PCM/PEM runs |
|---|
| 6 | |
|---|
| 7 | !======================================================================= |
|---|
| 8 | contains |
|---|
| 9 | !======================================================================= |
|---|
| 10 | |
|---|
| 11 | SUBROUTINE info_PEM(year_iter,stopPEM,i_myear,n_myear) |
|---|
| 12 | |
|---|
| 13 | !======================================================================= |
|---|
| 14 | ! |
|---|
| 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 |
|---|
| 17 | ! |
|---|
| 18 | ! Author: RV, JBC |
|---|
| 19 | !======================================================================= |
|---|
| 20 | |
|---|
| 21 | use time_evol_mod, only: convert_years, year_bp_ini |
|---|
| 22 | |
|---|
| 23 | implicit none |
|---|
| 24 | |
|---|
| 25 | !----- Arguments |
|---|
| 26 | integer, intent(in) :: year_iter, stopPEM ! # of year and reason to stop |
|---|
| 27 | integer, intent(in) :: i_myear, n_myear ! Current simulated Martian year and maximum number of Martian years to be simulated |
|---|
| 28 | |
|---|
| 29 | !----- Local variables |
|---|
| 30 | logical :: ok |
|---|
| 31 | integer :: cstat |
|---|
| 32 | character(10) :: ich1, ich2, ich3, ich4, ich5, ich6, fch |
|---|
| 33 | |
|---|
| 34 | !----- Code |
|---|
| 35 | inquire(file = 'info_PEM.txt',exist = ok) |
|---|
| 36 | if (ok) then |
|---|
| 37 | write(ich1,'(i0)') i_myear |
|---|
| 38 | write(ich2,'(i0)') n_myear |
|---|
| 39 | write(fch,'(f0.4)') convert_years ! 4 digits to the right of the decimal point to respect the precision of Martian year in "launch_pem.sh" |
|---|
| 40 | write(ich3,'(i0)') iPCM |
|---|
| 41 | write(ich4,'(i0)') iPEM + 1 |
|---|
| 42 | write(ich5,'(i0)') nPCM |
|---|
| 43 | write(ich6,'(i0)') nPCM_ini |
|---|
| 44 | call execute_command_line('sed -i "1s/.*/'//trim(ich1)//' '//trim(ich2)//' '//trim(fch)//' '//trim(ich3)//' '//trim(ich4)//' '//trim(ich5)//' '//trim(ich6)//'/" info_PEM.txt',cmdstat = cstat) |
|---|
| 45 | if (cstat > 0) then |
|---|
| 46 | error stop 'info_PEM: command execution failed!' |
|---|
| 47 | else if (cstat < 0) then |
|---|
| 48 | error stop 'info_PEM: command execution not supported!' |
|---|
| 49 | endif |
|---|
| 50 | open(1,file = 'info_PEM.txt',status = "old",position = "append",action = "write") |
|---|
| 51 | ! 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 |
|---|
| 52 | ! The conversion ratio from Planetary years to Earth years is given in the header of the file |
|---|
| 53 | write(1,*) year_bp_ini + i_myear, year_iter, i_myear, stopPEM |
|---|
| 54 | close(1) |
|---|
| 55 | else |
|---|
| 56 | error stop 'The file ''info_PEM.txt'' does not exist and cannot be updated!' |
|---|
| 57 | endif |
|---|
| 58 | |
|---|
| 59 | END SUBROUTINE info_PEM |
|---|
| 60 | |
|---|
| 61 | END MODULE info_PEM_mod |
|---|