Git Product home page Git Product logo

ncdf's Introduction

ncdf

Donate

A library to ease the creation of NetCDF files using a standard interface without the need to keep track of file, variable and attribute ID's.

Usage

It has proven quite useful as the necessity to switch between MPI and non-MPI NetCDF is extremely easy.

Downloading and installation

Installing ncdf requires a download of the library hosted at github at ncdf@git.

Note that ncdf depends on the dictionary library fdict@git.

If fdict is not already installed you may need to add the submodule

git submodule init
git submodule update

Extract and create an setup.make file for compilation, a minimal setup.make file can look like this

FC=gfortran
FFLAGS = -g
LDFLAGS = -L<path-to-netcdf> -lnetcdff -lnetcdf

Type make and a library called libncdf.a is created.
Subsequently the installation may be performed by:

make PREFIX=/papth/to/ncdf install

which installs the required files (modules and libraries) to the folder.

To use the library you need to add include statements for the modules as well as linking to the program.

To link ncdf to your program the following can be used in a Makefile

FDICT_PATH  = /path/to/fdict/parent
FDICT_LIBS  = -L$(FDICT_PATH) -lfdict
FDICT_INC   = -I$(FDICT_PATH)

NCDF_PATH  = /path/to/ncdf/parent
NCDF_LIBS  = -L$(NCDF_PATH) -lncdf
NCDF_INC   = -I$(NCDF_PATH)

Simple API discussion

The compilation of the ncdf library is performed through a couple of preprocessor flags. They are all prefixed with NCDF_ to not interfere with any custom flags.

  • MPI, allows for communicators and should be used for any code which uses MPI. It does not requires to have either CDF4, nor the PCDF flag. Flag: MPI
  • NCDF_4 allow the NetCDF 4 API for compression and the MPI layer with the MPI flag. Flag: NCDF_4

Coding usage

To ease the conversion back and forth between the NetCDF API and the ncdf API the names are very similar.

An easy remembering rule is that "nf90" has changed to "ncdf".

Here we provide a list which shows the details of the name-conversions

  • ncdf_open (nf90_open)
  • ncdf_close (nf90_close)
  • ncdf_enddef (nf90_enddef)
  • ncdf_redef (nf90_redef)
  • ncdf_sync (nf90_sync)
  • ncdf_inq (nf90_inquire)
  • ncdf_def_dim (nf90_def_dim)
  • ncdf_inq_dim (nf90_inq_dim, nf90_inq_dimid, nf90_inquire_dimension)
  • ncdf_rename_dim (nf90_rename_dim)
  • ncdf_def_var (nf90_def_var)
  • ncdf_inq_var (nf90_inq_var, nf90_inq_varid, nf90_inquire_variable)
  • ncdf_put_att (nf90_put_att)
  • ncdf_put_gatt (nf90_put_att(..,nf90_global,...))
  • ncdf_get_att (nf90_get_att)
  • ncdf_get_gatt (nf90_get_att(..,nf90_global,...))
  • ncdf_del_att (nf90_del_att)
  • ncdf_del_gatt (nf90_del_att(..,nf90_global,...))

Basically there was a couple of issues that was troubling the author.

  1. Using inq_dim, inq_dimid, inquire_dimension didn't seem obvious to me. Hence everything is fetched from one inquire routine. (inq_dim)
  2. The same thing applied for the inq_var, inq_varid and inquire_variable
  3. Global variables I thought should be able to be denoted specifically. Simply because of code clarity. However, the old method of NF90_GLOBAL is still allowed (basically the gatt routines are wrappers with the NF90_GLOBAL argument).
  4. For consistency I have renamed everything which uses the inquire suffix to inq

Here is the simple example:

use netcdf_ncdf

type(hNCDF) :: nf

call ncdf_create(nf,'Test.nc')
call ncdf_def_dim(nf,'MD',100)
call ncdf_def_var(nf,'E',NF90_DOUBLE,(/'MD'/))
call ncdf_put_var(nf,'E',E)
call ncdf_close(nf)

TODO

  • Consider changing the parallel logical to an integer to have several layers of interactions
  • Add to the original NetCDF the VAR_FILL routines (they are only defined in the INTEGER part)
  • Add an ncdf_assert (which can take several options)
    1. check that certain variables exists
    2. check dimension sizes...
  • Add a ncdf_dim function which returns a dimension array with correct formatting... ncdf_dim('a', 'oesntuh') > (/'a ','oesntuh'/)
  • Scour the NetCDF manual and add missing stuff
  • Fully determine whether the dictionary is the right way to go. It appears to be a great solution for the character attributes, however, it could be extended.

Contributions, issues and bugs

I would advice any users to contribute as much feedback and/or PRs to further maintain and expand this library.

Please do not hesitate to contribute!

If you find any bugs please form a bug report/issue.

If you have a fix please consider adding a pull request.

License

The ncdf license is LGPL, see the LICENSE file.

Thanks

A big thanks goes to Alberto Garcia for contributing ideas and giving me bug reports. Without him the interface would have been much more complex!

ncdf's People

Contributors

zerothi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

jonaslb

ncdf's Issues

sp definitions

! if ( present(fill_val) ) then
     !fill_val = cmplx(lfill_valr,lfill_valc, sp)
     fill_val = cmplx(0,0, sp)
     fill_val = cmplx(0.0_sp,0.0_sp, sp)
! end if
end subroutine inq_var_c0
subroutine put_var_c1_name(this,name,var,start,count)

Allow ufs: file specifications in file-names

On some systems it may be valuable to use a specific file-system to handle the IO.

The way this is done in NetCDF/hdf5 is to prefix with:

 ufs:<filename>

which disrupts the inquire statements. So basically we need a simple way of handling file-system specifications to file names.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.