A Fortran example program that performs backward and forward Spherical Harmonic Transforms using SHTns.
A Fortran example program that performs backward and forward Spherical Harmonic Transforms using SHTns. Compile using:
#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#include <math.h>
void write_vect(char *fn, double *vec, int N);
void write_mx(char *fn, double *mx, int N1, int N2);
int main()
{
long int NLM;
complex double *Slm, *Tlm;
double *Sh, *Th;
long int i,im,lm;
double t;
const int lmax = 5;
const int mmax = 3;
const int mres = 1;
const int nlat = 64;
const int nphi = 16;
Slm = (complex
double *)
shtns_malloc( NLM *
sizeof(complex
double));
Tlm = (complex
double *)
shtns_malloc( NLM *
sizeof(complex
double));
LM_LOOP(shtns, Slm[lm]=0.0; Tlm[lm] = 0.0; )
Slm[
LM(shtns, 2,0)] = 1.0;
write_vect("ylm",(double *) Slm,NLM*2);
write_mx("spat",Sh,nphi,nlat);
double t2;
SHqst_to_point(shtns, Tlm, Tlm, Slm, shtns->
ct[nlat/3], 2.*M_PI/(mres*nphi),&t2,&t2,&t);
printf("check if SH_to_point coincides with SH_to_spat : %f = %f\n",t,Sh[nlat/3]);
printf(
"ct*st = %f\n",shtns->
ct[nlat/3]*shtns->
st[nlat/3]);
for (im=0;im<nphi;im++) {
for (i=0;i<nlat;i++) {
Sh[im*nlat+i] *= Sh[im*nlat+i];
}
}
write_vect("ylm_nl",(double *) Tlm, NLM*2);
LM_LOOP(shtns, Slm[lm]=0.0; Tlm[lm] = 0.0; )
write_mx("spatt",Sh,nphi,nlat);
write_mx("spatp",Th,nphi,nlat);
for (im=0;im<nphi;im++) {
for (i=0;i<nlat;i++) {
Sh[im*nlat+i] = shtns->
ct[i];
}
}
write_vect("ylm_v",(double *) Slm,NLM*2);
}
void write_vect(char *fn, double *vec, int N)
{
FILE *fp;
int i;
fp = fopen(fn,"w");
for (i=0;i<N;i++) {
fprintf(fp,"%.6g ",vec[i]);
}
fclose(fp);
}
void write_mx(char *fn, double *mx, int N1, int N2)
{
FILE *fp;
int i,j;
fp = fopen(fn,"w");
for (i=0;i<N1;i++) {
for(j=0;j<N2;j++) {
fprintf(fp,"%.6g ",mx[i*N2+j]);
}
fprintf(fp,"\n");
}
fclose(fp);
}
int shtns_use_threads(int num_threads)
Enables multi-thread transform using OpenMP with num_threads (if available). Returns number of thread...
Definition sht_init.c:1605
void * shtns_malloc(size_t bytes)
allocate appropriate CPU memory (pinned for gpu, aligned for avx, ...). Use shtns_free to free it.
Definition sht_init.c:1316
shtns_cfg shtns_init(enum shtns_type flags, int lmax, int mmax, int mres, int nlat, int nphi)
Simple initialization of the spherical harmonic transforms of given size. Calls shtns_create and shtn...
Definition sht_init.c:1583
void SHqst_to_point(shtns_cfg, cplx *Qlm, cplx *Slm, cplx *Tlm, double cost, double phi, double *vr, double *vt, double *vp)
Evaluate vector SH representation Qlm at physical point defined by cost = cos(theta) and phi.
Definition sht_func.c:694
void SHtor_to_spat(shtns_cfg, cplx *Tlm, double *Vt, double *Vp)
transform toroidal spherical harmonic coefficients Tlm to the spatial theta and phi components (Vt,...
Definition sht_com.c:73
void SHsphtor_to_spat(shtns_cfg, cplx *Slm, cplx *Tlm, double *Vt, double *Vp)
transform spheroidal-toroidal spherical harmonic coefficients (Slm,Tlm) to the spatial theta and phi ...
Definition sht_com.c:57
void spat_to_SH(shtns_cfg shtns, double *Vr, cplx *Qlm)
transform the scalar field Vr into its spherical harmonic representation Qlm.
Definition sht_com.c:53
void SH_to_spat(shtns_cfg shtns, cplx *Qlm, double *Vr)
transform the spherical harmonic coefficients Qlm into its spatial representation Vr.
Definition sht_com.c:49
shtns.h is the definition file for SHTns : include this file in your source code to use SHTns.
#define NSPAT_ALLOC(shtns)
total number of 'doubles' required for a spatial field (includes FFTW reserved space).
Definition shtns.h:122
void shtns_verbose(int)
controls output during initialization: 0=no output (default), 1=some output, 2=degug (if compiled in)
Definition sht_init.c:51
#define LM(shtns, l, m)
LM(shtns, l,m) : macro returning array index for given l and m, corresponding to config shtns.
Definition shtns.h:108
#define LM_LOOP(shtns, action)
LM_LOOP( shtns, action ) : macro that performs "action" for every (l,m), with lm set,...
Definition shtns.h:111
@ sht_gauss
use gaussian grid and quadrature. Allows on-the-fly or matrix-based algorithms.
Definition shtns.h:58
const double *const ct
cos(theta) array (size nlat)
Definition shtns.h:91
const double *const st
sin(theta) array (size nlat)
Definition shtns.h:92
const unsigned int nlm
total number of (l,m) spherical harmonics components.
Definition shtns.h:81