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

Last change on this file since 4045 was 3983, checked in by cmv, 14 years ago

amelioration des reconstructions et fits du GSM, cmv 4/5/2011

File size: 3.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 rname = gsm820948
14// set fname = ( `cat ${rname}.list | awk '{print $3}' | sed 's/data/ppf/'` )
15// cmvgsm2cube -o ${rname}_cube.ppf -p 360,0.1666667,160. -t 360,0.1666667,30. $fname
16
17void usage(void)
18{
19cout
20<<"cmvgsm2cube [options] liste_des_spheres_healpix"<<endl
21<<" -o outname.ppf : ppf cube output file name (def=cmvgsm2cube.ppf)"<<endl
22<<" -p nphi,dphi,phi0 : phi0 -> phi0 + nphi*dphi (degres)"<<endl
23<<" -t ntheta,dtheta,theta0 : theta0 -> theta0 + ntheta*dtheta (degres)"<<endl
24<<endl;
25}
26
27
28int main(int narg,char *arg[])
29{
30 string ppfrn = "cmvgsm2cube.ppf";
31 int nphi=0, ntheta=0;
32 double dphi=-1., phi0=0.;
33 double dtheta=-1., theta0=0.;
34
35 if(narg<=1) {usage(); return -1;}
36
37// Read arguments
38 char c;
39 while ((c = getopt(narg, arg, "ho:p:t:")) != -1) {
40 switch (c) {
41 case 'o' :
42 ppfrn = optarg;
43 break;
44 case 'p' :
45 sscanf(optarg,"%d,%lf,%lf",&nphi,&dphi,&phi0);
46 break;
47 case 't' :
48 sscanf(optarg,"%d,%lf,%lf",&ntheta,&dtheta,&theta0);
49 break;
50 case 'h' :
51 default:
52 usage();
53 return -1;
54 }
55 }
56
57 if(nphi<=0 || dphi<=0. || ntheta<=0 || dtheta<=0.) {
58 cout<<"bad value for transverse dim."<<endl;
59 return -2;
60 }
61 cout<<"nphi="<<nphi<<" dphi="<<dphi<<" phi0="<<phi0<<endl;
62 cout<<"ntheta="<<ntheta<<" dtheta="<<dtheta<<" theta0="<<theta0<<" deg"<<endl;
63
64 vector<string> sphname;
65 for(int i=optind;i<narg;i++) sphname.push_back(arg[i]);
66 if(sphname.size()==0) {usage(); return -3;}
67 cout<<"Number of spheres "<<sphname.size()<<endl;
68
69 TVector<r_4> Theta(ntheta);
70 int nthgood = 0;
71 float thmin = 1.e30, thmax = -1.e30;
72 for(int it=0;it<ntheta;it++) {
73 Theta(it) = -9999.;
74 double t = theta0 + it*dtheta; t *= M_PI/180.;
75 if(t<0. || t>M_PI) continue; // [0,Pi]
76 Theta(it) = t;
77 nthgood += 1;
78 if(t<thmin) thmin = t;
79 if(t>thmax) thmax = t;
80 }
81 cout<<"Theta: ngood="<<nthgood<<" ["<<thmin*180/M_PI<<","<<thmax*180/M_PI
82 <<"] middle="<<0.5*(thmin+thmax)*180/M_PI<<endl;
83
84 TVector<r_4> Phi(nphi);
85 float phmin = 1.e30, phmax = -1.e30;
86 for(int ip=0;ip<nphi;ip++) {
87 double p = phi0 + ip*dphi; p *= M_PI/180.;
88 while(p<0.) p += 2.*M_PI;
89 while(p>=2.*M_PI) p -= 2.*M_PI;
90 Phi(ip) = p;
91 if(p<phmin) phmin = p;
92 if(p>phmax) phmax = p;
93 }
94 cout<<"Phi: ["<<phmin*180/M_PI<<","<<phmax*180/M_PI
95 <<"] middle="<<0.5*(phmin+phmax)*180/M_PI<<endl;
96
97
98 TVector<r_4> Freq(sphname.size()); Freq = -1.;
99 TArray<r_4> Cube(sphname.size(),nphi,ntheta); Cube = 0.;
100 for(unsigned int is=0;is<sphname.size();is++) {
101 cout<<"... "<<sphname[is]<<endl;
102 PInPersist pis(sphname[is]);
103 SphereHEALPix<r_4> sph;
104 pis>>PPFNameTag("sph")>>sph;
105 Freq(is) = (r_4)sph.Info()["FMHz"];
106 for(int it=0;it<Theta.Size();it++) {
107 double t = Theta(it);
108 if(t<0.) continue;
109 for(int ip=0;ip<Phi.Size();ip++) {
110 double p = Phi(ip);
111 int_4 ksph = sph.PixIndexSph(t,p);
112 Cube(is,ip,it) = sph(ksph);
113 }
114 }
115 }
116
117 POutPersist pos(ppfrn);
118 pos<<PPFNameTag("cube")<<Cube;
119 pos<<PPFNameTag("theta")<<Theta;
120 pos<<PPFNameTag("phi")<<Phi;
121 pos<<PPFNameTag("freq")<<Freq;
122
123 return 0;
124}
125
126/*
127openppf cmvgsm2cube.ppf
128
129print cube
130
131n/plot phi.val*180./M_PI%n ! ! "cpts"
132n/plot theta.val*180./M_PI%n ! ! "cpts"
133disp freq
134
135objaoper cube sliceyz 0
136objaoper cube sliceyz 128
137objaoper cube sliceyz 255
138objaoper cube slicexy 90
139
140 */
Note: See TracBrowser for help on using the repository browser.