gfortran

Fortran is reading beyond endfile record

元气小坏坏 提交于 2019-12-04 23:54:32
问题 I'm trying to read some data from a file, and the endfile record detection is important to stop reading. However, depending of the array dimensions of the array used to read data, I cannot detect properly the endfile record and my Fortran program stops. The program is below: !integer, dimension(3) :: x ! line 1.1 !integer, dimension(3,10) :: x ! line 1.2 integer, dimension(10,3) :: ! line 1.3 integer :: status,i=1 character(len=100) :: error open( 30, file='data.dat', status='old' ) do print

How to use loadlibrary and getprocaddress from gfortran?

老子叫甜甜 提交于 2019-12-04 21:49:35
I'm trying to learn how to call a function in a fortran dll from a fortran executable on windows. I'm working with gfortran 4.7 and photran in eclipse. My test dll has a single function in hello.f90: hello.f90 subroutine hello implicit none print *, "Hello World!" end subroutine hello with the following makefile: all: gfortran -Wall -c hello.f90 gfortran -shared -o hello.dll hello.o Dependency Walker confirms that the function "hello_" is exported. Now I'm trying to build a program that calls it dynamically. I've built the following based on examples I've found online, but it doesn't compile:

Save command line output to variable in Fortran

我怕爱的太早我们不能终老 提交于 2019-12-04 14:05:42
Is there a way to store the output of a command line utility to a variable in Fortran? I have a BASH based utility which gives me a number which needs to be used in a Fortran program. I want to call the utility through the program itself, and avoid writing the output to a file if possible. Something like this maybe? integer a write(a,*) call execute_command_line('echo 5') Or like this maybe? read(call execute_command_line('echo 5'),*) a I don't think either of these is right though. I would like to know if there is actually a method to do this. I read the docs for execute_command_line but I

Removing whitespace in string

淺唱寂寞╮ 提交于 2019-12-04 13:00:17
I have the following code: program main character (len=15) :: abc = "te st tex t" print *, trim(abc) end program main Which outputs: te st tex t I excepted all the whitespace to be removed but it wasn't. How can I remove all the whitespace from the string? Trim will remove spaces only at the edges, not in the middle (this is common behaviour on almost all languages/libraries). If you want to remove all spaces in the string, you will have to create your own function to do this, iterating through the string. Ex.: program Test implicit none ! Variables character(len=200) :: string ! Body of Test

Use of unlimited polymorphic type for array operation in Fortran 03/08 (gfortran compiler)

浪尽此生 提交于 2019-12-04 12:18:16
I'd like to realize useful array operations (add element, remove element, different realizations by allocatable/pointer/binary tree structures) by class(*) feature (unlimited polymorphism). I use gfortran 5.0 that should handle such a feature. I need it for not repeating identical code for each type I use. This should look something like function add_element(array,element) class(*),intent(in)::array(:) class(*),intent(in)::element class(*)::add_element(size(array)+1) add_element=[array,element] end function The problem is that when I try to use this function with some definite type, I have an

gfortran can't find library that IS there

梦想的初衷 提交于 2019-12-04 11:02:34
I'm having trouble linking my program to a library. I've never done this before so I'm probably doing something stupid, but as far as I can tell I'm doing the right thing. I need to link my program foo.f90 to a library libbar.a which is in a directory elsewhere below my home directory. I enter the command: gfortran -c foo.f90 gfortran -o foo foo.f90 -L/directory/of/library -llibbar.a But this throws: ld: library not found for -llibhealpix.a Where of course libhealpix.a is the real library (rather than libbar.a ) Any ideas as to why this would occur? Try -lbar (or perhaps -lhealpix , if that's

Linking fortran module: “undefined reference”

删除回忆录丶 提交于 2019-12-04 10:19:35
I'm trying to write some functions/subroutines in a module that call another function in the same module and running into linker errors. A toy example displaying the same behavior: !in test.f module m1 implicit none contains real function mult(a, b) real :: a real :: b mult = a * b return end function mult real function sq(a) real :: a, mult sq = mult(a, a) return end function sq end module m1 program main use m1 write(*,*) sq(2.0) end program When I try to compile this, I run into trouble: [christopher@archlinux metropolis]$ gfortran -ffree-form test.f /tmp/ccpzdTLE.o: In function `__m1_MOD

Correct way to statically link in gfortran libraries on OSX

做~自己de王妃 提交于 2019-12-04 08:32:02
问题 I've a fortran program I'd like to distribute, so I'd like to statically link in the gfortran libraries. If I compile the program with the following flags: gfortran -o myprog -static-libgfortran -static-libgcc myprog.f otool tells me it's statically linked in most of the gofrtran libraries, but not libquadmath: otool -L myprog /usr/local/gfortran/lib/libquadmath.0.dylib (compatibility version 1.0.0, current v /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

MinGW / gcc: The application was unable to start correctly (0xc000007b)

时光毁灭记忆、已成空白 提交于 2019-12-04 07:33:10
I have been using MinGW and the GNU Fortran compiler for a while in order to compile Fortran programs on Windows, which has always been a successful method. However, I have been getting the following error for the past 4 days: The application was unable to start correctly (0xc000007b). Click OK to close the application. The error only happens when running applications that I wrote myself, and that I compiled using the MinGW/gfortran combo. When compiling using Visual Studio and iFort, I have no problem running the applications. The error seems retroactive: applications that were compiled using

integer, do loop, fortran, error

风格不统一 提交于 2019-12-04 05:35:53
问题 I have the following fortran code defined under. I am trying to change the length of the do loop if i change the value of n. When i try to compile i get the error: ‘a’ argument of ‘floor’ intrinsic at (1) must be REAL. But when i change q and w to be defined as real i get another error message. How can i fix this? q and w is clearly a integer when i use floor(...) subroutine boundrycon(n,bc,u,v) !input integer :: n,bc !output real(8) :: u(n+2,n+2), v(n+2,n+2) !lokale integer :: j,i,w,q n=30 q