| 1 | MODULE workflow_status |
|---|
| 2 | !----------------------------------------------------------------------- |
|---|
| 3 | ! NAME |
|---|
| 4 | ! workflow_status |
|---|
| 5 | ! |
|---|
| 6 | ! DESCRIPTION |
|---|
| 7 | ! Handles counters for PCM/PEM coupled runs and duration information |
|---|
| 8 | ! of the simulation. |
|---|
| 9 | ! |
|---|
| 10 | ! AUTHORS & DATE |
|---|
| 11 | ! JB Clement, 2023-2025 |
|---|
| 12 | ! |
|---|
| 13 | ! NOTES |
|---|
| 14 | ! |
|---|
| 15 | !----------------------------------------------------------------------- |
|---|
| 16 | |
|---|
| 17 | ! DEPENDENCIES |
|---|
| 18 | ! ------------ |
|---|
| 19 | use numerics, only: dp, di, k4 |
|---|
| 20 | |
|---|
| 21 | ! DECLARATION |
|---|
| 22 | ! ----------- |
|---|
| 23 | implicit none |
|---|
| 24 | |
|---|
| 25 | ! PARAMETERS |
|---|
| 26 | ! ---------- |
|---|
| 27 | character(16), parameter :: statusfile_name = 'pem_workflow.sts' |
|---|
| 28 | integer(di), protected :: i_pcm_run, i_pem_run, n_pcm_runs, n_pcm_runs_ini ! Data about the chained simulation of PCM/PEM runs |
|---|
| 29 | |
|---|
| 30 | contains |
|---|
| 31 | !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|---|
| 32 | |
|---|
| 33 | !======================================================================= |
|---|
| 34 | SUBROUTINE read_workflow_status() |
|---|
| 35 | !----------------------------------------------------------------------- |
|---|
| 36 | ! NAME |
|---|
| 37 | ! read_workflow_status |
|---|
| 38 | ! |
|---|
| 39 | ! DESCRIPTION |
|---|
| 40 | ! Read the file "pem_workflow.sts" to get the number of simulated |
|---|
| 41 | ! years. |
|---|
| 42 | ! |
|---|
| 43 | ! AUTHORS & DATE |
|---|
| 44 | ! JB Clement, 12/2025 |
|---|
| 45 | ! |
|---|
| 46 | ! NOTES |
|---|
| 47 | ! |
|---|
| 48 | !----------------------------------------------------------------------- |
|---|
| 49 | |
|---|
| 50 | ! DEPENDENCIES |
|---|
| 51 | ! ------------ |
|---|
| 52 | use stoppage, only: stop_clean |
|---|
| 53 | use evolution, only: n_yr_sim, ntot_yr_sim, set_r_plnt2earth_yr |
|---|
| 54 | use display, only: print_msg |
|---|
| 55 | use utility, only: int2str |
|---|
| 56 | |
|---|
| 57 | ! DECLARATION |
|---|
| 58 | ! ----------- |
|---|
| 59 | implicit none |
|---|
| 60 | |
|---|
| 61 | ! LOCAL VARIABLES |
|---|
| 62 | ! --------------- |
|---|
| 63 | logical(k4) :: here |
|---|
| 64 | real(dp) :: tmp |
|---|
| 65 | integer(di) :: ierr, funit |
|---|
| 66 | |
|---|
| 67 | ! CODE |
|---|
| 68 | ! ---- |
|---|
| 69 | inquire(file = statusfile_name,exist = here) |
|---|
| 70 | if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1) |
|---|
| 71 | call print_msg('> Reading "'//statusfile_name//'"') |
|---|
| 72 | open(newunit = funit,file = statusfile_name,status = 'old',form = 'formatted',action = 'read',iostat = ierr) |
|---|
| 73 | if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr) |
|---|
| 74 | read(funit,*) n_yr_sim, ntot_yr_sim, tmp, i_pcm_run, i_pem_run, n_pcm_runs, n_pcm_runs_ini |
|---|
| 75 | call set_r_plnt2earth_yr(tmp) |
|---|
| 76 | close(funit) |
|---|
| 77 | |
|---|
| 78 | call print_msg('Current PEM run: '//int2str(i_pem_run)) |
|---|
| 79 | call print_msg('Input PCM runs : '//int2str(i_pcm_run - 1)//' and '//int2str(i_pcm_run)) |
|---|
| 80 | |
|---|
| 81 | END SUBROUTINE read_workflow_status |
|---|
| 82 | !======================================================================= |
|---|
| 83 | |
|---|
| 84 | !======================================================================= |
|---|
| 85 | SUBROUTINE update_workflow_status(n_yr_run,stopPEM,n_yr_sim,ntot_yr_sim) |
|---|
| 86 | !----------------------------------------------------------------------- |
|---|
| 87 | ! NAME |
|---|
| 88 | ! update_workflow_status |
|---|
| 89 | ! |
|---|
| 90 | ! DESCRIPTION |
|---|
| 91 | ! Update the first line of "pem_workflow.sts" to count the number of |
|---|
| 92 | ! simulated years. Write in "pem_workflow.sts" the reason why the PEM |
|---|
| 93 | ! stopped and the number of simulated years. |
|---|
| 94 | ! |
|---|
| 95 | ! AUTHORS & DATE |
|---|
| 96 | ! R. Vandemeulebrouck |
|---|
| 97 | ! JB Clement, 2023-2025 |
|---|
| 98 | ! |
|---|
| 99 | ! NOTES |
|---|
| 100 | ! |
|---|
| 101 | !----------------------------------------------------------------------- |
|---|
| 102 | |
|---|
| 103 | ! DEPENDENCIES |
|---|
| 104 | ! ------------ |
|---|
| 105 | use evolution, only: r_plnt2earth_yr, pem_ini_date |
|---|
| 106 | use utility, only: int2str, nb_digits |
|---|
| 107 | use stoppage, only: stop_clean |
|---|
| 108 | use display, only: print_msg |
|---|
| 109 | |
|---|
| 110 | ! DECLARATION |
|---|
| 111 | ! ----------- |
|---|
| 112 | implicit none |
|---|
| 113 | |
|---|
| 114 | ! ARGUMENTS |
|---|
| 115 | ! --------- |
|---|
| 116 | integer(di), intent(in) :: stopPEM ! Reason to stop |
|---|
| 117 | real(dp), intent(in) :: n_yr_run ! # of years |
|---|
| 118 | real(dp), intent(in) :: n_yr_sim ! Current simulated year |
|---|
| 119 | real(dp), intent(in) :: ntot_yr_sim ! Maximum number of years to be simulated |
|---|
| 120 | |
|---|
| 121 | ! LOCAL VARIABLES |
|---|
| 122 | ! --------------- |
|---|
| 123 | logical(k4) :: here |
|---|
| 124 | integer(di) :: cstat, ierr, funit |
|---|
| 125 | character(20) :: fch1, fch2, fch3 |
|---|
| 126 | |
|---|
| 127 | ! CODE |
|---|
| 128 | ! ---- |
|---|
| 129 | call print_msg('> Updating "'//statusfile_name//'"') |
|---|
| 130 | inquire(file = statusfile_name,exist = here) |
|---|
| 131 | if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1) |
|---|
| 132 | |
|---|
| 133 | ! Modify the header (first line) |
|---|
| 134 | write(fch1,'(f'//int2str(nb_digits(n_yr_sim) + 5)//'.4)') n_yr_sim |
|---|
| 135 | write(fch2,'(f'//int2str(nb_digits(ntot_yr_sim) + 5)//'.4)') ntot_yr_sim |
|---|
| 136 | write(fch3,'(f6.4)') r_plnt2earth_yr ! 4 digits to the right of the decimal point to respect the precision of year in "pem_workflow_lib.sh" |
|---|
| 137 | call execute_command_line('sed -i "1s/.*/'//trim(fch1)//' '//trim(fch2)//' '//trim(fch3)//' '//int2str(i_pcm_run)//' '//int2str(i_pem_run + 1)//' '//int2str(n_pcm_runs)//' '//int2str(n_pcm_runs_ini)//'/" pem_workflow.sts',cmdstat = cstat) |
|---|
| 138 | if (cstat > 0) then |
|---|
| 139 | call stop_clean(__FILE__,__LINE__,'command execution failed!',1) |
|---|
| 140 | else if (cstat < 0) then |
|---|
| 141 | call stop_clean(__FILE__,__LINE__,'command execution not supported!',1) |
|---|
| 142 | end if |
|---|
| 143 | |
|---|
| 144 | ! Add the information of current PEM run at the end of file |
|---|
| 145 | open(newunit = funit,file = statusfile_name,status = "old",position = "append",action = "write",iostat = ierr) |
|---|
| 146 | if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr) |
|---|
| 147 | ! Date, Number of years done by the PEM run, Number of years done by the chained simulation, Code of the stopping criterion |
|---|
| 148 | write(funit,'(f20.4,f20.4,f20.4,i20)') pem_ini_date + n_yr_sim, n_yr_run, n_yr_sim, stopPEM |
|---|
| 149 | close(funit) |
|---|
| 150 | |
|---|
| 151 | END SUBROUTINE update_workflow_status |
|---|
| 152 | !======================================================================= |
|---|
| 153 | |
|---|
| 154 | END MODULE workflow_status |
|---|