2D AMRCLAW
Functions/Subroutines
opendatafile.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine opendatafile (iunit, fname)
 

Function/Subroutine Documentation

◆ opendatafile()

subroutine opendatafile ( integer  iunit,
character(len=*)  fname 
)
Parameters
iunitOpen the file fname and determine how many leading lines are comments. Then rewind and skip over the comment lines so that the file is ready for reading data from.

All comment lines must start with # in the first column.

Definition at line 3 of file opendatafile.f.

Referenced by amr2(), gauges_module::set_gauges(), regions_module::set_regions(), and setgauges().

3 c #
9 
10  integer iunit, line, commentlines
11 
12 
13 c This allows for a variable name length and obsolves (I think) the
14 c length problem that appeared for some compilers (notably ifort)
15  character(len=*) :: fname
16 c character*25 fname
17 c character*12 fname12
18 
19  character*1 firstchar
20  logical foundfile
21 
22 c # Debug statement to test fname:
23 c write(6,*) '+++ fname = XXX',fname,'XXX'
24 
25  inquire(file=fname,exist=foundfile)
26  if (.not. foundfile) then
27 c # for backward compatability: maybe fname is declared character*12
28 c # in calling routine...
29 c fname12 = fname(1:12)
30 c #write(6,*) 'truncated fname12 = XXX',fname12,'XXX'
31 c inquire(file=fname12,exist=foundFile)
32  if (.not. foundfile) then
33  print "(2a)",'*** in opendatafile, file not found:', fname
34  stop
35  endif
36 c open(unit=iunit,file=fname12,status='old',form='formatted')
37 c write(6,*) 'Reading data file: ', fname12
38  else
39  open(unit=iunit,file=fname,status='old',form='formatted')
40  print "(2a)",'Reading data file: ', fname
41  endif
42 
43 c # this version may not work in f77
44 c firstchar = '#'
45 c commentlines = -1
46 c do while (firstchar == '#')
47 c read(iunit,*) firstchar
48 c commentlines = commentlines + 1
49 c enddo
50 
51  firstchar = '#'
52  commentlines = -1
53  do commentlines=-1,1000
54  if (firstchar .eq. '#') then
55  read(iunit,"(a1)") firstchar
56  else
57  exit
58  endif
59  enddo
60 
61  write(6,602) commentlines
62  602 format(' first',i2,
63  & ' lines are comments and will be skipped')
64 
65 c Rewind file and go back to data line
66 C print *,firstchar
67 C rewind(iunit)
68 C do line=1,commentlines
69 C read(iunit,*) firstchar
70 C print *,firstchar
71 C enddo
72 C
73  return
Here is the caller graph for this function: