Questions tagged [allocatable-array]

This tag is about the use of allocatable arrays in Fortran. Such arrays can have their bounds (shape) varying at run time. Questions using this tag should usually have the more general fortran tag also.

In Fortran, the bounds (and shape) of an allocatable array are determined when it is allocated. Subsequent redefinition or undefinition of any entities in the bound expressions does not affect the array specification.

If the lower bound is greater than the upper bound, that dimension has an extent of zero, and the array has a size of zero. If the lower bound is omitted, it is assumed to be 1.

When an array is allocated, it is definable. If you try to allocate a currently allocated allocatable array, an error occurs.

60 questions
1
vote
1 answer

I wish to create Jagged arrays in Fortran but receives "There is no specific subroutine for the generic ‘new’ at (1)"

I wish to create jagged arrays in Fortran with multiple levels of allocation. However I run in to the error of "There is no specific subroutine for the generic ‘new’ at (1)" for both my constructor and destructor procedures. I'm quite new at…
Jon Bjarke
  • 11
  • 2
1
vote
0 answers

f2py on module with allocatable string

I have written a very simple module (test.f90) module tt implicit none character(:),allocatable :: hh contains subroutine test() implicit none integer :: i end subroutine end module tt I want now to wrap it into an object for Python using…
Guuk
  • 505
  • 3
  • 17
1
vote
2 answers

Assignment of allocatable array with itself values

I would like to know whether it is possible in modern Fortran to assign an allocatable array using itself, or part of it, to do it. Here it is a simple example: module modu implicit none type :: t integer :: i end type contains subroutine…
franpena
  • 151
  • 11
1
vote
0 answers

Deallocation of array target, but pointer still seems to have the values

I have the following very simple code. What I don't understand is after I deallocate my array x, I would assume that my pointer ptr no longer can be dereferenced. However, If you run the program you will see that the print statement will correctly…
ATK
  • 1,296
  • 10
  • 26
1
vote
1 answer

Fortran subroutine forgets allocatable array element value after many iterations

I have a fortran program that has the structure given below. This program has been crashing with 'Segmentation fault' error, so I did a lot of digging into the root cause. It turns out, in the subroutine SUB1, when the DO loop counter variable I…
1
vote
1 answer

Use an allocatable array that is not allocated in an array assignment

In Fortran, if I use an allocatable array that is not allocated in an array assignment, I expect that there will appear some runtime errors. But it turns out that the allocatable array got allocated during the assignment. This seems to be a…
Youjun Hu
  • 991
  • 6
  • 18
1
vote
0 answers

using allocatable arrays from modules in f2py

I'm having issues with allocatable arrays in f2py. In the code below (stored in mymod.f90), I created two modules, vars and worker: vars stores and allocates the array b worker contains subroutines to work with this array from vars. The first…
John Smith
  • 1,059
  • 1
  • 13
  • 35
1
vote
1 answer

Check if array is allocatable in fortran

In fortran it is possible to check if an allocatable array is allocated using the allocated statement: program test_allocated integer :: i = 4 real(4), allocatable :: x(:) print *, 'before allocation of x' print *, 'allocated(x)' print *,…
user32882
  • 5,094
  • 5
  • 43
  • 82
1
vote
1 answer

Allocatable array '' at (1) must have a deferred shape or assumed rank, and Syntax error in READ statement at (1) errors

I am trying to read an ASCII file and am getting errors when compiling such as: Error: Syntax error in READ statement at (1) And Error: Allocatable array 'pos' at (1) must have a deferred shape or assumed rank My code: subroutine…
Elena.G
  • 15
  • 6
1
vote
1 answer

Recover storage of NON-allocatable large arrays in Fortran

The deallocate statement is used to recover storage of an allocatable array that is no more needed. What about non-allocatable arrays? Suppose (in the main and only program) there is a declaration like INTEGER, DIMENSION(100,100) :: A This array is…
Enlico
  • 23,259
  • 6
  • 48
  • 102
1
vote
1 answer

Openmp parallel workshare for allocatable array

I want to do some element-wise calculation on arrays in Fortran 90, while parallelize my code with openmp. I have now the following code : program test implicit none integer,parameter :: n=50 integer :: i integer(8) :: t1,t2,freq real(8) ::…
x1hgg1x
  • 115
  • 10
1
vote
1 answer

Fortran: Allocatable array of derived type containing an array of derived type

I am currently working on a large Fortran program where I have a discrete numerical grid that contains a series of particles that I track within the bounds of the grid. To do this I have defined the following three derived types: type :: particle …
cstraats
  • 117
  • 4
1
vote
3 answers

Allocating memory in C for a Fortran allocatable

We are trying to take over the memory allocation of a legacy Fortran code (+100,000 lines of code) in C++, because we are using a C library for partitioning and allocating distributed memory on a cluster. The allocatable variables are defined in…
1
vote
1 answer

`Allocatable array must have deferred shape` when moving from g95 to gfortran

When transitioning from using the g95 compiler to gfortran I get the following error when I try to compile what previously had been a working code Error: Allocatable array ' ' at (1) must have a deferred shape This happens in all of my subroutines…
spacegirl1923
  • 173
  • 2
  • 11
0
votes
1 answer

Why an allocated array gets unallocated when it is passed to a subroutine?

Passing an allocatable array via actual argument to a subroutine whose corresponding dummy argument is defined as an allocatable array: module m real, allocatable :: a(:,:) end module m module m2 contains subroutine p(c) implicit none …
Youjun Hu
  • 991
  • 6
  • 18