20 #include "../include/nc_file.h" 30 VERBOSE(
"Open the given NetCDF file... ");
33 if ((retval = nc_open(filename, NC_NOWRITE, &ncid)))
34 printf(
"Error: %s\n", nc_strerror(retval));
57 if ((retval = nc_inq_dimid(ncid, dim1, &lat_varid)))
58 printf(
"Error: %s\n", nc_strerror(retval));
59 if ((retval = nc_inq_dimlen(ncid, lat_varid, &lat_len)))
60 printf(
"Error: %s\n", nc_strerror(retval));
62 if ((retval = nc_inq_dimid(ncid, dim2 , &lon_varid)))
63 printf(
"Error: %s\n", nc_strerror(retval));
64 if ((retval = nc_inq_dimlen(ncid, lon_varid, &lon_len)))
65 printf(
"Error: %s\n", nc_strerror(retval));
67 return lat_len * lon_len;
83 double *lats_in, *lons_in;
87 VERBOSE(
"Read LOCS from the given NetCDF file... ");
90 if ((retval = nc_inq_dimid(ncid,
"latitude",&lat_varid)))
91 printf(
"Error: %s\n", nc_strerror(retval));
92 if ((retval = nc_inq_dimlen(ncid, lat_varid, &lat_len)))
93 printf(
"Error: %s\n", nc_strerror(retval));
95 if ((retval = nc_inq_dimid(ncid,
"longitude", &lon_varid)))
96 printf(
"Error: %s\n", nc_strerror(retval));
97 if ((retval = nc_inq_dimlen(ncid, lon_varid, &lon_len)))
98 printf(
"Error: %s\n", nc_strerror(retval));
100 n = lat_len * lon_len;
102 lats_in = (
double *) malloc(lat_len *
sizeof(
double));
103 lons_in = (
double *) malloc(lon_len *
sizeof(
double));
104 locations->
x = (
double *) malloc(n *
sizeof(
double));
105 locations->
y = (
double *) malloc(n *
sizeof(
double));
108 if ((retval = nc_inq_varid(ncid,
"latitude", &lat_varid)))
109 printf(
"Error: %s\n", nc_strerror(retval));
110 if ((retval = nc_inq_varid(ncid,
"longitude", &lon_varid)))
111 printf(
"Error: %s\n", nc_strerror(retval));
114 if ((retval = nc_get_var_double(ncid, lat_varid, &lats_in[0])))
115 printf(
"Error: %s\n", nc_strerror(retval));
116 if ((retval = nc_get_var_double(ncid, lon_varid, &lons_in[0])))
117 printf(
"Error: %s\n", nc_strerror(retval));
120 for (i = 0; i < lat_len ; i++)
121 for (j = 0; j < lon_len ; j++)
123 locations->
x[index] = lats_in[i];
124 locations->
y[index++] = lons_in[j];
151 VERBOSE(
"Read LOCS from the given NetCDF file... ");
154 if ((retval = nc_inq_dimid(ncid,
"west_east",&lat_varid)))
155 printf(
"Error: %s\n", nc_strerror(retval));
156 if ((retval = nc_inq_dimlen(ncid, lat_varid, &we_len)))
157 printf(
"Error: %s\n", nc_strerror(retval));
159 if ((retval = nc_inq_dimid(ncid,
"south_north", &lon_varid)))
160 printf(
"Error: %s\n", nc_strerror(retval));
161 if ((retval = nc_inq_dimlen(ncid, lon_varid, &sn_len)))
162 printf(
"Error: %s\n", nc_strerror(retval));
166 locations->
x = (
double *) malloc(n *
sizeof(
double));
167 locations->
y = (
double *) malloc(n *
sizeof(
double));
170 if ((retval = nc_inq_varid(ncid,
"XLAT", &lat_varid)))
171 printf(
"Error: %s\n", nc_strerror(retval));
172 if ((retval = nc_inq_varid(ncid,
"XLONG", &lon_varid)))
173 printf(
"Error: %s\n", nc_strerror(retval));
176 if ((retval = nc_get_var_double(ncid, lat_varid, locations->
x)))
177 printf(
"Error: %s\n", nc_strerror(retval));
178 if ((retval = nc_get_var_double(ncid, lon_varid, locations->
y)))
179 printf(
"Error: %s\n", nc_strerror(retval));
210 VERBOSE(
"Read observations from the given NetCDF variable... ");
212 if ((retval = nc_inq_dimid(ncid, dim1, &lat_varid)))
213 printf(
"Error: %s\n", nc_strerror(retval));
214 if ((retval = nc_inq_dimlen(ncid,lat_varid,&lat_len)))
215 printf(
"Error: %s\n", nc_strerror(retval));
217 if ((retval = nc_inq_dimid(ncid, dim2,&lon_varid)))
218 printf(
"Error: %s\n", nc_strerror(retval));
219 if ((retval = nc_inq_dimlen(ncid,lon_varid,&lon_len)))
220 printf(
"Error: %s\n", nc_strerror(retval));
223 size_t start[] = {0, 0, 0};
224 size_t count[] = {1, lat_len, lon_len};
227 if ((retval = nc_inq_varid(ncid, varname, &varid)))
228 printf(
"Error: %s\n", nc_strerror(retval));
229 if ((retval = nc_get_vara_double(ncid, varid, start, count, data_in)))
230 printf(
"Error: %s\n", nc_strerror(retval));
251 VERBOSE(
"Close the NetCDF file... ");
252 if ((retval = nc_close(ncid)))
253 printf(
"Error: %s\n", nc_strerror(retval));
void readLocsNC_1d(MLE_data *data, int ncid)
Read 1D locations from a given.
void readLocsNC_2d(MLE_data *data, int ncid)
Read 2D locations from a given.
int countlinesNC(int ncid, char *dim1, char *dim2)
Retrieve number of measurements.
double * y
Values in Y dimension.
double * x
Values in X dimension.
location l1
2D locations for the first dataset.
void readVarNCs(MLE_data *data, int ncid, char *varname, double *data_in, char *dim1, char *dim2)
Read Read observations from.
void closeFileNC(MLE_data *data, int ncid)
Close the NetCDF file.
int openFileNC(MLE_data *data, char *filename)
Open the NetCDF file.