Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
readgrd.cpp File Reference
#include <stdio.h>
#include "gridutil.h"
Include dependency graph for readgrd.cpp:

Go to the source code of this file.

Classes

class  gridgenGrdFormatter
 Abstracts the file format of a gridgen .grd file. More...
 
class  gridgenAsciiFormatter
 ASCII format input file: More...
 
class  gridgenBinaryFormatter< coordT >
 Machine binary input file: More...
 
class  gridgenBinaryFloatFormatter
 
class  gridgenBinaryDoubleFormatter
 

Typedefs

typedef int grdb_int_t
 
typedef double grdb_coord_t
 

Functions

static const char * readInt (FILE *f, int *dest)
 
static const char * readDouble (FILE *f, double *dest)
 
const char * read_general (const char *gridFile, gridgenGrdFormatter &fmt, blockConsumer &dest)
 
const char * read_grd (const char *gridFile, blockConsumer &dest)
 
const char * read_grds (const char *gridFile, blockConsumer &dest)
 
const char * read_grdd (const char *gridFile, blockConsumer &dest)
 

Typedef Documentation

typedef double grdb_coord_t

Definition at line 84 of file readgrd.cpp.

typedef int grdb_int_t

Definition at line 83 of file readgrd.cpp.

Function Documentation

const char* read_general ( const char *  gridFile,
gridgenGrdFormatter fmt,
blockConsumer dest 
)

Definition at line 152 of file readgrd.cpp.

References blockConsumer::allocateBlock(), blockConsumer::consume(), cimg_library::cimg::fclose(), cimg_library::cimg::fopen(), blockConsumer::freeBlock(), blockDim::getSize(), i, gridgenGrdFormatter::readDouble(), gridgenGrdFormatter::readInt(), and gridgenGrdFormatter::setFile().

Referenced by read_grd(), read_grdd(), and read_grds().

153 {
154  const char *err;
155  //Open the input file
156  FILE *f=fopen(gridFile,"r");
157  if (f==NULL) return "Couldn't open input .grd file";
158  fmt.setFile(f);
159 
160  //Read the header
161  int nBlocks=0;
162  if (NULL!=(err=fmt.readInt(&nBlocks))) return err;
163 
164  //Read the block sizes
165  blockDim *dims=new blockDim[nBlocks];
166  int b;
167  for (b=0;b<nBlocks;b++) {
168  int nx,ny,nz;
169  if (NULL!=(err=fmt.readInt(&nx))) return err;
170  if (NULL!=(err=fmt.readInt(&ny))) return err;
171  if (NULL!=(err=fmt.readInt(&nz))) return err;
172  dims[b]=blockDim(nx,ny,nz);
173  }
174 
175  //Read and consume each block's coordinates
176  for (b=0;b<nBlocks;b++) {
177  int nLocs=dims[b].getSize();
178  vector3d *locs=dest.allocateBlock(dims[b]);
179  for (int c=0;c<3;c++) //*outer* loop is coordinate axis
180  for (int i=0;i<nLocs;i++) {//*inner* loop is location #
181  double loc;
182  if (NULL!=(err=fmt.readDouble(&loc))) return err;
183  locs[i][c]=loc;
184  }
185  if (NULL!=(err=dest.consume(dims[b],locs))) return err;
186  dest.freeBlock(locs);
187  }
188 
189  //Finish up
190  delete[] dims;
191  fclose(f);
192  return NULL; //Everything worked
193 }
virtual const char * readDouble(double *dest)=0
int fclose(std::FILE *file)
Close a file, and check for possible errors.
Definition: CImg.h:5507
virtual vector3d * allocateBlock(blockDim &dim)
Definition: read.cpp:146
void setFile(FILE *f_)
Definition: readgrd.cpp:109
virtual void freeBlock(vector3d *blk)
Definition: read.cpp:150
blockLoc i
Definition: read.cpp:79
virtual const char * readInt(int *dest)=0
int getSize(void) const
Definition: gridutil.h:126
virtual const char * consume(const blockDim &dim, vector3d *locs)=0
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
Definition: CImg.h:5494

Here is the call graph for this function:

Here is the caller graph for this function:

const char* read_grd ( const char *  gridFile,
blockConsumer dest 
)

Definition at line 196 of file readgrd.cpp.

References read_general().

Referenced by read_file().

197 {
199  return read_general(gridFile,fmt,dest);
200 }
ASCII format input file:
Definition: readgrd.cpp:115
const char * read_general(const char *gridFile, gridgenGrdFormatter &fmt, blockConsumer &dest)
Definition: readgrd.cpp:152

Here is the call graph for this function:

Here is the caller graph for this function:

const char* read_grdd ( const char *  gridFile,
blockConsumer dest 
)

Definition at line 206 of file readgrd.cpp.

References read_general().

Referenced by read_file().

207 {
209  return read_general(gridFile,fmt,dest);
210 }
const char * read_general(const char *gridFile, gridgenGrdFormatter &fmt, blockConsumer &dest)
Definition: readgrd.cpp:152

Here is the call graph for this function:

Here is the caller graph for this function:

const char* read_grds ( const char *  gridFile,
blockConsumer dest 
)

Definition at line 201 of file readgrd.cpp.

References read_general().

Referenced by read_file().

202 {
204  return read_general(gridFile,fmt,dest);
205 }
const char * read_general(const char *gridFile, gridgenGrdFormatter &fmt, blockConsumer &dest)
Definition: readgrd.cpp:152

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* readDouble ( FILE *  f,
double *  dest 
)
static

Definition at line 96 of file readgrd.cpp.

References cimg_library::cimg::fread().

96  {
97  grdb_coord_t g;
98  if (1!=fread(&g,sizeof(g),1,f))
99  return "Error reading coordinate from .grdb file";
100  *dest=g;
101  return NULL;
102 }
int fread(T *const ptr, const unsigned int nmemb, std::FILE *stream)
Read file data, and check for possible errors.
Definition: CImg.h:5569
double grdb_coord_t
Definition: readgrd.cpp:84

Here is the call graph for this function:

static const char* readInt ( FILE *  f,
int *  dest 
)
static

Definition at line 87 of file readgrd.cpp.

References cimg_library::cimg::fread().

87  {
88  grdb_int_t g;
89  if (1!=fread(&g,sizeof(g),1,f))
90  return "Error reading integer from .grdb file";
91  *dest=g;
92  return NULL;
93 }
int fread(T *const ptr, const unsigned int nmemb, std::FILE *stream)
Read file data, and check for possible errors.
Definition: CImg.h:5569
int grdb_int_t
Definition: readgrd.cpp:83

Here is the call graph for this function: