source: Sophya/trunk/Cosmo/SimLSS/cmvgsm2cube.cc@ 3830

Last change on this file since 3830 was 3790, checked in by cmv, 15 years ago

etude des cubes generes par le GSM, cmv 28/06/2010

File size: 2.4 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdlib.h>
4#include <stdio.h>
5#include <iostream>
6#include <string.h>
7#include <unistd.h>
8#include <vector>
9
10#include "fioarr.h"
11#include "skymap.h"
12
13// set fname = ( `cat gsm820948.list | awk '{print $3}' | sed 's/data/ppf/'` )
14// cmvgsm2cube -o gsm820948_cube.ppf -p 360,0.1666667,160. -t 360,0.1666667,30. $fname
15
16void usage(void)
17{
18cout
19<<"cmvgsm2cube [options] liste_des_spheres_healpix"<<endl
20<<" -o outname.ppf : ppf cube output file name (def=cmvgsm2cube.ppf)"<<endl
21<<" -p nphi,dphi,phi0 : phi0 -> phi0+nphi*dphi (degres)"<<endl
22<<" -t ntheta,dtheta,theta0 : theta0 -> theta0+ntheta*dtheta (degres)"<<endl
23<<endl;
24}
25
26
27int main(int narg,char *arg[])
28{
29 string ppfrn = "cmvgsm2cube.ppf";
30 int nphi=0, ntheta=0;
31 double dphi=-1., phi0=0.;
32 double dtheta=-1., theta0=0.;
33
34 if(narg<=1) {usage(); return -1;}
35
36// Read arguments
37 char c;
38 while ((c = getopt(narg, arg, "ho:p:t:")) != -1) {
39 switch (c) {
40 case 'o' :
41 ppfrn = optarg;
42 break;
43 case 'p' :
44 sscanf(optarg,"%d,%lf,%lf",&nphi,&dphi,&phi0);
45 break;
46 case 't' :
47 sscanf(optarg,"%d,%lf,%lf",&ntheta,&dtheta,&theta0);
48 break;
49 case 'h' :
50 default:
51 usage();
52 return -1;
53 }
54 }
55
56 if(nphi<=0 || dphi<=0. || ntheta<=0 || dtheta<=0.) {
57 cout<<"bad value for transverse dim."<<endl;
58 return -2;
59 }
60 cout<<"nphi="<<nphi<<" dphi="<<dphi<<" phi0="<<phi0<<endl;
61 cout<<"ntheta="<<ntheta<<" dtheta="<<dtheta<<" theta0="<<theta0<<" deg"<<endl;
62
63 vector<string> sphname;
64 for(int i=optind;i<narg;i++) sphname.push_back(arg[i]);
65 if(sphname.size()==0) {usage(); return -3;}
66 cout<<"Number of spheres "<<sphname.size()<<endl;
67
68 TArray<r_4> Cube(sphname.size(),nphi,ntheta);
69 Cube = 0.;
70 for(unsigned int is=0;is<sphname.size();is++) {
71
72 cout<<"... "<<sphname[is]<<endl;
73 PInPersist pis(sphname[is]);
74 SphereHEALPix<r_4> sph;
75 pis>>PPFNameTag("sph")>>sph;
76
77 for(int it=0;it<ntheta;it++) {
78 double t = theta0 + it*dtheta; t *= M_PI/180.;
79 if(t<0. || t>M_PI) continue;
80 for(int ip=0;ip<nphi;ip++) {
81 double p = phi0 + ip*dphi; p *= M_PI/180.;
82 while(p<0.) p += 2.*M_PI;
83 while(p>=2.*M_PI) p -= 2.*M_PI;
84 int_4 ksph = sph.PixIndexSph(t,p);
85 Cube(is,ip,it) = sph(ksph);
86 }
87 }
88
89 }
90
91 POutPersist pos(ppfrn);
92 pos<<PPFNameTag("cube")<<Cube;
93
94 return 0;
95}
96
97/*
98openppf cmvgsm2cube.ppf
99
100print cube
101
102objaoper cube sliceyz 0
103objaoper cube sliceyz 128
104objaoper cube sliceyz 255
105objaoper cube slicexy 90
106
107 */
Note: See TracBrowser for help on using the repository browser.