質問編集履歴
2
ソースコードについてはsegmentation faultを解決しようとしてvevtorを使ってみたものです.
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,16 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
追記
|
20
|
+
|
21
|
+
segmentation faultを解決しようとしてvectorを使ってみたのですが,
|
22
|
+
|
23
|
+
”note : template argument deduction/substitution failed :”
|
24
|
+
|
25
|
+
というエラーが出てしまいました.
|
26
|
+
|
27
|
+
|
28
|
+
|
19
29
|
```lang-c++
|
20
30
|
|
21
31
|
#include <stdio.h>
|
1
ソースコードを載せました.初心者でお見苦しいかと思いますがよろしくお願いします.
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,197 @@
|
|
13
13
|
と出てしまいました.
|
14
14
|
|
15
15
|
これを解決したいのですが,どのようにすればいいでしょうか?
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```lang-c++
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
|
23
|
+
#include <vector>
|
24
|
+
|
25
|
+
using namespace std;
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
int main()
|
30
|
+
|
31
|
+
{
|
32
|
+
|
33
|
+
int nlin=0 , header=17;
|
34
|
+
|
35
|
+
int i,cnt,c,n;
|
36
|
+
|
37
|
+
vector<double> x1[cnt],x2[xnt],x3[cnt],x4[cnt];
|
38
|
+
|
39
|
+
double sum1,sum2,sum3,sum4;
|
40
|
+
|
41
|
+
double I1,I2,I3,I4;
|
42
|
+
|
43
|
+
double I1_,I2_,I3_,I4_;
|
44
|
+
|
45
|
+
double dt=0.0000001;
|
46
|
+
|
47
|
+
char bff[100];
|
48
|
+
|
49
|
+
FILE* fp;
|
50
|
+
|
51
|
+
FILE* save;
|
52
|
+
|
53
|
+
FILE* gp;
|
54
|
+
|
55
|
+
char fname[]={"file[n].csv"};
|
56
|
+
|
57
|
+
char save_fname[]={"save[n].csv"};
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
//file loop
|
62
|
+
|
63
|
+
for(n=0 ; n<=cnt ; n++)
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
//line count part
|
70
|
+
|
71
|
+
fp =fopen(fname,"r");
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
if(fp)
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
while(c=getc(fp)!=EOF);
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
if(c=='\n')cnt++;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
printf("%d\n",cnt);
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
//return first line
|
96
|
+
|
97
|
+
rewind(fp); nlin=0;
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
//file & gnuplot open for save
|
102
|
+
|
103
|
+
save = fopen("save[n].csv","w");
|
104
|
+
|
105
|
+
gp = popen("gnuplot -persist","w");
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
//header cut part
|
110
|
+
|
111
|
+
while(fgets(bff,100,fp)!=NULL)
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
if(++nlin <= header)continue;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
//calibration value ~ integrater
|
122
|
+
|
123
|
+
for(i=17 ; i<=2000 ; i++)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
while(fscanf(fp,"%lf%lf%lf%lf",&x1[cnt],&x2[cnt],&x3[cnt],&x4[cnt])==4)
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
sum1 += x1[i];
|
132
|
+
|
133
|
+
sum2 += x2[i];
|
134
|
+
|
135
|
+
sum3 += x3[i];
|
136
|
+
|
137
|
+
sum4 += x4[i];
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
for(i=17 ; i<=cnt ; i++)
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
//first point at each column
|
148
|
+
|
149
|
+
I1_= (x1[17] - sum1) * dt;
|
150
|
+
|
151
|
+
I2_= (x2[17] - sum2) * dt;
|
152
|
+
|
153
|
+
I3_= (x3[17] - sum3) * dt;
|
154
|
+
|
155
|
+
I4_= (x4[17] - sum4) * dt;
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
//second ~ final point at 4each column
|
160
|
+
|
161
|
+
I1 = I1_ + (x1[i+1] - sum1) * dt;
|
162
|
+
|
163
|
+
I2 = I2_ + (x2[i+1] - sum2) * dt;
|
164
|
+
|
165
|
+
I3 = I3_ + (x3[i+1] - sum3) * dt;
|
166
|
+
|
167
|
+
I4 = I4_ + (x4[i+1] - sum4) * dt;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
//writing part on file
|
172
|
+
|
173
|
+
fprintf(save,"%f \t %f \t %f \t %f \n",I1_,I2_,I3_,I4_);
|
174
|
+
|
175
|
+
fprintf(save,"%f \t %f \t %f \t %f \n",I1,I2,I3,I4);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
fprintf(gp,"plot %f with lines \n",I1);
|
180
|
+
|
181
|
+
fprintf(gp,"plot %f with lines \n",I2);
|
182
|
+
|
183
|
+
fprintf(gp,"plot %f with lines \n",I3);
|
184
|
+
|
185
|
+
fprintf(gp,"plot %f with lines \n",I4);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
pclose(gp);
|
194
|
+
|
195
|
+
fclose(save);
|
196
|
+
|
197
|
+
fclose(fp);
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
return 0;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
コード
|
208
|
+
|
209
|
+
```
|