Solved

Open a file Programmatically in Fortran.

Posted on 2006-11-01
5
320 Views
Last Modified: 2013-11-08
I want a small code in Fortran that opens a .txt file when executed. I have Lahey90 V4.5 to compile this program.

Thank you.
0
Comment
Question by:Aiysha
  • 2
5 Comments
 
LVL 11

Expert Comment

by:cup
ID: 17853927
You didn't say whether you wanted to read from it or to write to it.

To open a file for reading on channel nnnn

open (nnnn, 'afile.txt', status='old')

To open for writing

open (nnnn, 'afile.txt', status='new')
0
 

Author Comment

by:Aiysha
ID: 17853979
cup,
I might be asking for too much, but can you please send me a entire program, so I can just compile it..I am very new to fortran..

Thank you.
0
 
LVL 11

Accepted Solution

by:
cup earned 500 total points
ID: 17872978
Sure

program main
    ! SRC is the input channel
    ! DST is the output channel
    integer SRC, DST
    parameter (SRC = 20, DST = 30)  ! any number will do
    integer i, isq

    ! Output a table of squares
    ! use unknown so you can run the program over and  over again
    open (DST, file='squares.txt', status='unknown')
    do i = 1, 10, 1
       isq = i * i
       write (DST, '(I2, I4)') i, isq
    end do
    close (DST)

    ! Read the file and print it
    open (SRC, file='squares.txt', status='old')
    do while (.true.)
       read (SRC, '(I2, I4)', end = 100) i, isq
       print *, i, isq
    end do
!   end of file reached
100 continue
    close (SRC)
    stop
end program
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now