source: anuga_work/development/anugavis/src/height_quantity.c @ 5261

Last change on this file since 5261 was 5261, checked in by jack, 17 years ago

AnugaVis?: read lists of x and y points from NetCDF file.

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