fortran90

Looping variable names in fortran 90

Hi, I have a large amount of arrays of different dimensions. However, I name them with a sequential order, say var1, var2, and so on. In order to read them, I would be interested in looping over them in something like: do i=1,n read(1,*) var<i> enddo Of course, since the arrays are of different dimensions, I cannot simply add a ...

Fortran90 Error: EXTERNAL attribute conflicts with DIMENSION attribute

I've written a function which calculates the eigenvalues of a 2*2 matrix. It takes a 2*2 matrix as an argument and returns 2 eigenvalues via a 2-element array. I have declared the function in the program unit like this: real, dimension(2), external :: eigenvalues But it won't compile, it comes up with this error: Error: EXTERNAL attr...

How do I read an input in Fortran without interrupting the program?

An usual read statement in Fortran interrupts the execution of the program until the RETURN key was pressed. I am looking for a statement that reads any pressed key without waiting for the RETURN key. The program should not stop even if no key was pressed. Thank you for your answer. Edit: Here is some source code that should clarify the...

Value read from file is stored as a different value in Fortran.

I have an input file and the first line contains the following decimal. 0.5053102074297753 I have a Fortran 90 program which reads the file and outputs the value. read(*,*) answer write(*,"(F20.16)") answer This is the output: 0.5053101778030396 Apparently, what is stored is not the same as what is read. The question is, Why? ...

Function Returning an array in Fortran

It is my understanding that you can return an array from a function in Fortran, but for some reason my code is only returning the first value in the array I am asking it to return. This is the function: function polynomialMult(npts,x,y) integer npts double precision x(npts), results(npts + 1), y(npts,npts) polynomialMult = ...

Error: Unexpected end of format string in format string, fortran 90

Getting this error while trying to compile a copied code from a fortran 77 program. code: 900 FORMAT(1H0,2X,'ABSOLUTE GRID LIMITS FOR DATA RETENTION FOR RADAR',I3,' XMIN-XMAX ',2F8.3,' YMIN-YMAX ',2F8.3,' ZMAX ',F8.3, /3X,'WITH AZIMUTH LIMITS OF',2F8.2, 3X,'AND RANGE LIMITS OF',2F10.3,/) compiler error: messy21.f90:529.132: N FOR R...

Store a "pointer to function" in fortran 90 ?

in fortran, you can pass a function/subroutine A as an argument to another function/subroutine B, but can you store A for later retrieval and use? for example, this is allowed in C int foo(float, char, char) { /*whatever*/}; int (*pointerToFunction)(float, char, char); pointerToFunction = foo; In Fortran you can pass a subroutine as...

Fortran 90 compiling issue: undefined reference to <modulename>

I'm having trouble trying to compile a simple fortran program which uses a module in the same directory. I have 2 files: test1.f90 which contains the program and modtest.f90 which contains the module. This is test1.f90: program test use modtest implicit none print*,a end program test This is modtest.f90: module modtest impli...

pointer as a dummy argument.

I am somewhat puzzled by the following program module test implicit none type TestType integer :: i end type contains subroutine foo(test) type (TestType), intent(out) :: test test%i = 5 end subroutine subroutine bar(test) type (TestType), intent(out) :: test test%i = 6 end subrout...

Can I have a pointer to an item in an allocatable array?

I have a user-defined type vector. In another type, I have an allocatable array of vectors. I want to have a pointer to a single vector from this allocatable array. So I thought I would do this: type(vector),allocatable,target::my_vectors(:) and type(vector),pointer::pointed_vec But when I compile, the compiler complains that: Thi...

MPI_COMM_WORLD handle loses value in a subroutine

my program is as follows: module x use mpi !x includes mpi module implicit none ... contains subroutine do_something_with_mpicommworld !use mpi !uncommenting this makes a difference (****) call MPI_...(MPI_COMM_WORLD,...,ierr) end subroutine ... end module x program main use mpi use x MPI...

"Real world" use of parameter passing in Fortran

I always assumed that fortran passed entities "by reference" to a dummy argument. Then I got this answer (the actual argument of the answer was related, but not on this) The standard never specifies that and, indeed goes quite a lot out of its way to avoid such specification. Although yours is a common misconception, it was n...

difference between POINTER and ALLOCATABLE

what is the difference between these two codes type Foo real, allocatable :: bar(:) end type and type Foo real, pointer :: bar(:) end type in particular when it comes to the following code: type(Foo) :: myfoo allocate(myfoo%bar(10)) ...