source: anuga_work/development/anugavis/src/libanugavis/height_quantity.c @ 5228

Last change on this file since 5228 was 5228, checked in by jack, 16 years ago

anugavis: Added checking of dynamism in simple height quantities.
anugavis: Added basic OpenGL initialisation. Broke building of DLL.

File size: 2.0 KB
Line 
1#include <stdlib.h>
2#include <string.h>
3#include <netcdf.h>
4#include <SDL.h>
5#include "anugavis.h"
6#include "error.h"
7#include "globals.h"
8#include "height_quantity.h"
9
10int AnugaVis_DefineHeightQuantity(const char *name,
11                                  double offset, double scale,
12                                  int red, int green, int blue){
13  struct height_quantity_simple *height;
14  int ncstatus;
15  int ncvarid;
16  int numdims;
17  /* Check that it's actually in the NetCDF file */
18  if((ncstatus = nc_inq_varid(anugavis.netcdfId, name, &ncvarid)) != NC_NOERR){
19    AnugaVis_NetCDFError(ncstatus);
20    return -1;
21  }     
22
23  /* Redefining a quantity? */
24  for(height = anugavis.heights ; height != NULL ; height = height->next)
25    if(!strcmp(name, height->name)) break;
26
27  if(height == NULL){ /* Make a new entry. */
28    if((height = malloc(sizeof(struct height_quantity_simple))) == NULL){
29      AnugaVis_SetError("Failed to malloc %d bytes in "
30                        "AnugaVis_DefineHeightQuantity()",
31                        sizeof(struct height_quantity_simple));
32      return -1;
33    }
34    height->next = anugavis.heights;
35    anugavis.heights = height;
36  }
37 
38  /* If the NetCDF variable is 2-dimensional, then it's dynamic. */
39  if((ncstatus = nc_inq_varndims(anugavis.netcdfId,
40                                 ncvarid, &numdims)) != NC_NOERR){
41    AnugaVis_NetCDFError(ncstatus);
42    return -1;
43  }
44  height->dynamic = (numdims == 2);
45  height->offset = offset;
46  height->scale = scale;
47  height->color = SDL_MapRGB(anugavis.screen->format, red, green, blue);
48  return 0;
49}
50
51void AnugaVis_UndefineHeightQuantity(char *name){
52  struct height_quantity_simple *height = anugavis.heights;
53  struct height_quantity_simple *nextHeight;
54  if(height == NULL) return;
55  if(!strcmp(name, height->name)){
56    anugavis.heights = height->next;
57    free(height);
58    return;
59  }
60  for(; height != NULL ; height = height->next)
61    if(height->next == NULL) return;
62    if(!strcmp(name, height->next->name)){
63      nextHeight = height->next;
64      height->next = height->next->next;
65      free(nextHeight);
66      return;
67    }
68}
Note: See TracBrowser for help on using the repository browser.