MODULE info_pem !----------------------------------------------------------------------- ! NAME ! info_pem ! ! DESCRIPTION ! Handles counters for PCM/PEM coupled runs and simulation metadata. ! ! AUTHORS & DATE ! R. Vandemeulebrouck ! JB Clement, 2023-2025 ! ! NOTES ! !----------------------------------------------------------------------- ! DECLARATION ! ----------- implicit none ! MODULE VARIABLES ! ---------------- integer :: iPCM, iPEM, nPCM, nPCM_ini ! Data about the chained simulation of PCM/PEM runs contains !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ !======================================================================= SUBROUTINE update_info(i_myear_leg,stopPEM,i_myear,nyears_tot) !----------------------------------------------------------------------- ! NAME ! update_info ! ! DESCRIPTION ! Update the first line of "launchPEM.info" to count the number of ! simulated Martian years. Write in "launchPEM.info" 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: convert_years, year_bp_ini ! DECLARATION ! ----------- implicit none ! ARGUMENTS ! --------- integer, intent(in) :: stopPEM ! Reason to stop real, intent(in) :: i_myear_leg ! # of years real, intent(in) :: i_myear ! Current simulated Martian year real, intent(in) :: nyears_tot ! Maximum number of Martian years to be simulated ! LOCAL VARIABLES ! --------------- logical :: ok integer :: cstat character(20) :: fch1, fch2, fch3 ! CODE ! ---- inquire(file = 'launchPEM.info',exist = ok) if (ok) then write(fch1,'(f'//int2str(nb_digits(i_myear) + 5)//'.4)') i_myear write(fch2,'(f'//int2str(nb_digits(nyears_tot) + 5)//'.4)') nyears_tot 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" call execute_command_line('sed -i "1s/.*/'//trim(fch1)//' '//trim(fch2)//' '//trim(fch3)//' '//int2str(iPCM)//' '//int2str(iPEM + 1)//' '//int2str(nPCM)//' '//int2str(nPCM_ini)//'/" launchPEM.info',cmdstat = cstat) if (cstat > 0) then error stop 'update_info: command execution failed!' else if (cstat < 0) then error stop 'update_info: command execution not supported!' endif open(1,file = 'launchPEM.info',status = "old",position = "append",action = "write") ! 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 ! The conversion ratio from Planetary years to Earth years is given in the header of the file write(1,'(f20.4,f20.4,f20.4,i20)') year_bp_ini + i_myear, i_myear_leg, i_myear, stopPEM close(1) else error stop 'The file ''launchPEM.info'' does not exist and cannot be updated!' endif END SUBROUTINE update_info !======================================================================= !======================================================================= FUNCTION int2str(i) RESULT(str) !----------------------------------------------------------------------- ! NAME ! int2str ! ! DESCRIPTION ! Convert an integer into a string. ! ! AUTHORS & DATE ! JB Clement, 2023-2025 ! ! NOTES ! !----------------------------------------------------------------------- ! DECLARATION ! ----------- implicit none ! ARGUMENTS ! --------- integer, intent(in) :: i ! LOCAL VARIABLES ! --------------- character(20) :: str_tmp character(:), allocatable :: str ! CODE ! ---- if (nb_digits(real(i)) > len(str_tmp)) error stop 'int2str [info_pem]: invalid integer for conversion!' write(str_tmp,'(i0)') i str = trim(adjustl(str_tmp)) END FUNCTION int2str !======================================================================= !======================================================================= FUNCTION nb_digits(x) RESULT(idigits) !----------------------------------------------------------------------- ! NAME ! nb_digits ! ! DESCRIPTION ! Give the number of digits for the integer part of a real number. ! ! AUTHORS & DATE ! JB Clement, 2023-2025 ! ! NOTES ! !----------------------------------------------------------------------- ! DECLARATION ! ----------- implicit none ! ARGUMENTS ! --------- real, intent(in) :: x ! LOCAL VARIABLES ! --------------- integer :: idigits ! CODE ! ---- idigits = 1 ! If x /= 0 then: if (abs(x) > 1.e-10) idigits = int(log10(abs(x))) + 1 END FUNCTION nb_digits !======================================================================= END MODULE info_pem