Changeset 5490


Ignore:
Timestamp:
Jul 11, 2008, 3:41:45 PM (11 years ago)
Author:
jack
Message:

More work on the SWWFile class.

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

Legend:

Unmodified
Added
Removed
  • anuga_work/development/anugavis/src/sww_file.cc

    r5488 r5490  
     1#ifdef HAVE_CONFIG_H
     2#  include "config.h"
     3#endif
     4
    15#include <string>
     6#ifdef HAVE_SYS_TYPES_H
     7#  include <sys/types.h>
     8#endif
     9#include <boost/shared_array.hpp>
    210#include <netcdf.h>
    311#include "sww_file.hh"
    412
     13using boost::shared_array;
    514using std::string;
    615
     
    1019                         NC_SHARE, &this->netcdf_id)) != NC_NOERR)
    1120    throw nc_strerror(ncstatus);
     21  this->number_of_points = this->nc_inq_dimlen_by_name("number_of_points");
     22  this->number_of_vertices = this->nc_inq_dimlen_by_name("number_of_vertices");
     23  this->number_of_volumes = this->nc_inq_dimlen_by_name("number_of_volumes");
     24  this->x = shared_array<float>(new float[this->number_of_points]);
     25  this->nc_get_var_float_by_name("x", this->x.get());
     26  this->y = shared_array<float>(new float[this->number_of_points]);
     27  this->nc_get_var_float_by_name("y", this->y.get());
     28  this->volumes = shared_array<int>(new int[this->number_of_volumes *
     29                                            this->number_of_vertices]);
     30  this->nc_get_var_int_by_name("volumes", this->volumes.get());
     31  this->compute_extents();
    1232}
    1333
     
    1535  nc_close(this->netcdf_id);
    1636}
     37
     38void SWWFile::compute_extents(void){
     39  this->minX = this->x[0];
     40  this->maxX = this->x[0];
     41  this->minY = this->y[0];
     42  this->maxY = this->y[0];
     43  for(int i = 1 ; i < this->number_of_points ; ++i){
     44    if(this->x[i] < this->minX) this->minX = this->x[i];
     45    if(this->x[i] > this->maxX) this->maxX = this->x[i];
     46    if(this->y[i] < this->minY) this->minY = this->y[i];
     47    if(this->y[i] > this->maxY) this->maxY = this->y[i];
     48  }
     49}
     50
     51void SWWFile::nc_get_var_float_by_name(const string &name, float array[]){
     52  int ncstatus;
     53  int varid;
     54  if(((ncstatus = nc_inq_varid(this->netcdf_id,
     55                               name.c_str(), &varid)) != NC_NOERR) ||
     56     ((ncstatus = nc_get_var_float(this->netcdf_id,
     57                                   varid, array)) != NC_NOERR))
     58    throw nc_strerror(ncstatus);
     59}
     60
     61void SWWFile::nc_get_var_int_by_name(const string &name, int array[]){
     62  int ncstatus;
     63  int varid;
     64  if(((ncstatus = nc_inq_varid(this->netcdf_id,
     65                               name.c_str(), &varid)) != NC_NOERR) ||
     66     ((ncstatus = nc_get_var_int(this->netcdf_id,
     67                                 varid, array)) != NC_NOERR))
     68    throw nc_strerror(ncstatus);
     69}
     70
     71size_t SWWFile::nc_inq_dimlen_by_name(const string &name){
     72  int ncstatus;
     73  int dimid;
     74  size_t len;
     75  if(((ncstatus = nc_inq_dimid(this->netcdf_id,
     76                               name.c_str(), &dimid)) != NC_NOERR) ||
     77     ((ncstatus = nc_inq_dimlen(this->netcdf_id,
     78                                dimid, &len)) != NC_NOERR))
     79    throw nc_strerror(ncstatus);
     80  return len;
     81}
  • anuga_work/development/anugavis/src/sww_file.hh

    r5488 r5490  
    55   difficult to build the C++ binding on Win32 (further, it fails its
    66   test suite. */
     7#ifdef HAVE_CONFIG_H
     8#  include "config.h"
     9#endif
     10#include <string>
     11#ifdef HAVE_SYS_TYPES_H
     12#  include <sys/types.h>
     13#endif
     14#include <boost/shared_array.hpp>
    715
    8 #include <string>
     16using boost::shared_array;
    917using std::string;
    1018
     
    1422  ~SWWFile(void);
    1523private:
     24  void compute_extents(void);
     25  void nc_get_var_float_by_name(const string &name, float array[]);
     26  void nc_get_var_int_by_name(const string &name, int array[]);
     27  size_t nc_inq_dimlen_by_name(const string &name);
    1628  int netcdf_id;
     29  int number_of_points;
     30  int number_of_vertices;
     31  int number_of_volumes;
     32  shared_array<float> x;
     33  shared_array<float> y;
     34  shared_array<int> volumes;
     35  float minX;
     36  float maxX;
     37  float minY;
     38  float maxY;
    1739};
    1840
Note: See TracChangeset for help on using the changeset viewer.