1 /*
2  *  This file is part of libsharp2.
3  *
4  *  libsharp2 is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  libsharp2 is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with libsharp2; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 
19 /* libsharp2 is being developed at the Max-Planck-Institut fuer Astrophysik */
20 
21 /*! \file sharp_almhelpers.c
22  *  Spherical transform library
23  *
24  *  Copyright (C) 2008-2019 Max-Planck-Society
25  *  \author Martin Reinecke
26  */
27 
28 #include "libsharp2/sharp_almhelpers.h"
29 #include "libsharp2/sharp_utils.h"
30 
sharp_make_triangular_alm_info(int lmax,int mmax,int stride,sharp_alm_info ** alm_info)31 void sharp_make_triangular_alm_info (int lmax, int mmax, int stride,
32   sharp_alm_info **alm_info)
33   {
34   sharp_alm_info *info = RALLOC(sharp_alm_info,1);
35   info->lmax = lmax;
36   info->nm = mmax+1;
37   info->mval = RALLOC(int,mmax+1);
38   info->mvstart = RALLOC(ptrdiff_t,mmax+1);
39   info->stride = stride;
40   info->flags = 0;
41   ptrdiff_t tval = 2*lmax+1;
42   for (ptrdiff_t m=0; m<=mmax; ++m)
43     {
44     info->mval[m] = m;
45     info->mvstart[m] = stride*((m*(tval-m))>>1);
46     }
47   *alm_info = info;
48   }
49 
sharp_make_rectangular_alm_info(int lmax,int mmax,int stride,sharp_alm_info ** alm_info)50 void sharp_make_rectangular_alm_info (int lmax, int mmax, int stride,
51   sharp_alm_info **alm_info)
52   {
53   sharp_alm_info *info = RALLOC(sharp_alm_info,1);
54   info->lmax = lmax;
55   info->nm = mmax+1;
56   info->mval = RALLOC(int,mmax+1);
57   info->mvstart = RALLOC(ptrdiff_t,mmax+1);
58   info->stride = stride;
59   info->flags = 0;
60   for (ptrdiff_t m=0; m<=mmax; ++m)
61     {
62     info->mval[m] = m;
63     info->mvstart[m] = stride*m*(lmax+1);
64     }
65   *alm_info = info;
66   }
67 
sharp_make_mmajor_real_packed_alm_info(int lmax,int stride,int nm,const int * ms,sharp_alm_info ** alm_info)68 void sharp_make_mmajor_real_packed_alm_info (int lmax, int stride,
69   int nm, const int *ms, sharp_alm_info **alm_info)
70   {
71   ptrdiff_t idx;
72   int f;
73   sharp_alm_info *info = RALLOC(sharp_alm_info,1);
74   info->lmax = lmax;
75   info->nm = nm;
76   info->mval = RALLOC(int,nm);
77   info->mvstart = RALLOC(ptrdiff_t,nm);
78   info->stride = stride;
79   info->flags = SHARP_PACKED | SHARP_REAL_HARMONICS;
80   idx = 0;  /* tracks the number of 'consumed' elements so far; need to correct by m */
81   for (int im=0; im!=nm; ++im)
82     {
83     int m=(ms==NULL)?im:ms[im];
84     f = (m==0) ? 1 : 2;
85     info->mval[im] = m;
86     info->mvstart[im] = stride * (idx - f * m);
87     idx += f * (lmax + 1 - m);
88     }
89   *alm_info = info;
90   }
91