alex-robinson / ncio Goto Github PK
View Code? Open in Web Editor NEWSimple Fortran interface to NetCDF reading and writing.
Simple Fortran interface to NetCDF reading and writing.
I was trying to write a plain integer (one value) into a netCDF file. Using nc_write. According to the API:
filename name of the NetCDF file in which to write data
name name of the variable in NetCDF file to be written
dat Fortran data type of data to be written
dims vector of dimension names of the variable in NetCDF file (optional)
dim1,...,dim6 individual dimension names of the variable in NetCDF file (optional)
start vector of values specifying starting indices for reading data from each dimension (optional)
count vector of values specifying how many values to read in each dimension (optional)
long_name NetCDF attribute, a long descriptive name of variable (optional)
standard_name NetCDF attribute specifying the CF convention standard name of the variable (optional)
grid_mapping name of the grid this variable is mapped on (optional)
units NetCDF attribute of the units of the variable (optional)
missing_value Value of missing data to be written to file (optional)
ncid File ID for a file that remains open for various NCIO calls (optional)
... the only thing to provide are the first three arguments.
Thus using the simplest test possible:
program test
use ncio
call nc_create("test.nc",overwrite=.true.,netcdf4=.true.)
call nc_write("test.nc","int_var",1)
end program test
But this example compiles fine but do not run, error message is:
ncio:: nc_create :: test.nc
ncio:: error: NetCDF: Invalid dimension ID or name
STOP stopped by ncio.
Within the module it should be caught by nc_write_int_pt
that calls nc4_write_internal
, but I could not find the case where ndims=0
in the latter. I guess it defaults to ndims=1
and then crashes since none exist/specified.
The netCDF4 library allows one or more 'unlimited' dimensions so that arrays can be appended along them. Could the authors further implement the 'append' mode and allows the usages of multiple 'unlimited' dimensions?
When I try to write data into a non-existent file, the error message is misleading:
ncio:: error: NetCDF: String match to name in use
Example:
call nc_create ("test.nc")
call nc_write_dim ("nothere.nc", 'x', x=0, dx=1, nx=10)
ncio:: error: NetCDF: Variable not found
It would be nice to know, which variable causes this error.
I have looked into the source and it appears that this error message comes from the underlying netcdff library, so it should be fixed there, but maybe ncio could catch this error and provide additional information until then?
When using the debugging option I have a crash in nc_put_att
because of an un-allocated variable (see below). This only happens when I've exported the environment variable debug = 1
.
This doesn't seem to be a big problem, but it makes using ncio in debug mode a pain or even impossible.
I'm on a mac (10.15.7) using gfortran from macports (gcc version 11.2.0 (MacPorts gcc11 11.2.0_1)).
Monaco:ncio einola$ export debug=1
Monaco:ncio einola$ make test
gfortran -w -g -p -ggdb -ffpe-trap=invalid,zero,overflow,underflow -fbacktrace -fcheck=all -I.obj -J.obj -I/opt/local/include -c -o .obj/ncio.o ncio.f90
gfortran -w -g -p -ggdb -ffpe-trap=invalid,zero,overflow,underflow -fbacktrace -fcheck=all -I.obj -J.obj -I/opt/local/include -c -o .obj/ncio_transpose.o ncio_transpose.f90
gfortran -w -g -p -ggdb -ffpe-trap=invalid,zero,overflow,underflow -fbacktrace -fcheck=all -I.obj -J.obj -I/opt/local/include -o test_ncio.x .obj/ncio.o .obj/ncio_transpose.o test_ncio.f90 -L/opt/local/lib -lnetcdff -lnetcdf
test_ncio.x is ready.
Monaco:ncio einola$ ./test_ncio.x
====== WRITING ======
ncio:: nc_create :: out_ncio.nc
ncio:: nc_write_map:: out_ncio.nc : polar_stereographic
At line 822 of file ncio.f90
Fortran runtime error: Allocatable argument 'v' is not allocated
Error termination. Backtrace:
#0 0x102fe76e0 in ???
#1 0x102fe7f78 in ???
#2 0x102fe84eb in ???
#3 0x102e1e46b in nc_put_att
at /Users/einola/tmp/ncio/ncio.f90:822
#4 0x102e154cf in nc_write_dim_internal
at /Users/einola/tmp/ncio/ncio.f90:1833
#5 0x102e17b48 in __ncio_MOD_nc_write_dim_int_pt
at /Users/einola/tmp/ncio/ncio.f90:1605
#6 0x102e3401e in test
at /Users/einola/tmp/ncio/test_ncio.f90:74
#7 0x102e3b447 in main
at /Users/einola/tmp/ncio/test_ncio.f90:5
PS: Thanks for the code - it's a lifesaver!
This project is a very useful tools. But when I read a variable of a Group, I write like "nc_ndims(filename,"/G1/Longitude")", program will raise a error "ncio:: error: NetCDF: Variable not found".So what should I do to read variables of Group?
thanks
The ncio module was written in a single file to make it portable and easy of use, consistent with the overall idea of ncio. However, as pointed out by a reviewer, this advantage may become an obstacle for the developer when the source code grows in size, especially because of the necessary repetition of the same functional code for various variable types making up a single fortran interface.
A first and simple step, as suggested by the reviewer, could be separating the various functionality into separate files, and automatically aggregate the pieces into the user-ready ncio.f90 (for example as a Makefile command, possibly even a git hook on commit).
One may go further in this direction and reduce the amount of human-maintainable source code to type-independent prototype code, when possible, for instance by using the capability of the python language for processing strings (e.g. format method), or by using existing tools. Similarly, a Makefile command would process and aggregate the "source" code into a single ncio.f90 with full interfaces.
Thanks for making this. I hate the verbosity of the netcdf interface, so had always meant to write something like this. It is a welcome relief that someone else has beaten me to it.
I'm interested in creating an object-oriented interface, with a user defined netcdf type that can be automatically populated and queried.
Is the best approach to make a separate module (say ncio_oo) that uses the module as-is?
I would like to see more map projections added to NCIO. Specifically lambert conformal conic and gnomonic grids
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.