62 questions
0
votes
1
answer
188
views
How to solve LNK4098 warning, libcmt.lib conflicts with libraries? and subsequent erroneous results
I need to produce a static .exe to distribute to users that have no VisualStudio, no Intel Fortran/oneAPI, and no MKL.
My code "UgensTester.f90" worked fine since 2010 with yearly updates, ...
0
votes
0
answers
40
views
Fortran: Initialization of allocatable array with another array [duplicate]
I read a Fortran code :
program t
real :: x(5) =[1.,-2.,3.,-4.,5.]
real,allocatable :: y(:)
y = x
...
For me the normal way is
allocate(y,source=x)
I'm surprised that it works, both ...
0
votes
1
answer
80
views
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
...
1
vote
1
answer
283
views
Fortran derived-type parameter with allocatables
I have a derived-type with pointer (or allocatable) component
type Tmy
real, dimension(:), pointer :: vals
integer :: nVals
end type Tmy
And I want to create a parameter, e.g. to pass it to a ...
-1
votes
1
answer
231
views
How to read the second column of a text file in fortran and then allocate it in an array? [closed]
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 ...
1
vote
2
answers
214
views
How to have an allocatable array of variable rank (number of dimensions)?
I have two programs : 2D and 3D versions.
For example, this is a simplified 2D version :
program main
integer, parameter :: nDim = 2
integer :: size
real, dimension(:,:,:), allocatable :: ...
3
votes
2
answers
801
views
intent(out) and allocatable Fortran arrays: what is really done?
I read on many posts on Stack Overflow that an allocatable array is deallocated when it is passed in a subroutine where the dummy argument is intent(out).
If I consider the following code :
program ...
0
votes
0
answers
212
views
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 ...
0
votes
0
answers
334
views
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: ...
1
vote
1
answer
1k
views
Reset (deallocate / nullify) a Fortran allocatable array that has been corrupted
When a situation such as described in Incorrect fortran errors: allocatable array is already allocated; DEALLOCATE points to an array that cannot be deallocated happens (corrupted memory leaves an ...
0
votes
0
answers
205
views
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 ...
1
vote
1
answer
4k
views
How to solve 'Fortran runtime error: I/O past end of record on unformatted file'?
Now I have one 1024 * 1024 * 1024 array, whose dtype is float32. Firstly I save this array to one file in the format of '.bigfile'. And then I convert this bigfile to the Fortran unformatted file by ...
2
votes
0
answers
294
views
Fortran function returning allocatable array with non-trivial bounds [duplicate]
As per object, I'm struggling understanding the logic behind functions returning allocatable arrays. I like this construct because its clarity compared to subroutines, and because pure functions in ...
1
vote
1
answer
175
views
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 ...
2
votes
1
answer
119
views
Access extended type components in a SELECT TYPE construct
I'm trying to build an allocatable array with polymorphic elements. A minimal example is the following :
program PolyArray
implicit none
type basetype
integer :: ib
end type basetype
type, ...
1
vote
0
answers
268
views
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 ...
0
votes
0
answers
245
views
How to allocate columns in text file as variables then write to a file [duplicate]
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 ...
3
votes
2
answers
541
views
Fortran doesn't keep lower/upper array bounds after copy to another allocatable array
This doesn't work
program main
implicit none
integer :: nx = 3
integer :: ny = 5
integer :: nz = 8
real, allocatable, dimension(:,:,:) :: A
real, allocatable, dimension(:,:) :: B
...
7
votes
3
answers
3k
views
Fortran function returning allocatable array
Let me consider a function returning an allocatable array. Should the array variable holding the result (outside the function) be allocated before an assignment?
Consider, e.g., the following program
...
3
votes
1
answer
47
views
Unable to print allocated status of a allocatable inside a derived type
I would like to know why this code returns error in the last print.
With gfortran 7.4.0 fails but with ifort 18.0.3 works well.
program test
implicit none
type :: syntax
integer, allocatable :: f(:...
1
vote
2
answers
1k
views
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
...
1
vote
0
answers
35
views
Deallocation of array target, but pointer still seems to have the values [duplicate]
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 ...
1
vote
1
answer
119
views
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 ...
0
votes
1
answer
975
views
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 ...
2
votes
2
answers
1k
views
Unlimited polymorphic dummy argument with allocatable or pointer attributes?
In the project I'm working on, I find myself frequently needing to resize arrays of objects as new objects are created and old ones destroyed. This happens with numerous different derived types ...
5
votes
1
answer
981
views
Fortran (re-)allocation on assignment and gfortran warnings
A simple code:
program main
integer, allocatable :: A(:,:)
integer :: B(3,4)
B=1
A = B !A will get allocated, with the same shape and bounds as B
end program main
Compiling the above ...
3
votes
1
answer
1k
views
How to handle Fortran global allocatable variables in a module across subroutines
I have the following module with an allocatable variable which is defined in the module, allocated in a subroutine, and then also used in a second subroutine called by the first subroutine. In this ...
1
vote
1
answer
397
views
Use an allocatable array that is not allocated in an array assignment [duplicate]
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 ...
4
votes
1
answer
725
views
Array bounds with 0-sized array in Fortran
When allocating zero-sized arrays in Fortran, I am getting counterintuitive behavior.
This code:
program test_zerosized
implicit none
integer, allocatable :: a(:),b(:)
allocate(a(0))
print ...
2
votes
0
answers
525
views
Why does gfortran's runtime bounds check not work when passing allocatable arrays as automatic arrays to subroutines with wrong shape?
I compile the following program with gfortran -g -fcheck=all -Wall bug.F90:
program main
implicit none
real, dimension(:), allocatable :: arr
allocate (arr(5))
! should fail, but ...
4
votes
1
answer
1k
views
Read an allocatable string with a namelist in Fortran
Since Fortran 2003 is it possible to work with variable length character strings. Instead of working in an archaic way and declaring a constant string length I would like to read the character strings ...
2
votes
0
answers
663
views
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 ...
0
votes
1
answer
748
views
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 ...
2
votes
1
answer
587
views
Distinguishing generics in Fortran by other than type/kind/rank
I make huge use of non-1 indexed ALLOCATABLE arrays, whose actual lower (and thus upper) bounds I want to be known for the procedures they're given to as IN/INOUT args (so I declare these dummy ...
2
votes
2
answers
995
views
Fortran function returning unallocated array causes segmentation fault
I'm struggling with some Modern Fortran wrappers to some MPI scatter/gather routines. I am trying to have a wrapper interface that only has an array on input and returns the MPI-operated result on ...
0
votes
2
answers
2k
views
`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(...
2
votes
0
answers
588
views
Threadprivate allocatable performance issues with OpenMP and Fortran
I have a parrallel part of a code which uses a THREADPRIVATE ALLOCATABLE array of a derived type which, in turns, contains other ALLOCATABLE variables:
MODULE MYMOD
TYPE OBJ
REAL, DIMENSION(:), ...
2
votes
1
answer
4k
views
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 ...
2
votes
2
answers
1k
views
Can An Allocatable Intent(inout) Argument Be Optional?
I have problem trying to define a subroutine, whose argument contains an allocatable, optional, intent(inout) variable shown below. The code compiles fine, but get runtime error of "Segmentation fault ...
1
vote
1
answer
2k
views
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 ...
0
votes
2
answers
891
views
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 ...
0
votes
1
answer
1k
views
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' ...
2
votes
1
answer
1k
views
Passing a user defined data type allocatable array
I can define a user defined data type with allocatable array as its data type.
Allocation works perfectly while we are still in the same subroutine.
But i don't know how to pass this type of user ...
5
votes
1
answer
639
views
Internal memory representation of Fortran allocatable
I'd like to know what is the internal memory representation of a fortran allocatable array.
I understand this a bit more complex than a raw pointer, since shape and ranks must be stored as well.
I ...
3
votes
1
answer
921
views
Designing a derived type with array components
I have struggled to find any concrete information where designing a derived type is concerned. I think the best way to discuss this is through a couple of options. I have made up some sections of code ...
6
votes
2
answers
2k
views
Reading allocatable arrays from namelists
I am using GNU Fortran (GCC) 4.8.2
I want to read allocatable arrays from a namelist.
But I don't know in advance how many elements have to be read into the allocatable array, so I cannot allocate it ...
0
votes
1
answer
370
views
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 ...
0
votes
1
answer
443
views
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 ...
3
votes
2
answers
3k
views
Pointer to derived type that contains allocatable array
Generally speaking I want to rename allocatable variables in a derived type that are passed through subroutine arguments. Writing everything with 'derived%type_xx' is not so pleasant. Besides, I don't ...
1
vote
1
answer
172
views
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 ...