-
Notifications
You must be signed in to change notification settings - Fork 12
/
ParamFile.cpp
70 lines (59 loc) · 1.84 KB
/
ParamFile.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* This file is part of SRS project.
*
* SRS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SRS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SRS. If not, see <http://www.gnu.org/licenses/>.
*
* Created by: Yifang Sun, Jianbin Qin
* Last modified by: Yifang Sun, Jianbin Qin
*/
#include "ParamFile.h"
#include <stdio.h>
#include <string.h>
void writeParamFile(char * file_path, long long n, int d, int m, int B,
float * proj, const char * type) {
FILE * fp = fopen(file_path, "w");
fprintf(fp, "B = %d\n", B);
fprintf(fp, "n = %ld\n", n);
fprintf(fp, "d = %d\n", d);
fprintf(fp, "m = %d\n", m);
for (int i = 0; i < m * d; i++) {
fprintf(fp, "%f ", proj[i]);
}
fprintf(fp, "\n%s s", type);
fclose(fp);
}
float * readParamFile(char * index_path, long long &n, int &d, int &m, int &B,
char * type) {
char file_path[100];
strcpy(file_path, index_path);
strcat(file_path, "para.txt");
FILE *fp = fopen(file_path, "r");
fscanf(fp, "B = %d\n", &B);
fscanf(fp, "n = %ld\n", &n);
fscanf(fp, "d = %d\n", &d);
fscanf(fp, "m = %d\n", &m);
float *proj = new float[m * d];
for (int i = 0; i < m * d; i++) {
fscanf(fp, "%f", &proj[i]);
}
fscanf(fp, "\n");
int i = 0;
;
fgets(type, 100, fp); //, "%s", type);
for (; type[i] != ' '; ++i) {
}
type[i] = 0;
fclose(fp);
return proj;
}