Giter VIP home page Giter VIP logo

c-sharp-interface-to-netcdf's Introduction

C-sharp-Interface-to-netCDF

A C# safe, managed interface to the netCDF DLL

netCDF: doi:10.5065/D6H70CW6 https://doi.org/10.5065/D6H70CW6

This C# interface supports the functions provided by the Unidata netcdf.dll (https://www.unidata.ucar.edu/software/netcdf/) currently up to 4.8, although not all functions are supported (e.g. I have omitted the deprecated varm* functions).

This interface is intended as a more complete replacement of that provided by Microsoft Research as a part of SDS but which has not been updated in line with netCDF developments by UniData.

This file supports both x86 and x64 versions of the dlls, by defining the index[] start[] and count[] arrays for get_vara, get_var1 and get_vars methods as IntPtr. Wrappers for these methods have been provided so that these arrays can always be defined in the calling program as int[]. Note that this also applies to lengths, such as returned from nc_inq_dimlen, where again the lengths are defined as IntPtr but wrappers exists to allow int to be used.

A collection of C# friendly methods have been provided to simplify calls to functions returning string variables and also for getting and putting attributes. Thanks to https://stackoverflow.com/questions/6300093/why-cant-i-return-a-char-string-from-c-to-c-sharp-in-a-release-build (https://stackoverflow.com/users/1164966/benoit-blanchon) for the custom marshaller.

Also, I have provided a couple of examples of how to get or put multidimensional arrays without reformatting. Any of the functions can be copied and modified to provide direct access to multidimensional arrays simply by changing the method from:

      nc_put_var_float(int ncid, int varid, float[] op);

      to nc_put_var_float(int ncid, int varid, float[,] op);
      or nc_put_var_float(int ncid, int varid, float[,,] op);

I suggest putting these modified methods into the CSnetCDFExtensions.cs file, to keep the principal interface more closely focussed on the netCDF C interface API.

Data types Some of the data types supported by the netCDF dll do not map exactly to C# data types The following netCDF data types are defined:

  NC_BYTE     C# sbyte
  NC_CHAR     C# byte
  NC_SHORT    C# short
  NC_INT      C# int
  NC_FLOAT    C# float
  NC_DOUBLE   C# double
  NC_UBYTE    C# byte
  NC_USHORT   C# ushort
  NC_UINT     C# uint
  NC_INT64    C# long
  NC_UINT64   C# ulong
  NC_STRING   C# string

Additionally, the following_var* functions do not have an exact netCDF data type

  text
  schar   
  uchar

Also NC_CHAR and NC_BYTE do not have an exact set of_var* functions

Note that I have not yet implemented functions related to user defined, compound or variable length data types. I have not used these myself (nor encountered then in the datasets I work with) so have not seen them as a priority. Nonetheless, I will get around to sorting these out soon.

c-sharp-interface-to-netcdf's People

Contributors

nickhumphries avatar

Stargazers

 avatar Steve Hayles avatar

Watchers

 avatar

c-sharp-interface-to-netcdf's Issues

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.