Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
README.md | 2023-10-24 | 11.6 kB | |
Using Fortran Modules from within GCC.docx | 2023-10-23 | 17.3 kB | |
Totals: 2 Items | 28.9 kB | 0 |
Fortran Resources
Example
This is based around Qt-based command line for Qt 6.6.0
Files
Examples (from http://matrixprogramming.rudnyi.ru/category/tools/ accessed 2023-10-23):
File: call.cpp
// Adapted from Evgenii B. Rudnyi, http://Evgenii.Rudnyi.Ru
#include <iostream>
#include <cstring>
#include <string>
using namespace::std;
extern "C" int test_(char *str, double *adbl, double *dbl, int *aint, int *intv, int nstr);
int main()
{
char str[20];
strcpy(str,"test");
double dbl = 4.5;
double adbl[4] = {1.2, 3.4, 5.6, 7.8};
int intv = 3;
int aint[4] = {3, 4, 5, 6};
cout << "calling Fortran" << endl;
test_(str, adbl, &dbl, aint, &intv, 4);
return 0;
}
File: sub.f
c Evgenii B. Rudnyi, http://Evgenii.Rudnyi.Ru
subroutine test(str, adbl, dbl, aint, int)
character*4 str
double precision adbl(4), dbl
integer aint(4), int
print *, 'str ', str
print *, 'dbl ', dbl
print *, 'int ', int
print *, 'adbl ', (adbl(i), i = 1, 4)
print *, 'aint ', (aint(i), i = 1, 4)
return
end
Qt Environment
Based on Windows 11
• Start / All Apps / Qt / Qt 6.6.0 (MinGW 11.2.0 64-bit)
• Change into source directory (i.e. cd c:\Users\<userid>\Documents\fortran )
Build, Compile and Link Source
• Compile Fortran Source:
c:\Users\<userid>\Documents\Fortran>gfortran -c sub.f
• Compile G++ source:
c:\Users\<userid>\Documents\Fortran>g++ -c -fno-leading-underscore call.cpp
• Link object to libraries and produce executable
c:\Users\<userid>\Documents\Fortran>g++ sub.o call.o -o main.exe -lgfortran
Test
c:\Users\<userid>\Documents\Fortran>main.exe
calling Fortran
str test
dbl 4.5000000000000000
int 3
adbl 1.2000000000000000 3.3999999999999999 5.5999999999999996 7.7999999999999998
aint 3 4 5 6
c:\Users\<userid>\Documents\Fortran>
Resources
Here are resources that experimenters may find useful with regards to understanding Fortran and using Fortran-derived modules in their work.
This may also help to explain techniques used by Joe Taylor in the development of WSJT-X.
Links
- https://annefou.github.io/Fortran/basics/basics.html <== Start here
- https://gcc.gnu.org/wiki/GFortranGettingStarted <== Second site to visit !
- http://matrixprogramming.rudnyi.ru/2008/03/usingfortranfromc/
- https://laptops.eng.uci.edu/engineering-software/programming-basics/gfortran-hello-world
- https://medium.com/@waltermateriais/calling-fortran-from-c-c-aa32867bde20
- https://github.com/WallyTutor/medium-articles/tree/main/medium/2023-05-25-Calling-Fortran-From-C%2B%2B
- https://fortran-lang.org/learn/building_programs/compiling_source/
- https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/F90-Array.pdf <== Subscript ranges
Contributions
How Can I Help?
We require people to make these README.md scripts better by contributing resources !
** ALL CONTRIBUTIONS AND COMMENTS ARE GRATEFULLY WELCOMED **
Conclusion and Further References
Base ref: https://sourceforge.net/projects/hamlib-sdk/files/Programming/Fortran/README.md Date: 2023-10-24
https://annefou.github.io/Fortran/basics/basics.html <== Start here [F1]: https://gcc.gnu.org/wiki/GFortranGettingStarted <== Second site to visit !