Skip to content

Commit

Permalink
updates error checking for reading in parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeter committed Sep 19, 2024
1 parent 1ddef3d commit a836dc2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/shared/read_parameter_file.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,8 @@ subroutine read_parameter_file_only()

if (some_parameters_missing_from_Par_file) then
write(*,*)
write(*,*) 'All the above parameters are missing from your Par_file.'
write(*,*) 'Please cut and paste them somewhere in your Par_file (any place is fine), change their values if needed'
write(*,*) 'All the above parameters are either in a wrong number format or missing from your Par_file.'
write(*,*) 'Please correct or cut&paste them somewhere in your Par_file (any place is fine), change their values if needed'
write(*,*) '(the above values are just default values), and restart your run.'
write(*,*)
call stop_the_code('Error: some parameters are missing in your Par_file, it is incomplete or in an older format, &
Expand Down
12 changes: 12 additions & 0 deletions src/shared/read_source_file.f90
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ subroutine read_source_file(NSOURCES,BROADCAST_AFTER_READ)
character(len=256) string_read
character(len=MAX_STRING_LEN) :: source_filename,path_to_add
integer, parameter :: IIN_SOURCE = 22
logical :: stf_exists

! user output
if (myrank == 0) then
Expand Down Expand Up @@ -315,6 +316,17 @@ subroutine read_source_file(NSOURCES,BROADCAST_AFTER_READ)
write(IMAIN,*) ' Multiplying factor = ',factor(i_source)
write(IMAIN,*)

! check if external stf file exists
if (time_function_type(i_source) == 8) then
inquire(file=trim(name_of_source_file(i_source)),exist=stf_exists)
if (.not. stf_exists) then
write(*,*) ''
write(*,*) 'Error external source time function file: ',trim(name_of_source_file(i_source)),' not found.'
write(*,*) ''
call stop_the_code('Error reading SOURCE file: could not find specified external source time function file')
endif
endif

enddo ! do i_source= 1,NSOURCES
close(IIN_SOURCE)

Expand Down
12 changes: 6 additions & 6 deletions src/shared/read_value_parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ subroutine read_value_integer_p(value_to_read, name)

call param_read(string_read, len(string_read), name, len(name), ierr)
if (ierr /= 0) return
read(string_read,*) value_to_read
read(string_read,*,iostat=ierr) value_to_read

end subroutine read_value_integer_p

Expand All @@ -217,7 +217,7 @@ subroutine read_value_double_precision_p(value_to_read, name)

call param_read(string_read, len(string_read), name, len(name), ierr)
if (ierr /= 0) return
read(string_read,*) value_to_read
read(string_read,*,iostat=ierr) value_to_read

end subroutine read_value_double_precision_p

Expand All @@ -237,7 +237,7 @@ subroutine read_value_logical_p(value_to_read, name)

call param_read(string_read, len(string_read), name, len(name), ierr)
if (ierr /= 0) return
read(string_read,*) value_to_read
read(string_read,*,iostat=ierr) value_to_read

end subroutine read_value_logical_p

Expand Down Expand Up @@ -277,7 +277,7 @@ subroutine read_value_integer_next_p(value_to_read, name)

call param_read_nextparam(string_read, len(string_read), name, len(name), ierr)
if (ierr /= 0) return
read(string_read,*) value_to_read
read(string_read,*,iostat=ierr) value_to_read

end subroutine read_value_integer_next_p

Expand All @@ -297,7 +297,7 @@ subroutine read_value_double_prec_next_p(value_to_read, name)

call param_read_nextparam(string_read, len(string_read), name, len(name), ierr)
if (ierr /= 0) return
read(string_read,*) value_to_read
read(string_read,*,iostat=ierr) value_to_read

end subroutine read_value_double_prec_next_p

Expand All @@ -317,7 +317,7 @@ subroutine read_value_logical_next_p(value_to_read, name)

call param_read_nextparam(string_read, len(string_read), name, len(name), ierr)
if (ierr /= 0) return
read(string_read,*) value_to_read
read(string_read,*,iostat=ierr) value_to_read

end subroutine read_value_logical_next_p

Expand Down
10 changes: 6 additions & 4 deletions src/specfem2D/setup_sources_receivers.F90
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ subroutine setup_sources()

! user output
if (not_in_mesh_domain) then
write(IMAIN,*) 'Source ',i
write(IMAIN,*) ' Position (x,z) of the source = ',x_source(i),z_source(i)
write(IMAIN,*) 'Invalid position, mesh dimensions are: xmin/max = ',xmin,xmax,'zmin/zmax',zmin,zmax
write(IMAIN,*) 'Please fix source location, exiting...'
write(IMAIN,*) 'Error: Source ',i
write(IMAIN,*) ' Position (x,z) of the source = ',x_source(i),z_source(i)
write(IMAIN,*)
write(IMAIN,*) ' Invalid position, mesh dimensions are: xmin/max = ',xmin,xmax,'zmin/zmax',zmin,zmax
write(IMAIN,*) ' Please fix source location, exiting...'
write(IMAIN,*)
if (x_source(i) < xmin) call stop_the_code('Error: at least one source has x < xmin of the mesh')
if (x_source(i) > xmax) call stop_the_code('Error: at least one source has x > xmax of the mesh')
if (z_source(i) < zmin) call stop_the_code('Error: at least one source has z < zmin of the mesh')
Expand Down

0 comments on commit a836dc2

Please sign in to comment.