source: anuga_work/development/anugavis/src/init.c @ 5264

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

AnugaVis? loads volume data from NetCDF file.

File size: 3.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_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 "netcdf_util.h"
23#include "xmalloc.h"
24
25int AnugaVis_Init(int width, int height, const char *swwFilePath){
26  int ncstatus;
27  int ncdimid;
28  int ncvarid;
29  anugavis.x = NULL;
30  anugavis.y = NULL;
31  anugavis.volumes = NULL;
32  anugavis.heights = NULL;
33  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
34     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
35     (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) ||
36     (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) ||
37     (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) ||
38     (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) ||
39     ((anugavis.screen = 
40       SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL)){
41    AnugaVis_SDLError();
42    return -1;
43  }
44
45  glEnable(GL_DEPTH_TEST);
46  glShadeModel(GL_FLAT);
47  glEnable(GL_NORMALIZE);
48  glMatrixMode(GL_PROJECTION);
49  gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000);
50  glMatrixMode(GL_MODELVIEW);
51  glLoadIdentity();
52
53  if((ncstatus = nc_open(swwFilePath, NC_SHARE,
54                         &anugavis.netcdfId)) != NC_NOERR){
55    SDL_Quit();
56    return -1;
57  }
58
59  if((nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_points",
60                            &anugavis.number_of_points) != NC_NOERR) ||
61     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_vertices",
62                            &anugavis.number_of_vertices) != NC_NOERR) ||
63     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_volumes",
64                            &anugavis.number_of_volumes) != NC_NOERR) ||
65     ((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points,
66                            "AnugaVis_Init()")) == NULL) ||
67     ((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points,
68                            "AnugaVis_Init()")) == NULL) ||
69     ((anugavis.volumes = xmalloc(sizeof(int)
70                                  * anugavis.number_of_volumes
71                                  * anugavis.number_of_vertices,
72                                  "AnugaVis_Init()")) == NULL) ||
73     (nc_get_var_float_by_name(anugavis.netcdfId, "x",
74                               anugavis.x) != NC_NOERR) ||
75     (nc_get_var_float_by_name(anugavis.netcdfId, "y",
76                               anugavis.y) != NC_NOERR) ||
77     (nc_get_var_int_by_name(anugavis.netcdfId, "volumes",
78                             anugavis.volumes) != NC_NOERR)){
79    nc_close(anugavis.netcdfId);
80    if(anugavis.x != NULL) free(anugavis.x);
81    if(anugavis.y != NULL) free(anugavis.y);
82    if(anugavis.volumes != NULL) free(anugavis.volumes);
83    SDL_Quit();
84    return -1;
85  }
86  return 0;
87}
88
89void AnugaVis_DeInit(void){
90  while(anugavis.heights != NULL)
91    AnugaVis_UndefineHeightQuantity(anugavis.heights->name);
92  nc_close(anugavis.netcdfId);
93  free(anugavis.x);
94  free(anugavis.y);
95  free(anugavis.volumes);
96  SDL_Quit();
97}
Note: See TracBrowser for help on using the repository browser.