File: akimaSpline.cpp

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (70 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download
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
// BEGIN LICENSE BLOCK
/*
Copyright (c) 2009 , UT-Battelle, LLC
All rights reserved

[PsimagLite, Version 1.0.0]

*********************************************************
THE SOFTWARE IS SUPPLIED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED.

Please see full open source license included in file LICENSE.
*********************************************************

*/
// END LICENSE BLOCK

#include "AkimaSpline.h"
#include "Vector.h"
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

typedef double FieldType;
typedef typename Vector<FieldType>::Type VectorType;
typedef AkimaSpline<VectorType> AkimaSplineType;
typedef AkimaSplineType::IntervalType IntervalType;

void readTwoColumnData(const String& file, VectorType& v0, VectorType& v1)
{
	std::ifstream fin(file.c_str());
	if (!fin || !fin.good() || fin.bad())
		throw RuntimeError("Cannot open file\n");
	while (!fin.eof()) {
		String s;
		fin >> s;
		if (s[0] == '#')
			continue;
		FieldType x = std::atof(s.c_str());
		SizeType size = v0.size();
		if (size > 1 && x < v0[size - 1])
			break;
		v0.push_back(x);
		fin >> s;
		if (s[0] == '#')
			continue;
		v1.push_back(atof(s.c_str()));
	}
	fin.close();
}

int main(int argc, char* argv[])
{
	VectorType x, s;
	readTwoColumnData(argv[1], x, s);

	AkimaSplineType akimaSpline(x, s);
	FieldType xstart = std::atof(argv[2]);
	FieldType xend = std::atof(argv[3]);
	SizeType total = std::atoi(argv[4]);
	FieldType xstep = (xend - xstart) / total;

	for (FieldType x = xstart; x < xend; x += xstep) {
		std::cout << x << " " << akimaSpline(x) << "\n";
	}
}