Solved

Open a file Programmatically in Fortran.

Posted on 2006-11-01
5
323 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countEvens challenge 2 79
isEverywhere  challenge 19 72
groupSumClump challenge 9 103
numbers ascending pyramid 100 141
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

863 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

20 Experts available now in Live!

Get 1:1 Help Now