forked from geodynamics/hc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_test.c
56 lines (46 loc) · 1.33 KB
/
simple_test.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
#include <stdio.h>
#include <math.h>
#define vshd2c vshd2c_
#define gauleg gauleg_
extern void vshd2c(int *,double *,double *,double *,double *,int *,
double *,double *);
extern void gauleg(double *,double *,double*,double *,int*);
void main(void)
{
int lmax,nlat,nlon,lmsize,i,j,index;
double *datax,*datay,*cpol,*ctor,*z,*w,unity,negunity;
unity = 1.0;negunity=-1.0;
/* */
lmax = 63;
/* sizes */
nlat = lmax+1;
nlon = nlat * 2;
lmsize = (lmax+1)*(lmax+2)/2;
/* allocate */
hc_dvecalloc(&cpol,lmsize*2,"");
hc_dvecalloc(&ctor,lmsize*2,"");
hc_dvecalloc(&datax,nlon*nlat,"");
hc_dvecalloc(&datay,nlon*nlat,"");
hc_dvecalloc(&z,nlat,"");
hc_dvecalloc(&w,nlon*nlat,"");
/* gauss points */
gauleg(&negunity,&unity,z,w,&nlat);
/* read in data */
for(index=0;index<nlon*nlat;index++){
if(fscanf(stdin,"%*lf %*lf %*lf %lf %lf",
(datay+index),(datax+index))!=2){
fprintf(stderr,"read error data\n");
exit(-1);
}
}
/* get coefficients */
vshd2c(&lmax,z,w,cpol,ctor,&lmax,datax,datay);
/*
output of pol/tor components, flip sign since Gauleq is now
called -1 to 1
*/
fprintf(stderr,"%i\n",lmax);
for(i=0;i<lmsize*2;i++)
fprintf(stderr,"%i %15.7e %15.7e\t%15.7e %15.7e\t%15.7e %15.7e\n",i,
0.,0.,-cpol[i*2],-cpol[i*2+1],-ctor[i*2],-ctor[i*2+1]);
}