mjwoods / RNetCDF

Read and write netcdf format in R
Other
24 stars 9 forks source link

Version on a Mac #48

Closed rmendels closed 5 years ago

rmendels commented 5 years ago

I would like to test version 2 on my Mac. Just trying devtools::install_github() fails because there must be flags or paths set that I don't have correctly. Any suggestions of key things to look for? I have a complete netcdf installed through Fink, I probably need to point to that correctly.

Thanks for any help and your work on this.

mjwoods commented 5 years ago

Hi @rmendels , thanks for testing the package. I'm keen to fix any problems you uncover.

I haven't tried using devtools::install_github before, so I installed it (under MacPorts). Then I tried the following:

> library(devtools)
> ?install_github
Help on topic ‘install_github’ was found in the following packages:

  Package               Library
  remotes               ...
  devtools              ...

Choose one 

1: Attempts to install a package directly from GitHub. {remotes}
2: Objects exported from other packages {devtools}

Based on the description, I suspected that devtools::install_github doesn't do quite what the name suggests. So I tried the other package in the list, and it worked for me:

library(remotes)
install_github("https://github.com/mjwoods/RNetCDF.git")
rmendels commented 5 years ago

Thanks @mjwoods, the problems I am having is figuring out all the flags that need to be set and have them find it. I have a nc-config, and I am passing that, but it still is having trouble with netcdf.h, though the includes are defined in nc-config. What would help is a list of flags you feel need to be set and how to pass them to R CMD (I assume you have a bunch of "with_xxx="

mjwoods commented 5 years ago

The configure script in RNetCDF runs two nc-config commands, which should return all of the required details. For example, on MacPorts:

$ nc-config --libs
-L/opt/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lz -ldl -lm -lcurl
$ nc-config --cflags
-I/opt/local/include

If your nc-config is returning the wrong details, you could copy it somewhere, fix the details, then add the new location to your PATH.

If you really get stuck, there is a method for installing without nc-config described in the INSTALL file (see the top-level directory of the RNetCDF source package). I haven't used it for a long time, and I hope it still works.

rmendels commented 5 years ago

I was able to get it to compile by taking the source, hard-coding some info in the configure.ac file, re-creating the .tgz file, and doing:

R CMD install RNetCDF.tgz --configure-args='CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib'

Library loads and the example for print.nc() works, so it means it finds the libraries and can run. Hope to be able to test it in the next couple of days. You can close this issue also.

mjwoods commented 5 years ago

It's a bit of a worry that so much effort was needed. I would have expected nc-config to provide those paths as results of the commands I showed earlier. What results do they give on your Mac?

Also, what did you need to hard-code in configure.ac?

rmendels commented 5 years ago

Hi Milton:

My nc-config is fine, it showed what your's did plus some other stuff. The problem was no matter or how I did/did not pass on info about nc-config (and it is in my PATH), it was not being found in the script. What I had to do was disable the logic of:

AC_ARG_WITH([nc-config],
    AS_HELP_STRING([--without-nc-config],
        [do not use nc-config to get netcdf configuration]),
    [],
    [with_nc_config=yes])

AS_IF([test "x$with_nc_config" != xno],
      [AC_CHECK_PROG(have_nc_config, nc-config, yes, no, [], [])]
)

AS_IF([test "x$have_nc_config" == xyes],
  [
    # Find libraries and cflags used to build netcdf:
    AC_MSG_CHECKING(netcdf linker flags)
    NETCDF_LIBS=`nc-config --libs`
    AC_MSG_RESULT($NETCDF_LIBS)
    LDFLAGS="$NETCDF_LIBS $LDFLAGS"
    AC_MSG_CHECKING(netcdf compiler flags)
    NETCDF_CFLAGS=`nc-config --cflags`
    AC_MSG_RESULT($NETCDF_CFLAGS)
    CFLAGS="$NETCDF_CFLAGS $CFLAGS"
  ], [
    # Check that netcdf header files can be compiled:
    AC_CHECK_HEADERS(netcdf.h, [],
       AC_MSG_ERROR("netcdf.h was not compiled - defining CPPFLAGS may help"))
    # Add netcdf library to LIBS if it can be linked (and is not already being linked):
    AC_SEARCH_LIBS(nc_open, netcdf, [],
        AC_MSG_ERROR("netcdf library was not linked - defining LDFLAGS may help"))
  ]
)

# Check for the existence of optional netcdf routines.
# Afterwards, C preprocessor macros HAVE_DECL_symbols are defined,
# with value 1 if routine is declared or 0 if not.
AC_CHECK_DECLS([nc_rename_grp], [], [], [[#include <netcdf.h>]])

so I just removed all those tests on whether to use nc-config but kept the lines following:

    # Find libraries and cflags used to build netcdf:

and hard-coded the location of nc-config.

mjwoods commented 5 years ago

Thanks for the explanation. There is something strange going on if nc-config can't be found.

I wonder if R is messing with your PATH. From inside R, does system("nc-config --libs") produce any errors?

I'm also interested in seeing some verbose output from the original configure script in RNetCDF. Could you please post the output from the following command, run from inside the RNetCDF source directory?

bash -x ./configure 2>&1 | grep nc-config
rmendels commented 5 years ago

It is well known that on the Mac at least R does not pick up all the environmental info. I tried including that info in the R CMD install, in every way I could think of from both looking a "configure --help" and just looking at the code. So maybe I just wasn't passing it the correct flag or with the correct setting, but as soon as I disabled all the tests and made it use the specific nc-config, everything worked.

mjwoods commented 5 years ago

I can't understand why R would have any effect on nc-config. If you can provide the results from configure (as above), that may give me some clues about what is happening. Otherwise, I'll try to install fink and reproduce the problem ... but that will take a few days (at least).

mjwoods commented 5 years ago

The plot thickens. I was able to install Fink, and eventually worked out how to install the following packages:

r-base34
r-base34-dev
r-base34-shlibs
netcdf-bin (4.6.2-1, programs)
netcdf-c13 (4.6.2-1, C headers and docs)
netcdf-c13-shlibs (4.6.2-1, C library)
udunits2 (2.2.20-1)
udunits2-dev (2.2.20-1, headers)
udunits2-shlibs (2.2.20-1, shared libs)

After starting R, I was able to install devtools, then I used install_github to install the latest RNetCDF. I couldn't reproduce your problem.

Some ideas:

rmendels commented 5 years ago

I have R installed through the usual installer, as most users will. Please understand, once the nc-config was found, everything worked fine. So nothing is wrong with my Fink installation. The problem has to do with some interaction of the standard R distro, Fink, and your configure logic for testing if there is an nc-config. Once I disabled you logic so that is just said there is a nc-config, there was no problem.

I am pretty busy at work right now, I can't spend much time on this for the rest of the week.

mjwoods commented 5 years ago

Just so I understand clearly, you are using an R binary installation from CRAN, and then building RNetCDF from source code using Fink. Am I right?

rmendels commented 5 years ago

R was installed using the CRAN installer netcdf was installed using Fink. The fink paths are defined in my .profile, and the command "which nc-config" finds nc-config I tried to install RNetCDF 3 ways:

  1. using devtools::install_github(), fails because it doesn't find nc-config, can't find netcdf.h
  2. Download directory, convert to a .tgz, install from the command line using RCMD. I tried passing it every combination of "--configure-args" that I could think of, based on looking at the uncompressed directory, and running ./configure --help, or looking at the configure code. If there is an argument to pass to it telling it where the nc-config feel is, couldn't find it.
  3. Got in and hand edited the configure file so it new where things where and re-tarrred. Then i could just run the usual R CDM install passing the C options using "--configure-args".

HTH

mjwoods commented 5 years ago

Thanks Roy,

I think I have found the problems now. For a start, my configure logic was wrong, as you suggested. A variable was being defined in configure but not passed into the make step. I have fixed that now, and tidied up a couple of other details.

I suspect that your PATH variable could still be a problem. Depending on how you start the R for Mac GUI, the initial PATH may only include basic system directories. You can see the initial PATH in the GUI as follows:

Sys.getenv("PATH")

On my system, the results do not include Fink, so nc-config is not found by RNetCDF. I used the following commands (in the GUI) to adjust the PATH and then install RNetCDF:

Sys.setenv(PATH=paste(Sys.getenv("PATH"), "/sw/bin", sep=":"))
library(devtools)
install_github("mjwoods/RNetCDF", ref="build_in_R_gui_on_mac")

Can you please try the commands above (or similar), and let me know if the new branch works for you?

Regards, Milton.

mjwoods commented 5 years ago

Hi @rmendels , have you been able to test my new branch? If it works for you, I will merge it into the master branch.

rmendels commented 5 years ago

@mjwoods My apologies. This slipped through the cracks. just tried the three lines you sent and it did indeed work,

Thanks, HTH.

-Roy

mjwoods commented 5 years ago

Excellent! Thanks Roy.