Skip to content

Commit a836dc2

Browse files
committed
updates error checking for reading in parameters
1 parent 1ddef3d commit a836dc2

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/shared/read_parameter_file.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,8 +1395,8 @@ subroutine read_parameter_file_only()
13951395

13961396
if (some_parameters_missing_from_Par_file) then
13971397
write(*,*)
1398-
write(*,*) 'All the above parameters are missing from your Par_file.'
1399-
write(*,*) 'Please cut and paste them somewhere in your Par_file (any place is fine), change their values if needed'
1398+
write(*,*) 'All the above parameters are either in a wrong number format or missing from your Par_file.'
1399+
write(*,*) 'Please correct or cut&paste them somewhere in your Par_file (any place is fine), change their values if needed'
14001400
write(*,*) '(the above values are just default values), and restart your run.'
14011401
write(*,*)
14021402
call stop_the_code('Error: some parameters are missing in your Par_file, it is incomplete or in an older format, &

src/shared/read_source_file.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ subroutine read_source_file(NSOURCES,BROADCAST_AFTER_READ)
5252
character(len=256) string_read
5353
character(len=MAX_STRING_LEN) :: source_filename,path_to_add
5454
integer, parameter :: IIN_SOURCE = 22
55+
logical :: stf_exists
5556

5657
! user output
5758
if (myrank == 0) then
@@ -315,6 +316,17 @@ subroutine read_source_file(NSOURCES,BROADCAST_AFTER_READ)
315316
write(IMAIN,*) ' Multiplying factor = ',factor(i_source)
316317
write(IMAIN,*)
317318

319+
! check if external stf file exists
320+
if (time_function_type(i_source) == 8) then
321+
inquire(file=trim(name_of_source_file(i_source)),exist=stf_exists)
322+
if (.not. stf_exists) then
323+
write(*,*) ''
324+
write(*,*) 'Error external source time function file: ',trim(name_of_source_file(i_source)),' not found.'
325+
write(*,*) ''
326+
call stop_the_code('Error reading SOURCE file: could not find specified external source time function file')
327+
endif
328+
endif
329+
318330
enddo ! do i_source= 1,NSOURCES
319331
close(IIN_SOURCE)
320332

src/shared/read_value_parameters.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ subroutine read_value_integer_p(value_to_read, name)
197197

198198
call param_read(string_read, len(string_read), name, len(name), ierr)
199199
if (ierr /= 0) return
200-
read(string_read,*) value_to_read
200+
read(string_read,*,iostat=ierr) value_to_read
201201

202202
end subroutine read_value_integer_p
203203

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

218218
call param_read(string_read, len(string_read), name, len(name), ierr)
219219
if (ierr /= 0) return
220-
read(string_read,*) value_to_read
220+
read(string_read,*,iostat=ierr) value_to_read
221221

222222
end subroutine read_value_double_precision_p
223223

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

238238
call param_read(string_read, len(string_read), name, len(name), ierr)
239239
if (ierr /= 0) return
240-
read(string_read,*) value_to_read
240+
read(string_read,*,iostat=ierr) value_to_read
241241

242242
end subroutine read_value_logical_p
243243

@@ -277,7 +277,7 @@ subroutine read_value_integer_next_p(value_to_read, name)
277277

278278
call param_read_nextparam(string_read, len(string_read), name, len(name), ierr)
279279
if (ierr /= 0) return
280-
read(string_read,*) value_to_read
280+
read(string_read,*,iostat=ierr) value_to_read
281281

282282
end subroutine read_value_integer_next_p
283283

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

298298
call param_read_nextparam(string_read, len(string_read), name, len(name), ierr)
299299
if (ierr /= 0) return
300-
read(string_read,*) value_to_read
300+
read(string_read,*,iostat=ierr) value_to_read
301301

302302
end subroutine read_value_double_prec_next_p
303303

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

318318
call param_read_nextparam(string_read, len(string_read), name, len(name), ierr)
319319
if (ierr /= 0) return
320-
read(string_read,*) value_to_read
320+
read(string_read,*,iostat=ierr) value_to_read
321321

322322
end subroutine read_value_logical_next_p
323323

src/specfem2D/setup_sources_receivers.F90

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ subroutine setup_sources()
140140

141141
! user output
142142
if (not_in_mesh_domain) then
143-
write(IMAIN,*) 'Source ',i
144-
write(IMAIN,*) ' Position (x,z) of the source = ',x_source(i),z_source(i)
145-
write(IMAIN,*) 'Invalid position, mesh dimensions are: xmin/max = ',xmin,xmax,'zmin/zmax',zmin,zmax
146-
write(IMAIN,*) 'Please fix source location, exiting...'
143+
write(IMAIN,*) 'Error: Source ',i
144+
write(IMAIN,*) ' Position (x,z) of the source = ',x_source(i),z_source(i)
145+
write(IMAIN,*)
146+
write(IMAIN,*) ' Invalid position, mesh dimensions are: xmin/max = ',xmin,xmax,'zmin/zmax',zmin,zmax
147+
write(IMAIN,*) ' Please fix source location, exiting...'
148+
write(IMAIN,*)
147149
if (x_source(i) < xmin) call stop_the_code('Error: at least one source has x < xmin of the mesh')
148150
if (x_source(i) > xmax) call stop_the_code('Error: at least one source has x > xmax of the mesh')
149151
if (z_source(i) < zmin) call stop_the_code('Error: at least one source has z < zmin of the mesh')

0 commit comments

Comments
 (0)