Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

GFortran Module Problem

  1. Jan 15, 2012 #1
    Hi!

    I am writing a simple code to get familiar with creating Fortran module. The program consist of a main.f and a module.mod file. When I type in:

    Code (Text):
    gfortran main.f
    I get the following error:

    Code (Text):
    Fatal Error: File 'module.mod' opened at (1) is not a GFORTRAN module file
    I think I found the problem but I dont know how to fix it. It turns out that module.mod is a file with property type: Amiga SoundTracker audio (audio/x-mod). The extention .mod is being recognized by defult as an audio file and not as a Fortran text file.

    I have done every thing I can. I changed the "open with" option to open with GVim by defult but that does not change the file type to a Fortran text file. I also tried changing the name to module.f wich changes the property type to Fortran source code (text/x-fortran) but then when I execute teh main,f file I get this error instead:

    Code (Text):
    Fatal Error: Can't open module file 'module.mod' for reading at (1): No such file or directory
    The file <filename> and stat <filename> commands have not helped eather. It seems like an easy problem to fix but I just dont know how :(

    Please help
     
    Last edited: Jan 15, 2012
  2. jcsd
  3. Jan 16, 2012 #2

    Mark44

    Staff: Mentor

    I'm not expert in Fortran, and haven't written any code in that language for about 15 years. With that said, I believe that your file extension is throwing off the compiler. The file extension should be .f, not .mod.

    As far as your fatal error is concerned, I'm betting that your make file still has module.mod listed in it.
     
  4. Jan 16, 2012 #3
    Ok ... I found out how to solve my problem so I am going to post this for any other people out there who happen to run into the same thing:

    note: I am using linux as my operating system, vim as my text editor, and fortran 95 as my compiler

    on linux comand line:
    Code (Text):
    vim main.f                       # create and save main.f note: main is the name of the main file
    vim mod_module.f                 # create and save mod_module.f note: moduel is the name of the module file and mod_ is a prefix type of extention
    cat mod_module.f                 # you should see your code as an output
    cat main.f                       # output code
    f95 -o main mod_module.f main.f  # this will create an executable file
    ./main                           # execute the file created
    Apparently fortran needs to execute everything all at once so it needs to create an executable file. This helped me get around the .mod problem because in order to create the executable file I only needed .f files. Note the module files must be compiled before the main file.

    :smile:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: GFortran Module Problem
  1. Cuda for gfortran ? (Replies: 4)

Loading...