Fortran How can I fix the Fortran module problem with gfortran?

  • Thread starter Thread starter mgborja
  • Start date Start date
  • Tags Tags
    Gfortran module
AI Thread Summary
The discussion revolves around resolving a compilation error in Fortran related to file extensions and module recognition. The user initially encounters a fatal error indicating that 'module.mod' is not recognized as a GFORTRAN module file due to the file being misidentified as an audio file. The confusion stems from the use of the .mod extension, which is typically associated with audio files rather than Fortran modules. To fix the issue, the user changes the file extension to .f for the module file, but this leads to another error indicating that the module file cannot be found. The solution involves creating a new module file with a proper .f extension, ensuring that both the module and main files are compiled together to generate an executable. The user successfully compiles and executes the program by using the command line to compile both .f files, highlighting the necessity of compiling module files before the main program. This experience emphasizes the importance of correct file extensions and compilation order in Fortran programming.
mgborja
Messages
2
Reaction score
0
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:
gfortran main.f

I get the following error:

Code:
Fatal Error: File 'module.mod' opened at (1) is not a GFORTRAN module file

I think I found the problem but I don't 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 which 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:
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 don't know how :(

Please help
 
Last edited:
Technology news on Phys.org
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.
 
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:
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:
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
17
Views
6K
Replies
5
Views
2K
Replies
1
Views
3K
Replies
9
Views
9K
Replies
0
Views
2K
Replies
13
Views
5K
Back
Top