Changeset 5261


Ignore:
Timestamp:
May 1, 2008, 3:02:09 PM (16 years ago)
Author:
jack
Message:

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

Location:
anuga_work/development/anugavis/src
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/anugavis/src/Makefile.am

    r5260 r5261  
    1212                        height_quantity.h \
    1313                        init.c \
    14                         init.h
     14                        init.h \
     15                        xmalloc.c \
     16                        xmalloc.h
    1517libanugavis_a_CFLAGS = @SDL_CFLAGS@ @GLU_CFLAGS@
    1618libanugavis_a_LIBADD = @LIBOBJS@
  • anuga_work/development/anugavis/src/globals.h

    r5259 r5261  
    99  int netcdfId;
    1010  size_t number_of_points;
     11  float *x;
     12  float *y;
     13  float *cells;
    1114  struct height_quantity_simple *heights;
    1215} ANUGAVIS;
  • anuga_work/development/anugavis/src/height_quantity.c

    r5260 r5261  
    1414#include "globals.h"
    1515#include "height_quantity.h"
     16#include "xmalloc.h"
    1617
    1718int AnugaVis_DefineHeightQuantity(const char *name,
     
    3334
    3435  if(height == NULL){ /* Make a new entry. */
    35     if((height = malloc(sizeof(struct height_quantity_simple))) == NULL){
    36       AnugaVis_SetError("Failed to malloc %d bytes in "
    37                         "AnugaVis_DefineHeightQuantity()",
    38                         sizeof(struct height_quantity_simple));
     36    if((height = xmalloc(sizeof(struct height_quantity_simple),
     37                         "AnugaVis_DefineHeightQuantity()")) == NULL)
    3938      return -1;
    40     }
    4139    height->next = anugavis.heights;
    4240    anugavis.heights = height;
  • anuga_work/development/anugavis/src/init.c

    r5260 r5261  
    33#endif
    44
     5#ifdef HAVE_STDLIB_H
     6#  include <stdlib.h>
     7#endif
    58#ifdef HAVE_GL_GL_H
    69#  include <GL/gl.h>
     
    1720#include "error.h"
    1821#include "globals.h"
     22#include "xmalloc.h"
    1923
    2024int AnugaVis_Init(int width, int height, const char *swwFilePath){
    2125  int ncstatus;
    2226  int ncdimid;
     27  int ncvarid;
     28  anugavis.x = NULL;
     29  anugavis.y = NULL;
     30  anugavis.cells = NULL;
     31  anugavis.heights = NULL;
    2332  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
    2433     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
     
    4453                         &anugavis.netcdfId)) != NC_NOERR) goto nc_err;
    4554  if((ncstatus = nc_inq_dimid(anugavis.netcdfId, "number_of_points",
    46                               &ncdimid)) != NC_NOERR) goto nc_err;
     55                              &ncdimid)) != NC_NOERR) goto nc_err1;
    4756  if((ncstatus = nc_inq_dimlen(anugavis.netcdfId, ncdimid,
    4857                               &anugavis.number_of_points)) != NC_NOERR)
    49     goto nc_err;
     58    goto nc_err1;
    5059
    51   anugavis.heights = NULL;
     60  /* Get the number of vertices to keep space for. */
     61  if((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points,
     62                           "AnugaVis_Init()")) == NULL)
     63    goto bad_malloc;
     64  if((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points,
     65                           "AnugaVis_Init()")) == NULL)
     66    goto bad_malloc;
     67
     68  /* Load the list of x and y points from the NetCDF file. */
     69  if((ncstatus = nc_inq_varid(anugavis.netcdfId, "x",
     70                              &ncvarid)) != NC_NOERR) goto nc_err1;
     71  if((ncstatus = nc_get_var_float(anugavis.netcdfId, ncvarid,
     72                                  anugavis.x)) != NC_NOERR) goto nc_err1;
     73  if((ncstatus = nc_inq_varid(anugavis.netcdfId, "y",
     74                              &ncvarid)) != NC_NOERR) goto nc_err1;
     75  if((ncstatus = nc_get_var_float(anugavis.netcdfId, ncvarid,
     76                                  anugavis.y)) != NC_NOERR) goto nc_err1;
     77
    5278  return 0;
     79 nc_err1:
     80  nc_close(anugavis.netcdfId);
    5381 nc_err:
    5482  AnugaVis_NetCDFError(ncstatus);
     83 bad_malloc:
     84  if(anugavis.x != NULL) free(anugavis.x);
     85  if(anugavis.y != NULL) free(anugavis.y);
    5586  SDL_Quit();
    5687  return -1;
     
    6192    AnugaVis_UndefineHeightQuantity(anugavis.heights->name);
    6293  nc_close(anugavis.netcdfId);
     94  free(anugavis.x);
     95  free(anugavis.y);
    6396  SDL_Quit();
    6497}
Note: See TracChangeset for help on using the changeset viewer.