- Infos im HLRS Wiki sind nicht rechtsverbindlich und ohne Gewähr -
- Information contained in the HLRS Wiki is not legally binding and HLRS is not responsible for any damages that might result from its use -
NetCDF: Difference between revisions
From HLRS Platforms
Jump to navigationJump to search
(Created page with "{{Infobox software | description = '''NetCDF''' is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sha...") |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Infobox software | {{Infobox software | ||
| description = '''NetCDF''' is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. | | description = '''NetCDF''' ('''Network Common Data Form''') is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. The project homepage is hosted by the Unidata program at the University Corporation for Atmospheric Research (UCAR). | ||
| logo = [] | | logo = [[Image:netcdf2.png]] | ||
| developer = | | developer = [https://en.wikipedia.org/wiki/University_Corporation_for_Atmospheric_Research UCAR] | ||
| available on = [[NEC Nehalem Cluster]] | | available on = [[NEC Nehalem Cluster]] | ||
| category = [[:Category:Storage Formats | Storage Formats]] | | category = [[:Category:Storage Formats | Storage Formats]] | ||
| license = Open Source | | license = Open Source | ||
| website = [http://www.unidata.ucar.edu/software/netcdf/ Official NetCDF Homepage] | | website = [http://www.unidata.ucar.edu/software/netcdf/ Official NetCDF Homepage] | ||
}} | |||
=== Using NetCDF on Nehalem cluster === | |||
There are two versions of NetCDF instaled on Nehalem cluster: | |||
* intel | |||
* gnu | |||
=== Example === | |||
This example shows the basic steps when using NetCDF. | |||
Load the necessary module, for example the intel version: | |||
{{Command| command =<nowiki> | |||
module load tools/netcdf/4.3.3-intel-14.0.4 | |||
</nowiki> | |||
}} | |||
Simple program using NetCDF: | |||
{{File|filename = ex_netcdf.c | |||
| content = <pre> | |||
#include <stdlib.h> | |||
#include <stdio.h> | |||
#include <netcdf.h> | |||
/* This is the name of the data file we will create. */ | |||
#define FILE_NAME "ex_netcdf.nc" | |||
/* We are writing 2D data, a 6 x 12 grid. */ | |||
#define NDIMS 2 | |||
#define NX 60 | |||
#define NY 120 | |||
/* Handle errors by printing an error message and exiting with a | |||
* non-zero status. */ | |||
#define ERRCODE 2 | |||
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} | |||
int | |||
main() | |||
{ | |||
int ncid, x_dimid, y_dimid, varid; | |||
int dimids[NDIMS]; | |||
size_t chunks[NDIMS]; | |||
int shuffle, deflate, deflate_level; | |||
int data_out[NX][NY]; | |||
int x, y, retval; | |||
/* Set chunking, shuffle, and deflate. */ | |||
shuffle = NC_SHUFFLE; | |||
deflate = 1; | |||
deflate_level = 1; | |||
/* Create some pretend data. If this wasn't an example program, we | |||
* would have some real data to write, for example, model output. */ | |||
for (x = 0; x < NX; x++) | |||
for (y = 0; y < NY; y++) | |||
data_out[x][y] = x * NY + y; | |||
/* Create the file. The NC_NETCDF4 parameter tells netCDF to create | |||
* a file in netCDF-4/HDF5 standard. */ | |||
if ((retval = nc_create(FILE_NAME, NC_NETCDF4, &ncid))) | |||
ERR(retval); | |||
/* Define the dimensions. */ | |||
if ((retval = nc_def_dim(ncid, "x", NX, &x_dimid))) | |||
ERR(retval); | |||
if ((retval = nc_def_dim(ncid, "y", NY, &y_dimid))) | |||
ERR(retval); | |||
/* Set up variabe data. */ | |||
dimids[0] = x_dimid; | |||
dimids[1] = y_dimid; | |||
chunks[0] = NX/4; | |||
chunks[1] = NY/4; | |||
/* Define the variable. */ | |||
if ((retval = nc_def_var(ncid, "data", NC_INT, NDIMS, | |||
dimids, &varid))) | |||
ERR(retval); | |||
if ((retval = nc_def_var_chunking(ncid, varid, 0, &chunks[0]))) | |||
ERR(retval); | |||
if ((retval = nc_def_var_deflate(ncid, varid, shuffle, deflate, | |||
deflate_level))) | |||
ERR(retval); | |||
/* No need to explicitly end define mode for netCDF-4 files. Write | |||
* the pretend data to the file. */ | |||
if ((retval = nc_put_var_int(ncid, varid, &data_out[0][0]))) | |||
ERR(retval); | |||
/* Close the file. */ | |||
if ((retval = nc_close(ncid))) | |||
ERR(retval); | |||
printf("*** SUCCESS writing example file simple_xy_nc4.nc!\n"); | |||
return 0; | |||
} | |||
</pre>}} | |||
Compile with: | |||
{{Command| command = | |||
icc ex_netcdf.c -I /opt/tools/netcdf/4.3.3-intel-14.0.4/include/ -L /opt/tools/netcdf/4.3.3-intel-14.0.4/lib/ -lnetcdf | |||
}} | |||
or if you have a fortran program | |||
{{Command| command = | |||
ifort ex_netcdf.f90 -I /opt/tools/netcdf/4.3.3-intel-14.0.4/include/ -L /opt/tools/netcdf/4.3.3-intel-14.0.4/lib/ -lnetcdff -lnetcdf | |||
}} | }} | ||
Latest revision as of 13:06, 20 October 2015
NetCDF (Network Common Data Form) is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. The project homepage is hosted by the Unidata program at the University Corporation for Atmospheric Research (UCAR). |
|
Using NetCDF on Nehalem cluster
There are two versions of NetCDF instaled on Nehalem cluster:
- intel
- gnu
Example
This example shows the basic steps when using NetCDF.
Load the necessary module, for example the intel version:
module load tools/netcdf/4.3.3-intel-14.0.4
Simple program using NetCDF:
File: ex_netcdf.c
#include <stdlib.h> #include <stdio.h> #include <netcdf.h> /* This is the name of the data file we will create. */ #define FILE_NAME "ex_netcdf.nc" /* We are writing 2D data, a 6 x 12 grid. */ #define NDIMS 2 #define NX 60 #define NY 120 /* Handle errors by printing an error message and exiting with a * non-zero status. */ #define ERRCODE 2 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} int main() { int ncid, x_dimid, y_dimid, varid; int dimids[NDIMS]; size_t chunks[NDIMS]; int shuffle, deflate, deflate_level; int data_out[NX][NY]; int x, y, retval; /* Set chunking, shuffle, and deflate. */ shuffle = NC_SHUFFLE; deflate = 1; deflate_level = 1; /* Create some pretend data. If this wasn't an example program, we * would have some real data to write, for example, model output. */ for (x = 0; x < NX; x++) for (y = 0; y < NY; y++) data_out[x][y] = x * NY + y; /* Create the file. The NC_NETCDF4 parameter tells netCDF to create * a file in netCDF-4/HDF5 standard. */ if ((retval = nc_create(FILE_NAME, NC_NETCDF4, &ncid))) ERR(retval); /* Define the dimensions. */ if ((retval = nc_def_dim(ncid, "x", NX, &x_dimid))) ERR(retval); if ((retval = nc_def_dim(ncid, "y", NY, &y_dimid))) ERR(retval); /* Set up variabe data. */ dimids[0] = x_dimid; dimids[1] = y_dimid; chunks[0] = NX/4; chunks[1] = NY/4; /* Define the variable. */ if ((retval = nc_def_var(ncid, "data", NC_INT, NDIMS, dimids, &varid))) ERR(retval); if ((retval = nc_def_var_chunking(ncid, varid, 0, &chunks[0]))) ERR(retval); if ((retval = nc_def_var_deflate(ncid, varid, shuffle, deflate, deflate_level))) ERR(retval); /* No need to explicitly end define mode for netCDF-4 files. Write * the pretend data to the file. */ if ((retval = nc_put_var_int(ncid, varid, &data_out[0][0]))) ERR(retval); /* Close the file. */ if ((retval = nc_close(ncid))) ERR(retval); printf("*** SUCCESS writing example file simple_xy_nc4.nc!\n"); return 0; }
Compile with:
icc ex_netcdf.c -I /opt/tools/netcdf/4.3.3-intel-14.0.4/include/ -L /opt/tools/netcdf/4.3.3-intel-14.0.4/lib/ -lnetcdf
or if you have a fortran program
ifort ex_netcdf.f90 -I /opt/tools/netcdf/4.3.3-intel-14.0.4/include/ -L /opt/tools/netcdf/4.3.3-intel-14.0.4/lib/ -lnetcdff -lnetcdf