-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIO.h
59 lines (46 loc) · 3.87 KB
/
IO.h
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
#include <stdio.h>
#define INPUTDATA(Type, flag) \
void InputData_##Type(Type * input, const int size, const char * name_file){\
FILE * fp = fopen(name_file, "r"); \
if (fp==NULL){ \
printf("open file: %s failed!", name_file); \
exit(-1); \
} \
int cnt=0; \
while( cnt< size ){ \
if( fscanf(fp,#flag, &input[cnt]) >0 ){ \
cnt++; \
} \
else{ \
break; \
} \
} \
if(cnt<size){ \
printf("from file %s : got %d raw data, which is less than size- %d !\n", name_file, cnt, size); \
} \
fclose(fp); \
}
#define OUTPUTDATA(Type, flag) \
void OutputData_##Type(Type * output, const int size, const char * name_file){ \
FILE * fp = fopen(name_file, "w"); \
if (fp==NULL){ \
printf("open file: %s failed!", name_file); \
exit(-1); \
} \
int cnt=0; \
while( cnt< size ){ \
fprintf(fp,#flag,output[cnt]); \
fprintf(fp," "); \
cnt++; \
} \
if(cnt<size){ \
printf("write %d data into file %s , which is less than size- %d !\n", cnt, name_file, size); \
} \
fclose(fp); \
}
INPUTDATA(float, %f)
INPUTDATA(double, %lf)
INPUTDATA(int, %d)
OUTPUTDATA(float, %f)
OUTPUTDATA(double, %f)
OUTPUTDATA(int, %d)