35 #include "fitshandle.h" 37 #include "safe_cast.h" 38 #include "share_utils.h" 44 if (inp.key_present(
"MAX-LPOL") && inp.key_present(
"MAX-MPOL"))
46 inp.get_key (
"MAX-LPOL",lmax);
47 inp.get_key (
"MAX-MPOL",mmax);
51 int n_alms = safe_cast<
int>(inp.nelems(1));
54 chunkMaker cm(n_alms,inp.efficientChunkSize(1));
56 while(cm.getNext(offset,ppix))
59 inp.read_column(1,index,offset);
61 for (tsize i=0; i<ppix; ++i)
63 int l = isqrt(index[i]-1);
64 int m = index[i] - l*l - l - 1;
71 void get_almsize(
const string &filename,
int &lmax,
int &mmax,
int hdunum)
85 for (
int hdu=2; hdu<=4; ++hdu)
89 if (tlmax>lmax) lmax=tlmax;
90 if (tmmax>mmax) mmax=tmmax;
95 (fitshandle &inp,
Alm<xcomplex<T> >&alms,
int lmax,
int mmax)
97 int n_alms = safe_cast<
int>(inp.nelems(1));
101 alms.Set(lmax, mmax);
103 int max_index = lmax*lmax + lmax + mmax + 1;
104 chunkMaker cm(n_alms,inp.efficientChunkSize(1));
106 while(cm.getNext(offset,ppix))
109 re.alloc(ppix); im.alloc(ppix);
110 inp.read_column(1,index,offset);
111 inp.read_column(2,re,offset);
112 inp.read_column(3,im,offset);
114 for (tsize i=0; i<ppix; ++i)
116 if (index[i]>max_index)
continue;
118 int l = isqrt(index[i]-1);
119 int m = index[i] - l*l - l - 1;
120 planck_assert(m>=0,
"negative m encountered");
121 planck_assert(l>=m,
"wrong l,m combination");
122 if ((l<=lmax) && (m<=mmax))
123 alms(l,m) = xcomplex<T> (re[i], im[i]);
129 Alm<xcomplex<double> > &alms,
int lmax,
int mmax);
131 Alm<xcomplex<float> > &alms,
int lmax,
int mmax);
135 (
const string &filename,
Alm<xcomplex<T> >&alms,
int lmax,
int mmax,
140 inp.goto_hdu(hdunum);
145 Alm<xcomplex<double> > &alms,
int lmax,
int mmax,
int hdunum);
147 Alm<xcomplex<float> > &alms,
int lmax,
int mmax,
int hdunum);
151 (fitshandle &out,
const Alm<xcomplex<T> > &alms,
int lmax,
int mmax,
154 vector<fitscolumn> cols;
155 cols.push_back (fitscolumn(
"index",
"l*l+l+m+1",1,PLANCK_INT32));
156 cols.push_back (fitscolumn(
"real",
"unknown",1,datatype));
157 cols.push_back (fitscolumn(
"imag",
"unknown",1,datatype));
158 out.insert_bintab(cols);
162 int lm=alms.Lmax(), mm=alms.Mmax();
163 int n_alms = ((mmax+1)*(mmax+2))/2 + (mmax+1)*(lmax-mmax);
166 chunkMaker cm(n_alms,out.efficientChunkSize(1));
168 while(cm.getNext(offset,ppix))
171 re.alloc(ppix); im.alloc(ppix);
172 for (tsize i=0; i<ppix; ++i)
174 index[i] = l*l + l + m + 1;
175 if ((l<=lm) && (m<=mm))
176 { re[i] = alms(l,m).real(); im[i] = alms(l,m).imag(); }
178 { re[i] = 0; im[i] = 0; }
180 if ((m>l) || (m>mmax)) { ++l; m=0; }
182 out.write_column(1,index,offset);
183 out.write_column(2,re,offset);
184 out.write_column(3,im,offset);
186 out.set_key(
"MAX-LPOL",lmax,
"highest l in the table");
187 out.set_key(
"MAX-MPOL",mmax,
"highest m in the table");
191 (fitshandle &out,
const Alm<xcomplex<double> > &alms,
int lmax,
192 int mmax, PDT datatype);
194 (fitshandle &out,
const Alm<xcomplex<float> > &alms,
int lmax,
195 int mmax, PDT datatype);
199 (fitshandle &out,
const Alm<xcomplex<T> > &alms,
int lmax,
int mmax,
202 vector<fitscolumn> cols;
203 cols.push_back (fitscolumn(
"index",
"l*l+l+m+1",1,PLANCK_INT32));
204 cols.push_back (fitscolumn(
"real",
"unknown",1,datatype));
205 cols.push_back (fitscolumn(
"imag",
"unknown",1,datatype));
206 out.insert_bintab(cols);
211 for (
int m=0; m<=mmax; ++m)
212 for (
int l=m; l<=lmax; ++l)
213 if (norm(alms(l,m))>0) ++n_alms;
216 int real_lmax=0, real_mmax=0;
217 chunkMaker cm(n_alms,out.efficientChunkSize(1));
219 while(cm.getNext(offset,ppix))
222 re.alloc(ppix); im.alloc(ppix);
223 for (tsize i=0; i<ppix; ++i)
225 while (norm(alms(l,m))==0)
228 if ((m>l) || (m>mmax)) { ++l; m=0; }
230 index[i] = l*l + l + m + 1;
231 re[i] = alms(l,m).real();
232 im[i] = alms(l,m).imag();
233 if (l>real_lmax) real_lmax=l;
234 if (m>real_mmax) real_mmax=m;
236 if ((m>l) || (m>mmax)) { ++l; m=0; }
238 out.write_column(1,index,offset);
239 out.write_column(2,re,offset);
240 out.write_column(3,im,offset);
242 out.set_key(
"MAX-LPOL",real_lmax,
"highest l in the table");
243 out.set_key(
"MAX-MPOL",real_mmax,
"highest m in the table");
247 (fitshandle &out,
const Alm<xcomplex<double> > &alms,
int lmax,
248 int mmax, PDT datatype);
250 (fitshandle &out,
const Alm<xcomplex<float> > &alms,
int lmax,
251 int mmax, PDT datatype);
void write_Alm_to_fits(fitshandle &out, const Alm< xcomplex< T > > &alms, int lmax, int mmax, PDT datatype)
void read_Alm_from_fits(fitshandle &inp, Alm< xcomplex< T > > &alms, int lmax, int mmax)
void get_almsize_pol(const std::string &filename, int &lmax, int &mmax)
void get_almsize(fitshandle &inp, int &lmax, int &mmax)
void write_compressed_Alm_to_fits(fitshandle &out, const Alm< xcomplex< T > > &alms, int lmax, int mmax, PDT datatype)