87 static const char *
readInt(FILE *f,
int *dest) {
89 if (1!=
fread(&g,
sizeof(g),1,f))
90 return "Error reading integer from .grdb file";
98 if (1!=
fread(&g,
sizeof(g),1,f))
99 return "Error reading coordinate from .grdb file";
110 virtual const char *
readInt(
int *dest) =0;
111 virtual const char *
readDouble(
double *dest) =0;
118 if (1!=fscanf(
f,
"%d",dest))
119 return "Could not read integer from .grd file\n";
123 if (1!=fscanf(
f,
"%lf",dest))
124 return "Could not read coordinate from .grd file\n";
130 template <
class coordT>
134 if (1!=
fread(dest,
sizeof(*dest),1,
f))
135 return "Could not read integer from binary .grd[sd] file\n";
140 if (1!=
fread(&in,
sizeof(in),1,
f))
141 return "Could not read coordinate from binary .grd[sd] file\n";
156 FILE *f=
fopen(gridFile,
"r");
157 if (f==NULL)
return "Couldn't open input .grd file";
162 if (NULL!=(err=fmt.
readInt(&nBlocks)))
return err;
167 for (b=0;b<nBlocks;b++) {
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;
176 for (b=0;b<nBlocks;b++) {
179 for (
int c=0;c<3;c++)
180 for (
int i=0;
i<nLocs;
i++) {
182 if (NULL!=(err=fmt.
readDouble(&loc)))
return err;
185 if (NULL!=(err=dest.
consume(dims[b],locs)))
return err;
int fread(T *const ptr, const unsigned int nmemb, std::FILE *stream)
Read file data, and check for possible errors.
static const char * readInt(FILE *f, int *dest)
int fclose(std::FILE *file)
Close a file, and check for possible errors.
virtual vector3d * allocateBlock(blockDim &dim)
const char * read_grds(const char *gridFile, blockConsumer &dest)
virtual void freeBlock(vector3d *blk)
static const char * readDouble(FILE *f, double *dest)
const char * read_grdd(const char *gridFile, blockConsumer &dest)
const char * read_grd(const char *gridFile, blockConsumer &dest)
const char * read_general(const char *gridFile, gridgenGrdFormatter &fmt, blockConsumer &dest)
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.