Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if output and restart file path is writeable #167

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/io/io_routines.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,28 @@ integer function io_newunit(unit)
if (present(unit)) unit=io_newunit
end function io_newunit

!>------------------------------------------------------------
!! Checks if path exists from filename string
!!
!! If directory does not exist print error message and stop program
!!
!! @param filename string of path to write output/restart files to
!!
!!------------------------------------------------------------
subroutine check_writeable_path(filename)
use icar_constants, only : kMAX_FILE_LENGTH
implicit none
character(len=kMAX_FILE_LENGTH), intent(in) :: filename
character(len=kMAX_FILE_LENGTH) :: dir_path
integer :: dir_separator
logical :: dir_exists
dir_separator = index(filename, '/', back=.true.)
if (dir_separator > 0) then
dir_path = filename(1:dir_separator)
inquire(file=dir_path, exist=dir_exists)
if (dir_exists .eqv. .false.) then
stop "Following directory does not exist to write to: " // dir_path
end if
end if
end subroutine check_writeable_path
end module io_routines
2 changes: 1 addition & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ $(BUILD)pbl_utilities.o:$(UTIL)pbl_utilities.f90 $(BUILD)icar_constants.o \
# I/O routines
###################################################################

$(BUILD)io_routines.o:$(IO)io_routines.f90 $(BUILD)data_structures.o
$(BUILD)io_routines.o:$(IO)io_routines.f90 $(BUILD)data_structures.o $(BUILD)icar_constants.o

$(BUILD)lt_lut_io.o: $(IO)lt_lut_io.f90 $(BUILD)data_structures.o $(BUILD)io_routines.o \
$(BUILD)string.o $(BUILD)opt_types.o $(BUILD)icar_constants.o
Expand Down
9 changes: 6 additions & 3 deletions src/objects/options_obj.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
kNO_STOCHASTIC, kVERSION_STRING, kMAX_FILE_LENGTH, kMAX_NAME_LENGTH, pi, &
kWATER_LAKE, &
kWIND_LINEAR, kLINEAR_ITERATIVE_WINDS, kITERATIVE_WINDS, kCONSERVE_MASS
use io_routines, only : io_newunit
use io_routines, only : io_newunit, check_writeable_path
use time_io, only : find_timestep_in_file
use time_delta_object, only : time_delta_t
use time_object, only : Time_type
Expand Down Expand Up @@ -510,7 +510,7 @@ subroutine init_restart_options(filename, options)
restart_file = get_image_filename(this_image(), restart_file, restart_time)
restart_step = find_timestep_in_file(restart_file, 'time', restart_time, time_at_step)

! check to see if we actually udpated the restart date and print if in a more verbose mode
! check to see if we actually updated the restart date and print if in a more verbose mode
if (options%debug) then
if (restart_time /= time_at_step) then
if (this_image()==1) write(*,*) " updated restart date: ", trim(time_at_step%as_string())
Expand Down Expand Up @@ -702,10 +702,13 @@ subroutine output_namelist(filename, options)
options%restart_count = max(24, nint(restartinterval))
endif

! check if directory paths to output and restart file strings exist
! stop and report error if they do not rather than failing at write step
call check_writeable_path(output_file)
call check_writeable_path(restart_file)
options%output_file = output_file
options%restart_file = restart_file


end subroutine output_namelist


Expand Down