forked from jhjin/overfeat-torch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParamBank.c
55 lines (48 loc) · 1.05 KB
/
ParamBank.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
FILE *fp = NULL;
size_t fp_pos = 0;
int init(const char *fpath) {
fp = fopen(fpath, "r");
fp_pos = 0;
if (fp == NULL) {
printf("ERROR: could not find the file (%s)\n", fpath);
return 1;
}
return 0;
}
int close(void) {
if (fp != NULL) {
fclose(fp);
fp = NULL;
}
return 0;
}
int read(float *storage, long offset, long length) {
const int wordsize = sizeof(float);
if (fp != NULL) {
if (fp_pos != offset*wordsize)
fseek(fp, offset*wordsize, SEEK_SET);
assert(fread(storage, wordsize, length, fp) == length);
fp_pos += length*wordsize;
return 0;
} else {
printf("ERROR: could not read the file pointer\n");
return 1;
}
}
int print(long length) {
const int wordsize = sizeof(float);
int i;
float buffer;
for (i = 0; i < length; i++) {
if (fp == NULL) {
return 1;
} else {
fread(&buffer, wordsize, 1, fp);
printf("%f\n", buffer);
}
}
return 0;
}