×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Fortran 77 - read from an init file - add comments

Fortran 77 - read from an init file - add comments

Fortran 77 - read from an init file - add comments

(OP)
Hi,

I have an input file for a fortran 77 program and since there are many lines and many constants to be given, it has become quite complicated to read.

I would like to add comments on this input file but I don't want him to read them, just jump over anything that is NAN, something like :

initial point: 3.0 0.0
end point: 3.0 0.8
stretch: 5.0E-5
angle: 90

Thanks,

Widukin

RE: Fortran 77 - read from an init file - add comments

The routine getval below expects an array.  For single variables, I've equivalenced them with an array of dimension 1 to keep the compiler happy.

CODE

      subroutine getval (chan, val, count)
      integer chan
      real val(*)
      integer count
      integer i, start
      character*80 line
      read (chan, '(A)') line
      start = index (line, ':')
      if (start .ne. 0) then
         read (line(start + 1:), *) (val(i), i = 1, count, 1)
      endif
      return
      end
      
      program main
      real initpt(2)
      real endpt(2)
      real stretch, stretchalt(1)
      real angle, anglealt(1)
      equivalence (stretch, stretchalt(1))
      equivalence (angle, anglealt(1))
      integer chan
      data chan /10/
      
      open (chan, file='data.txt', status='unknown')
      call getval (chan, initpt, 2)
      call getval (chan, endpt, 2)
      call getval (chan, stretchalt, 1)
      call getval (chan, anglealt, 1)
      close (chan)
      
      print *, 'init ', initpt(1), initpt(2)
      print *, 'end  ', endpt(1), endpt(2)
      print *, 'stretch ', stretch
      print *, 'angle ', angle
      stop
      end

RE: Fortran 77 - read from an init file - add comments

(OP)
Thanks, it was really usefull and I got to do a comprehensive input file. Since you are at ease with this kind of question I would like to ask another one :). If then I have a file such as:

********* general information *********

date (IDATE): 20/07/2005.
title (ITITRE): fiber

********* Definition of the fiber *********

Number of available space steps (NH): 1
initial point: 3.0 0.0
end point: 3.0 0.8
stretch: 5.0E-5
angle: 90.

What can I add or with what format so that I can jump the empty lines and the *** remarks.

Another question, since I have double floats, strings and integers, should I make 3 different functions to apply to each case?

Thanks again,

Widukin

RE: Fortran 77 - read from an init file - add comments

CODE

      subroutine getval (chan, val, count)
      integer chan
      real val(*)
      integer count
      integer i, start
      character*80 line
C     Skip until we find something with a value
10    continue
      read (chan, '(A)', end=20) line
      start = index (line, ':')
      if (start .eq. 0) goto 10
C     Get the value
      read (line(start + 1:), *) (val(i), i = 1, count, 1)
20    return
      end

Yes - you will have to write different subroutines: one for each type

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close