94 printf(
" initc: using zlib version %s\n",ZLIB_VERSION);
110void openc(
const char *fileName,
int lfn,
int nFileIn,
int *errorFlag)
127 int fileIndex = nFileIn - 1;
133 char *s = malloc(lfn+1);
135 for (
i=0;
i<lfn;
i++ ) {
140 files[fileIndex] = gzopen(s,
"rb");
141 if (!
files[fileIndex]) {
145 files[fileIndex] = fopen(s,
"rb");
146 if (!
files[fileIndex]) {
148 }
else if (ferror(
files[fileIndex])) {
149 fclose(
files[fileIndex]);
150 files[fileIndex] = 0;
169 int fileIndex = nFileIn - 1;
173 gzclose(
files[fileIndex]);
175 fclose(
files[fileIndex]);
177 files[fileIndex] = 0;
186 int fileIndex = nFileIn - 1;
190 gzrewind(
files[fileIndex]);
193 fseek(
files[fileIndex], 0L, SEEK_SET);
194 clearerr(
files[fileIndex]);
219void readc(
double *bufferDouble,
float *bufferFloat,
int *bufferInt,
220 int *lengthBuffers,
int nFileIn,
int *errorFlag) {
232 int fileIndex = nFileIn - 1;
235 if (!bufferFloat || !bufferInt || !lengthBuffers) {
241 int recordLength = 0;
243 int nCheckR = gzread(
files[fileIndex], &recordLength,
sizeof(recordLength));
244 if (gzeof(
files[fileIndex])) {
249 if (recordLength<0) {
251 recordLength = -recordLength;
253 if (
sizeof(recordLength) != nCheckR) {
254 printf(
"readc: problem reading length of record file %d\n", fileIndex);
259 if (recordLength/2 > *lengthBuffers) {
265 for (;
i< recordLength/2; ++
i)
267 int nCheckD = gzread(
files[fileIndex], bufferDouble,
sizeof(bufferDouble[0]));
268 if (nCheckD !=
sizeof(bufferDouble[0])) {
269 printf(
"readc: problem with stream or EOF skipping doubles\n");
275 for (;
i< recordLength/2; ++
i)
277 int nCheckF = gzread(
files[fileIndex], bufferFloat,
sizeof(bufferFloat[0]));
278 if (nCheckF !=
sizeof(bufferFloat[0])) {
279 printf(
"readc: problem with stream or EOF skipping floats\n");
287 for (;
i< recordLength/2; ++
i)
289 int nCheckI = gzread(
files[fileIndex], bufferInt,
sizeof(bufferInt[0]));
290 if (nCheckI !=
sizeof(bufferInt[0])) {
291 printf(
"readc: problem with stream or EOF skipping ints\n");
298 *lengthBuffers = recordLength/2;
301 *lengthBuffers = recordLength/2;
306 int nCheckD = gzread(
files[fileIndex], bufferDouble, *lengthBuffers*8);
307 if (nCheckD != *lengthBuffers*8) {
308 printf(
"readc: problem with stream or EOF reading doubles\n");
313 int nCheckF = gzread(
files[fileIndex], bufferFloat, *lengthBuffers*4);
314 if (nCheckF != *lengthBuffers*4) {
315 printf(
"readc: problem with stream or EOF reading floats\n");
320 for (;
i< recordLength/2; ++
i) bufferDouble[
i] = (
double) bufferFloat[
i];
324 int nCheckI = gzread(
files[fileIndex], bufferInt, *lengthBuffers*4);
325 if (nCheckI != *lengthBuffers*4) {
326 printf(
"readc: problem with stream or EOF reading ints\n");
331 size_t nCheckR = fread(&recordLength,
sizeof(recordLength), 1,
333 if (feof(
files[fileIndex])) {
341 if (1 != nCheckR || ferror(
files[fileIndex])) {
342 printf(
"readc: problem reading length of record, file %d\n", fileIndex);
347 if (recordLength < 0) {
349 recordLength = -recordLength;
351 if (recordLength / 2 > *lengthBuffers) {
357 for (;
i < recordLength / 2; ++
i) {
358 size_t nCheckD = fread(bufferDouble,
sizeof(bufferDouble[0]), 1,
360 if (ferror(
files[fileIndex]) || feof(
files[fileIndex])
361 || nCheckD != *lengthBuffers) {
363 "readc: problem with stream or EOF skipping doubles\n");
369 for (;
i < recordLength / 2; ++
i) {
370 size_t nCheckF = fread(bufferFloat,
sizeof(bufferFloat[0]), 1,
372 if (ferror(
files[fileIndex]) || feof(
files[fileIndex])
373 || nCheckF != *lengthBuffers) {
375 "readc: problem with stream or EOF skipping floats\n");
383 for (;
i < recordLength / 2; ++
i) {
384 size_t nCheckI = fread(bufferInt,
sizeof(bufferInt[0]), 1,
386 if (ferror(
files[fileIndex]) || feof(
files[fileIndex])
387 || nCheckI != *lengthBuffers) {
388 printf(
"readc: problem with stream or EOF skiping ints\n");
395 *lengthBuffers = recordLength / 2;
398 *lengthBuffers = recordLength / 2;
403 size_t nCheckD = fread(bufferDouble,
sizeof(bufferDouble[0]),
404 *lengthBuffers,
files[fileIndex]);
405 if (ferror(
files[fileIndex]) || feof(
files[fileIndex])
406 || nCheckD != *lengthBuffers) {
407 printf(
"readc: problem with stream or EOF reading doubles\n");
412 size_t nCheckF = fread(bufferFloat,
sizeof(bufferFloat[0]),
413 *lengthBuffers,
files[fileIndex]);
414 if (ferror(
files[fileIndex]) || feof(
files[fileIndex])
415 || nCheckF != *lengthBuffers) {
416 printf(
"readc: problem with stream or EOF reading floats\n");
421 for (;
i < recordLength / 2; ++
i)
422 bufferDouble[
i] = (
double) bufferFloat[
i];
425 size_t nCheckI = fread(bufferInt,
sizeof(bufferInt[0]), *lengthBuffers,
427 if (ferror(
files[fileIndex]) || feof(
files[fileIndex])
428 || nCheckI != *lengthBuffers) {
429 printf(
"readc: problem with stream or EOF reading ints\n");
435 *errorFlag = 4 * (doublePrec + 1);
void resetc(int nFileIn)
Rewind file.
void initc(int nFiles)
Initialises the 'global' variables used for file handling.
void closec(int nFileIn)
Close file.
unsigned int maxNumFiles
max number of files
void readc(double *bufferDouble, float *bufferFloat, int *bufferInt, int *lengthBuffers, int nFileIn, int *errorFlag)
Read record from file.
unsigned int numAllFiles
number of opened files
void openc(const char *fileName, int lfn, int nFileIn, int *errorFlag)
Open file.
FILE ** files
pointer to list of pointers to opened binary files