Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
611 views
in Technique[技术] by (71.8m points)

fortran - Skip a line from text file in Fortran90

I'm writing in fortran (90). My program must read file1, do something with every line of it and write result to file2. But the problem - file1 has some unneeded information in first line.

How can I skip a line from input file using Fortran?

The code:

open (18, file='m3dv.dat')
open (19, file='m3dv2.dat')
do
  read(18,*) x
  tmp = sqrt(x**2 + 1)
  write(19, *) tmp
end do

First line is a combination of text and numbers.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You already found the solution but I just wanted to add that you don't even need a dummy variable, just a blank read statement before entering the loop is enough:

open(18, file='m3dv.dat')
read(18,*)
do
    ...

The other answers are correct but this can improve conciseness and (thus) readability of your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...