MODULE workflow_status !----------------------------------------------------------------------- ! NAME ! workflow_status ! ! DESCRIPTION ! Handles counters for PCM/PEM coupled runs and duration information ! of the simulation. ! ! AUTHORS & DATE ! JB Clement, 2023-2025 ! ! NOTES ! !----------------------------------------------------------------------- ! DEPENDENCIES ! ------------ use numerics, only: dp, di, k4 ! DECLARATION ! ----------- implicit none ! PARAMETERS ! ---------- character(16), parameter :: statusfile_name = 'pem_workflow.sts' 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 contains !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ !======================================================================= SUBROUTINE read_workflow_status() !----------------------------------------------------------------------- ! NAME ! read_workflow_status ! ! DESCRIPTION ! Read the file "pem_workflow.sts" to get the number of simulated ! years. ! ! AUTHORS & DATE ! JB Clement, 12/2025 ! ! NOTES ! !----------------------------------------------------------------------- ! DEPENDENCIES ! ------------ use stoppage, only: stop_clean use evolution, only: n_yr_sim, ntot_yr_sim, set_r_plnt2earth_yr use display, only: print_msg use utility, only: int2str ! DECLARATION ! ----------- implicit none ! LOCAL VARIABLES ! --------------- logical(k4) :: here real(dp) :: tmp integer(di) :: ierr, funit ! CODE ! ---- inquire(file = statusfile_name,exist = here) if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1) call print_msg('> Reading "'//statusfile_name//'"') open(newunit = funit,file = statusfile_name,status = 'old',form = 'formatted',action = 'read',iostat = ierr) if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr) read(funit,*) n_yr_sim, ntot_yr_sim, tmp, i_pcm_run, i_pem_run, n_pcm_runs, n_pcm_runs_ini call set_r_plnt2earth_yr(tmp) close(funit) call print_msg('Current PEM run: '//int2str(i_pem_run)) call print_msg('Input PCM runs : '//int2str(i_pcm_run - 1)//' and '//int2str(i_pcm_run)) END SUBROUTINE read_workflow_status !======================================================================= !======================================================================= SUBROUTINE update_workflow_status(n_yr_run,stopPEM,n_yr_sim,ntot_yr_sim) !----------------------------------------------------------------------- ! NAME ! update_workflow_status ! ! DESCRIPTION ! Update the first line of "pem_workflow.sts" to count the number of ! simulated years. Write in "pem_workflow.sts" the reason why the PEM ! stopped and the number of simulated years. ! ! AUTHORS & DATE ! R. Vandemeulebrouck ! JB Clement, 2023-2025 ! ! NOTES ! !----------------------------------------------------------------------- ! DEPENDENCIES ! ------------ use evolution, only: r_plnt2earth_yr, pem_ini_date use utility, only: int2str, nb_digits use stoppage, only: stop_clean use display, only: print_msg ! DECLARATION ! ----------- implicit none ! ARGUMENTS ! --------- integer(di), intent(in) :: stopPEM ! Reason to stop real(dp), intent(in) :: n_yr_run ! # of years real(dp), intent(in) :: n_yr_sim ! Current simulated year real(dp), intent(in) :: ntot_yr_sim ! Maximum number of years to be simulated ! LOCAL VARIABLES ! --------------- logical(k4) :: here integer(di) :: cstat, ierr, funit character(20) :: fch1, fch2, fch3 ! CODE ! ---- call print_msg('> Updating "'//statusfile_name//'"') inquire(file = statusfile_name,exist = here) if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1) ! Modify the header (first line) write(fch1,'(f'//int2str(nb_digits(n_yr_sim) + 5)//'.4)') n_yr_sim write(fch2,'(f'//int2str(nb_digits(ntot_yr_sim) + 5)//'.4)') ntot_yr_sim 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" 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) if (cstat > 0) then call stop_clean(__FILE__,__LINE__,'command execution failed!',1) else if (cstat < 0) then call stop_clean(__FILE__,__LINE__,'command execution not supported!',1) end if ! Add the information of current PEM run at the end of file open(newunit = funit,file = statusfile_name,status = "old",position = "append",action = "write",iostat = ierr) if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr) ! Date, Number of years done by the PEM run, Number of years done by the chained simulation, Code of the stopping criterion write(funit,'(f20.4,f20.4,f20.4,i20)') pem_ini_date + n_yr_sim, n_yr_run, n_yr_sim, stopPEM close(funit) END SUBROUTINE update_workflow_status !======================================================================= END MODULE workflow_status