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

Last change on this file since 4076 was 4075, checked in by jbclement, 11 days ago

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

File size: 5.7 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)               :: i, cstat, ierr, funit, id_PCM_1, n_id_PCM
125character(20)             :: header1, header2, header3
126character(:), allocatable :: headline
127
128! CODE
129! ----
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)
133
134! Modify the header (first line)
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)
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
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
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)//')'
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)
161write(funit,'(a,f20.4,f20.4,f20.4,i4)') headline, pem_ini_date + n_yr_sim, n_yr_sim, n_yr_run, stopPEM
162close(funit)
163
164END SUBROUTINE update_workflow_status
165!=======================================================================
166
167END MODULE workflow_status
Note: See TracBrowser for help on using the repository browser.