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
0
votes
0 answers

Problem with deallocate allocatable arrays in Fortran

I am converting a legacy code and employing allocatable arrays Now a subroutine(STIFFR) calls another subroutine(RADaU5) which needs workspace and tolerance specifying arrays. Since these depend on the dimensionality of the problem (passed to…
0
votes
0 answers

Fortran low performance with allocatable arrays

I use Intel Visual Fortran, both IVF2013 and IVF2019. When using allocatable arrays, the program is much slower than the one using static memory allocation. That is to say, if I change from Method 1: by using fixed array do i = 1, 1000 call A end…
Vivey
  • 1
  • 1
0
votes
0 answers

Deallocate causes program to stop without error message

I'm learning Fortran with the book Fortran 90 for scientists and engineers by Brian Hahn. In chapter 9 about arrays, pages 131/132, he gives the following code as an example of dynamic arrays Program Chap_9_Allocatable_Array Implicit none !…
0
votes
0 answers

How to allocate columns in text file as variables then write to a file

I have a data file containing 4 columns and many rows, I want to allocate the first column to t, second to x, third to y, and fourth to z. And have the data being read by row. So to imagine: **T X Y Z** 10, 1.0, 2.0, 3.0 20, 1.0, 2.0, 4.0 How…
0
votes
1 answer

Nested data structure of User-Defined Type in Fortran

I'm looking for a way to build a tree structure using a User-Defined Type in Fortran 2008. While I can get some basic code working, I'm encountering memory leaks I am unable to pinpoint. The tree structure does not have to be overly generic since…
0
votes
1 answer

Fortran runtime error: End of file for allocatable arrays

I'm doing an assignment for a class where we need to write a program using allocatable arrays to hold an arbitrary number of x and y data pairs, allocate the extent of the arrays accordingly, and then calculate the correlation coefficient of the…
0
votes
2 answers

`ALLOCATABLE or POINTER attribute dictates a deferred-shape-array` in ABAQUS subroutine

Code: double precision maxstress(w) real, dimension(:), allocatable, save :: han(w) integer jang(w) do i=1,nblock if(maxstress(i) . gt. 1000) then jang(i) =1 han(i) = han(i) + 1 else jang(i) =0 …
0
votes
2 answers

Allocatable arrays in CUDA-Fortran device data structures

I'm trying to use allocatable arrays inside "device" data structures that reside in GPU memory. Code (pasted below) compiles, but gives a segfault. Am I doing something obviously wrong? Module file is called 'gpu_modules.F90', given…
ansri
  • 37
  • 6
0
votes
1 answer

Access violation when writing to a Fortran allocatable array

Program Main Implicit None Integer, Parameter :: iwp = SELECTED_Real_KIND(15) Integer, allocatable :: Num(:) Num(1)=1 ...... End Program Main When I use allocatable to define a void array 'num' and then run the program, it reveals that error as…
FortranFun
  • 156
  • 1
  • 11
0
votes
1 answer

Passing a subarray of allocatable array to a subroutine, with right bounds

In the parallel program I'm writing, I defined a lot of multidimensional allocatable arrays (actually just 1D, 2D or 3D) which are allocated with negative lower bounds during the execution. The reason why I did that is that each process handles, in…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

How to pass the size of an allocatable user-defined (derived-type, data structure) variable to a subroutine in fortran?

I want to create a derived-type variable (a.k.a. structure or user-defined variable), calculate it in one subroutine and use it in another subroutine. Both components of the structure are allocatable arrays. I want to know how to tell the…
0
votes
3 answers

subroutine calls with allocatable arrays

In my code, I have memory problems due to the machine that I use, so I want to allocate the least memory possible during passing arguments. My example code: program test double precision, ALLOCATABLE :: arrayA(:) allocate (arrayA(n)) call mySub…
Cagatay
  • 1
  • 4
0
votes
2 answers

Why does this Fortran module interface give different results depending on how many of its functions are used?

I have written a module that contains a interface called 'push' that pushes values onto allocatable arrays. I want it to have generic behavior so that I can add a new function for a given type to the 'push' interface as needed. The problem is that…
0
votes
1 answer

Do I need an explicit interface to allocate a component of a derived type in a subroutine?

I have a derived type: module foo type bar integer, allocatable, dimension(:) :: data end type bar end module foo Now I would like to allocate bar's data within a subroutine without an explicit interface: program main use foo …
mgilson
  • 300,191
  • 65
  • 633
  • 696
-1
votes
1 answer

How to read the second column of a text file in fortran and then allocate it in an array?

I have a text file with two colums with real numbers. How can I import the numbers from the second colum in an array ? I think I first need to define an allocatble array, then read my text file and then allocate the second column to the array, but I…
1 2 3
4