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

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

PEM:
Modify the PEM semantics to standardize file/functions/variable names and avoid ambiguity: workflow = repetion of cycles; cycle = PCM phase + PEM phase; PCM phase = 2+ PCM runs of 1 year each, PEM phase = 1 PEM run of 'x' years.
JBC

File size: 5.2 KB
Line 
1MODULE 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! ------------
19use numerics, only: dp, di, k4
20
21! DECLARATION
22! -----------
23implicit none
24
25! PARAMETERS
26! ----------
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
29
30contains
31!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
33!=======================================================================
34SUBROUTINE 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! ------------
52use stoppage,  only: stop_clean
53use evolution, only: n_yr_sim, ntot_yr_sim, set_r_plnt2earth_yr
54use display,   only: print_msg
55use utility,   only: int2str
56
57! DECLARATION
58! -----------
59implicit none
60
61! LOCAL VARIABLES
62! ---------------
63logical(k4) :: here
64real(dp)    :: tmp
65integer(di) :: ierr, funit
66
67! CODE
68! ----
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
75call set_r_plnt2earth_yr(tmp)
76close(funit)
77
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
82!=======================================================================
83
84!=======================================================================
85SUBROUTINE 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! ------------
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
110! DECLARATION
111! -----------
112implicit none
113
114! ARGUMENTS
115! ---------
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
119real(dp),    intent(in) :: ntot_yr_sim ! Maximum number of years to be simulated
120
121! LOCAL VARIABLES
122! ---------------
123logical(k4)   :: here
124integer(di)   :: cstat, ierr, funit
125character(20) :: fch1, fch2, fch3
126
127! CODE
128! ----
129call print_msg('> Updating "'//statusfile_name//'"')
130inquire(file = statusfile_name,exist = here)
131if (.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)
134write(fch1,'(f'//int2str(nb_digits(n_yr_sim) + 5)//'.4)') n_yr_sim
135write(fch2,'(f'//int2str(nb_digits(ntot_yr_sim) + 5)//'.4)') ntot_yr_sim
136write(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"
137call 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)
138if (cstat > 0) then
139    call stop_clean(__FILE__,__LINE__,'command execution failed!',1)
140else if (cstat < 0) then
141    call stop_clean(__FILE__,__LINE__,'command execution not supported!',1)
142end if
143
144! Add the information of current PEM run at the end of file
145open(newunit = funit,file = statusfile_name,status = "old",position = "append",action = "write",iostat = ierr)
146if (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
148write(funit,'(f20.4,f20.4,f20.4,i20)') pem_ini_date + n_yr_sim, n_yr_run, n_yr_sim, stopPEM
149close(funit)
150
151END SUBROUTINE update_workflow_status
152!=======================================================================
153
154END MODULE workflow_status
Note: See TracBrowser for help on using the repository browser.