1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fortran Programming

  1. May 26, 2009 #1
    I feel very silly for asking this but I have just downloaded Fortran 90 and am trying to figure out how to open the command window. I am used to using MATLAB which automatically opens a command window when you open the program. I have the option of opening the developer studio or the command prompt.

    If I open the command prompt it says the following:

    Setting environment for using Visual Fortran tools

    C:\Documents and Settings\Owner>

    If I open the developer studio, I can write a program but I feel like I need to open a command window of some sort in order to run it.

    I am familiar with MATLAB but am very lost and don't even know how to start if I can't even open a command window to write a program or assign a variable. I have been searching on the internet and in the library and I think my question is so basic that the authors don't even bother to answer it.

    Any help would be much appreciated.
  2. jcsd
  3. May 26, 2009 #2


    User Avatar
    Science Advisor

    By the phrase
    do you mean that you installed a compiler? Fortran is simply a language, not unlike English, which doesn't need a word processor to be used. You do however need a compiler to convert the language into a usable program.

    With that aside, you can open the command prompt by Start>Run > cmd.exe

    Aside from that, i'm not real sure I understand your question/problem
  4. May 26, 2009 #3
    I downloaded 'Compaque Visual Fortran 6'
    This came with: WinDiff, VF reporter, Spy++, Process Viewer, OLE-COM object viewer, Fortran Module Wizard, Fortran Command Prompt, Error Lookup, Developer Studio, Dependency Walker.

    I guess my question is how to run a program once it is written. I have opened developer studio and copied the following simple program from a tutorial I found online.

    REAL :: Value, Inverse
    PRINT *, "Type in a value to invert"
    READ *, Value
    Inverse = 1.0/Value
    PRINT *, "Value", Value, " Inverse", Inverse

    Now, I am stuck as in how to compile and how to run the program. If it is obvious that I have not downloaded a compiler, where do I go to do that?
  5. May 26, 2009 #4
    I know that I can go to Build in the toolbar and click on "Compile invert.f90". And this comes up in the bottom window:

    --------------------Configuration: myproj - Win32 Debug--------------------
    Compiling Fortran...
    C:\Program Files\Microsoft Visual Studio\MyProjects\myproj\invert.f90

    invert.obj - 0 error(s), 0 warning(s)

    yet, I am still at a loss in how to run my program.
  6. May 26, 2009 #5


    User Avatar
    Science Advisor
    Homework Helper

    zandria: This is a guess. After executing the command you described in post 4, look for a file named a.out, a.exe, or invert.exe in the same directory where invert.obj is located, and double-click that file, or enter its name (or enter just "a" or invert, without the extension) at the command prompt, to execute your compiled Fortran 90 program. If a.out, a.exe, or invert.exe was not created by the compile command you executed and does not exist in the same directory where invert.obj is located, then look for the "link" command in your Fortran application, or perhaps enter the command gfortran invert.obj, or gfortran invert.f90, which will hopefully create a.out or a.exe. If gfortran is not the correct name of the link command in your application, search your Fortran application Help for the "link" command.
  7. May 27, 2009 #6


    User Avatar
    Science Advisor

    I believe in Visual Fortran, aside from compile, there is Build, which actually links the object to an executable. There should also be an execute under the same tab which will let you run the program.

    Note that if you are using this method the command prompt will close as soon as the program is finished running. So, if you have something like:
    Code (Text):

    DO i=1,nPts
      WRITE(6,*) DATA(i,:)
    END DO

    And you're banking on being able to see your data, you won't. As soon as it writes the data it exits the program. In order to remedy this, either run the program directly from the command prompt, or insert a read statement before the program ends, e.g.
    Code (Text):

    WRITE(6,*) DATA
    WRITE(6,*) 'Press any key to exit program'

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook