#include <stdlib.h>
#include <stdio.h>
#define FILE_NAME "simple_nc4.nc"
#define NDIMS 2
#define NX 6
#define NY 12
#define ERRCODE 2
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
int
main()
{
int ncid, x_dimid, y_dimid, varid1, varid2, grp1id, grp2id, typeid;
int dimids[NDIMS];
unsigned long long data_out[NX][NY];
int x, y, retval;
struct s1
{
int i1;
int i2;
};
struct s1 compound_data[NX][NY];
for (x = 0; x < NX; x++)
for (y = 0; y < NY; y++)
{
data_out[x][y] = x * NY + y;
compound_data[x][y].i1 = 42;
compound_data[x][y].i2 = -42;
}
ERR(retval);
if ((retval =
nc_def_dim(ncid,
"x", NX, &x_dimid)))
ERR(retval);
if ((retval =
nc_def_dim(ncid,
"y", NY, &y_dimid)))
ERR(retval);
dimids[0] = x_dimid;
dimids[1] = y_dimid;
ERR (retval);
ERR (retval);
dimids, &varid1)))
ERR(retval);
ERR(retval);
&typeid))
ERR(retval);
offsetof(
struct s1, i1),
NC_INT))
ERR(retval);
offsetof(
struct s1, i2),
NC_INT))
ERR(retval);
if ((retval =
nc_def_var(grp2id,
"data",
typeid, NDIMS,
dimids, &varid2)))
ERR(retval);
if ((retval =
nc_put_var(grp2id, varid2, &compound_data[0][0])))
ERR(retval);
ERR(retval);
printf("*** SUCCESS writing example file simple_nc4.nc!\n");
return 0;
}