11module SHTns
22
33using SHTns_jll
4- export SHTns_jll
4+ # to use system build SHTns library (needs to be a shared library)
5+ # e.g. using
6+ # gcc -lfftw3 -lfftw3_omp -fopenmp -shared libshtns.so *.o
7+ const libshtns = Ref {String} ()
8+
9+ function __init__ ()
10+ if haskey (ENV , " SHTNS_PATH" )
11+ libshtns[] = ENV [" SHTNS_PATH" ]
12+ else
13+ libshtns[] = SHTns_jll. LibSHTns
14+ end
15+ end
516
6- import Base: convert, show, propertynames, getproperty
717
8- const libshtns = SHTns_jll . LibSHTns
18+ import Base : convert, show, propertynames, getproperty
919
1020
1121const shtns_norm = UInt32
8999
90100function _init_checks (shtype, lmax, mmax, mres, nlat, nphi)
91101 @assert lmax > 1
92- @assert nphi > 2 lmax
93102 @assert mmax* mres <= lmax
94103 @assert mres > 0
95- @assert nlat >= 32 # shtns wants nlat > 4*VSIZE2
104+ @assert nlat >= 16 # shtns wants nlat > 4*VSIZE2
105+ @assert nphi > 2 mmax # sampling theorem
96106 if typeof (shtype) <: Union{Gauss, GaussFly, QuickInit}
97107 @assert nlat > lmax
98108 else
@@ -110,6 +120,20 @@ mutable struct SHTnsCfg{N<:SHTnsNorm, T<:SHTnsType}
110120 norm:: N
111121 shtype:: T
112122 robert_form:: Bool
123+ nlm:: Int
124+ lmax:: Int
125+ mmax:: Int
126+ mres:: Int
127+ nlat_2:: Int
128+ nlat:: Int
129+ nphi:: Int
130+ nspat:: Int
131+ li:: Vector{Int}
132+ mi:: Vector{Int}
133+ ct:: Vector{Float64}
134+ st:: Vector{Float64}
135+ nlat_padded:: Int
136+ nlm_cplx:: Int
113137 function SHTnsCfg (lmax, mmax, mres, nlat, nphi;
114138 shtype:: T = QuickInit (),
115139 norm:: N = Orthonormal (),
@@ -120,9 +144,13 @@ mutable struct SHTnsCfg{N<:SHTnsNorm, T<:SHTnsType}
120144 _init_checks (shtype, lmax, mmax, mres, nlat, nphi)
121145 cfg = shtns_create (lmax, mmax, mres, norm)
122146 robert_form && shtns_robert_form (cfg,1 )
123-
124147 shtns_set_grid (cfg, shtype, eps, nlat, nphi)
125- stream = new {N,T} (cfg, norm, shtype, robert_form)
148+ info = unsafe_load (cfg)
149+ li = Vector {Int} (unsafe_wrap (Vector{Cushort},info. li,Int (info. nlm)))
150+ mi = Vector {Int} (unsafe_wrap (Vector{Cushort},info. mi,Int (info. nlm)))
151+ ct = Vector {Float64} (unsafe_wrap (Vector{Cdouble},info. ct,Int (info. nlat)))
152+ st = Vector {Float64} (unsafe_wrap (Vector{Cdouble},info. st,Int (info. nlat)))
153+ stream = new {N,T} (cfg, norm, shtype, robert_form, info. nlm, info. lmax, info. mmax, info. mres, info. nlat_2, info. nlat, info. nphi, info. nspat, li, mi, ct, st, info. nlat_padded, info. nlm_cplx)
126154 finalizer (x-> shtns_destroy (x. cfg), stream)
127155 return stream
128156 end
@@ -142,43 +170,29 @@ mutable struct SHTnsCfg{N<:SHTnsNorm, T<:SHTnsType}
142170 robert_form && shtns_robert_form (cfg,1 )
143171 info = unsafe_load (cfg)
144172 shtns_set_grid_auto (cfg, shtype, eps, nl_order, Ref (info. nlat), Ref (info. nphi))
145- stream = new {N,T} (cfg, norm, shtype, robert_form)
173+ info = unsafe_load (cfg)
174+ li = Vector {Int} (unsafe_wrap (Vector{Cushort},info. li,Int (info. nlm)))
175+ mi = Vector {Int} (unsafe_wrap (Vector{Cushort},info. mi,Int (info. nlm)))
176+ ct = Vector {Float64} (unsafe_wrap (Vector{Cdouble},info. ct,Int (info. nlat)))
177+ st = Vector {Float64} (unsafe_wrap (Vector{Cdouble},info. st,Int (info. nlat)))
178+ stream = new {N,T} (cfg, norm, shtype, robert_form, info. nlm, info. lmax, info. mmax, info. mres, info. nlat_2, info. nlat, info. nphi, info. nspat, li, mi, ct, st, info. nlat_padded, info. nlm_cplx)
146179 finalizer (x-> shtns_destroy (x. cfg), stream)
147180 return stream
148181 end
149182
150183 end
151184
152185
153- function Base. propertynames (:: SHTnsCfg , private:: Bool = false )
154- publicnames = (:nlm , :lmax , :mmax , :mres , :nlat_2 , :nlat , :nphi ,
155- :nspat , :li , :mi , :ct , :st , :nlat_padded , :nlm_cplx , :norm , :type , :csphase , :robert_form )
156- privatenames = (:cfg , )
157- if private
158- return (publicnames... , privatenames... )
159- else
160- return publicnames
161- end
162- end
163-
164- function Base. getproperty (cfg:: SHTnsCfg , p:: Symbol )
165- if p ∈ (:nlm , :lmax , :mmax , :mres , :nlat_2 , :nlat , :nphi ,
166- :nspat , :nlat_padded , :nlm_cplx )
167- return Int (getproperty (unsafe_load (cfg. cfg),p))
168- elseif p ∈ (:li , :mi )
169- info = unsafe_load (cfg. cfg)
170- u = Vector {Int} (unsafe_wrap (Vector{Cushort},getproperty (info,p),Int (info. nlm)))
171- return u
172- elseif p ∈ (:ct , :st )
173- info = unsafe_load (cfg. cfg)
174- u = Vector {Float64} (unsafe_wrap (Vector{Cdouble},getproperty (info,p),Int (info. nlat)))
175- return u
176- elseif p ∈ (:norm , :type )
177- return getfield (cfg, p)
178- else
179- return getfield (cfg, p)
180- end
181- end
186+ # function Base.propertynames(::SHTnsCfg, private::Bool=false)
187+ # publicnames = (:nlm, :lmax, :mmax, :mres, :nlat_2, :nlat, :nphi,
188+ # :nspat, :li, :mi, :ct, :st, :nlat_padded, :nlm_cplx, :norm, :type, :robert_form)
189+ # privatenames = (:cfg, )
190+ # if private
191+ # return (publicnames..., privatenames...)
192+ # else
193+ # return publicnames
194+ # end
195+ # end
182196
183197function Base. show (io:: IO , mime:: MIME{Symbol("text/plain")} , cfg:: SHTnsCfg )
184198 summary (io, cfg); println (io)
0 commit comments