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_GL_GL_H |
---|
9 | # include <GL/gl.h> |
---|
10 | #elif HAVE_OPENGL_GL_H |
---|
11 | # include <OpenGL/gl.h> |
---|
12 | #endif |
---|
13 | #ifdef HAVE_GL_GLU_H |
---|
14 | # include <GL/glu.h> |
---|
15 | #elif HAVE_OPENGL_GLU_H |
---|
16 | # include <OpenGL/glu.h> |
---|
17 | #endif |
---|
18 | #include <netcdf.h> |
---|
19 | #include <SDL.h> |
---|
20 | #include "error.h" |
---|
21 | #include "globals.h" |
---|
22 | #include "init.h" |
---|
23 | #include "netcdf_util.h" |
---|
24 | #include "xfunctions.h" |
---|
25 | |
---|
26 | int AnugaVis_Init(int width, int height, const char *swwFilePath){ |
---|
27 | int ncstatus; |
---|
28 | int ncdimid; |
---|
29 | int ncvarid; |
---|
30 | anugavis.x = NULL; |
---|
31 | anugavis.y = NULL; |
---|
32 | anugavis.volumes = NULL; |
---|
33 | anugavis.heights = NULL; |
---|
34 | if((SDL_Init(SDL_INIT_VIDEO) == -1) || |
---|
35 | (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) || |
---|
36 | (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) || |
---|
37 | (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) || |
---|
38 | (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) || |
---|
39 | (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) || |
---|
40 | ((anugavis.screen = |
---|
41 | SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL)){ |
---|
42 | AnugaVis_SDLError(); |
---|
43 | return -1; |
---|
44 | } |
---|
45 | |
---|
46 | SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser"); |
---|
47 | glEnable(GL_DEPTH_TEST); |
---|
48 | glShadeModel(GL_FLAT); |
---|
49 | glEnable(GL_NORMALIZE); |
---|
50 | glMatrixMode(GL_PROJECTION); |
---|
51 | gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000); |
---|
52 | glMatrixMode(GL_MODELVIEW); |
---|
53 | glLoadIdentity(); |
---|
54 | |
---|
55 | if((ncstatus = nc_open(swwFilePath, NC_SHARE, |
---|
56 | &anugavis.netcdfId)) != NC_NOERR){ |
---|
57 | SDL_Quit(); |
---|
58 | return -1; |
---|
59 | } |
---|
60 | |
---|
61 | if((nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_points", |
---|
62 | &anugavis.number_of_points) != NC_NOERR) || |
---|
63 | (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_vertices", |
---|
64 | &anugavis.number_of_vertices) != NC_NOERR) || |
---|
65 | (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_volumes", |
---|
66 | &anugavis.number_of_volumes) != NC_NOERR) || |
---|
67 | (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_timesteps", |
---|
68 | &anugavis.number_of_timesteps) != NC_NOERR) || |
---|
69 | ((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points, |
---|
70 | "AnugaVis_Init()")) == NULL) || |
---|
71 | ((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points, |
---|
72 | "AnugaVis_Init()")) == NULL) || |
---|
73 | ((anugavis.volumes = xmalloc(sizeof(int) |
---|
74 | * anugavis.number_of_volumes |
---|
75 | * anugavis.number_of_vertices, |
---|
76 | "AnugaVis_Init()")) == NULL) || |
---|
77 | (nc_get_var_float_by_name(anugavis.netcdfId, "x", |
---|
78 | anugavis.x) != NC_NOERR) || |
---|
79 | (nc_get_var_float_by_name(anugavis.netcdfId, "y", |
---|
80 | anugavis.y) != NC_NOERR) || |
---|
81 | (nc_get_var_int_by_name(anugavis.netcdfId, "volumes", |
---|
82 | anugavis.volumes) != NC_NOERR)){ |
---|
83 | AnugaVis_DeInit(); |
---|
84 | return -1; |
---|
85 | } |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | void AnugaVis_DeInit(void){ |
---|
90 | while(anugavis.heights != NULL) |
---|
91 | AnugaVis_UndefineHeightQuantity(anugavis.heights->name); |
---|
92 | nc_close(anugavis.netcdfId); |
---|
93 | if(anugavis.x != NULL) free(anugavis.x); |
---|
94 | if(anugavis.y != NULL) free(anugavis.y); |
---|
95 | if(anugavis.volumes != NULL) free(anugavis.volumes); |
---|
96 | SDL_Quit(); |
---|
97 | } |
---|