[3790] | 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 |
|
---|
[3983] | 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
|
---|
[3790] | 16 |
|
---|
| 17 | void usage(void)
|
---|
| 18 | {
|
---|
| 19 | cout
|
---|
| 20 | <<"cmvgsm2cube [options] liste_des_spheres_healpix"<<endl
|
---|
| 21 | <<" -o outname.ppf : ppf cube output file name (def=cmvgsm2cube.ppf)"<<endl
|
---|
[3983] | 22 | <<" -p nphi,dphi,phi0 : phi0 -> phi0 + nphi*dphi (degres)"<<endl
|
---|
| 23 | <<" -t ntheta,dtheta,theta0 : theta0 -> theta0 + ntheta*dtheta (degres)"<<endl
|
---|
[3790] | 24 | <<endl;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | int 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 |
|
---|
[3983] | 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.;
|
---|
[3790] | 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;
|
---|
[3983] | 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 | }
|
---|
[3790] | 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | POutPersist pos(ppfrn);
|
---|
| 118 | pos<<PPFNameTag("cube")<<Cube;
|
---|
[3983] | 119 | pos<<PPFNameTag("theta")<<Theta;
|
---|
| 120 | pos<<PPFNameTag("phi")<<Phi;
|
---|
| 121 | pos<<PPFNameTag("freq")<<Freq;
|
---|
[3790] | 122 |
|
---|
| 123 | return 0;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /*
|
---|
| 127 | openppf cmvgsm2cube.ppf
|
---|
| 128 |
|
---|
| 129 | print cube
|
---|
| 130 |
|
---|
[3983] | 131 | n/plot phi.val*180./M_PI%n ! ! "cpts"
|
---|
| 132 | n/plot theta.val*180./M_PI%n ! ! "cpts"
|
---|
| 133 | disp freq
|
---|
| 134 |
|
---|
[3790] | 135 | objaoper cube sliceyz 0
|
---|
| 136 | objaoper cube sliceyz 128
|
---|
| 137 | objaoper cube sliceyz 255
|
---|
| 138 | objaoper cube slicexy 90
|
---|
| 139 |
|
---|
| 140 | */
|
---|