int main(int argc,char*argv[]){ struct timeval tv1, tv2; gettimeofday(&tv1, NULL); const int lvl=7; const int size=256; int count=childs, dec=lvl; while(--dec > 1) count=(count*childs)+childs; ++count; pool=new node_t[count]; /* raw */ end=pool+count; create(pool,lvl,count,v_t(0,0,0),v_t(+.25,+1,-.5).norm(),1.); /* cooked */ printf("P2\n%d %d\n%d\n", size, size, size); // std::cout << "P2\n" << size << " " << size << "\n" << size << "\n"; trace_rgss(size, size); /* served */ gettimeofday(&tv2, NULL); printf ("Total time = %f seconds\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); return 0; }
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr TSDFVolumeOctree::renderColoredView (const Eigen::Affine3d& trans, int downsampleBy) const { pcl::PointCloud<pcl::PointNormal>::Ptr grayscale = renderView (trans, downsampleBy); pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr colored (new pcl::PointCloud<pcl::PointXYZRGBNormal> (grayscale->width, grayscale->height)); colored->is_dense = false; #pragma omp parallel for for (size_t i = 0; i < colored->size(); ++i) { pcl::PointXYZRGBNormal& pt = colored->at(i); pt.getVector3fMap() = grayscale->at(i).getVector3fMap(); pt.getNormalVector3fMap() = grayscale->at(i).getNormalVector3fMap(); if (pcl_isnan (pt.z)) continue; Eigen::Vector3f v_t = trans.cast<float> () * pt.getVector3fMap(); const OctreeNode* voxel = octree_->getContainingVoxel (v_t (0), v_t (1), v_t (2)); if (!voxel) continue; voxel->getRGB (pt.r, pt.g, pt.b); } return (colored); }
static void trace_rgss(const int width,const int height) { const double w=width,h=height,rcp=1/double(ss),scale=256./double(ss_sqr); ray_t ray(v_t(0,0,-4.5)); /* eye, looking into Z */ v_t rgss[ss_sqr]; for(int i=0;i<ss_sqr;++i) /*precomp.*/ { rgss[i]=v_t(grid[i][0]*rcp-w/2.,grid[i][1]*rcp-h/2.,0); } v_t scan(0,w-1,std::max(w,h)); /*scan line*/ for(int i=height;i;--i) { int lineMean = 0; for(int j=width;j;--j) { double g=0; for(int idx=0;idx < ss_sqr;++idx){ /*AA*/ ray.d=(scan+rgss[idx]).norm(); g+=ray_trace(pool,ray); /*trace*/ } lineMean += int(scale*g); scan.x+=1; /*next pixel*/ } printf("%d : %d\n", i, lineMean/width); scan.x=0;scan.y-=1; /*next line*/ } }
basis_t(const v_t&v){ const v_t n(v.norm()); if ((n.x*n.x !=1.)&(n.y*n.y !=1.)&(n.z*n.z !=1.)) {/*cough*/ b1=n; if(n.y*n.y>n.x*n.x) { if(n.y*n.y>n.z*n.z) b1.y=-b1.y; else b1.z=-b1.z; } else if(n.z*n.z > n.x*n.x) b1.z=-b1.z; else b1.x=-b1.x; } else b1=v_t(n.z,n.x,n.y);/*leaves some cases out,dodge them*/ up=n; b2=up.cross(b1); b1=up.cross(b2); }
static const double infinity = 1./0, epsilon = 1e-12; struct v_t{ double x,y,z;v_t(){} v_t(const double a,const double b,const double c):x(a),y(b),z(c){} v_t operator+(const v_t&v)const{return v_t(x+v.x,y+v.y,z+v.z);} v_t operator-(const v_t&v)const{return v_t(x-v.x,y-v.y,z-v.z);} v_t operator-()const{return v_t(-x,-y,-z);} v_t operator*(const double d)const{return v_t(x*d,y*d,z*d);} v_t cross(const v_t&v)const{return v_t(y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x);} v_t norm()const{return*this*(1./sqrt(magsqr()));} double dot(const v_t&v)const{return x*v.x+y*v.y+z*v.z;} double magsqr()const{return dot(*this);} }; //static const v_t light(v_t(0.5,-.95,1.775).norm()); /*pick one*/ static const v_t light(v_t(-0.5,-.65,.9).norm()); /*fiat lux*/ struct ray_t{ v_t o,d; ray_t(const v_t&v):o(v){} ray_t(const v_t&v,const v_t&w):o(v),d(w){} }; struct hit_t { v_t n; double t; hit_t():n(v_t(0,0,0)),t(infinity){} }; struct sphere_t{ v_t o; double r;
N2::N2() : teplojomkost() { set_v_max( 26 ); v_t(1) = 0; v_Cp( 1 ) = 0.2482; v_Cv( 1 ) = 0.1773; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.2489; v_Cv( 2 ) = 0.178; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.2512; v_Cv( 3 ) = 0.1804; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.2554; v_Cv( 4 ) = 0.1845; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.2607; v_Cv( 5 ) = 0.1898; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.2664; v_Cv( 6 ) = 0.1955; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.2721; v_Cv( 7 ) = 0.2012; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.2774; v_Cv( 8 ) = 0.2065; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.2822; v_Cv( 9 ) = 0.2113; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.2864; v_Cv( 10 ) = 0.2156; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.2902; v_Cv( 11 ) = 0.2193; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.2935; v_Cv( 12 ) = 0.2226; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.2964; v_Cv( 13 ) = 0.2255; v_S( 13 ) = 0; v_t(14) = 1300; v_Cp( 14 ) = 0.2989; v_Cv( 14 ) = 0.228; v_S( 14 ) = 0; v_t(15) = 1400; v_Cp( 15 ) = 0.3011; v_Cv( 15 ) = 0.2302; v_S( 15 ) = 0; v_t(16) = 1500; v_Cp( 16 ) = 0.303; v_Cv( 16 ) = 0.2322; v_S( 16 ) = 0; v_t(17) = 1600; v_Cp( 17 ) = 0.3048; v_Cv( 17 ) = 0.2339; v_S( 17 ) = 0; v_t(18) = 1700; v_Cp( 18 ) = 0.3063; v_Cv( 18 ) = 0.2354; v_S( 18 ) = 0; v_t(19) = 1800; v_Cp( 19 ) = 0.3077; v_Cv( 19 ) = 0.2358; v_S( 19 ) = 0; v_t(20) = 1900; v_Cp( 20 ) = 0.3089; v_Cv( 20 ) = 0.238; v_S( 20 ) = 0; v_t(21) = 2000; v_Cp( 21 ) = 0.31; v_Cv( 21 ) = 0.2391; v_S( 21 ) = 0; v_t(22) = 2100; v_Cp( 22 ) = 0.311; v_Cv( 22 ) = 0.2401; v_S( 22 ) = 0; v_t(23) = 2200; v_Cp( 23 ) = 0.312; v_Cv( 23 ) = 0.2411; v_S( 23 ) = 0; v_t(24) = 2300; v_Cp( 24 ) = 0.3128; v_Cv( 24 ) = 0.2419; v_S( 24 ) = 0; v_t(25) = 2400; v_Cp( 25 ) = 0.3136; v_Cv( 25 ) = 0.2427; v_S( 25 ) = 0; v_t(26) = 2500; v_Cp( 26 ) = 0.3143; v_Cv( 26 ) = 0.2434; v_S( 26 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=2500) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
v_t cross(const v_t&v)const{return v_t(y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x);}
v_t operator-()const{return v_t(-x,-y,-z);}
C3H6::C3H6() : teplojomkost() { set_v_max( 13 ); v_t(1) = 0; v_Cp( 1 ) = 0.3406; v_Cv( 1 ) = 0.2933; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.4299; v_Cv( 2 ) = 0.3826; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.5159; v_Cv( 3 ) = 0.4686; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.5915; v_Cv( 4 ) = 0.5442; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.6576; v_Cv( 5 ) = 0.6103; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.7146; v_Cv( 6 ) = 0.6673; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.7643; v_Cv( 7 ) = 0.717; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.8078; v_Cv( 8 ) = 0.7605; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.8456; v_Cv( 9 ) = 0.7983; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.8784; v_Cv( 10 ) = 0.8311; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.9071; v_Cv( 11 ) = 0.8598; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.9321; v_Cv( 12 ) = 0.8848; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.9535; v_Cv( 13 ) = 0.9062; v_S( 13 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=1200) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
NO::NO() : teplojomkost() { set_v_max( 31 ); v_t(1) = 0; v_Cp( 1 ) = 0.2386; v_Cv( 1 ) = 0.1724; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.2381; v_Cv( 2 ) = 0.1719; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.2414; v_Cv( 3 ) = 0.1752; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 5.2472; v_Cv( 4 ) = 0.181; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.2534; v_Cv( 5 ) = 0.1872; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.2594; v_Cv( 6 ) = 0.1932; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.2648; v_Cv( 7 ) = 0.1986; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.2695; v_Cv( 8 ) = 0.2033; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.2736; v_Cv( 9 ) = 0.2074; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.277; v_Cv( 10 ) = 0.2108; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.2799; v_Cv( 11 ) = 0.2137; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.2824; v_Cv( 12 ) = 0.2165; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.2845; v_Cv( 13 ) = 0.2183; v_S( 13 ) = 0; v_t(14) = 1300; v_Cp( 14 ) = 0.2864; v_Cv( 14 ) = 0.2202; v_S( 14 ) = 0; v_t(15) = 1400; v_Cp( 15 ) = 0.2881; v_Cv( 15 ) = 0.2219; v_S( 15 ) = 0; v_t(16) = 1500; v_Cp( 16 ) = 0.2895; v_Cv( 16 ) = 0.2233; v_S( 16 ) = 0; v_t(17) = 1600; v_Cp( 17 ) = 0.2907; v_Cv( 17 ) = 0.2245; v_S( 17 ) = 0; v_t(18) = 1700; v_Cp( 18 ) = 0.2918; v_Cv( 18 ) = 0.2256; v_S( 18 ) = 0; v_t(19) = 1800; v_Cp( 19 ) = 0.2928; v_Cv( 19 ) = 0.2267; v_S( 19 ) = 0; v_t(20) = 1900; v_Cp( 20 ) = 0.2938; v_Cv( 20 ) = 0.2276; v_S( 20 ) = 0; v_t(21) = 2000; v_Cp( 21 ) = 0.2947; v_Cv( 21 ) = 0.2285; v_S( 21 ) = 0; v_t(22) = 2100; v_Cp( 22 ) = 0.2954; v_Cv( 22 ) = 0.2292; v_S( 22 ) = 0; v_t(23) = 2200; v_Cp( 23 ) = 0.296; v_Cv( 23 ) = 0.2299; v_S( 23 ) = 0; v_t(24) = 2300; v_Cp( 24 ) = 0.2967; v_Cv( 24 ) = 0.2305; v_S( 24 ) = 0; v_t(25) = 2400; v_Cp( 25 ) = 0.2973; v_Cv( 25 ) = 0.2311; v_S( 25 ) = 0; v_t(26) = 2500; v_Cp( 26 ) = 0.2978; v_Cv( 26 ) = 0.2317; v_S( 26 ) = 0; v_t(27) = 2600; v_Cp( 27 ) = 0.2984; v_Cv( 27 ) = 0.2322; v_S( 27 ) = 0; v_t(28) = 2700; v_Cp( 28 ) = 0.2989; v_Cv( 28 ) = 0.2323; v_S( 28 ) = 0; v_t(29) = 2800; v_Cp( 29 ) = 0.2994; v_Cv( 29 ) = 0.2333; v_S( 29 ) = 0; v_t(30) = 2900; v_Cp( 30 ) = 0.2999; v_Cv( 30 ) = 0.2338; v_S( 30 ) = 0; v_t(31) = 3000; v_Cp( 31 ) = 0.3004; v_Cv( 31 ) = 0.2342; v_S( 31 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=3000) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
CH4::CH4() : teplojomkost() { set_v_max( 13 ); v_t(1) = 0; v_Cp( 1 ) = 0.5172; v_Cv( 1 ) = 0.3934; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.5848; v_Cv( 2 ) = 0.461; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.6704; v_Cv( 3 ) = 0.5466; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.7584; v_Cv( 4 ) = 0.6346; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.843; v_Cv( 5 ) = 0.7192; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.921; v_Cv( 6 ) = 0.7972; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.9919; v_Cv( 7 ) = 0.8681; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 1.056; v_Cv( 8 ) = 0.9322; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 1.1129; v_Cv( 9 ) = 0.9891; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 1.1638; v_Cv( 10 ) = 1.04; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 1.2089; v_Cv( 11 ) = 1.0851; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 1.2483; v_Cv( 12 ) = 1.1245; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 1.282; v_Cv( 13 ) = 1.1582; v_S( 13 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=1200) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
C3H8::C3H8() : teplojomkost() { set_v_max( 13 ); v_t(1) = 0; v_Cp( 1 ) = 0.3701; v_Cv( 1 ) = 0.325; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.4817; v_Cv( 2 ) = 0.4366; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.5871; v_Cv( 3 ) = 0.512; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.677; v_Cv( 4 ) = 0.6318; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.755; v_Cv( 5 ) = 0.7098; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.8237; v_Cv( 6 ) = 0.7786; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.8831; v_Cv( 7 ) = 0.838; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.9353; v_Cv( 8 ) = 0.8901; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.9775; v_Cv( 9 ) = 0.9323; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 1.0151; v_Cv( 10 ) = 0.97; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 1.0496; v_Cv( 11 ) = 1.0044; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 1.0811; v_Cv( 12 ) = 1.036; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 1.1094; v_Cv( 13 ) = 1.0643; v_S( 13 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=1200) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
CO2::CO2() : teplojomkost() { set_v_max( 26 ); v_t( 1 ) = 0.0 ; v_Cp( 1 ) = 0.1946 ; v_Cv( 1 ) = 0.1495; v_S( 1 ) = 0.0; v_t( 2 ) = 100.0 ; v_Cp( 2 ) = 0.2182 ; v_Cv( 2 ) = 0.1731; v_S( 2 ) = 0.0; v_t( 3 ) = 200.0 ; v_Cp( 3 ) = 0.2371 ; v_Cv( 3 ) = 0.1920; v_S( 3 ) = 0.0; v_t( 4 ) = 300.0 ; v_Cp( 4 ) = 0.2524 ; v_Cv( 4 ) = 0.2073; v_S( 4 ) = 0.0; v_t( 5 ) = 400.0 ; v_Cp( 5 ) = 0.2652 ; v_Cv( 5 ) = 0.2200; v_S( 5 ) = 0.0; v_t( 6 ) = 500.0 ; v_Cp( 6 ) = 0.2758 ; v_Cv( 6 ) = 0.2307; v_S( 6 ) = 0.0; v_t( 7 ) = 600.0 ; v_Cp( 7 ) = 0.2847 ; v_Cv( 7 ) = 0.2395; v_S( 7 ) = 0.0; v_t( 8) = 700.0 ; v_Cp( 8 ) = 0.2921 ; v_Cv( 8 ) = 0.2470; v_S( 8 ) = 0.0; v_t( 9 ) = 800.0 ; v_Cp( 9 ) = 0.2984 ; v_Cv( 9 ) = 0.2532; v_S( 9 ) = 0.0; v_t( 10 ) = 900.0 ; v_Cp( 10 ) = 0.3037 ; v_Cv( 10 ) = 0.2585; v_S( 10 ) = 0.0; v_t( 11 ) = 1000.0 ; v_Cp( 11 ) = 0.3081 ; v_Cv( 11 ) = 0.2630; v_S( 11 ) = 0.0; v_t( 12 ) = 1100.0 ; v_Cp( 12 ) = 0.3119 ; v_Cv( 12 ) = 0.2668; v_S( 12 ) = 0.0; v_t( 13 ) = 1200.0 ; v_Cp( 13 ) = 0.3152 ; v_Cv( 13 ) = 0.2700; v_S( 13 ) = 0.0; v_t( 14 ) = 1300.0 ; v_Cp( 14 ) = 0.3180 ; v_Cv( 14 ) = 0.2728; v_S( 14 ) = 0.0; v_t( 15 ) = 1400.0 ; v_Cp( 15 ) = 0.3204 ; v_Cv( 15 ) = 0.2752; v_S( 15 ) = 0.0; v_t( 16 ) = 1500.0 ; v_Cp( 16 ) = 0.3224 ; v_Cv( 16 ) = 0.2773; v_S( 16 ) = 0.0; v_t( 17 ) = 1600.0 ; v_Cp( 17 ) = 0.3242 ; v_Cv( 17 ) = 0.2791; v_S( 17 ) = 0.0; v_t( 18 ) = 1700.0 ; v_Cp( 18 ) = 0.3257 ; v_Cv( 18 ) = 0.2806; v_S( 18 ) = 0.0; v_t( 19 ) = 1800.0 ; v_Cp( 19 ) = 0.3271 ; v_Cv( 19 ) = 0.2820; v_S( 19 ) = 0.0; v_t( 20 ) = 1900.0 ; v_Cp( 20 ) = 0.3282 ; v_Cv( 20 ) = 0.2831; v_S( 20 ) = 0.0; v_t( 21 ) = 2000.0 ; v_Cp( 21 ) = 0.3292 ; v_Cv( 21 ) = 0.2840; v_S( 21 ) = 0.0; v_t( 22 ) = 2100.0 ; v_Cp( 22 ) = 0.3300 ; v_Cv( 22 ) = 0.2848; v_S( 22 ) = 0.0; v_t( 23 ) = 2200.0 ; v_Cp( 23 ) = 0.3306 ; v_Cv( 23 ) = 0.2855; v_S( 23 ) = 0.0; v_t( 24 ) = 2300.0 ; v_Cp( 24 ) = 0.3311 ; v_Cv( 24 ) = 0.2860; v_S( 24 ) = 0.0; v_t( 25 ) = 2400.0 ; v_Cp( 25 ) = 0.3314 ; v_Cv( 25 ) = 0.2863; v_S( 25 ) = 0.0; v_t( 26 ) = 2500.0 ; v_Cp( 26 ) = 0.3315 ; v_Cv( 26 ) = 0.2864; v_S( 26 ) = 0.0; v_t=v_t/1000.0; reculc_polynoms(); cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=2500) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
int DoIt(){ /* Variable declarations */ /* Generic use variables */ int i,j,k,l,n; /* Generic loop counters */ /* DRMS/JSOC variables */ char *harpnum,*time_range; /* SHARPs ID and time range from module_args[] */ double umb_sig, pen_sig; /* Cutoffs for sunspots */ int num_divs; /* Number of divisions to break a data strip into for trend removal */ char *drms_query; /* The DRMS query we are going to send */ int num_query_chars; /* Number of characters in total query for malloc definition */ CmdParams_t *params=&cmdparams; /* For the module_args stuff */ DRMS_RecordSet_t *drms_ids; /* Holds the id structure of the records */ DRMS_Record_t *drms_record; /* Holds specific record information */ DRMS_Segment_t *drms_segment; /* Segment information */ int drms_status; /* Status variable */ int num_records; /* Number of records and variables to get the segment locations we need */ /* cfitsio-related variables */ fitsfile *v_ptr,*i_ptr,*c_ptr; /* Pointers for FITS files */ fitsfile *info_ptr; int v_status,i_status,c_status; /* Status checker for opening files */ int info_status; int hdu_pos,num_hdus; /* HDU number and location */ int needed_hdu; /* The HDU we want to be on */ int any_nulls; /* Nonzero if there are null values in data */ char i_filename[DRMS_MAXPATHLEN+1],v_filename[DRMS_MAXPATHLEN+1]; /* Containers for the filenames */ char c_filename[DRMS_MAXPATHLEN+1],info_filename[DRMS_MAXPATHLEN+1]; double nulval; /* Container for what null values in data should be set to */ long l_nulval; /* Needed FITS keywords */ int naxis1,naxis2,naxis; /* Length of axes */ double crpix1,crpix2; /* SHARPs CRPIX is the center of the Sun relative to the lower left of the patch (fortranL 1,1) */ double imcrpix1,imcrpix2; /* SHARPs IMCRPIX is the center of the Sun in full plate coordinates (fortran) */ double cdelt1,cdelt2; /* HMI pixel sizes in as */ double blank; /* Values of bad data */ double crota2,crln_obs,crlt_obs; /* Rotation, carrington observer location */ double dsun_obs,rsun_obs; /* Distance to and radius of the sun, observed at t_obs */ double obs_vr,obs_vw,obs_vn; /* Satellite velocity keywords */ TIME t_obs; /* Observation time, ZULU */ char **t_obs_s; /* String version of observation time */ long *quality; /* Data quality keyword */ /* Data-related variables */ double **vlos_dat, **inc_dat; /* Data arrays, size defined once naxis1/2 are known */ double **con_dat; long **info_dat; double *v_pixel_strip; /* Strip of pixels read from the field data */ double *i_pixel_strip; /* Strip of pixels read from the inclination data */ double *c_pixel_strip; /* Strip of pixels read from the continuum data */ long *info_pixel_strip; /* Strip of pixels read from the continuum data */ long fpixel[2]; /* Holds the location of pixel to be read */ LONGLONG nelements; /* Number of elements in a strip to be read (naxis2) */ FILE *outptr,*bad_outptr; /* Pointer to the outfile */ char outfile_name[25]; /* Name of the outfile */ char bad_outfile_name[24]; /* Name of the outfile for bad quality*/ /* Variables related to the actual task */ double rscx,rscy; /* Disk center, plate coordinates */ double rllx,rlly; /* Disk center, patch coordinates */ double rpllx,rplly; /* Lower left of patch, plate coordinates */ double **radius; /* Array to hold where the Sun's boundaries are, column major order */ double umb,pen; /* Intensity cutoffs for the umbra and penumbra */ double num_good; /* The number of nonzero continuum values in a sunspot region */ double mu; /* Angle from solar center */ double rsun_pix,xx,yy,r; /* Variables associated with radial boundaries */ long *t_secs; /* T_OBS time converted to seconds since UNIX epoch */ double *umb_p_vel,*umb_n_vel; /* Umbral LOS velocities */ double *pen_p_vel,*pen_n_vel; /* Penumbral LOS velocities */ double umb_p_counter,umb_n_counter; /* Counters for averages */ double pen_p_counter,pen_n_counter; double vr,vn,vw,vt; /* Various LOS velocities due to satellite motion and solar rotation */ double vlos; /* VLOS after removing all of the satellite motion and solar rotation */ double **y_axis; /* Array to be looped over wrt naxis2 to remove trends */ double **y_error; /* Error on y axis, taken as 1 */ double **x_axis; /* Array to be looped over that holds naxis1 information for fitting */ double x,y; /* Pixel location on the solar disk */ double ttx,tty,tx,ty,zz; /* Intermediate variables for coordinate conversions */ double lat,lon; /* Carrington coordinate latitude and longitude */ double p,t; /* Spherical phi and theta coordinates */ int noaa_ar; /* Active region number */ mp_result result; /* Fitting result structure */ mp_config config; /* Configuration options for fitting structure */ double perror[2]; /* Error on fitting coefficients */ double fit_params[2]; /* Fitting coefficients */ struct vars_struct v; /* Private data, shared between main and functions */ int fit_status; /* Fitting returned status */ int inv_len; /* Interval length for breaking data up */ /* Initialise variables that need it */ drms_status=0; memset(&result,0,sizeof(result)); memset(&config,0,sizeof(config)); /* Set the error stuff for cmfit */ result.xerror=perror; /* Set the default options for cmfit */ config.ftol=1.49012e-08; config.xtol=1.49012e-08; config.gtol=0.0; config.maxfev=0; /* Grab values from module_args[] */ harpnum=strdup(params_get_str(params,"harpnum")); time_range=strdup(params_get_str(params,"time_range")); umb_sig=params_get_double(params,"umb_sig"); pen_sig=params_get_double(params,"pen_sig"); num_divs=params_get_int(params,"num_divs"); /* Now we start the main program. The rough layout is as follows: 1. Query drms. Based on what we learn, either exit or grab what we need from it. 2. Loop through the files, calculate field stuff. 3. Print out a table of values at the end. */ /* Forge the DRMS query. */ num_query_chars=16+strlen(harpnum); /* hmi.sharp_720s[] is 16 characters */ if (time_range!="[]"){ num_query_chars+=strlen(time_range); } drms_query=calloc(num_query_chars,sizeof(char)); strcat(drms_query,"hmi.sharp_720s["); strcat(drms_query,harpnum); strcat(drms_query,"]"); if (time_range!="[]"){ strcat(drms_query,time_range); } /* Query DRMS for the records. */ printf("Querying DRMS. This may take some time.\n"); if (!(drms_ids=drms_open_records(drms_env,drms_query,&drms_status))){ printf("No record sets match your criteria. Check your SHARPs ID and your time range.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); free(drms_query); return 0; } free(drms_query); num_records=drms_ids->n; printf("%d records match. Checking to make sure we have the needed data segments.\n",num_records); drms_record=drms_ids->records[0]; if (!(drms_segment_lookup(drms_record,"vlos_mag"))){ printf("vlos_mag segment not present! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(drms_segment_lookup(drms_record,"inclination"))){ printf("Inclination segment not present! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(drms_segment_lookup(drms_record,"continuum"))){ printf("Continuum segment not present! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(drms_segment_lookup(drms_record,"info_map"))){ printf("Info_map segment not present! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } /* Now we can start. We loop over all records, get the keyword information we need, get the data, and then calculate. */ /* First set the size of some of the pointers that are intended to be arrays. */ /* Time-related arrays */ t_secs=malloc(num_records*sizeof(long)); t_obs_s=malloc(num_records*sizeof(char *)); for (i=0;i<num_records;i++){ t_obs_s[i]=malloc(T_OBS_LENGTH*sizeof(char)); } /* Data-related arrays */ umb_p_vel=malloc(num_records*sizeof(double)); pen_p_vel=malloc(num_records*sizeof(double)); umb_n_vel=malloc(num_records*sizeof(double)); pen_n_vel=malloc(num_records*sizeof(double)); /* Record quality */ quality=malloc(num_records*sizeof(long)); for (k=0;k<num_records;k++){ drms_record=drms_ids->records[k]; /* Check to see if we have data for a particular observation time */ if (!(t_obs=drms_getkey_time(drms_record,"T_OBS",&drms_status))){ printf("Keyword %s not present! Exiting.\n","T_OBS"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (time_is_invalid(t_obs)){ printf("Bad record, skipping.\n"); } else { if (k == 0){ /* Get active region number for pregame info */ if (!(noaa_ar=drms_getkey_int(drms_record,"NOAA_AR",&drms_status))){ printf("Keyword %s not present! Exiting.\n","NOAA_AR"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } /* Create data output filename */ sprintf(outfile_name,"AR%d.fvlos-output.dat",noaa_ar); sprintf(bad_outfile_name,"AR%d.bad-quality.dat",noaa_ar); /* Print out some stats before we run */ printf("Pre-analysis details:\n"); printf("Analyzing: HARP Number: %s\t NOAA AR: %d\n",harpnum,noaa_ar); printf("Output file: %s\n",outfile_name); if (time_range == "[]\0"){ printf("We are covering the entire data set.\n"); } else { printf("Time range: %s\n",time_range); } printf("\n\n"); } printf("Processing record %d of %d.\n",k+1,num_records); /* Fill keywords */ if (!(quality[k]=drms_getkey_longlong(drms_record,"QUALITY",&drms_status))){ quality[k]=0; } if (!(crpix1=drms_getkey_double(drms_record,"CRPIX1",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CRPIX1"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(crpix2=drms_getkey_double(drms_record,"CRPIX2",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CRPIX2"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(cdelt1=drms_getkey_double(drms_record,"CDELT1",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CDELT1"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(cdelt2=drms_getkey_double(drms_record,"CDELT2",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CDELT2"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(imcrpix1=drms_getkey_double(drms_record,"IMCRPIX1",&drms_status))){ printf("Keyword %s not present! Exiting.\n","IMCRPIX1"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(imcrpix2=drms_getkey_double(drms_record,"IMCRPIX2",&drms_status))){ printf("Keyword %s not present! Exiting.\n","IMCRPIX2"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(rsun_obs=drms_getkey_double(drms_record,"RSUN_OBS",&drms_status))){ printf("Keyword %s not present! Exiting.\n","RSUN_OBS"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(dsun_obs=drms_getkey_double(drms_record,"DSUN_OBS",&drms_status))){ printf("Keyword %s not present! Exiting.\n","DSUN_OBS"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(obs_vr=drms_getkey_double(drms_record,"OBS_VR",&drms_status))){ printf("Keyword %s not present! Exiting.\n","OBS_VR"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(obs_vn=drms_getkey_double(drms_record,"OBS_VN",&drms_status))){ printf("Keyword %s not present! Exiting.\n","OBS_VN"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(obs_vw=drms_getkey_double(drms_record,"OBS_VW",&drms_status))){ printf("Keyword %s not present! Exiting.\n","OBS_VW"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(crota2=drms_getkey_double(drms_record,"CROTA2",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CROTA2"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(crln_obs=drms_getkey_double(drms_record,"CRLN_OBS",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CRLN_OBS"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(crlt_obs=drms_getkey_double(drms_record,"CRLT_OBS",&drms_status))){ printf("Keyword %s not present! Exiting.\n","CRLT_OBS"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } if (!(blank=drms_getkey_double(drms_record,"BLANK",&drms_status))){ printf("Keyword %s not present! Exiting.\n","BLANK"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } sprint_ut(t_obs_s[k],t_obs); /* Convert to string */ printf(" Checking quality.\n"); if (quality[k] == 0){ /* Ok, now we get the file locations for the data from DRMS. Originally I attempted * to pull the data directly from DRMS but there were vague free() and malloc() issues * possibly due to icc and multithreading, or library problems. */ if (!(drms_segment=drms_segment_lookup(drms_record,"vlos_mag"))){ printf("Problem opening the vlos_mag segment! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } drms_segment_filename(drms_segment,v_filename); if (!(drms_segment=drms_segment_lookup(drms_record,"continuum"))){ printf("Problem opening the continuum segment! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } drms_segment_filename(drms_segment,c_filename); /* naxis1 and naxis2 we get from segment information */ naxis1=(int)drms_segment->axis[0]; naxis2=(int)drms_segment->axis[1]; if (!(drms_segment=drms_segment_lookup(drms_record,"inclination"))){ printf("Problem opening the inclination segment! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } drms_segment_filename(drms_segment,i_filename); if (!(drms_segment=drms_segment_lookup(drms_record,"info_map"))){ printf("Problem opening the info_map segment! Exiting.\n"); drms_close_records(drms_ids,DRMS_FREE_RECORD); return 0; } drms_segment_filename(drms_segment,info_filename); printf(" Opening FITs files.\n"); /* Now open the FITS files and get to work. */ v_status=0; i_status=0; c_status=0; info_status=0; any_nulls=0; if (fits_open_file(&v_ptr,v_filename,READONLY,&v_status)){ printf("Cannot open %s! Exiting.\n",v_filename); exit(0); } if (fits_open_file(&i_ptr,i_filename,READONLY,&i_status)){ printf("Cannot open %s! Exiting.\n",i_filename); fits_close_file(i_ptr,&i_status); exit(0); } if (fits_open_file(&c_ptr,c_filename,READONLY,&c_status)){ printf("Cannot open %s! Exiting.\n",c_filename); fits_close_file(c_ptr,&c_status); exit(0); } if (fits_open_file(&info_ptr,info_filename,READONLY,&info_status)){ printf("Cannot open %s! Exiting.\n",info_filename); fits_close_file(info_ptr,&info_status); exit(0); } /* Walk through the HDUs until we get to one with NAXIS=2 */ /* Number of headers and which one we are on */ fits_get_num_hdus(v_ptr,&num_hdus,&v_status); fits_get_hdu_num(v_ptr,&hdu_pos); /* Find the one with two naxes */ naxis=0; for (i=1;i<=num_hdus;i++){ fits_movabs_hdu(v_ptr,i,NULL,&v_status); fits_read_key(v_ptr,TINT,"NAXIS",&naxis,NULL,&v_status); if (naxis == 2){ needed_hdu=i; } } /* Set all to the needed HDU */ if (naxis == 0){ printf("HDU problems: can't find one with the required number of axes.\n"); fits_close_file(v_ptr,&v_status); fits_close_file(i_ptr,&i_status); fits_close_file(c_ptr,&c_status); fits_close_file(info_ptr,&info_status); exit(0); } else { fits_movabs_hdu(v_ptr,needed_hdu,NULL,&v_status); fits_movabs_hdu(i_ptr,needed_hdu,NULL,&i_status); fits_movabs_hdu(c_ptr,needed_hdu,NULL,&c_status); fits_movabs_hdu(info_ptr,needed_hdu,NULL,&info_status); } /* Now set some definite boundaries on arrays to help with memory usage. Arrays are called as con_dat[y][x]. */ inv_len=naxis1/num_divs; vlos_dat=malloc(naxis2*sizeof(double *)); inc_dat=malloc(naxis2*sizeof(double *)); con_dat=malloc(naxis2*sizeof(double *)); radius=malloc(naxis2*sizeof(double *)); info_dat=malloc(naxis2*sizeof(long *)); y_axis=malloc(num_divs*sizeof(double *)); y_error=malloc(num_divs*sizeof(double *)); x_axis=malloc(num_divs*sizeof(double *)); v_pixel_strip=calloc(naxis1,sizeof(double)); i_pixel_strip=calloc(naxis1,sizeof(double)); c_pixel_strip=calloc(naxis1,sizeof(double)); info_pixel_strip=calloc(naxis1,sizeof(long)); for (j=0;j<naxis2;j++){ vlos_dat[j]=calloc(naxis1,sizeof(double)); inc_dat[j]=calloc(naxis1,sizeof(double)); con_dat[j]=calloc(naxis1,sizeof(double)); radius[j]=calloc(naxis1,sizeof(double)); info_dat[j]=calloc(naxis1,sizeof(long)); } for (j=0;j<(num_divs-1);j++){ x_axis[j]=calloc((inv_len),sizeof(double)); y_axis[j]=calloc((inv_len),sizeof(double)); y_error[j]=calloc((inv_len),sizeof(double)); } x_axis[num_divs-1]=calloc((inv_len + naxis1%num_divs),sizeof(double)); y_axis[num_divs-1]=calloc((inv_len + naxis1%num_divs),sizeof(double)); y_error[num_divs-1]=calloc((inv_len + naxis1%num_divs),sizeof(double)); /* Next, put data in the arrays, clear out blank values and NaNs from the data */ fpixel[0]=1; /* cfitsio uses fortran reference instead of c when accessing data */ nelements=naxis1; nulval=0; l_nulval=0; any_nulls=0; for (j=0;j<naxis2;j++){ fpixel[1]=j+1; /* Add 1 to account for fortran FITS indexing */ fits_read_pix(v_ptr,TDOUBLE,fpixel,nelements,&nulval,v_pixel_strip,&any_nulls,&v_status); fits_read_pix(i_ptr,TDOUBLE,fpixel,nelements,&nulval,i_pixel_strip,&any_nulls,&i_status); fits_read_pix(c_ptr,TDOUBLE,fpixel,nelements,&nulval,c_pixel_strip,&any_nulls,&c_status); fits_read_pix(info_ptr,TLONG,fpixel,nelements,&l_nulval,info_pixel_strip,&any_nulls,&info_status); for (i=0;i<naxis1;i++){ /* Kill blank values if present, if not assign to the correct place in array */ if (v_pixel_strip[i] == blank){ vlos_dat[j][i]=0.0; } else { vlos_dat[j][i]=v_pixel_strip[i]; } if (i_pixel_strip[i] == blank){ inc_dat[j][i]=0.0; } else { inc_dat[j][i]=i_pixel_strip[i]; } if (c_pixel_strip[i] == blank){ con_dat[j][i]=0.0; } else { con_dat[j][i]=c_pixel_strip[i]; } info_dat[j][i]=info_pixel_strip[i]; } } printf(" Analyzing data.\n"); /* Coordinate variable definitions for future use. See the declaration section */ /* at the front of the code to understand what these refer to. */ rscx=(imcrpix1-1.0); rscy=(imcrpix2-1.0); rllx=(crpix1-1.0); rlly=(crpix2-1.0); rpllx=(rscx-rllx); rplly=(rscy-rlly); /* Fill the radius array, handle limb darkening */ rsun_pix=rsun_obs/cdelt1; for (i=0;i<naxis1;i++){ for (j=0;j<naxis2;j++){ xx=(double)i-rllx; yy=(double)j-rlly; r=sqrt(xx*xx+yy*yy); if (r <= rsun_pix){ radius[j][i]=r; mu=sqrt(1-pow(r/rsun_pix,2.0)); con_dat[j][i]=con_dat[j][i]/limb_darken(mu); } } } /* Determine if we actually have an active region here. */ spotbounds(con_dat,naxis1,naxis2,&umb,&pen,umb_sig,pen_sig); num_good=0; for (i=0;i<naxis1;i++){ for (j=0;j<naxis2;j++){ if ((radius[j][i] > 0)&&(con_dat[j][i] <= pen)&&(con_dat[j][i] > 0)){ num_good++; } } } /* Now find the average LOS velocities. */ umb_p_vel[k]=0; pen_p_vel[k]=0; umb_n_vel[k]=0; pen_n_vel[k]=0; umb_p_counter=0.0; umb_n_counter=0.0; pen_p_counter=0.0; pen_n_counter=0.0; if (num_good > 0){ /* We're going to do these loops twice - first to remove any satellite and differential * rotation effects, then again to fit and remove trends. */ /* First the satellite motion and the differential rotation */ for (i=0;i<naxis1;i++){ for (j=0;j<naxis2;j++){ if ((radius[j][i] > 0)&&(good_pixel(info_dat[j][i]))){ /* Get the pixel location in HPL coordinates */ x=rpllx+(double)i; y=rplly+(double)j; /* Stonyhurst/carrington needed for photospheric velocity calcs */ pixel2hpl(x,y,crota2,imcrpix1,imcrpix2,cdelt1,cdelt2,&tx,&ty); hpl2stony(tx,ty,dsun_obs,crln_obs,crlt_obs,&lat,&lon); /* Photospheric rotation removal */ vt=v_t(lat,0,0,0)*along_phi(t,p,dsun_obs); /*0's are for default coefficients */ /* Convert to spherical with no rotation to account for sat orientation and handle LOS stuff */ pixel2hpl(x,y,0.0,imcrpix1,imcrpix2,cdelt1,cdelt2,&tx,&ty); hpl2hpc(tx,ty,&ttx,&tty); hpc2hcc(ttx,tty,dsun_obs,&xx,&yy,&zz); hcc2sphere(xx,yy,zz,&t,&p); /* LOS satellite velocity components */ vr=obs_vr*along_obs(t,p,dsun_obs); vn=obs_vn*along_north(t,p,dsun_obs); vw=obs_vw*along_west(t,p,dsun_obs); /* vlos after removing all of the doppler effects. The * division by 100 is to convert cm/s to m/s. */ vlos_dat[j][i]=(vlos_dat[j][i]/100)-vr-vn-vw-vt; } } } /* Next we fit a function across x, not including points that would be in a sunspot or off-disk points. * Then we subtract this trend from the remaining data. */ for (j=0;j<naxis2;j++){ /* Fill the arrays along x */ for (i=0;i<num_divs;i++){ if (i < (num_divs-1)){ /* There are a total of num_divs segments in a data strip. * To handle remainders when determining how many points to * place in a segment, we first do the remainderless ones. * The last may or may not have a remainder, but that's where * one would go if it did, so we do it separately. */ for (l=0;l<inv_len;l++){ n=i*inv_len+l; y_error[i][l]=1; x_axis[i][l]=(double)n; if ((radius[j][n] > 0)&&(con_dat[j][n] > pen)&&(good_pixel(info_dat[j][n]))){ y_axis[i][l]=vlos_dat[j][n]; } else { y_axis[i][l]=0.0; } } } else { /* Handle the one that might have a remainder */ for (l=0;l<(inv_len + naxis1%num_divs);l++){ n=(num_divs-1)*inv_len+l; y_error[num_divs-1][l]=1; x_axis[num_divs-1][l]=(double)n; if ((radius[j][n] > 0)&&(con_dat[j][n] > pen)&&(good_pixel(info_dat[j][n]))){ y_axis[num_divs-1][l]=vlos_dat[j][n]; } else { y_axis[num_divs-1][l]=0.0; } } } } /* Now we fit, but in strips determined by num_divs */ for (i=0;i<num_divs;i++){ if (i < (num_divs-1)){ v.x=x_axis[i]; v.y=y_axis[i]; v.ey=y_error[i]; fit_status=mpfit(fit_me,inv_len,2,fit_params,0,&config,(void *)&v,&result); for (l=0;l<inv_len;l++){ n=i*inv_len+l; vlos_dat[j][n]=vlos_dat[j][n]-(fit_params[0]*x_axis[i][l]+fit_params[1]); /* Subtract trend */ } } else { v.x=x_axis[num_divs-1]; v.y=y_axis[num_divs-1]; v.ey=y_error[num_divs-1]; fit_status=mpfit(fit_me,inv_len + naxis1%num_divs,2,fit_params,0,&config,(void *)&v,&result); for (l=0;l<(inv_len + naxis1%num_divs);l++){ n=(num_divs-1)*inv_len+l; vlos_dat[j][n]=vlos_dat[j][n]-(fit_params[0]*x_axis[num_divs-1][l]+fit_params[1]); /* Subtract trend */ } } } } /* Finally, we have a clean data set. Now get to work on it. */ for (i=0;i<naxis1;i++){ for (j=0;j<naxis2;j++){ if ((radius[j][i] > 0)&&(con_dat[j][i] < pen)&&(good_pixel(info_dat[j][i]))){ /* "Positive" sunspot polarities. */ vlos=vlos_dat[j][i]; if (inc_dat[j][i] < 90){ if (con_dat[j][i] <= umb){ umb_p_vel[k]+=vlos; umb_p_counter++; } if (con_dat[j][i] > umb){ pen_p_vel[k]+=vlos; pen_p_counter++; } } /* "Negative" sunspot polarities. */ if (inc_dat[j][i] > 90){ if (con_dat[j][i] <= umb){ umb_n_vel[k]+=vlos; umb_n_counter++; } if (con_dat[j][i] > umb){ pen_n_vel[k]+=vlos; pen_n_counter++; } } } } } } if (umb_p_counter > 0){ umb_p_vel[k]/=umb_p_counter; } else { umb_p_vel[k]=0; } if (umb_n_counter > 0){ umb_n_vel[k]/=umb_n_counter; } else { umb_n_vel[k]=0; } if (pen_p_counter > 0){ pen_p_vel[k]/=pen_p_counter; } else { pen_p_vel[k]=0; } if (pen_n_counter > 0){ pen_n_vel[k]/=pen_n_counter; } else { pen_n_vel[k]=0; } /* Free up dynamic arrays and close the files for the next iteration. */ for (i=0;i<naxis2;i++){ free(vlos_dat[i]); free(inc_dat[i]); free(con_dat[i]); free(radius[i]); free(info_dat[i]); } free(vlos_dat); free(inc_dat); free(con_dat); free(radius); free(info_dat); free(v_pixel_strip); free(i_pixel_strip); free(c_pixel_strip); free(info_pixel_strip); free(x_axis); free(y_axis); free(y_error); fits_close_file(v_ptr,&v_status); fits_close_file(i_ptr,&i_status); fits_close_file(c_ptr,&c_status); fits_close_file(info_ptr,&info_status); } } printf(" Completed run %d of %d.\n",k+1,num_records); } /* Output the results to a text file. */ /* First, convert t_obs to a more reasonable product. */ for (i=0;i<num_records;i++){ t_secs[i]=isotime(t_obs_s[i]); } printf("Writing to file %s.\n",outfile_name); outptr=fopen(outfile_name,"w"); bad_outptr=fopen(bad_outfile_name,"w"); fprintf(outptr,"Active Region: %d\tVelocities are in m/s, fvlos is scaled to remove limb effects.\n",noaa_ar); fprintf(outptr,"Full UT Time time(s) vlos pumb vlos ppen vlos numb vlos npen\n"); fprintf(outptr,"---------------------- ------- --------- --------- --------- ---------\n"); fprintf(bad_outptr,"Active Region: AR%d\n",noaa_ar); fprintf(bad_outptr,"Full UT Time quality time(s) number\n"); fprintf(bad_outptr,"---------------------- ------- ------- ------\n"); for (i=0;i<num_records;i++){ /* Make times relative to the first recorded one. */ if (quality[i] == 0){ fprintf(outptr,"%s %7ld %6.2lf %6.2lf %6.2lf %6.2lf\n",t_obs_s[i],t_secs[i]-t_secs[0],umb_p_vel[i],pen_p_vel[i],umb_n_vel[i],pen_n_vel[i]); } else { fprintf(bad_outptr,"%s 0x%08lX %7ld %d\n",t_obs_s[i],quality[i],t_secs[i],i+1); } } fclose(outptr); fclose(bad_outptr); printf("Done!\n"); /* Free memory associated with dynamic arrays. */ free(t_secs); free(t_obs_s); free(umb_p_vel); free(pen_p_vel); free(umb_n_vel); free(pen_n_vel); free(quality); /* Close the drms records connection */ drms_close_records(drms_ids,DRMS_FREE_RECORD); /* Done! */ return 0; }
v_t operator+(const v_t&v)const{return v_t(x+v.x,y+v.y,z+v.z);}
C2H2::C2H2() : teplojomkost() { set_v_max( 13 ); v_t(1) = 0; v_Cp( 1 ) = 0.38447; v_Cv( 1 ) = 0.308; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.44669; v_Cv( 2 ) = 0.3703; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.48817; v_Cv( 3 ) = 0.4117; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.51928; v_Cv( 4 ) = 0.4428; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.54501; v_Cv( 5 ) = 0.4686; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.56756; v_Cv( 6 ) = 0.49128; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.58784; v_Cv( 7 ) = 0.51156; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.60643; v_Cv( 8 ) = 0.53015; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.62337; v_Cv( 9 ) = 0.54709; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.63881; v_Cv( 10 ) = 0.56253; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.65279; v_Cv( 11 ) = 0.57651; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.66542; v_Cv( 12 ) = 0.58915; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.67672; v_Cv( 13 ) = 0.60044; v_S( 13 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=1200) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
v_t operator-(const v_t&v)const{return v_t(x-v.x,y-v.y,z-v.z);}
C2H4::C2H4() : teplojomkost() { set_v_max( 13 ); v_t(1) = 0; v_Cp( 1 ) = 0.3486; v_Cv( 1 ) = 0.2777; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.4363; v_Cv( 2 ) = 0.3654; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.5197; v_Cv( 3 ) = 0.4488; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.5918; v_Cv( 4 ) = 0.5208; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.6534; v_Cv( 5 ) = 0.5825; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.7065; v_Cv( 6 ) = 0.6356; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.7532; v_Cv( 7 ) = 0.6823; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.7942; v_Cv( 8 ) = 0.7233; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.8295; v_Cv( 9 ) = 0.7586; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.8609; v_Cv( 10 ) = 0.79; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.8887; v_Cv( 11 ) = 0.8178; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.9126; v_Cv( 12 ) = 0.8416; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.9336; v_Cv( 13 ) = 0.8627; v_S( 13 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=1200) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
v_t operator*(const double d)const{return v_t(x*d,y*d,z*d);}
CO::CO() : teplojomkost() { set_v_max( 26 ); v_t(1) = 0; v_Cp( 1 ) = 0.2483; v_Cv( 1 ) = 0.1774; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.2495; v_Cv( 2 ) = 0.1786; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.2528; v_Cv( 3 ) = 0.1819; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.258; v_Cv( 4 ) = 0.1871; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.2641; v_Cv( 5 ) = 0.1932; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.2704; v_Cv( 6 ) = 0.1995; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.2763; v_Cv( 7 ) = 0.2054; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.2816; v_Cv( 8 ) = 0.2107; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.2863; v_Cv( 9 ) = 0.2154; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.2904; v_Cv( 10 ) = 0.2195; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.2939; v_Cv( 11 ) = 0.223; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.297; v_Cv( 12 ) = 0.2261; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.2996; v_Cv( 13 ) = 0.2287; v_S( 13 ) = 0; v_t(14) = 1300; v_Cp( 14 ) = 0.302; v_Cv( 14 ) = 0.2311; v_S( 14 ) = 0; v_t(15) = 1400; v_Cp( 15 ) = 0.304; v_Cv( 15 ) = 0.233; v_S( 15 ) = 0; v_t(16) = 1500; v_Cp( 16 ) = 0.3057; v_Cv( 16 ) = 0.2348; v_S( 16 ) = 0; v_t(17) = 1600; v_Cp( 17 ) = 0.3073; v_Cv( 17 ) = 0.2364; v_S( 17 ) = 0; v_t(18) = 1700; v_Cp( 18 ) = 0.3087; v_Cv( 18 ) = 0.2378; v_S( 18 ) = 0; v_t(19) = 1800; v_Cp( 19 ) = 0.31; v_Cv( 19 ) = 0.239; v_S( 19 ) = 0; v_t(20) = 1900; v_Cp( 20 ) = 0.3111; v_Cv( 20 ) = 0.2402; v_S( 20 ) = 0; v_t(21) = 2000; v_Cp( 21 ) = 0.3121; v_Cv( 21 ) = 0.2412; v_S( 21 ) = 0; v_t(22) = 2100; v_Cp( 22 ) = 0.313; v_Cv( 22 ) = 0.2421; v_S( 22 ) = 0; v_t(23) = 2200; v_Cp( 23 ) = 0.3138; v_Cv( 23 ) = 0.2429; v_S( 23 ) = 0; v_t(24) = 2300; v_Cp( 24 ) = 0.3146; v_Cv( 24 ) = 0.2437; v_S( 24 ) = 0; v_t(25) = 2400; v_Cp( 25 ) = 0.3153; v_Cv( 25 ) = 0.2444; v_S( 25 ) = 0; v_t(26) = 2500; v_Cp( 26 ) = 0.316; v_Cv( 26 ) = 0.245; v_S( 26 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=2500) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }
hit_t():n(v_t(0,0,0)),t(infinity){}
N2_ATM::N2_ATM() : teplojomkost() { set_v_max( 26 ); v_t(1) = 0; v_Cp( 1 ) = 0.2461; v_Cv( 1 ) = 0.1756; v_S( 1 ) = 0; v_t(2) = 100; v_Cp( 2 ) = 0.2469; v_Cv( 2 ) = 0.1763; v_S( 2 ) = 0; v_t(3) = 200; v_Cp( 3 ) = 0.2491; v_Cv( 3 ) = 0.1786; v_S( 3 ) = 0; v_t(4) = 300; v_Cp( 4 ) = 0.2532; v_Cv( 4 ) = 0.1827; v_S( 4 ) = 0; v_t(5) = 400; v_Cp( 5 ) = 0.2584; v_Cv( 5 ) = 0.1879; v_S( 5 ) = 0; v_t(6) = 500; v_Cp( 6 ) = 0.2641; v_Cv( 6 ) = 0.1935; v_S( 6 ) = 0; v_t(7) = 600; v_Cp( 7 ) = 0.2697; v_Cv( 7 ) = 0.1992; v_S( 7 ) = 0; v_t(8) = 700; v_Cp( 8 ) = 0.2749; v_Cv( 8 ) = 0.2044; v_S( 8 ) = 0; v_t(9) = 800; v_Cp( 9 ) = 0.2793; v_Cv( 9 ) = 0.2091; v_S( 9 ) = 0; v_t(10) = 900; v_Cp( 10 ) = 0.2833; v_Cv( 10 ) = 0.2132; v_S( 10 ) = 0; v_t(11) = 1000; v_Cp( 11 ) = 0.2874; v_Cv( 11 ) = 0.2169; v_S( 11 ) = 0; v_t(12) = 1100; v_Cp( 12 ) = 0.2907; v_Cv( 12 ) = 0.2202; v_S( 12 ) = 0; v_t(13) = 1200; v_Cp( 13 ) = 0.2935; v_Cv( 13 ) = 0.223; v_S( 13 ) = 0; v_t(14) = 1300; v_Cp( 14 ) = 0.295; v_Cv( 14 ) = 0.2255; v_S( 14 ) = 0; v_t(15) = 1400; v_Cp( 15 ) = 0.2982; v_Cv( 15 ) = 0.2277; v_S( 15 ) = 0; v_t(16) = 1500; v_Cp( 16 ) = 0.3001; v_Cv( 16 ) = 0.2296; v_S( 16 ) = 0; v_t(17) = 1600; v_Cp( 17 ) = 0.3018; v_Cv( 17 ) = 0.2313; v_S( 17 ) = 0; v_t(18) = 1700; v_Cp( 18 ) = 0.3033; v_Cv( 18 ) = 0.2328; v_S( 18 ) = 0; v_t(19) = 1800; v_Cp( 19 ) = 0.3047; v_Cv( 19 ) = 0.2341; v_S( 19 ) = 0; v_t(20) = 1900; v_Cp( 20 ) = 0.3059; v_Cv( 20 ) = 0.2354; v_S( 20 ) = 0; v_t(21) = 2000; v_Cp( 21 ) = 0.307; v_Cv( 21 ) = 0.2364; v_S( 21 ) = 0; v_t(22) = 2100; v_Cp( 22 ) = 0.308; v_Cv( 22 ) = 0.2374; v_S( 22 ) = 0; v_t(23) = 2200; v_Cp( 23 ) = 0.3089; v_Cv( 23 ) = 0.2383; v_S( 23 ) = 0; v_t(24) = 2300; v_Cp( 24 ) = 0.3097; v_Cv( 24 ) = 0.2392; v_S( 24 ) = 0; v_t(25) = 2400; v_Cp( 25 ) = 0.3105; v_Cv( 25 ) = 0.24; v_S( 25 ) = 0; v_t(26) = 2500; v_Cp( 26 ) = 0.3112; v_Cv( 26 ) = 0.2407; v_S( 26 ) = 0; v_t=v_t/1000.0; reculc_polynoms(); cout << Name() << endl << Formula() << endl; cout << p_t_Cp; cout << p_t_Cv ; cout << p_t_S ; int i =0; while (i<=2500) { cout << i <<" "<<Cp(i) <<" "<< Cv(i) <<" "<< S(i)<< endl; i+=100; } }