-
Notifications
You must be signed in to change notification settings - Fork 1
/
saveFile.c
91 lines (78 loc) · 2.47 KB
/
saveFile.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//---------------------------------------------------------------------------
//
// Functions to save data into files
// Created by Feixiong Huang on 1/21/18
//
//***************************************************************************
#include "forwardmodel.h"
#include "complex.h"
#include <string.h>
void DDMfm_saveToFile(struct DDMfm ddm_fm, int index, int pathType, char saveDir[1000]) {
double val;
char filename[50];
char temp[1000];
strcpy(temp,saveDir);
FILE *outp;
switch(pathType){
case 0:
outp = fopen("DDMfm.dat","wb");
break;
case 1:
sprintf(filename, "DDMfm/DDMfm%d.dat", index);
outp = fopen(filename, "wb");
break;
case 2:
strcat(temp, "DDMfm.dat");
outp = fopen(temp,"wb");
break;
}
for (int i = 0; i < ddm_fm.numDelaybins * ddm_fm.numDopplerbins; i++) {
val = ddm_fm.data[i].power;
fwrite(&val, 1, sizeof(double), outp);
}
fclose(outp);
printf("save FM DDM into file\n");
}
void Jacobian_saveToFile(struct Jacobian jacob, int index, int pathType, char saveDir[1000]){
// pathType:
// 0 for save in current directory;
// 1 for save in a folder; (not supported)
// 2 for in VAM folder
double val;
char temp[1000];
strcpy(temp,saveDir);
FILE *outp;
switch(pathType){
case 0:
outp = fopen("Jacobian.dat", "wb");
break;
case 1:
printf("save Jacobian not available\n");
break;
case 2:
strcat(temp, "Jacobian.dat");
outp = fopen(temp, "wb");
break;
}
double numDDMbins,numPts_LL;
numDDMbins = (double)jacob.numDDMbins;
numPts_LL = (double)jacob.numPts_LL;
fwrite(&numDDMbins, 1, sizeof(double), outp);
fwrite(&numPts_LL, 1, sizeof(double), outp);
for (int i = 0; i < jacob.numDDMbins * jacob.numPts_LL; i++) {
val = jacob.data[i].value;
fwrite(&val, 1, sizeof(double), outp);
}
fclose(outp);
printf("save Jacobian into file\n");
}
void indexLL_saveToFile(struct Jacobian jacob, char saveDir[1000]) {
// indexLL: indices of the grid points in the input wind field
char temp[1000];
strcpy(temp,saveDir);
strcat(temp, "indexLL.dat");
FILE *outp = fopen(temp, "wb");
fwrite(jacob.Pts_ind_vec, sizeof(int), jacob.numPts_LL, outp);
fclose(outp);
printf("save index of points in LL into file\n");
}