| 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) :: i, cstat, ierr, funit, id_PCM_1, n_id_PCM |
|---|
| 125 | character(20) :: header1, header2, header3 |
|---|
| 126 | character(:), allocatable :: headline |
|---|
| 127 | |
|---|
| 128 | ! CODE |
|---|
| 129 | ! ---- |
|---|
| 130 | call print_msg('> Updating "'//statusfile_name//'"') |
|---|
| 131 | inquire(file = statusfile_name,exist = here) |
|---|
| 132 | if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1) |
|---|
| 133 | |
|---|
| 134 | ! Modify the header (first line) |
|---|
| 135 | write(header1,'(f'//int2str(nb_digits(n_yr_sim) + 5)//'.4)') n_yr_sim |
|---|
| 136 | write(header2,'(f'//int2str(nb_digits(ntot_yr_sim) + 5)//'.4)') ntot_yr_sim |
|---|
| 137 | write(header3,'(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" |
|---|
| 138 | call execute_command_line('sed -i "1s/.*/'//trim(header1)//' '//trim(header2)//' '//trim(header3)//' '//int2str(i_pcm_run)//' '//int2str(i_pem_run + 1)//' '//int2str(n_pcm_runs)//' '//int2str(n_pcm_runs_ini)//'/" pem_workflow.sts',cmdstat = cstat) |
|---|
| 139 | if (cstat > 0) then |
|---|
| 140 | call stop_clean(__FILE__,__LINE__,'command execution failed!',1) |
|---|
| 141 | else if (cstat < 0) then |
|---|
| 142 | call stop_clean(__FILE__,__LINE__,'command execution not supported!',1) |
|---|
| 143 | end if |
|---|
| 144 | |
|---|
| 145 | ! Add the information of current PEM run at the end of file |
|---|
| 146 | ! Headline (cycle infomation), Date, Number of years done by the chained simulation, Number of years done by the PEM run, Code of the stopping criterion |
|---|
| 147 | if (i_pcm_run - 1 <= n_pcm_runs_ini) then |
|---|
| 148 | id_PCM_1 = i_pcm_run - n_pcm_runs_ini |
|---|
| 149 | n_id_PCM = n_pcm_runs_ini |
|---|
| 150 | else |
|---|
| 151 | id_PCM_1 = i_pcm_run - n_pcm_runs |
|---|
| 152 | n_id_PCM = n_pcm_runs |
|---|
| 153 | end if |
|---|
| 154 | headline = 'cycle=PCM('//int2str(id_PCM_1) |
|---|
| 155 | do i = 1,n_id_PCM - 1 |
|---|
| 156 | headline = headline//'+'//int2str(id_PCM_1 + i) |
|---|
| 157 | end do |
|---|
| 158 | headline = headline//')+PEM('//int2str(i_pem_run)//')' |
|---|
| 159 | open(newunit = funit,file = statusfile_name,status = "old",position = "append",action = "write",iostat = ierr) |
|---|
| 160 | if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr) |
|---|
| 161 | write(funit,'(a,f20.4,f20.4,f20.4,i4)') headline, pem_ini_date + n_yr_sim, n_yr_sim, n_yr_run, stopPEM |
|---|
| 162 | close(funit) |
|---|
| 163 | |
|---|
| 164 | END SUBROUTINE update_workflow_status |
|---|
| 165 | !======================================================================= |
|---|
| 166 | |
|---|
| 167 | END MODULE workflow_status |
|---|