What is the solution for skipping the last line in a FORTRAN program?

In summary, the speaker is a newbie programmer seeking help with modifying a fortran code. They want to extract dates from a data file and write them to an output text file, but are having trouble skipping the last line. Their code currently skips the first two lines successfully, but they are still unsure how to skip the last line. They mention having little programming experience and express their gratitude for any assistance. The conversation also includes the data and code being used.
  • #1
mandel
1
0
Hi,
I am an newbie programmer and I need some help with modifying a code in fortran. This program is supposed to skip the first two lines and the last line of the sample data and then extract only the date from the date column and write it to and output text file. The program I have now manages to skip the first two lines but I cannot seem to figure out how to skip the last line. Any help would be appreciated. As I indicated I have very little programming experience. Thanks.

DATA:

Date Data
mm/dd/yyyy units
01/01/0001 3.08E+02
01/02/0001 9.50E+01
01/03/0001 5.80E+01
01/04/0001 4.60E+01
01/05/0001 3.90E+01
01/06/0001 3.30E+01
01/07/0001 3.00E+01
01/08/0001 2.90E+01
01/09/0001 2.70E+01
01/10/0001 2.50E+01
Total 6.90E+02

CODE:
Program edate
implicit none
character*10 eDate
integer x,y
integer lntop
integer lnend

lnend = 12
lntop = 2

open(unit=5, file="datafllow.txt")
open(unit=6,file="extDate.txt")

do x=1,lntop
read(5,1000)
enddo

do y=1,lnend
read(5,1010) eDate
write(6,1020) eDate
enddo

close(5)
close(6)

1000 format(1x)
1010 format(a10)
1020 format (a10)
stop
end
 
Technology news on Phys.org
  • #2
mandel said:
do y=1,lnend
read(5,1010) eDate
write(6,1020) eDate
enddo

change to
mandel said:
read(5,1010) eDate
do y=1,lnend
write(6,1020) eDate
read(5,1010) eDate
enddo

That will skip the last line.
 

1. How do I get started with writing a FORTRAN program?

To get started with writing a FORTRAN program, you will need a text editor or an Integrated Development Environment (IDE) that supports FORTRAN. Some popular options include Visual Studio, Eclipse, and Code::Blocks. You will also need to have a compiler installed on your computer, such as GFortran or Intel FORTRAN. Once you have these tools set up, you can start writing your program using FORTRAN syntax.

2. What are the basic data types in FORTRAN?

The basic data types in FORTRAN include integers, real numbers, and characters. Integers are whole numbers without a decimal point, real numbers are numbers with a decimal point, and characters are used to represent letters and symbols. FORTRAN also has a complex data type for handling complex numbers.

3. How can I debug my FORTRAN program?

To debug a FORTRAN program, you can use a debugger tool that is included in most IDEs. This tool allows you to step through your code line by line and see the values of variables at different points in your program. You can also use print statements in your code to track the flow of your program and see the values of variables.

4. Can I use FORTRAN to create graphical user interfaces (GUIs)?

Yes, FORTRAN has libraries and tools that allow you to create GUIs. The most commonly used library for creating GUIs in FORTRAN is the FLTK library. It provides a set of tools for creating windows, buttons, menus, and other GUI elements.

5. How do I optimize my FORTRAN program for performance?

To optimize a FORTRAN program for performance, you can use techniques such as loop unrolling, vectorization, and parallelization. Loop unrolling involves manually expanding loops to reduce the number of iterations. Vectorization allows you to perform operations on multiple data elements at once, which can speed up your program. Parallelization involves splitting your program into smaller parts that can be executed simultaneously on multiple processors or cores.

Similar threads

  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
8K
  • General Engineering
Replies
20
Views
5K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
4
Views
13K
Back
Top