Skip to content

Commit

Permalink
Merge pull request #1 from FrancescoAvanzi/main
Browse files Browse the repository at this point in the history
change to process pid
  • Loading branch information
FrancescoAvanzi authored Dec 18, 2023
2 parents 689d482 + dcec140 commit 44250dd
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

Version 5.3.0 (20231215)
========================
- Improved handling of input, assimilation, and restard data to allow multiple, parallel runs on the same input data. The improved approach generates temporary copies of inpit files using process PID to avoid problems with concurrent reading of the same netCDF file.

Version 5.2.0 (20230208)
========================
- Improved handling of restard data, with a more rigorous check on the existence of both file and NC layers to avoid spurious results
Expand Down
10 changes: 5 additions & 5 deletions S3M_Main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
! S3M
!***********************************************************************************
!
! brief S3M Snow Multidata Mapping and Modeling (Boni et al. 2010, Avanzi et al. 2022)
! brief S3M Snow Multidata Mapping and Modeling (Avanzi et al. 2022)
!
! history FRANCESCO AVANZI (CIMAFOUNDATION)
!+ 09/02/2023
!+ v5p2r0
!+ 15/12/2023
!+ v5p3r0
!
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -34,15 +34,15 @@
! 4) Snow age, albedo, melt, and snowpack runoff
! 5) Ice thickness.

! S3M 5.2.0 is distributed through the CIMA Research Foundation - Department of Hydrology and Hydraulics GitHub repo at
! S3M 5.3.0 is distributed through the CIMA Research Foundation - Department of Hydrology and Hydraulics GitHub repo at
! https://github.com/c-hydro
! A complete manual regarding model installation, run, as well as pre- and post-processing can be found at:
! https://gmd.copernicus.org/articles/15/4853/2022/
!
!-----------------------------------------------------------------------------------
! COMMAND LINE (example)
!-----------------------------------------------------------------------------------
! ./S3M_v5p2.x --> parameter(s): S3M_info_domain_DataDa_DataA.txt
! ./S3M_v5p3.x --> parameter(s): S3M_infofile.txt
!
! All compiling and debugging options for S3M are described at https://github.com/c-hydro/hmc-dev
!
Expand Down
84 changes: 57 additions & 27 deletions S3M_Module_Data_Forcing_Gridded.f90

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions S3M_Module_Data_Restart_Gridded.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani, Francesco Avanzi.
!
! Created on May 7, 2015, 1:27 PM
! Last update on February 09, 2023 10:30 AM
! Last update on December 15, 2023 11:20 AM
!
! Module to read restart data.
!------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -44,7 +44,7 @@ module S3M_Module_Data_Restart_Gridded
S3M_Tools_Generic_UnzipFile, &
S3M_Tools_Generic_RemoveFile, &
transpose3Dvar, &
checkdomainvar
checkdomainvar, getProcessID

! Implicit none for all subroutines in this module
implicit none
Expand Down Expand Up @@ -271,7 +271,7 @@ subroutine S3M_Data_Restart_Gridded_NC(iID, &
integer(kind = 4) :: iID

character(len = 256), intent(in) :: sPathData_Restart
character(len = 700) :: sFileNameData_Restart, sFileNameData_Restart_Zip
character(len = 700) :: sFileNameData_Restart, sFileNameData_Restart_Zip, sFileNameData_Temp
character(len = 700) :: sCommandUnzipFile
character(len = 256) :: sVarName
integer(kind = 4), intent(in) :: iRows, iCols
Expand All @@ -295,7 +295,7 @@ subroutine S3M_Data_Restart_Gridded_NC(iID, &
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarLat
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarLon

character(len = 256) :: sVarUnits
character(len = 256) :: sVarUnits, sPID
integer(kind = 4) :: iErr
integer(kind = 4) :: iFileID
integer(kind = 4) :: iFlagIceMassBalance
Expand All @@ -313,13 +313,18 @@ subroutine S3M_Data_Restart_Gridded_NC(iID, &
a2dVarLat = -9999.0; a2dVarLon = -9999.0;
bCheckRestart = .false.;
bCheckVar = .true.;

sPID = ''; sFileNameData_Temp = ''
!------------------------------------------------------------------------------------------

!------------------------------------------------------------------------------------------
! Get global information
sCommandUnzipFile = oS3M_Namelist(iID)%sCommandUnzipFile
! Info start
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded :: NetCDF ... ' )

! Get unique process ID
sPID = adjustl(getProcessID())
!------------------------------------------------------------------------------------------

!------------------------------------------------------------------------------------------
Expand All @@ -328,6 +333,11 @@ subroutine S3M_Data_Restart_Gridded_NC(iID, &
sTime(1:4)//sTime(6:7)//sTime(9:10)// &
sTime(12:13)//sTime(15:16)// &
".nc"
! Create Filename with unique PID number to avoid simultaneously access to the same Forcing file
sFileNameData_Temp = trim(sPathData_Restart)//"S3M_"// &
sTime(1:4)//sTime(6:7)//sTime(9:10)// &
sTime(12:13)//sTime(15:16)//'_'//trim(sPID)// &
".nc"

! Info netCDF filename
call mprintf(.true., iINFO_Basic, ' Get filename (restart gridded): '//trim(sFileNameData_Restart)//' ... ' )
Expand All @@ -350,12 +360,12 @@ subroutine S3M_Data_Restart_Gridded_NC(iID, &
! Unzip file
call S3M_Tools_Generic_UnzipFile(sCommandUnzipFile, &
sFileNameData_Restart_Zip, &
sFileNameData_Restart, .true.)
sFileNameData_Temp, .true.)
!------------------------------------------------------------------------------------------

!------------------------------------------------------------------------------------------
! Opening netCDF file
iErr = nf90_open(trim(sFileNameData_Restart), NF90_NOWRITE, iFileID)
iErr = nf90_open(trim(sFileNameData_Temp), NF90_NOWRITE, iFileID)
if (iErr /= 0) then

!------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -538,6 +548,10 @@ subroutine S3M_Data_Restart_Gridded_NC(iID, &

! Closing netcdf file (drops db)
iErr = nf90_close(iFileID)

! Remove uncompressed file (to save space on disk)
call S3M_Tools_Generic_RemoveFile(oS3M_Namelist(iID)%sCommandRemoveFile, &
sFileNameData_Temp, .false.)
!------------------------------------------------------------------------------------------

!------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 44250dd

Please sign in to comment.