Marine systems simulation
netcdf_handler.h
1#ifndef NETCDF_HANDLER
2#define NETCDF_HANDLER
3
4#include "netcdf.h"
5#include <math.h>
6#include <vector>
7#include <string>
8#include <iostream>
9#include <fstream>
10
11
13 const int U_V_FILE = 0,
14 Z_X_VELOCITY_FILE = 1,
15 Z_PROFILE_FILE = 2,
16 U_V_W_FILE = 3;
17
18 //NcFile *nf;
19 int ncid;
20 int type = U_V_FILE;
21 size_t dim1 = -1, dim2 = -1, dim3 = -1;
22 int xdim = -1, ydim = -1, zdim = -1;
23 //std::vector<float> geo1, geo2;
24 float* geo1;
25 float* geo2;
26 float* geo3;
27 float low1, low2, low3, diff1, diff2, diff3;
28 float minVal, meanVal, maxVal;
29 bool hasCachedValues = false;
30 std::vector<std::vector<std::vector<float>>> currentFieldU, currentFieldV, currentFieldW;
31 public:
32 /*
33 * Open the given NetCDF file and extract basic information about its contents.
34 */
35 void readNCFile(const char *filename);
36
37 /*
38 * Read the entire current field of the opened NetCDF file and store in memory. Any lookup of
39 * current values using getCurrentSpeedAt() afterwards will be based on the cached values.
40 */
41 int cacheCurrentField();
42
43
44 /*
45 * Close the opened NetCDF file. If cacheCurrentField() has been called, lookup of current speed values can be
46 * done after closing the file.
47 */
48 void closeNCFile();
49
50 /*
51 * Get a 6 element matrix containing the lower and upper bounds for the x, y and z axes of the
52 * opened NetCDF file.
53 */
54 void getDomainBounds(float* bounds);
55
56 int getVar(char* name);
57 // getVar(char* name, std::vector<size_t> start, std::vector<size_t> count, float value[][2]);
58 int getCurrentSpeedAt(float x, float y, float z, float *value);
59 int calculateDescriptorValues(float *values);
60 bool isProfileFile();
61
62};
63#endif
Definition: netcdf_handler.h:12