ESDM
Middleware for Earth System Data
esdm-grid.h
1 #ifndef ESDM_GRID_H
2 #define ESDM_GRID_H
3 
4 #include <esdm-datatypes-internal.h>
5 
6 #include <stdbool.h>
7 
47 esdm_status esdm_grid_create(esdm_dataset_t* dataset, int64_t dimCount, int64_t* offset, int64_t* size, esdm_grid_t** out_grid);
48 esdm_status esdm_grid_createSimple(esdm_dataset_t* dataset, int64_t dimCount, int64_t* size, esdm_grid_t** out_grid);
49 
70 esdm_status esdm_grid_createSubgrid(esdm_grid_t* parent, int64_t* index, esdm_grid_t** out_child);
71 
89 esdm_status esdm_grid_subdivideFixed(esdm_grid_t* grid, int64_t dim, int64_t size, bool allowIncomplete);
90 
108 esdm_status esdm_grid_subdivideFlexible(esdm_grid_t* grid, int64_t dim, int64_t count);
109 
132 esdm_status esdm_grid_subdivide(esdm_grid_t* grid, int64_t dim, int64_t count, int64_t* bounds);
133 
152 esdm_status esdm_grid_cellSize(const esdm_grid_t* grid, int64_t* cellIndex, int64_t* out_offset, int64_t* out_size);
153 
171 esdm_status esdm_grid_cellExtends(const esdm_grid_t* grid, int64_t* cellIndex, esdmI_hypercube_t** out_extends);
172 
189 esdm_status esdm_grid_getBound(const esdm_grid_t* grid, int64_t dim, int64_t index, int64_t* out_bound);
190 
208 esdm_status esdm_write_grid(esdm_grid_t* grid, esdm_dataspace_t* memspace, void* buffer);
209 
231 esdm_status esdm_read_grid(esdm_grid_t* grid, esdm_dataspace_t* memspace, void* buffer);
232 
255 esdm_status esdm_dataset_grids(esdm_dataset_t* dataset, int64_t* out_count, esdm_grid_t*** out_grids);
256 
276 esdm_status esdm_gridIterator_create(esdm_grid_t* grid, esdm_gridIterator_t** out_iterator);
277 
301 esdm_status esdm_gridIterator_next(esdm_gridIterator_t** inout_iterator, int64_t increment, esdm_dataspace_t** out_dataspace);
302 
311 void esdm_gridIterator_destroy(esdm_gridIterator_t* iterator);
312 
314 // Internal API ////////////////////////////////////////////////////////////////////////////////////
316 
317 
318 void esdmI_dataset_registerGrid(esdm_dataset_t* dataset, esdm_grid_t* grid);
319 void esdmI_dataset_registerGridCompletion(esdm_dataset_t* dataset, esdm_grid_t* grid);
320 
321 //Compute the total size of the grid cells that intersect the region.
322 //This assumes that the grid is complete, i.e. it does not waste time checking presence of fragments and subgrids.
323 int64_t esdmI_grid_coverRegionSize(const esdm_grid_t* grid, const esdmI_hypercube_t* region);
324 
325 //Compute the total size of data that would need to be fetched to cover the region, minus the cover region size.
326 //TODO: Make this recurs into subgrids to get a precise result, currently this may overestimate the overhead.
327 int64_t esdmI_grid_coverRegionOverhead(esdm_grid_t* grid, esdmI_hypercube_t* region);
328 
329 //Recursively list all fragments in the grid that intersect with the given region.
330 //There must be no empty cells within the provided region, and there must be an overlap with the region.
331 esdm_status esdmI_grid_fragmentsInRegion(esdm_grid_t* grid, esdmI_hypercube_t* region, int64_t* out_fragmentCount, esdm_fragment_t*** out_fragments);
332 
333 //For use by esdm_mpi and storing as metadata.
334 //This puts the grid into fixed structure state.
335 void esdmI_grid_serialize(smd_string_stream_t* stream, esdm_grid_t* grid); //the resulting stream is in JSON format
336 esdm_status esdmI_grid_createFromJson(json_t* json, esdm_dataset_t* dataset, esdm_grid_t* parent, esdm_grid_t** out_grid);
337 esdm_status esdmI_grid_createFromString(const char* serializedGrid, esdm_dataset_t* dataset, esdm_grid_t** out_grid);
338 //These two functions must be called with a string/json that was created from a copy of the grid, i.e. the grid IDs must match.
339 esdm_status esdmI_grid_mergeWithJson(esdm_grid_t* grid, json_t* json);
340 esdm_status esdmI_grid_mergeWithString(esdm_grid_t* grid, const char* serializedGrid);
341 
342 //Access the ID of a grid.
343 //Returns NULL if the grid is not in fixed structure state yet (i.e. if it has not been (de-)serialized yet).
344 //The returned pointer is owned by the grid, do not modify or deallocate it.
345 const char* esdmI_grid_id(esdm_grid_t* grid);
346 bool esdmI_grid_matchesId(const esdm_grid_t* grid, const char* id);
347 
348 void esdmI_grid_destroy(esdm_grid_t* grid); //must only be called by the owning dataset
349 
350 #endif
esdm_status
Definition: esdm-datatypes.h:37
Definition: esdm-datatypes-internal.h:354
Definition: esdm-datatypes-internal.h:59
Definition: esdm-datatypes.h:81
Definition: esdm-datatypes-internal.h:78
Definition: esdm-grid.c:30
Definition: esdm-grid.c:18