Changeset 5263


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

AnugaVis?: Tightened up the init code.

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

Legend:

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

    r5261 r5263  
    1313                        init.c \
    1414                        init.h \
     15                        netcdf_util.c \
     16                        netcdf_util.h \
    1517                        xmalloc.c \
    1618                        xmalloc.h
  • anuga_work/development/anugavis/src/anugavis_simple.c

    r5262 r5263  
    33#include "height_quantity.h"
    44#include "init.h"
     5#include "globals.h"
     6#include <stdio.h>
    57int main(int argc, char *argv[]){
    68  if(argc != 2){
     
    1214    return 1;
    1315  }
     16
     17  printf("points: %d\nvertices: %d\nvolumes: %d\n",
     18         anugavis.number_of_points,
     19         anugavis.number_of_vertices,
     20         anugavis.number_of_volumes);
    1421
    1522  if(AnugaVis_DefineHeightQuantity("elevation", 0, 1, 128, 128, 128) == -1){
  • anuga_work/development/anugavis/src/globals.h

    r5261 r5263  
    99  int netcdfId;
    1010  size_t number_of_points;
     11  size_t number_of_vertices;
     12  size_t number_of_volumes;
    1113  float *x;
    1214  float *y;
  • anuga_work/development/anugavis/src/init.c

    r5261 r5263  
    2020#include "error.h"
    2121#include "globals.h"
     22#include "netcdf_util.h"
    2223#include "xmalloc.h"
    2324
     
    5152
    5253  if((ncstatus = nc_open(swwFilePath, NC_SHARE,
    53                          &anugavis.netcdfId)) != NC_NOERR) goto nc_err;
    54   if((ncstatus = nc_inq_dimid(anugavis.netcdfId, "number_of_points",
    55                               &ncdimid)) != NC_NOERR) goto nc_err1;
    56   if((ncstatus = nc_inq_dimlen(anugavis.netcdfId, ncdimid,
    57                                &anugavis.number_of_points)) != NC_NOERR)
    58     goto nc_err1;
     54                         &anugavis.netcdfId)) != NC_NOERR){
     55    SDL_Quit();
     56    return -1;
     57  }
    5958
    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 
     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     (nc_get_var_float_by_name(anugavis.netcdfId, "x",
     70                               anugavis.x) != NC_NOERR) ||
     71     (nc_get_var_float_by_name(anugavis.netcdfId, "y",
     72                               anugavis.y) != NC_NOERR)){
     73    nc_close(anugavis.netcdfId);
     74    if(anugavis.x != NULL) free(anugavis.x);
     75    if(anugavis.y != NULL) free(anugavis.y);
     76    SDL_Quit();
     77    return -1;
     78  }
    7879  return 0;
    79  nc_err1:
    80   nc_close(anugavis.netcdfId);
    81  nc_err:
    82   AnugaVis_NetCDFError(ncstatus);
    83  bad_malloc:
    84   if(anugavis.x != NULL) free(anugavis.x);
    85   if(anugavis.y != NULL) free(anugavis.y);
    86   SDL_Quit();
    87   return -1;
    8880}
    8981
Note: See TracChangeset for help on using the changeset viewer.