MRedies / NPY-for-Fortran

A FORTRAN module to write Numpy's *.npy and *.npz files
MIT License
40 stars 9 forks source link

Compiling and some basic fortran questions #8

Closed jackcshigz closed 2 years ago

jackcshigz commented 2 years ago

Hi!, I have very little experience with Fortran, but I still hope to use your script to save some Fortran arrays as npy files. And I am experiencing some issues right now. First of all, I have put the npy.f90 file and the simulation code in the directory And then in the simulation code, I added the call save_npy("pressure.npy", p) just after where the Fortran code reads the UNFORMATTED Fortran array.

do k = 1, kr_fine-kl_fine+1
   do j = 1, jr_fine-jl_fine+1
       do i = 1, ir_fine-il_fine+1
            p(i, j, k) = vars(i+il_fine-1, j+jl_fine-1, k+kl_fine-1, 1)
            !print*, 'p(i,j,k) = ', p(i, j, k)
        end do
    end do
end do
call save_npy("pressure.npy", p)

When I compile the main code, I get an error message

ifort dat_to_npy.f90 -o dat_to_txt.exe /tmp/iforth8PVRN.o: In function MAIN__': dat_to_npy.f90:(.text+0xfe17): undefined reference tom_npy_mp_write_dbl3dt'

So I wonder if I need to compile npy.f90 before compiling my main code.

Also, the name of my main code is not called "main", instead it is Page up PROGRAM als_projection_method so I wonder I need to change somewhere to make things work and still keep the program name als_projection_method

Thanks

MRedies commented 2 years ago

Hello jackcshigz,

the name of the program shouldn't be an issue. In the error message is says MAIN__ because that's the internal name, so the OS knows where to start. You can keeps the name as is.

You need to keep in mind that Fortran (unlike C) also has module file (.mod) in addition to the .o files. Try compiling like this:

ifort npy.f90 dat_to_npy.f90 -o dat_to_txt.exe
jackcshigz commented 2 years ago

It works! Thank you very much!