How to Run Fortran Code in Windows (check description)

Channel:
Subscribers:
21
Published on ● Video Link: https://www.youtube.com/watch?v=4QU05PH0s2o



Category:
Guide
Duration: 16:43
2,171 views
19


how to run FORTRAN code in Windows.

1. install minGW from this link:
https://osdn.net/projects/mingw/releases/

2. from the basic setup, select all except ada and objc.

3. it will download lots of files, will take around 5mins. when download and install are completed, close the window.

4. Windows need the gfortran file to run FORTRAN code. so we'll add the directory of it to the path variable.
we've added path C:\MinGW\bin as a user path variable.

5. let's use vs code to write a FORTRAN code and run it. there's an extension in vs code to highlight FORTRAN codes called 'Modern Fortran'. install it.

6. I've used (.f90) as the extension. using (.f) extension has its own issues.

7. in windows, the FORTRAN file will get compiled into a (.exe) file, and then running that (.exe) file will show the output.
to simplify it, we can use a batch (.bat) file on the same folder as the (test.f90) file.

here's the content of the batch file:
--------------
gfortran test.f90 -o output.exe
output.exe
--------------
here, the 1st line tells windows to use gfortran to compile (test.f90) file into (output.exe) file. the 2nd line tells windows to run that (output.exe) file. you'll change the name of the FORTRAN file (test.f90) as needed.

8. now we'll run the (.bat) file to see the output of the program. you can use the following command to run the batch file:
----
.\run.bat
----

you can even use read statement, just type the value in console/cmd when the cursor blinks, and press enter.