I am trying to replicate an old fortran code so I can use it in python. The hardest part is importing the data which is stored in a rather convoluted shape.
I have a text file with 14500 data points stored in 5 columns separated by commas:
9.832e-06, 2.121e-16, 3.862e-21, 2.677e-23, 1.099e-22,
5.314e-23, 1.366e-23, 6.504e-23, 3.936e-23, 1.175e-22,
1.033e-23, 5.262e-23, 3.457e-23, 9.673e-23, 1.903e-22,
3.153e-10, 2.572e-21, 5.350e-23, 4.522e-22, 1.468e-22,
2.195e-23, 2.493e-22, 1.075e-22, 3.525e-22, 1.541e-23,
1.935e-22, 9.220e-23, ..., ..., ...,
The fortran code declares two variables to store these data: pg and ping. The first one is a 4D matrix and the second is a 1D array with the data points array length (14500)
parameter(NSIZ=29)
parameter(NTg=5)
parameter(NDg=5)
parameter(NTAUg=20)
real pg(NSIZ,NDg,NTg,NTAUg)
real ping(NSIZ*NDg*NTg*NTAUg)
So far so good, but now I have an equivalence command:
equivalence(pg,ping)
which as far as I understand it points the pg matrix to the ping array. The final part is a loop which reads the lines from the data file and allocates them to the ping array:
NCOLs=5
NROWS=NTg*NDg*NTAUg*NSIZ / NCOLs
irow=1
do i=1,NROWS
read(nat,*) (ping((irow-1)*NCOLs+k),k=1,NCOLs)
print *, ping(irow)
irow=irow+1
enddo
I would like to replicate this code in python but I do not understand how the read command is assigning the data to the 4D matrix. Could anyone offer any advice?