Possible error storing data array in binary format using fortran

Viewed 64

I'm using a Fortran code to numerically solve the TDSE.
To run the code I need to provide the potential multipole coefficients stored unformatted in binary form in the following way:
enter image description here

It has worked smoothly with spherical potentials, where I have stored all data in a single column. To create this binary file I have used codes similarly to this:

program ar_pot
integer(kind=4) :: lmax, nr
real(kind=8) :: rmax
integer(kind=1) :: spherical, linear, even
integer :: i
real(kind=8) :: pi, r, V00
nr = 1024
lmax = 40
rmax = 160d0
spherical = 1
linear = 0
even = 0
pi = acos(-1d0)
open(1,file="potential",form="unformatted")
write(1) lmax,nr,rmax,spherical,linear,even !creating header
do i = 1, nr
    read(*,*) V00
    write(1) V00*sqrt(4.0*pi)
    write(*,*) i, V00
end do
close(1)
end program ar_pot

Where I have read .txt files with a single column of data and nr rows. ( ./a.out <data.txt )

The issue is that I'm not working with a spherical potential. So instead I want to work with the general case stated in the picture (otherwise case). But when I'm running the TDSE code using the binary file for a non-spherical, non-linear and uneven potential I run into an error message (forrtl: severe (151): allocatable array is already allocated) and I'm trying to figure out, whether I'm not saving the data correctly in the binary file, or whether the program doesn't work correctly. So for the simplest case, I wanted to construct an array with zeros in all rows and columns except for the first column. The first column should then have the same data as in data.txt. That way I could run the code and should get the same results as previously.

To do this I created the code:

program h_pot
integer(kind=4) :: lmax, nr
real(kind=8) :: rmax
integer(kind=1) :: spherical, linear, even
integer :: i
real(kind=8) :: pi, r
character*100000000 :: V00
nr = 1024
lmax = 40
rmax = 160d0
spherical = 0
linear = 0
even = 0
pi = acos(-1d0)
open(1,file="potential2",form="unformatted")
write(1) lmax,nr,rmax,spherical,linear,even
do i = 1, nr
    read(*,'(A)') V00
    write(1) trim(V00)
end do
close(1)
end program h_pot

Where I compile by ./a.out <data2 , and data2 is a .txt file with first column equal to data.txt and all other columns equal to zero (with the number of columns running up to (lmax+1)^2 ) and data points separated by tabs. (Actually the l_max stored in the header and the l_max in the figure above are not necessarily the same)

Can you see any obvious flaws here?

The full error message is

"forrtl: severe (151): allocatable array is already allocated
Image PC Routine Line Source
libifcoremt.so.5 00007F081093280F for_alloc_allocat Unknown Unknown
tdse3d-splitop 000000000041F641 Unknown Unknown Unknown
tdse3d-splitop 000000000040CFB3 Unknown Unknown Unknown
tdse3d-splitop 0000000000402662 Unknown Unknown Unknown
libc-2.17.so 00007F080DC20B15 __libc_start_main Unknown Unknown
tdse3d-splitop 0000000000402559 Unknown Unknown Unknown"

Note that I'm a novice when it comes to Fortran and storing data in binary format.

0 Answers
Related