This contains examples for read_woa_data.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <netcdf.h>
#include "tests.h"
#include "test_common.h"
#define LON (16)
#define LAT (8)
#define DEPTH (4)
#define TIME (2)
#define NV (2)
static void write_test_data_file(char const * file_name);
char const * test_data_file_name = "test_read_woa_data.nc";
write_test_data_file(test_data_file_name);
{
char * woa_field_name = "s_an";
if (field_info.nbrTimeSteps != TIME)
PUT_ERR("ERROR in meta data (nbrTimeSteps)");
if (field_info.nbrLevels != DEPTH)
PUT_ERR("ERROR in meta data (nbrLevels)");
if (field_info.nbrLatPoints != LAT)
PUT_ERR("ERROR in meta data (nbrLatPoints)");
if (field_info.nbrLonPoints != LON)
PUT_ERR("ERROR in meta data (nbrLonPoints)");
for (int time = 0; time < TIME; ++time) {
for (int depth = 0; depth < DEPTH; ++depth) {
woa_file, global_salinity, field_info, time+1, depth+1);
for (int i = 0; i < LON * LAT; ++i)
if (fabs(global_salinity[i] - (double)(time * 100 + depth)) > 1e-6)
PUT_ERR("ERROR in field data");
}
}
}
unlink(test_data_file_name);
return TEST_EXIT_CODE;
}
static void write_test_data_file(char const * file_name) {
int ncid;
int dim_lon_id, dim_lat_id, dim_depth_id, dim_time_id, dim_nv_id;
int var_s_an_id;
nc_def_var(
ncid, "s_an", NC_FLOAT, 4,
(int[]){dim_time_id,dim_depth_id,dim_lat_id,dim_lon_id},
&var_s_an_id));
float dummy_data[TIME][DEPTH][LAT][LON];
for (int time = 0; time < TIME; ++time)
for (int depth = 0; depth < DEPTH; ++depth)
for (int lat = 0; lat < LAT; ++lat)
for (int lon = 0; lon < LON; ++lon)
dummy_data[time][depth][lat][lon] = (float)(time * 100 + depth);
}
int main(int argc, char **argv)
void yac_nc_create(const char *path, int cmode, int *ncidp)
#define YAC_HANDLE_ERROR(exp)
void yac_read_woa_timestep_level(int fileId, double *cell_data, struct yac_fieldMetadata fieldInfo, int timeStep, int level)
void yac_close_woa_output(int ncid)
int yac_open_woa_output(char const *input_file)
void yac_read_woa_dimensions(int fileId, char const *fieldName, struct yac_fieldMetadata *fieldInfo)
double * yac_get_woa_memory(struct yac_fieldMetadata fieldInfo)
void yac_free_woa_memory(double *data)
general routines for reading WOA output NetCDF files