C+ C NAME: C averagenight_transit.f C PURPOSE: C This subroutine takes the three triangle arrays(node, nodeid, and hits) C and averages them and puts them into a two-dimensional data array(image) C which can be printed out and viewed as a picture using Surfer C CATEGORY: C Data processing C CALLING SEQUENCE: C call averagenight(node,nodeid,hits,TOP_KMAX,level,cra,cdec,image) C INPUTS: C node real*4 array of size TOP_KMAX storing the response value C corresponding to a triangle of any index C nodeid integer*8 array of size TOP_KMAX storing the name of a triangle C in format(uint64 in C++) useful for JHU Spatial Index routines C hits integer*2 array of size TOP_KMAX storing the number of frames contributing C to a triangles response(node array) C TOP_KMAX integer*8 the size of the three triangle arrays C level integer*2 the level of the spatial index to be used C cra,cdec real*8 the ra/dec coordinates of the center of the field of view for C the image array C imagecnt integer*4 array of size (3200,1600), storing the final image to be viewed C polarimagecnt integer*4 array of size(1600,1600) storing final polar(dec>50) image C OUTPUTS: C outputs the final image to printed out and viewed by the Surfer imaging program C CALLS: C TRIANGLECENTER C++ function returning the ra/dec of the center of a triangle C MODIFICATION HISTORY: C May 2003 Aaron Smith (UCSD/CASS) C C- subroutine averagenight(node, nodeid, hits, index, level, cra, cdec, imagecnt) integer*8 index, badcnt,cnt integer*2 level, hits(index), ibad integer*4 imagecnt(200,200), xarg, yarg, i, j integer*8 nodeid(index), imagenode real*4 node(index), image(200,200), noderesponse real*8 cra, cdec, ra, dec, sdec, sum, rsum, dsum, rac, decc integer*4 x0, y0, maxr,minr,response, test integer*8 xsum, ysum real*8 xcen, ycen,dra, ddec real*4 radius sum=0.D0 rsum=0.D0 dsum=0.D0 do i=1,200 do j=1,200 image(i,j)=0.0 imagecnt(i,j)=0 enddo enddo badcnt=0 cnt=0 do i=1,index if(node(i).gt.0.0.and.hits(i).gt.0)then !Here test on both response and hits cnt=cnt+1 imagenode = nodeid(i) noderesponse = node(i)/float(hits(i)) CALL TRIANGLECENTER(level, imagenode, ra, dec) sum=sum+noderesponse rsum=rsum+(ra*noderesponse) dsum=dsum+(dec*noderesponse) if( (ra-cra).gt.180.D0 ) ra=ra-360.D0 if( (ra-cra).lt.-180.D0 ) ra=ra+360.D0 ibad=0 C xarg = nint( -(ra-cra)*40.D0*dcosd(dec) + 100.5D0 ) xarg = nint( -(ra-cra)*40.D0 + 100.5D0 ) yarg = nint( (dec-cdec)*40.D0 + 100.5D0 ) if(xarg.lt.1.or.xarg.gt.200.or.yarg.lt.1.or.yarg.gt.200)ibad=1 if(ibad.eq.0)then image(xarg,yarg) = image(xarg,yarg) + noderesponse imagecnt(xarg,yarg) = imagecnt(xarg,yarg) + 1 endif endif enddo do i=1,200 do j=1,200 if(imagecnt(i,j).gt.0) then image(i,j)=image(i,j)/float(imagecnt(i,j)) imagecnt(i,j)=nint(image(i,j)) endif enddo enddo !! find brightest pixel to draw box around c do j=1,200 c do i=1,200 c if(image(i,j).gt.maxr)then c maxr=image(i,j) c x0=i c y0=j c endif c enddo c enddo c y0=y0-3 c sum=0 c xsum=0 c ysum=0 !!find background within circle c do j=1,200 c do i=1,200 c radius = sqrt( float((i-x0)*(i-x0) + (j-y0)*(j-y0)) ) c if(radius.lt.18)then c if(imagecnt(i,j).lt.minr) minr=imagecnt(i,j) c endif c enddo c enddo !! find centroid of star c do j=1,200 c do i=1,200 c radius = sqrt( float((i-x0)*(i-x0) + (j-y0)*(j-y0)) ) c if(radius.lt.18)then c response=imagecnt(i,j)-minr c sum = sum + response c xsum = xsum + (i*response) c ysum = ysum + (j*response) c endif c enddo c enddo c xcen=dfloat(xsum)/sum c ycen=dfloat(ysum)/sum c image(nint(xcen),nint(ycen))=-100 c dec = cdec + (ycen - 101.D0)*0.025D0 c ra = cra - (xcen - 101.D0)*0.025D0 c ddec=dec-cdec c dra=ra-cra c print*, 'X,Y: ',xcen,ycen c print*, 'RA/DEC: ',ra,dec c print*, 'Discrep: ',dra,ddec C print*, 'Total Count: ',cnt C print*, 'Bad Count: ',badcnt return end