gfortran issue

Discussion in 'Mac Programming' started by wfguiteau, Sep 2, 2011.

  1. wfguiteau macrumors newbie

    Sep 2, 2011
    Hello everyone,

    I'm trying a foray into fortran (I'm a scientist and a lot of the code I work with is in fortran), so I'm starting from the beginning.

    I used the following hello world program:

    and compile it in the terminal using gfortran, i.e. 'gfortran hello.f90'. It SHOULD prompt me for the name input and then print the output, but it does neither. No error messages, creates a file called 'a.out', but no read and no print. In the absence of error messages, I have no clue what's going wrong. Any suggestions?
  2. dylanryan macrumors member

    Aug 21, 2011
    gfortran is just the compiler, it compiles the code into an executable (the a.out file). If you now run the a.out file (./a.out), it will actually execute your code.
  3. itsmrjon, Sep 4, 2011
    Last edited: Sep 4, 2011

    itsmrjon macrumors regular

    Jun 11, 2011
    Your code tidbit is not F90. gfortran also does not have a direct 90 compiler, it hasn't been supported in a while. use mpif90 (part of openMPI), ifort, or absoft.

    First and foremost make sure this is the version of gfortran you have

    nextly this is proper f90
          [COLOR="Blue"]program[/COLOR] helloWorld
                [COLOR="Magenta"]!proper new style fortran declaration[/COLOR]
                [COLOR="blue"]character[/COLOR](len=50)   :: name
                [COLOR="Magenta"]!This is my ghetto fortran[/COLOR]
                [COLOR="blue"]write[/COLOR](*,*) 'Who you be gangster?'
                [COLOR="blue"]read[/COLOR](*,*) name
               [COLOR="Magenta"] !the trim is used to eliminate trailing blanks[/COLOR]
                [COLOR="blue"]write[/COLOR](*,*) 'Wow ', trim(name),', you be fortran gangsta!' 
               [COLOR="Magenta"] !i mean you could use a fmt statement too, but i didnt feel like looking one up for this example[/COLOR]
          [COLOR="blue"]end program[/COLOR]
    the above code will compile with gfortran, and do exactly what it is you wanted to do in your code snippet. I double checked just to be sure.

    now as to running
    save the above code as hello.f90
    go in terminal and type: gfortran hello.f90 -o hello
    then to execute, type: ./hello

    youll see it all work now

    (if it doesnt allow you to execute, make sure you chmod to executable)

    finally if you want to compile openMPI for parallel fortran (we use it almost exclusively in computational physics), i explained it in an old post of mine here

Share This Page