problem with pyroms.grid.Gridgen

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
sonaljit.m
Posts: 43
Joined: Wed Nov 30, 2016 11:18 pm
Location: University of Massachusetts Dartmouth

problem with pyroms.grid.Gridgen

#1 Unread post by sonaljit.m »

Hi all,
I recently joined the ROMS community and started working with the ROMS model as part of my postdoctoral work. Currently I am trying to setup the grid for my simulations using pyroms, bathy_smoother and pyroms_toolbox. I'm running python2.7 with anaconda2 on Ubuntu 16.04.

I have installed the three pyroms packages using the setup.py files following the instructions on github, into this path: /home/sonaljit/anaconda2/lib/python2.7/site-packages/

Now, when I run a simple test-code that generates a grid using the routine pyroms.grid.Gridgen, it gives me an error message that says:
File "/home/sonaljit/anaconda2/lib/python2.7/site-packages/numpy/ctypeslib.py", line 155, in load_library
raise OSError("no file with expected extension")
OSError: no file with expected extension

Exception AttributeError: "'Gridgen' object has no attribute '_libgridgen'" in <bound method Gridgen.__del__ of <pyroms.hgrid.Gridgen object at 0x7f950b149790>> ignored


I think the code is looking for the file libgridgen.so in the path "~/anaconda2/lib/python2.7/site-packages/pyroms/". I checked in the path and there is no such .so file available there. There are some .so files in other folders like site-packages/bathy_smoother/ and site-packages/pyroms_toolsbox/, but none within pyroms/

Can anyone suggest how to fix this problem? Probably libgridgen.so was not created during the installation. Is there a way libgridgen.so could be generated?

Thanks,
Sonaljit.

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: problem with pyroms.grid.Gridgen

#2 Unread post by kate »

You can go into the pyroms/pyroms directory and look at the install_pyroms.sh script there. What you can do is cut and paste from this script into a terminal running a bash shell. The gridgen part is this:

Code: Select all

echo "installing gridgen..."
cd $CURDIR/external/nn
./configure --prefix=$DESTDIR
make install
cd $CURDIR/external/csa
./configure --prefix=$DESTDIR
make install
cd $CURDIR/external/gridutils
./configure --prefix=$DESTDIR
make install
cd $CURDIR/external/gridgen
./configure --prefix=$DESTDIR
make
make lib
make shlib
make install
PYROMS_PATH=`python -c 'import pyroms ; print pyroms.__path__[0]'`
cp libgridgen.so $PYROMS_PATH
#cp $LOCALDIR/lib/libgridgen.so $PYROMS_PATH
Be sure to set DESTDIR and CURDIR first. One benefit to doing it this way is to watch for errors as you go. If the PYROMS_PATH thing doesn't work, you will know.

sonaljit.m
Posts: 43
Joined: Wed Nov 30, 2016 11:18 pm
Location: University of Massachusetts Dartmouth

Re: problem with pyroms.grid.Gridgen

#3 Unread post by sonaljit.m »

Thanks Kate. The error seems to have gone; the Gridgen code is compiling.

I'm facing another problem. Even though this is not interfering with Gridgen, but it says 'scrip.so missing. Remapping function will not be available'

Looks like I could not get the scrip.so file installed. I tried running the instructions given in install_pyroms.sh for scrip. The error I'm getting is related to netcdf: undefined reference to `nf_open_'. The source files remap_write.f and grids.f (in the scrips folder) are giving me this error during compilation.

I think it is unable to locate the netcdf routines in my system. I provided the paths to the netcdf lib. and inc. files in the makefile (and makefile2) in the following manner:
LIBDIR=/home/sonaljit/.local/lib
INCDIR=/home/sonaljit/.local/include
F2PY_LIB = -L${LIBDIR} -lnetcdff -lhdf5 -lhdf5_hl

However, it is still giving the above error. Probably I'm doing something wrong here. Any suggestions?

Sonaljit.

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: problem with pyroms.grid.Gridgen

#4 Unread post by kate »

You should have -lnetcdf in there as well. In fact, "nc-config --flibs" or "nf-config --flibs" tells you what all is needed on your system.

sonaljit.m
Posts: 43
Joined: Wed Nov 30, 2016 11:18 pm
Location: University of Massachusetts Dartmouth

Re: problem with pyroms.grid.Gridgen

#5 Unread post by sonaljit.m »

Hello,
The netcdf issue got solved; I re-installed netcdf and provided the correct path to -lnetcdf in the makefile. The command make -f makefile2 (in the makefile) is working. Thank you Kate.

Following that - I'm facing another error while compiling pyscrip.f90 (the command make -f makefile2 f2py ). The code in the makefile linked with this command is:

$(F2PY) --fcompiler=gnu95 --f90flags=$(F2PY_F90_FLAG) \
$(F2PY_LIB) $(F2PY_INCLUDE) -m scrip \
-c $(OBJF2PY) pyscrip.f90


I changed gnu95 to gfortran and provided the appropriate library paths to it. The error I am getting is:

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status


Any suggestions?

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: problem with pyroms.grid.Gridgen

#6 Unread post by kate »

Did you try it with gnu95 instead of gfortran? That's what I use for gfortran.

sonaljit.m
Posts: 43
Joined: Wed Nov 30, 2016 11:18 pm
Location: University of Massachusetts Dartmouth

Re: problem with pyroms.grid.Gridgen

#7 Unread post by sonaljit.m »

Hello,
After a few modifications, the pyroms code got installed in my system. I was having problems with the module scrip, and with the compilers gfortran and f2py for linking with netcdf. I will explain the solutions below (in case anyone faces these problems during installation).

netcdf: For installing the scrip module using gfortran, the source files grids.f, netcdf.f, remap_write.f and remap_read.f require linking with the netcdf libraries since they contain netcdf routines. The command for compilation of remap_write, as given in the makefile, is:

remap_write.o: $(SRCDIR)/remap_write.f kinds_mod.o constants.o \
netcdf.o remap_vars.o grids.o
$(COMPILE) $(FLAGS) $(INCLUDE) -c $(SRCDIR)/remap_write.f


This instruction isn't having the netcdf library linked to it, so I provided the netcdf link as below:
NETCDFLIB = -L/home/sonaljit/anaconda2/lib -lnetcdf
$(COMPILE) $(FLAGS) $(INCLUDE) -c $(SRCDIR)/remap_write.f
$(NETCDFLIB)

and it worked. Likewise, I did it for the instructions for compiling grids.f, remap_read.f and netcdf.f in the makefile.
$(COMPILE) $(FLAGS) $(INCLUDE) -c $(SRCDIR)/netcdf.f $(NETCDFLIB)
$(COMPILE) $(FLAGS) $(INCLUDE) -c $(SRCDIR)/remap_write.f $(NETCDFLIB)
$(COMPILE) $(FLAGS) $(INCLUDE) -c $(SRCDIR)/remap_read.f $(NETCDFLIB)
$(COMPILE) $(FLAGS) $(INCLUDE) -c $(SRCDIR)/grids.f $(NETCDFLIB)

The other source files do not require this modification for compiling since they aren't accessing any netcdf routines. I'm not sure if these modifications are specific to only my system, but they seem to solve the errors I was facing earlier. So, I'd recommend doing this in case anyone would face this error.

f2py: Regarding the error with the f2py instruction:

$(F2PY) --fcompiler=gfortran --f90flags=$(F2PY_F90_FLAG) \
$(F2PY_LIB) $(F2PY_INCLUDE) -m scrip \
-c $(OBJF2PY) pyscrip.f90


The problem here was, $(F2PY_LIB) was linked to the static (.a) netcdf library. However, since the above instruction creates a shared dynamic (.so) library, it will require a shared dynamic netcdf library to compile properly. In my system, the netcdf shared dynamic library is located at ~/anaconda2/lib/libnetcdff.so. The same directory also has the static library libnetcdf.a. Since -lnetcdff link wasn't provided before, f2py was having trouble accessing the static .a version. So, I was getting the error: /lib/libnetcdf.a: error adding symbols: Bad value

Again, I don't know if this is specific to only my system. But, they seem to work.

Thanks Kate.

Sonaljit.

caioerick

Re: problem with pyroms.grid.Gridgen

#8 Unread post by caioerick »

kate wrote:You can go into the pyroms/pyroms directory and look at the install_pyroms.sh script there. What you can do is cut and paste from this script into a terminal running a bash shell. The gridgen part is this:

Code: Select all

echo "installing gridgen..."
cd $CURDIR/external/nn
./configure --prefix=$DESTDIR
make install
cd $CURDIR/external/csa
./configure --prefix=$DESTDIR
make install
cd $CURDIR/external/gridutils
./configure --prefix=$DESTDIR
make install
cd $CURDIR/external/gridgen
./configure --prefix=$DESTDIR
make
make lib
make shlib
make install
PYROMS_PATH=`python -c 'import pyroms ; print pyroms.__path__[0]'`
cp libgridgen.so $PYROMS_PATH
#cp $LOCALDIR/lib/libgridgen.so $PYROMS_PATH
Be sure to set DESTDIR and CURDIR first. One benefit to doing it this way is to watch for errors as you go. If the PYROMS_PATH thing doesn't work, you will know.
Hello dear :)

I have had a problem with the 'make lib' and 'make shlib' command. When I try, it alerts...

Code: Select all

make: Nothing to be done for 'lib'.
make: Nothing to be done for 'shlib'.
And in the previous command (in ./configure --prefix = $ DESTDIR), it also displays two alerts:

Code: Select all

configure: WARNING: unable to find gridnodes.h. You will not be able to compile the library function gridgen_generategrid2 (). Please modify your LD_LIBRARY_PATH and re-run this script if necessary.
configure: WARNING: unable to find library libgu; you will not be able to build the shared library
I was trying to create my grid and gave the same problem with libgridgen.

Did you or anyone know how to fix the problem?

Thanks you very much!

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: problem with pyroms.grid.Gridgen

#9 Unread post by kate »

For generating grids, you might look into pygridtools. They seem more advanced in their Python support.

Post Reply