Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F74171025
write_series.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jul 26, 06:47
Size
1 KB
Mime Type
text/x-c
Expires
Sun, Jul 28, 06:47 (2 d)
Engine
blob
Format
Raw Data
Handle
19350261
Attached To
R9482 SP4E_Homework_Ashtari_Sieber
write_series.cc
View Options
#include "write_series.hh"
WriteSeries
::
WriteSeries
(
Series
&
series
,
unsigned
int
N
,
std
::
string
separator
,
unsigned
int
precision
)
:
DumperSeries
(
series
)
{
maxiter
=
N
;
dump_precision
=
precision
;
setSeparator
(
separator
);
}
void
WriteSeries
::
setSeparator
(
std
::
string
separator
)
{
if
(
separator
==
"comma"
)
{
sep
=
", "
;
format
=
".csv"
;
}
else
if
(
separator
==
"pipe"
)
{
sep
=
"|"
;
format
=
".psv"
;
}
else
{
sep
=
"
\t
"
;
format
=
".txt"
;
if
(
separator
!=
"tab"
)
{
std
::
cout
<<
"----> WARNING: Data are written to a txt fille with a tab separator."
<<
std
::
endl
;
}
}
}
void
WriteSeries
::
dump
(
std
::
ostream
&
os
)
{
std
::
string
file_name
=
"series_output"
;
file_name
.
append
(
format
);
std
::
ofstream
my_file
;
my_file
.
open
(
file_name
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
double
computed
,
analytical
,
error
;
for
(
int
i
=
1
;
i
<=
maxiter
;
i
++
)
{
computed
=
series
.
compute
(
i
);
my_file
<<
i
<<
sep
<<
std
::
fixed
<<
std
::
setprecision
(
dump_precision
)
<<
computed
;
// Checking whether analytical value exists
if
(
!
std
::
isnan
(
series
.
getAnalyticPrediction
()))
{
analytical
=
series
.
getAnalyticPrediction
();
error
=
100.0
*
std
::
abs
(
analytical
-
computed
)
/
analytical
;
my_file
<<
sep
<<
std
::
fixed
<<
std
::
setprecision
(
dump_precision
)
<<
analytical
<<
sep
<<
std
::
fixed
<<
std
::
setprecision
(
dump_precision
)
<<
error
;
}
my_file
<<
std
::
endl
;
}
my_file
.
close
();
}
Event Timeline
Log In to Comment