//+ // NAME: // A_mod_L12_all // PURPOSE: // CATEGORY: // CALLING SEQUENCE: // INPUTS: // OUTPUTS: // CALLS: // SEE ALSO: // INCLUDE: // SIDE EFFECTS: // RESTRICTIONS: // PROCEDURE: // This file contains all of the C++ Spatial Index functions to // be called from Fortran in order to index and make a sky map // from TMO/SMEI data frames. // All of the Spatial Index functions have been taken from the // free software developed by Peter Z. Kunzst of The Johns Hopkins University // at http://www.sdss.org // MODIFICATION HISTORY: // ???-2002, Aaron Smith (UCSD/CASS) // Original version // DEC-2002, Paul Hick (UCSD/CASS; pphick@ucsd.edu) // Fixed bug in subroutine indexframe (fdusk was not declared as pointer) // DEC-2002, Andy Buffington (UCSD/CASS; abuffington@ucsd.edu) // Changed bunch of scalar variables from single to double precision. //- #include #include "VarStr.h" #include "SpatialIndex.h" #include "SpatialGeneral.h" #include "SpatialVector.h" #include "SpatialConvex.h" #include #include #include #include #define NORTH 1 #define SOUTH 0 //the extern "C" eliminates all function name mangling, allowing for calls //to be made from Fortran extern "C" void averagenight_(short * level, float node[], uint64 nodeid[], short hits[], float64 * cra,float64 * cdec, int imagecnt[1600][3200]); extern "C" void indexframe_(short * level, float node[], uint64 nodeid[], short hits[], float data[600][1280],int * fnight, int * fn, float64 *ddusk, float64 euler[3], float64 affine[6]); extern "C" int airplane_(int night, int f, int j); extern "C" void writedata_(char * nameoutFile, int imagecnt[1600][3200]); extern "C" void readfile_(char * nameFile, float data[600][1280]); extern "C" void pedestal_(float frame[600][1280]); extern "C" long getindex_(const short level, short idx[]); extern "C" void getindices_(const short level, const uint64 id, short index[]); extern "C" void rotate_(float64 alfa, float64 beta, float64 gamma, float64 *ra, float64 *dec); ////////////////////////////////////////////////////////////////////// // Euler rotation function ////////////////////////////////////////////////////////////////////// void rotate_(float64 alfa, float64 beta, float64 gamma, float64 *ra, float64 *dec) { float64 sinb, cosb, sinl, cosl, sinp, cosp, cost; float64 degtorad=0.0174533, radtodeg=57.29578; float64 phi, rlat; phi = *ra; rlat = *dec; //convert from degrees to radians alfa = alfa * degtorad; beta = beta * degtorad; gamma = gamma * degtorad; phi = phi * degtorad; rlat = rlat * degtorad; phi = phi - alfa; // rotation 1 sinb = sin(beta); // rotation 2... cosb = cos(beta); sinl = sin(rlat); cosl = cos(rlat); sinp = sin(phi); cosp = cos(phi); cost = ( sinl*cosb ) + ( cosl*sinb*cosp ); if (fabs(cost)!=1) { sinp = cosl*sinp; cosp = ( cosl*cosb*cosp ) - ( sinl*sinb ); }else if (sinb == 0.0) { cosp = cosb*cosp; } phi = atan2(sinp,cosp); phi = phi - gamma; // rotation 3 //convert back to degrees alfa = alfa * radtodeg; beta = beta * radtodeg; gamma = gamma * radtodeg; phi = phi * radtodeg; rlat = rlat * radtodeg; phi = fmod(fmod(phi,360.0) + 360.0, 360.0); // 0exit } size=(IDSIZE-i) >> 1; for(i=0; i> i*2) & 3); } if( (id>>(size*2-2)) & 1) { index[0] = NORTH; }else { index[0] = SOUTH; } return; } ////////////////////////////////////////////////////////////////// // convert index_size(level+2) indices to one indice ////////////////////////////////////////////////////////////////// long getindex_(const short level, short idx[]) { int i,e,p; long indice=0, max=0; max = 2*pow(4,level+1); for(i=0,e=level+1; imax || indice<0) { printf("Bad Indice: %ld\n",indice); printf("Indices: "); for(i=0; i 1239)airplane=1; if(f == 341 && fabs(j-150) < 20)airplane=1; if(f < 2 && fabs(j-459) < 2)airplane=1; //(end night 42) } if(night==41) { if(f == 22 && fabs(j-160) < 20)airplane=1; //(begin night 41) if(f == 37 && fabs(j-45) < 15)airplane=1; if(f == 42 && fabs(j-180) < 20)airplane=1; if(f == 48 && fabs(j-730) < 100)airplane=1; if(f == 82 && fabs(j-172) < 19)airplane=1; if(f == 105 && fabs(j-55) < 15)airplane=1; if(f == 303 && fabs(j-860) < 20)airplane=1; if(f == 340 && fabs(j-80) < 20)airplane=1; if(f < 4 && fabs(j-459) < 2)airplane=1; //(end night 41) } if(night==40) { if(f == 41 && j > 1189)airplane=1; //(begin night 40) if(f == 62 && fabs(j-1005) < 45)airplane=1; if(f == 46 && fabs(j-95) < 15)airplane=1; if(f == 119 && fabs(j-250) < 21)airplane=1; if(f == 153 && fabs(j-166) < 19)airplane=1; if(f == 381 && j < 55)airplane=1; if(f == 416 && fabs(j-45) < 15)airplane=1; if(f == 515 && fabs(j-750) < 10)airplane=1; if(f == 12 && fabs(j-165) < 15)airplane=1; if(f < 15 && fabs(j-459) < 2)airplane=1; //(end night 40) } return airplane; } ////////////////////////////////////////////////////////////////// // module to index a frame ////////////////////////////////////////////////////////////////// void indexframe_(short * ilevel, float node[], uint64 nodeid[], short hits[], float data[600][1280], int * fnight, int * fn, float64 * ddusk, float64 euler[3], float64 affine[6]) { short level=*ilevel; float64 dusk=*ddusk; size_t flen; long index; int airplane=0, night, ncount=0, hcount=0; int i, j, k, a, b, p, n, f=*fn; float64 aq, bq, cq, rq, dr, thetax, thetaxsq, thetay, cx, cy, cz, crsq, cr, phi, rlat; // float64 gamma=0.0, beta, alfa=0.50, camlat=34.9471, float64 cra, cdec, alfa, beta, gamma; // float64 degperminute=0.2506844731, float64 degtorad=0.0174533, radtodeg=57.29578; float64 x0=630.6, y0=1291.38, r0=1194.5, rccd; // ra0=279.425; float64 x[4], y[4], tempx, *pra, *pdec; float64 rup=0, rdown=360,dup=0,ddown=90; float response=0, arg, arg1; SpatialIndex si(level,2); SpatialVector *v[4], *tempv; SpatialConvex *pixelconvex; ValVec *partialvec, fullvec, *tempfullvec; uint64 *partialnode, *fullnode, imagenode; short idx[level+2], triangle; time_t frametime, ti, tf; ti=clock(); alfa=euler[0]; beta=euler[1]; gamma=euler[2]; night= *fnight; //initializ dynamic arrays partialvec = new ValVec(); tempfullvec = new ValVec(); //// loop for each pixel //// for (i=0; i<350; i++) { for (j=22; j<1264; j++) // 220) { phi = atan2(cy,cx); }else { phi = 0; } cz = sqrt(1-(crsq)); rlat = radtodeg*asin(cz); phi = radtodeg*phi; // beta = camlat-90; // gamma = (-f*degperminute)-ra0; //(frame#+1)*degperminute pra = φ pdec = &rlat; rotate_(alfa, beta, gamma, pra, pdec); v[k] = new SpatialVector(*pra, *pdec); }//end vertex loop pixelconvex = new SpatialConvex(v[0], v[1], v[2], v[3]); //free vector memory delete v[0]; delete v[1]; delete v[2]; delete v[3]; //intersect with index pixelconvex->intersect(&si, partialvec, tempfullvec); fullvec = *tempfullvec; tempfullvec->keep(tempfullvec->length()); //test center of partial nodes to see if they are within pixelconvex partialnode = partialvec->vector_; for (k=0; k<(partialvec->length()); k++, partialnode++) { si.CASStriangleCenter(*partialnode, pra, pdec ); tempv = new SpatialVector(*pra, *pdec); triangle = pixelconvex->CASStestVertex(*tempv); delete tempv; // triangle = 1 or 0 for in or out of the pixel if (triangle == 1) fullvec.append(*partialnode); } delete pixelconvex; partialvec->keep(partialvec->length()); //give each triangle an equal portion of the response fullnode = fullvec.vector_; flen = fullvec.length(); for(k=0; k0) { imagenode = nodeid[i]; //average noderesponse by the number of hits the node got noderesponse = node[i] / hits[i]; si.CASStriangleCenter(imagenode, pra, pdec ); if((*pra-cra)>180) *pra=*pra-360;//fix discontinuity over 0=360 if((*pra-cra)<-180) *pra=*pra+360; //*pra = (*pra - cra)*cos(*pdec*degtorad) + cra; xarg = -( (*pra) - cra )*20 +1599;//x-coordinate, now flipped for true sky frame yarg = ( (*pdec) - cdec )*20 + 799;//y-coordinate //make sure xarg/yarg are within array bounds if (xarg<0) { xarg=0; }else if (xarg>=3200) { xarg=3199; } if (yarg<0) { yarg=0; }else if (yarg>=1600) { yarg=1599; } //image[y][x] because C fills columns before rows image[yarg][xarg] = image[yarg][xarg] + noderesponse; imagecnt[yarg][xarg] = imagecnt[yarg][xarg] + 1; }//end if routine for all indices with response } //average image and put into into imagecnt to print out integers; //dont worry about losing decimal precision for(i=0; i<1600; i++) { for(j=0; j<3200; j++) { if(imagecnt[i][j]>0) image[i][j]=image[i][j]/imagecnt[i][j]; imagecnt[i][j]=image[i][j]; } } return; }