-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsplines.cpp
53 lines (52 loc) · 2.07 KB
/
bsplines.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
/*============================================================================
* Daniel J. Greenhoe
*============================================================================*/
/*=====================================
* headers
*=====================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "main.h"
/*---------------------------------------------------------------------------
* plot auto-power spectrum data for plotting
* within LaTeX ps-tricks environment
*---------------------------------------------------------------------------*/
int bspline_Sdat(void){
time_t time1; time(&time1); //starting time stamp (passed to plotting routine)
struct tm *gmt;
gmt = gmtime(&time1);
char tbuffer[80];
const double n=3; // order of B-spline
const long M=1024; // approximate number of data points
const long N=1000000; // number of iterations per data point
double w=0,s=0;
long k=0;
strftime(tbuffer,80,"%Y %B %d %A %I:%M:%S %p UTC",gmt);
printf("%%============================================================================\n");
printf("%% Daniel J. Greenhoe\n");
printf("%% n=%1.0lf order B-spline auto-power spectrum data\n",n);
printf("%% M = number of data points approx= %ld\n",M);
printf("%% N = iterations per data point = %ld\n",N);
printf("%% %s\n",tbuffer);
printf("%% The command \fileplot{d4_phi.dat} may be used in a LaTeX environment for plotting data.\n");
printf("%% \\fileplot is available in the LaTeX PSTricks package.\n");
printf("%% Reference: http://www.ctan.org/pkg/pstricks\n");
printf("%%============================================================================\n");
printf("[\n");
for(w=-8.0;w<=8.0;w+=16./(double)M){
s=0;
for(k=1; k<=N; k++){
s += pow(1.0/(2*k-w/PI),2.*n+2.);
s += pow(1.0/(2*k+w/PI),2.*n+2.);
}
s*=pow(sin(w/2.)/(PI/2.),2.*n+2.);
if(w==0) s+=1; // use l'Hopital's rule
else s+=pow(sin(w/2.)/(w/2.),2.*n+2.);
printf("(%lf, %lf)\n",w,s);
}
printf("]\n");
return 0;
}