Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using comments in input files

Status
Not open for further replies.

raghu81

Technical User
Apr 9, 2008
28
DE
Hello everyone,
I am writing some programs in GFortran for educational purposes. For some programs, the input files have a lot of data and I like to mark them with comments using special symbols for ex., "#"

Can any one suggest me a way to make the program ignore the comment line which is followed by the special symbol?

For example,

#Matrix size ---comment line-----
3
#Number of rotations ---comment line-----
10
#Matrix elements ---comment line-----
1 1 1
1 1 1
1 1 1

Thanx in advance,
Raghu.
 
Read the line twice: once into a string and then from the string
Code:
character*80:: line
integer:: matsize, matrot
...

open (20, ...

call skipcomments (20, line)
read (line, *) matsize
call skipcomments (20, line)
read (line, *) matrot
...
close (20)
stop
end

subroutine skipcomments (chan, line)
   integer, intent(in):: chan
   character*80, intent(inout):: line

10 continue
   read (chan, *) line
   if (line(1:1) .eq. '#') goto 10
   return
end subroutine skipcomments
 
Hi xwb,

Thanx for ur method. It works very well.

-regards,
raghu
 
Likewise you could just put your comments after the variable. Mine usually look like:

2.0 ! constant 1
4 ! constant 2
.true. ! constant 3

etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top