source: trunk/LMDZ.COMMON/libf/evolution/workflow_status.F90 @ 4075

Last change on this file since 4075 was 4075, checked in by jbclement, 2 weeks ago

PEM:
Addition of runs ID for the current cycle in "pem_workflow.sts".
JBC

File size: 5.7 KB
RevLine 
[4072]1MODULE workflow_status
[3991]2!-----------------------------------------------------------------------
3! NAME
[4072]4!     workflow_status
[3991]5!
6! DESCRIPTION
[4065]7!     Handles counters for PCM/PEM coupled runs and duration information
[4072]8!     of the simulation.
[3991]9!
10! AUTHORS & DATE
11!     JB Clement, 2023-2025
12!
13! NOTES
14!
15!-----------------------------------------------------------------------
[3076]16
[4065]17! DEPENDENCIES
18! ------------
19use numerics, only: dp, di, k4
20
[3991]21! DECLARATION
22! -----------
[3076]23implicit none
24
[4065]25! PARAMETERS
26! ----------
[4072]27character(16), parameter :: statusfile_name = 'pem_workflow.sts'
28integer(di),   protected :: i_pcm_run, i_pem_run, n_pcm_runs, n_pcm_runs_ini ! Data about the chained simulation of PCM/PEM runs
[3349]29
[3076]30contains
[3991]31!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
[3076]33!=======================================================================
[4072]34SUBROUTINE read_workflow_status()
[3991]35!-----------------------------------------------------------------------
36! NAME
[4072]37!    read_workflow_status
[2980]38!
[3991]39! DESCRIPTION
[4072]40!    Read the file "pem_workflow.sts" to get the number of simulated
[4065]41!    years.
[2980]42!
[3991]43! AUTHORS & DATE
[4065]44!    JB Clement, 12/2025
[3991]45!
46! NOTES
47!
48!-----------------------------------------------------------------------
[2980]49
[3991]50! DEPENDENCIES
51! ------------
[4065]52use stoppage,  only: stop_clean
[4072]53use evolution, only: n_yr_sim, ntot_yr_sim, set_r_plnt2earth_yr
[4065]54use display,   only: print_msg
[4072]55use utility,   only: int2str
[2886]56
[3991]57! DECLARATION
58! -----------
[3076]59implicit none
[2886]60
[3991]61! LOCAL VARIABLES
62! ---------------
[4065]63logical(k4) :: here
64real(dp)    :: tmp
65integer(di) :: ierr, funit
[2886]66
[3991]67! CODE
68! ----
[4072]69inquire(file = statusfile_name,exist = here)
70if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1)
71call print_msg('> Reading "'//statusfile_name//'"')
72open(newunit = funit,file = statusfile_name,status = 'old',form = 'formatted',action = 'read',iostat = ierr)
73if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr)
74read(funit,*) n_yr_sim, ntot_yr_sim, tmp, i_pcm_run, i_pem_run, n_pcm_runs, n_pcm_runs_ini
[4065]75call set_r_plnt2earth_yr(tmp)
76close(funit)
[3039]77
[4072]78call print_msg('Current PEM run: '//int2str(i_pem_run))
79call print_msg('Input PCM runs : '//int2str(i_pcm_run - 1)//' and '//int2str(i_pcm_run))
80
81END SUBROUTINE read_workflow_status
[3991]82!=======================================================================
[3039]83
[3512]84!=======================================================================
[4072]85SUBROUTINE update_workflow_status(n_yr_run,stopPEM,n_yr_sim,ntot_yr_sim)
[3991]86!-----------------------------------------------------------------------
87! NAME
[4072]88!    update_workflow_status
[3991]89!
90! DESCRIPTION
[4072]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
[4065]93!    stopped and the number of simulated years.
[3991]94!
95! AUTHORS & DATE
[4065]96!    R. Vandemeulebrouck
97!    JB Clement, 2023-2025
[3991]98!
99! NOTES
100!
101!-----------------------------------------------------------------------
[3512]102
[4065]103! DEPENDENCIES
104! ------------
105use evolution, only: r_plnt2earth_yr, pem_ini_date
106use utility,   only: int2str, nb_digits
107use stoppage,  only: stop_clean
108use display,   only: print_msg
109
[3991]110! DECLARATION
111! -----------
112implicit none
113
114! ARGUMENTS
115! ---------
[4071]116integer(di), intent(in) :: stopPEM     ! Reason to stop
117real(dp),    intent(in) :: n_yr_run    ! # of years
118real(dp),    intent(in) :: n_yr_sim    ! Current simulated year
[4072]119real(dp),    intent(in) :: ntot_yr_sim ! Maximum number of years to be simulated
[3991]120
121! LOCAL VARIABLES
122! ---------------
[4075]123logical(k4)               :: here
124integer(di)               :: i, cstat, ierr, funit, id_PCM_1, n_id_PCM
125character(20)             :: header1, header2, header3
126character(:), allocatable :: headline
[3512]127
[3991]128! CODE
129! ----
[4072]130call print_msg('> Updating "'//statusfile_name//'"')
131inquire(file = statusfile_name,exist = here)
132if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//statusfile_name//'"! It should be created by the PEM workflow script.',1)
[3512]133
[4065]134! Modify the header (first line)
[4075]135write(header1,'(f'//int2str(nb_digits(n_yr_sim) + 5)//'.4)') n_yr_sim
136write(header2,'(f'//int2str(nb_digits(ntot_yr_sim) + 5)//'.4)') ntot_yr_sim
137write(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"
138call 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)
[4065]139if (cstat > 0) then
140    call stop_clean(__FILE__,__LINE__,'command execution failed!',1)
141else if (cstat < 0) then
142    call stop_clean(__FILE__,__LINE__,'command execution not supported!',1)
143end if
[3512]144
[4065]145! Add the information of current PEM run at the end of file
[4075]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
147if (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
150else
151    id_PCM_1 = i_pcm_run - n_pcm_runs
152    n_id_PCM = n_pcm_runs
153end if
154headline = 'cycle=PCM('//int2str(id_PCM_1)
155do i = 1,n_id_PCM - 1
156    headline = headline//'+'//int2str(id_PCM_1 + i)
157end do
158headline = headline//')+PEM('//int2str(i_pem_run)//')'
[4072]159open(newunit = funit,file = statusfile_name,status = "old",position = "append",action = "write",iostat = ierr)
160if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//statusfile_name//'"!',ierr)
[4075]161write(funit,'(a,f20.4,f20.4,f20.4,i4)') headline, pem_ini_date + n_yr_sim, n_yr_sim, n_yr_run, stopPEM
[4065]162close(funit)
[3512]163
[4072]164END SUBROUTINE update_workflow_status
[3991]165!=======================================================================
[3512]166
[4072]167END MODULE workflow_status
Note: See TracBrowser for help on using the repository browser.