66 Subroutine get_integer_val(ival,filename,argname,line,echo,start,finish)
68 integer,
intent(out) :: ival
69 character(len=*),
intent(in ) :: filename
70 character(len=*),
intent(in ) :: argname
71 integer,
intent(out) :: line
72 logical,
optional,
intent(in) :: echo
73 integer,
optional,
intent(in) :: start
74 integer,
optional,
intent(in) :: finish
76 character(len=80) :: argval
77 character(len=80) :: argtype
82 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
83 'file: '//trim(filename)//
' does not exist')
87 if(
present(start) .and.
present(finish))
then 88 if(finish < start)
then 89 call error(
'Get_Val',
'halt',
'finish must be greater than or equal to start')
96 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
97 'does not exist in file: '//trim(filename))
102 if(trim(argtype) /=
'integer')
then 103 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
104 'in file: '//trim(filename), &
105 'should be integer but is: '//trim(argtype))
112 if(
present(echo))
then 114 write(*,
'(A20,I10)')trim(argname)//
': ',ival
124 Subroutine get_float_val(fval,filename,argname,line,echo,start,finish)
126 real(sp),
intent(out) :: fval
127 character(len=*),
intent(in ) :: filename
128 character(len=*),
intent(in ) :: argname
129 integer,
intent(out) :: line
130 logical,
optional,
intent(in) :: echo
131 integer,
optional,
intent(in) :: start
132 integer,
optional,
intent(in) :: finish
134 character(len=80) :: argval
135 character(len=80) :: argtype
141 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
142 'file: '//trim(filename)//
' does not exist')
146 if(
present(start) .and.
present(finish))
then 147 if(finish < start)
then 148 call error(
'Get_Val',
'halt',
'finish must be greater than or equal to start')
155 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
156 'does not exist in file: '//trim(filename))
161 if(trim(argtype) /=
'float')
then 162 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
163 'in file: '//trim(filename), &
164 'should be float but is: '//trim(argtype))
171 if(
present(echo))
then 173 write(*,
'(A20,F10.4)')trim(argname)//
': ',fval
184 Subroutine get_logical_val(lval,filename,argname,line,echo,start,finish)
186 logical,
intent(out) :: lval
187 character(len=*),
intent(in ) :: filename
188 character(len=*),
intent(in ) :: argname
189 integer,
intent(out) :: line
190 logical,
optional,
intent(in) :: echo
191 integer,
optional,
intent(in) :: start
192 integer,
optional,
intent(in) :: finish
194 character(len=80) :: argval
195 character(len=80) :: argtype
200 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
201 'file: '//trim(filename)//
' does not exist')
205 if(
present(start) .and.
present(finish))
then 206 if(finish < start)
then 207 call error(
'Get_Val',
'halt',
'finish must be greater than or equal to start')
214 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
215 'does not exist in file: '//trim(filename))
220 if(trim(argtype) /=
'logical')
then 221 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
222 'in file: '//trim(filename), &
223 'should be logical but is: '//trim(argtype))
228 if(argval(1:1) ==
'T') lval = .true.
231 if(
present(echo))
then 233 write(*,
'(A20,L10)')trim(argname)//
': ',lval
243 Subroutine get_string_val(sval,filename,argname,line,echo,start,finish)
245 character(len=*),
intent(out) :: sval
246 character(len=*),
intent(in ) :: filename
247 character(len=*),
intent(in ) :: argname
248 integer,
intent(out) :: line
249 logical,
optional,
intent(in) :: echo
250 integer,
optional,
intent(in) :: start
251 integer,
optional,
intent(in) :: finish
253 character(len=80) :: argval
254 character(len=80) :: argtype
259 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
260 'file: '//trim(filename)//
' does not exist')
264 if(
present(start) .and.
present(finish))
then 265 if(finish < start)
then 266 call error(
'Get_Val',
'halt',
'finish must be greater than or equal to start')
273 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
274 'does not exist in file: '//trim(filename))
279 if(trim(argtype) /=
'string')
then 280 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
281 'in file: '//trim(filename), &
282 'should be string but is: '//trim(argtype))
286 sval = adjustl(trim(argval))
289 if(
present(echo))
then 291 write(*,
'(A20,A20)') trim(argname)//
': ',trim(sval)
303 character(len=*),
intent(in ) :: filename
304 character(len=*),
intent(in ) :: argname
305 integer,
intent(in) :: SIZE
306 real(sp),
dimension(size),
intent(out) :: fval
307 logical,
optional,
intent(in) :: echo
311 character(len=80) :: argval
312 character(len=80) :: argtype
317 real(sp) :: REALVEC(150)
323 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
324 'file: '//trim(filename)//
' does not exist')
328 iscan =
scan_file3(filename,argname,fvec = realvec,nsze = ntemp)
330 WRITE(ipt,*)
'ERROR READING: ',trim(argname),
': ',iscan
331 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
332 'does not exist in file: '//trim(filename))
336 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 337 WRITE(*,*)
'AND READ: ',realvec(1:ntemp)
338 call error(
'Get_Val',
'warning',
'warning reading variable: '//trim(argname), &
339 'number of specified size in : '//trim(filename)//
' in not eq& 340 &ual to expected size,specified size is used in the model ')
341 ELSEIF(ntemp < size)
THEN 342 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 343 WRITE(*,*)
'AND READ: ',realvec
344 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
345 'number of specified size in : '//trim(filename)//
' in not eq& 346 &ual to expected size ')
349 fval(1:size)= realvec(1:size)
352 if(
present(echo))
then 354 write(*,
'(A20,<size>F10.4)')trim(argname)//
': ',fval(1:size)
372 character(len=*),
intent(in ) :: filename
373 character(len=*),
intent(in ) :: argname
374 integer,
intent(in) :: SIZE
375 integer,
dimension(size),
intent(out) :: ival
376 logical,
optional,
intent(in) :: echo
380 character(len=80) :: argval
381 character(len=80) :: argtype
386 real(sp) :: REALVEC(150)
392 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
393 'file: '//trim(filename)//
' does not exist')
397 iscan =
scan_file3(filename,argname,fvec = realvec,nsze = ntemp)
399 WRITE(ipt,*)
'ERROR READING',trim(argname),
': ',iscan
400 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
401 'does not exist in file: '//trim(filename))
405 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 406 WRITE(*,*)
'AND READ: ',realvec(1:ntemp)
407 call error(
'Get_Val',
'warning',
'warning reading variable: '//trim(argname), &
408 'number of specified size in : '//trim(filename)//
' in not eq& 409 &ual to expected size,specified size is used in the model ')
410 ELSEIF(ntemp < size)
THEN 411 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 412 WRITE(*,*)
'AND READ: ',realvec
413 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
414 'number of specified size in : '//trim(filename)//
' in not eq& 415 &ual to expected size ')
418 ival(1:size)= realvec(1:size)
421 if(
present(echo))
then 423 write(*,
'(A20,<size>I10)')trim(argname)//
': ',ival(1:size)
440 character(len=*),
intent(in ) :: filename
441 character(len=*),
intent(in ) :: argname
442 integer,
intent(in) :: SIZE
443 logical,
dimension(size),
intent(out) :: cval
444 logical,
optional,
intent(in) :: echo
448 character(len=80) :: argval
449 character(len=80) :: argtype
454 character(len=80),
dimension(100):: CHARVEC
460 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
461 'file: '//trim(filename)//
' does not exist')
465 iscan =
scan_file3(filename,argname,cvec = charvec,nsze = ntemp)
467 WRITE(ipt,*)
'ERROR READING:',trim(argname),
': ',iscan
468 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
469 'does not exist in file: '//trim(filename))
473 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 474 WRITE(*,*)
'AND READ: ',charvec(1:ntemp)
475 call error(
'Get_Val',
'warning',
'warning reading variable: '//trim(argname), &
476 'number of specified size in : '//trim(filename)//
' in not eq& 477 &ual to expected size,specified size is used in the model ')
478 ELSEIF(ntemp < size)
THEN 479 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 480 WRITE(*,*)
'AND READ: ',charvec
481 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
482 'number of specified size in : '//trim(filename)//
' in not eq& 483 &ual to expected size ')
487 IF((trim(charvec(i))==
"T" .OR. trim(charvec(i))==
"F").and.(len(trim(charvec(i)))==1))
THEN 488 if(trim(charvec(i)) ==
"T")cval(i)=.true.
489 if(trim(charvec(i)) ==
"F")cval(i)=.false.
494 if(
present(echo))
then 496 write(*,
'(A20,<size>L10)')trim(argname)//
': ',cval(1:size)
517 character(len=*),
intent(in ) :: filename
518 character(len=*),
intent(in ) :: argname
519 integer,
intent(in) :: SIZE
520 character(len=*),
dimension(size),
intent(out) :: sval
521 logical,
optional,
intent(in) :: echo
525 character(len=80) :: argval
526 character(len=80) :: argtype
531 character(len=80),
dimension(100):: CHARVEC
537 call error(
'Get_Val',
'halt',
'error reading: '//trim(argname), &
538 'file: '//trim(filename)//
' does not exist')
542 iscan =
scan_file3(filename,argname,cvec = charvec,nsze = ntemp)
544 WRITE(ipt,*)
'ERROR READING:',trim(argname),
': ',iscan
545 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
546 'does not exist in file: '//trim(filename))
550 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 551 WRITE(*,*)
'AND READ: ',charvec(1:ntemp)
552 call error(
'Get_Val',
'warning',
'warning reading variable: '//trim(argname), &
553 'number of specified size in : '//trim(filename)//
' in not eq& 554 &ual to expected size,specified size is used in the model ')
555 ELSEIF(ntemp < size)
THEN 556 WRITE(*,*)
'EXPECTED SIZE:',
SIZE 557 WRITE(*,*)
'AND READ: ',charvec
558 call error(
'Get_Val',
'halt',
'error reading variable: '//trim(argname), &
559 'number of specified size in : '//trim(filename)//
' in not eq& 560 &ual to expected size ')
564 sval(1:size)= charvec(1:size)
567 if(
present(echo))
then 569 write(*,
'(A20,<size>A10)')trim(argname)//
': ',sval(1:size)
585 character(len=* ),
intent(in ) :: fname
586 character(len=* ),
intent(in ) :: argname
587 character(len=80),
intent(out) :: argval
588 integer,
intent(out) :: ierr
589 integer,
intent(out) :: line
590 integer,
optional,
intent(in ) :: start
591 integer,
optional,
intent(in ) :: finish
593 character(len=80) :: temp,temp2,text_line,inpline
594 integer :: locex,eqloc,length,i,linecnt
597 open(10,file=trim(fname)) ; rewind(10)
601 if(
present(start))
then 604 linecnt = linecnt + 1
609 read(10,
'(A)',end=20) inpline
610 linecnt = linecnt + 1
614 if(locex == 0)locex = len_trim(inpline)+1
615 temp = inpline(1:locex-1)
619 length = len_trim(text_line)
622 eqloc = index(text_line,
"=")
626 temp2 = text_line(1:eqloc-1)
627 if(adjustl(trim(temp2)) == trim(argname))
then 628 argval = adjustl(text_line(eqloc+1:length))
635 if(
present(finish))
then 636 if(linecnt==finish)
exit 652 character(len=80),
intent(out) :: argtype
653 character(len=80),
intent(in ) :: argval
655 character(len=16) :: numchars
659 numchars =
"0123456789+-Ee. " 662 largval = len_trim(adjustl(argval))
666 if(argval(1:1) ==
"T" .or. argval(1:1) ==
"F")
then 674 if(index(numchars,argval(i:i)) == 0)
then 681 dotloc = index(argval,
".")
695 Subroutine error(subname,errtype,err1,err2,err3)
696 character(len=*) :: subname
697 character(len=*) :: errtype
698 character(len=*) :: err1
699 character(len=*),
optional :: err2
700 character(len=*),
optional :: err3
702 if(errtype ==
'halt')
then 704 write(*,*)
'FATAL ERROR in subroutine: ',trim(subname)
706 if(
present(err2))
write(*,*)trim(err2)
707 if(
present(err2))
write(*,*)trim(err3)
709 else if(errtype ==
'warning')
then 711 write(*,*)
'WARNING from subroutine: ',trim(subname)
713 if(
present(err2))
write(*,*)trim(err2)
714 if(
present(err2))
write(*,*)trim(err3)
716 write(*,*)
'incorrect usage of subroutine Error' 717 write(*,*)
'called from subroutine: ',trim(subname)
718 write(*,*)
'errtype must be halt or warning' 730 character(len=*) :: filein
732 inquire(exist=fexist,file=filein)
739 Subroutine check_alloc(errorin,dsize,varname,subname)
741 integer,
intent(in) :: errorin
742 integer,
intent(in) :: dsize
743 character(len=*),
intent(in) :: varname
744 character(len=*),
intent(in) :: subname
747 write(*,*)
'insufficient space to allocate array: '//trim(varname)
748 write(*,*)
'in subroutine: '//trim(subname)
749 write(*,*)
'tried to allocate ',dsize,
' units' 762 integer,
intent(in) :: errorin
763 character(len=*),
intent(in) :: filename
764 character(len=*),
intent(in) :: varname
767 write(*,*)
'failed read/write of: '//trim(varname)
768 write(*,*)
'from file: '//trim(filename)
logical function dbg_set(vrb)
integer function scan_file3(FNAME, VNAME, ISCAL, FSCAL, IVEC, FVEC, CVEC, NSZE, CVAL, LVAL)
integer, parameter dbg_sbr