Solved

Open a file Programmatically in Fortran.

Posted on 2006-11-01
5
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
EvenOdd challenge 10 144
countClumps  challenge 10 211
copyEndy  challenge 15 102
WPF issue with Trigger 2 128
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

735 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