1 | #include <stdlib.h> |
---|
2 | #include <string.h> |
---|
3 | #include <SDL.h> |
---|
4 | #include "anugavis.h" |
---|
5 | #include "error.h" |
---|
6 | #include "globals.h" |
---|
7 | #include "height_quantity.h" |
---|
8 | |
---|
9 | int AnugaVis_DefineHeightQuantity(char *name, |
---|
10 | double offset, double scale, |
---|
11 | int red, int green, int blue){ |
---|
12 | struct height_quantity_simple *height; |
---|
13 | /* Redefining a quantity? */ |
---|
14 | for(height = anugavis.heights ; height != NULL ; height = height->next) |
---|
15 | if(!strcmp(name, height->name)) break; |
---|
16 | |
---|
17 | if(height == NULL){ /* Make a new entry. */ |
---|
18 | if((height = malloc(sizeof(struct height_quantity_simple))) == NULL){ |
---|
19 | AnugaVis_SetError("Failed to malloc %d bytes in " |
---|
20 | "AnugaVis_DefineHeightQuantity()", |
---|
21 | sizeof(struct height_quantity_simple)); |
---|
22 | return -1; |
---|
23 | } |
---|
24 | height->next = anugavis.heights; |
---|
25 | anugavis.heights = height; |
---|
26 | } |
---|
27 | |
---|
28 | /* TODO: use NetCDF to check if the quantity is dynamic */ |
---|
29 | height->offset = offset; |
---|
30 | height->scale = scale; |
---|
31 | height->color = SDL_MapRGB(anugavis.screen->format, red, green, blue); |
---|
32 | return 0; |
---|
33 | } |
---|
34 | |
---|
35 | void AnugaVis_UndefineHeightQuantity(char *name){ |
---|
36 | struct height_quantity_simple *height = anugavis.heights; |
---|
37 | struct height_quantity_simple *nextHeight; |
---|
38 | if(height == NULL) return; |
---|
39 | if(!strcmp(name, height->name)){ |
---|
40 | anugavis.heights = height->next; |
---|
41 | free(height); |
---|
42 | return; |
---|
43 | } |
---|
44 | for(; height != NULL ; height = height->next) |
---|
45 | if(height->next == NULL) return; |
---|
46 | if(!strcmp(name, height->next->name)){ |
---|
47 | nextHeight = height->next; |
---|
48 | height->next = height->next->next; |
---|
49 | free(nextHeight); |
---|
50 | return; |
---|
51 | } |
---|
52 | } |
---|