Hello, I am also very interested in being able to work with netcdf and hdf files in Sage.
I already is possible if what you want to do is simple. Scipy has a netcdf class. All you have to do is: from scipy.io.netcdf import * ncfile=netcdf_file(yourfilename,'r') Then ncfile.variables.keys() to list all the variables or var1 = ncfile.variables['variable_1'][:] to import the variable named "variable_1". Easy. You can have a look at this web site: http://xenocoder.wordpress.com/2008/07/21/trying-sage-mathematical-software-part-ii-running-trials-1/ I had some problem with this approach though. In my analysis, I needed to import a given data from many files, store it and perform some statistical analysis. The problem I got is that I could not analyze more than 1000 (ish, it depends on your platform) files. It was as if the ncfile.close() did not really close the file. I could replicate the problem in C++ if I did not close all the files after importing the variable I needed. Needless to say, that in all my C++ programs the destructors now work and close all the netcdf files once I imported the needed variable(s). I documented this problem on this sage-support and on the scipy web site. I did not get any answer from the scipy web site. I had another problem with scipy.io.netcdf, I could not write or create a netcdf file from within Sage. My conclusion is that if you want to do some simple analysis, scipy.io.netcdf might be helpful. But that's it. A different but somewhat related problem, is that if you want to plot some variable and overlay a (world) map on top of that you need (or maybe I just don't know Sage enough) to install something else not included in Sage. I still find the customization of Sage a little difficult. One can find bits and pieces from sage-support to customize Sage but there is no one source that describe the different alternatives (from the sage shell, ...) with their pros and cons, clearly. For instance, it would be nice to be able to install Basemap a matplotlib toolkit to plot different maps but I don't know how. There is another solution. It is possible to install R packages from within Sage. You can install the netcdf R package. I only installed it but did not have time to try it. Can you please let us know if your (or any other) solution worked? Alex On Sep 7, 3:49 am, samrat <[email protected]> wrote: > Hi, > > Thanks for your replies. No one replied for a couple of days and so i > thought that it would remain status quo. So - well - i compiled > netcdf-4.1.1 with the -fPIC flag. As you said netcdf-4.1.1 does not > have the default compile time option of shared libs being built. > Enabling build of shared libs caused errors during the make process > and i ditched the effort. I just gave the -fPIC flag. > > On Sep 6, 9:35 pm, "Dr. David Kirkby" <[email protected]> wrote: > > > On 09/ 6/10 11:12 AM, Minh Nguyen wrote: > > > > Hi, > > > > On Fri, Sep 3, 2010 at 8:03 PM, samrat<[email protected]> wrote: > > >> When i recompilenetcdf-4.1.1 with CFLAGS=-fPIC i no longer get this > > >> error. It this a bug in sage or what i have done is correct? > > > > Many standard packages that are shipped by default with Sage are > > > usually compiled with CFLAGS=-fPIC. So what you did was OK. Thank you > > > for sharing your workaround. > > > >> Will > > >> there be any further problems in thenetcdf-4.1.1 installation? > > > > It's hard to say. The packagenetcdfis not maintained in any way by > > > any Sage contributor. Also, the package itself is not listed on any of > > > the standard, optional, or contributed (formerly experimental) package > > > repositories [1]. > > > > [1]http://www.sagemath.org/download-packages.html > > > It it's a shared library, then is *should* be built with -fPIC. It is > > unfortunate that > > > * You can often get away without my -fPIC > > * -fPIC causes a small slowdown. > > > Because of this, some people build libraries without it, but it sometimes > > fails, > > as you have found out. I managed to convince the Pari developers to always > > build > > with -fPIC. > > > The gcc manual sort of implies this, but is not very specific about it. > > > The Sun linker manual is very clear - shared libraries should be compiled > > position independent. > > > Will's workaround is sensible. Had the package been maintained, then I would > > suggest we implement it, but if nobody is bothering with it, there's not a > > lot > > of point. > > > Dave > > -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
