source: trunk/LMDZ.COMMON/libf/evolution/info_PEM_mod.F90 @ 3532

Last change on this file since 3532 was 3532, checked in by jbclement, 3 weeks ago

PEM:
Removing unecessary module/subroutine "interpol_TI_PEM2PCM.F90" + Few small corrections/cleanings.
JBC

File size: 3.4 KB
RevLine 
[3096]1MODULE info_PEM_mod
[3076]2
3implicit none
4
[3349]5integer :: iPCM, iPEM, nPCM, nPCM_ini ! Data about the chained simulation of PCM/PEM runs
6
[3076]7!=======================================================================
8contains
9!=======================================================================
10
[3498]11SUBROUTINE info_PEM(i_myear_leg,stopPEM,i_myear,n_myear)
[2886]12
[2980]13!=======================================================================
14!
[3096]15! Purpose: Update the first line of "info_PEM.txt" to count the number of simulated Martian years
16!          Write in "info_PEM.txt" the reason why the PEM stopped and the number of simulated years
[2980]17!
[3039]18! Author: RV, JBC
[2980]19!=======================================================================
20
[3173]21use time_evol_mod, only: convert_years, year_bp_ini
[2886]22
[3076]23implicit none
[2886]24
[3076]25!----- Arguments
[3498]26integer, intent(in) :: stopPEM          ! Reason to stop
27real,    intent(in) :: i_myear_leg      ! # of years
28real,    intent(in) :: i_myear, n_myear ! Current simulated Martian year and maximum number of Martian years to be simulated
[2886]29
[3076]30!----- Local variables
[3096]31logical       :: ok
32integer       :: cstat
[3532]33character(50) :: info_frmt
[3512]34character(20) :: ich1, ich2, ich3, ich4, fch1, fch2, fch3
[2886]35
[3076]36!----- Code
[3387]37inquire(file = 'info_PEM.txt',exist = ok)
[3039]38if (ok) then
[3512]39    write(fch1,'(f'//int2str(nb_digits(i_myear) + 5)//'.4)') i_myear
40    write(fch2,'(f'//int2str(nb_digits(n_myear) + 5)//'.4)') n_myear
41    write(fch3,'(f6.4)') convert_years ! 4 digits to the right of the decimal point to respect the precision of Martian year in "launch_pem.sh"
42    write(ich1,'(i0)') iPCM
43    write(ich2,'(i0)') iPEM + 1
44    write(ich3,'(i0)') nPCM
45    write(ich4,'(i0)') nPCM_ini
46    call execute_command_line('sed -i "1s/.*/'//trim(fch1)//' '//trim(fch2)//' '//trim(fch3)//' '//trim(ich1)//' '//trim(ich2)//' '//trim(ich3)//' '//trim(ich4)//'/" info_PEM.txt',cmdstat = cstat)
[3096]47    if (cstat > 0) then
[3297]48        error stop 'info_PEM: command execution failed!'
[3096]49    else if (cstat < 0) then
50        error stop 'info_PEM: command execution not supported!'
51    endif
52    open(1,file = 'info_PEM.txt',status = "old",position = "append",action = "write")
[3173]53    ! Martian date, Number of Martians years done by the PEM run, Number of Martians years done by the chainded simulation, Code of the stopping criterion
54    ! The conversion ratio from Planetary years to Earth years is given in the header of the file
[3532]55    info_frmt = '(f'//int2str(nb_digits(year_bp_ini + i_myear) + 5)//'.4,'//'f'//int2str(nb_digits(i_myear_leg) + 5)//'.4,'//'f'//int2str(nb_digits(i_myear) + 5)//'.4,'//'i0)'
56    write(1,trim(adjustl(info_frmt))) year_bp_ini + i_myear, i_myear_leg, i_myear, stopPEM
[3096]57    close(1)
[3039]58else
[3096]59    error stop 'The file ''info_PEM.txt'' does not exist and cannot be updated!'
[3039]60endif
61
[3096]62END SUBROUTINE info_PEM
[3039]63
[3512]64!=======================================================================
65
66FUNCTION int2str(i) RESULT(str)
67! Function to convert an integer into a string
68
69integer, intent(in) :: i
70character(20)       :: str
71
72if (nb_digits(real(i)) > len(str)) error stop 'int2str [info_PEM_mod]: invalid integer for conversion!'
73write(str,'(i0)') i
74str = trim(adjustl(str))
75
76END FUNCTION int2str
77
78!=======================================================================
79
80FUNCTION nb_digits(x) RESULT(idigits)
81! Function to give the number of digits for the integer part of a real number
82
83real, intent(in) :: x
84integer          :: idigits
85
86idigits = 1
87! If x /= 0 then:
88if (abs(x) > 1.e-10) idigits = int(log10(abs(x))) + 1
89
90END FUNCTION nb_digits
91
[3096]92END MODULE info_PEM_mod
Note: See TracBrowser for help on using the repository browser.