46 nc_read_from_file (
const int ncid,
50 nelem = nc_get_dim (ncid,
"nelem");
52 long *vnrows =
new long[nelem];
53 long *vncols =
new long[nelem];
55 nc_get_data_long (ncid,
"Matrix_nrows", vnrows);
56 nc_get_data_long (ncid,
"Matrix_ncols", vncols);
58 for (
Index i = 0; i < nelem; i++)
60 aom[i].resize (vnrows[i], vncols[i]);
61 nc_get_dataa_double (ncid,
"ArrayOfMatrix", pos, vnrows[i] * vncols[i],
62 aom[i].get_c_array());
63 pos += vnrows[i] * vncols[i];
77 nc_write_to_file (
const int ncid,
81 int ncdim, varid_nrows, varid_ncols;
82 int ncdim_total, varid;
84 long *vncols =
new long[aom.
nelem()];
85 long *vnrows =
new long[aom.
nelem()];
88 vnrows[i] = aom[i].nrows();
89 vncols[i] = aom[i].ncols();
90 nelem_total += vnrows[i] * vncols[i];
93 if ((retval = nc_def_dim (ncid,
"nelem", aom.
nelem(), &ncdim)))
94 ncerror (retval,
"nc_def_dim");
95 if ((retval = nc_def_dim (ncid,
"nelem_total", nelem_total, &ncdim_total)))
96 ncerror (retval,
"nc_def_dim");
98 if ((retval = nc_def_var (ncid,
"Matrix_nrows", NC_LONG, 1,
99 &ncdim, &varid_nrows)))
100 ncerror (retval,
"nc_def_var");
101 if ((retval = nc_def_var (ncid,
"Matrix_ncols", NC_LONG, 1,
102 &ncdim, &varid_ncols)))
103 ncerror (retval,
"nc_def_var");
104 if ((retval = nc_def_var (ncid,
"ArrayOfMatrix", NC_DOUBLE, 1,
105 &ncdim_total, &varid)))
106 ncerror (retval,
"nc_def_var");
108 if ((retval = nc_enddef (ncid))) ncerror (retval,
"nc_enddef");
110 if ((retval = nc_put_var_long (ncid, varid_nrows, vnrows)))
111 ncerror (retval,
"nc_put_var");
112 if ((retval = nc_put_var_long (ncid, varid_ncols, vncols)))
113 ncerror (retval,
"nc_put_var");
118 size_t count = aom[i].nrows() * aom[i].ncols();
119 if ((retval = nc_put_vara_double (ncid, varid, &pos, &count,
120 aom[i].get_c_array())))
121 ncerror (retval,
"nc_put_var");
138 nc_read_from_file (
const int ncid,
142 nelem = nc_get_dim (ncid,
"nelem");
144 long *vnelem =
new long[nelem];
146 nc_get_data_long (ncid,
"Vector_nelem", vnelem);
148 for (
Index i = 0; i < nelem; i++)
150 aov[i].resize (vnelem[i]);
151 nc_get_dataa_double (ncid,
"ArrayOfVector", pos, vnelem[i],
152 aov[i].get_c_array());
166 nc_write_to_file (
const int ncid,
170 int ncdim, varid_nelem;
171 int ncdim_total, varid;
172 long nelem_total = 0;
173 long *velems =
new long[aov.
nelem()];
176 velems[i] = aov[i].
nelem();
177 nelem_total += velems[i];
180 if ((retval = nc_def_dim (ncid,
"nelem", aov.
nelem(), &ncdim)))
181 ncerror (retval,
"nc_def_dim");
182 if ((retval = nc_def_dim (ncid,
"nelem_total", nelem_total, &ncdim_total)))
183 ncerror (retval,
"nc_def_dim");
185 if ((retval = nc_def_var (ncid,
"Vector_nelem", NC_LONG, 1,
186 &ncdim, &varid_nelem)))
187 ncerror (retval,
"nc_def_var");
188 if ((retval = nc_def_var (ncid,
"ArrayOfVector", NC_DOUBLE, 1,
189 &ncdim_total, &varid)))
190 ncerror (retval,
"nc_def_var");
192 if ((retval = nc_enddef (ncid))) ncerror (retval,
"nc_enddef");
194 if ((retval = nc_put_var_long (ncid, varid_nelem, velems)))
195 ncerror (retval,
"nc_put_var");
200 size_t count = aov[i].
nelem();
201 if ((retval = nc_put_vara_double (ncid, varid, &pos, &count,
202 aov[i].get_c_array())))
203 ncerror (retval,
"nc_put_var");
216 #define TMPL_NC_READ_WRITE_FILE_DUMMY(what) \
217 void nc_write_to_file (const int, const what&) \
219 throw runtime_error ("NetCDF support not yet implemented for this type!"); \
221 void nc_read_from_file (const int, what&) \
223 throw runtime_error ("NetCDF support not yet implemented for this type!"); \
263 #undef TMPL_NC_READ_WRITE_FILE_DUMMY