00001 /* 00002 * Copyright (C) 2005 Badri Krishnan, Alicia Sintes 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with with program; see the file COPYING. If not, write to the 00016 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00017 * MA 02111-1307 USA 00018 */ 00019 00020 /** \file Peak2PHMD.c 00021 * \ingroup pulsarHough 00022 * \date $Date: 2007/08/21 11:49:26 $ 00023 * \brief Construction of Partial-Hough-Map-Derivatives given a peak-gram and the look-up-table. 00024 * \author Sintes, A.M. 00025 * 00026 * Revision: $Id: Peak2PHMD.c,v 1.10 2007/08/21 11:49:26 badri Exp $ 00027 * 00028 * History: Created by Sintes June 20, 2001 00029 * Modified... 00030 * 00031 * 00032 00033 \par Description 00034 00035 This routine produces a phmd at a certain frequency for a given peak-gram and 00036 look-up-table. 00037 00038 The inputs are: 00039 00040 phmd->fBin: The frequency bin of this phmd. 00041 00042 lut : The look-up-table HOUGHptfLUT 00043 00044 pg : The peak-gram HOUGHPeakGram 00045 00046 00047 The function LALHOUGHPeak2PHMD() makes sure that the lut the 00048 peak-gram and also the frequency of the phmd 00049 are compatible. 00050 00051 The output HOUGHphmd is a structure 00052 containing the frequency bin of this phmd 00053 the total number of borders of each type Left and Right to be 00054 marked, the pointers to the borders in the corresponding 00055 look-up-table, plus border effects of clipping on a finite 00056 patch. 00057 00058 \par Uses 00059 \code 00060 LALHOUGHPeak2PHMD() 00061 \endcode 00062 00063 */ 00064 00065 /************************************ <lalVerbatim file="Peak2PHMDCV"> 00066 Author: Sintes, A. M. 00067 $Id: Peak2PHMD.c,v 1.10 2007/08/21 11:49:26 badri Exp $ 00068 ************************************* </lalVerbatim> */ 00069 00070 00071 /* <lalLaTeX> 00072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00073 \subsection{Module \texttt{Peak2PHMD.c}} 00074 \label{ss:Peak2PHMD.c} 00075 Construction of Partial-Hough-Map-Derivatives ({\sc phmd}) given a peak-gram 00076 and the look-up-table. 00077 00078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00079 \subsubsection*{Prototypes} 00080 \vspace{0.1in} 00081 \input{Peak2PHMDD} 00082 \index{\verb&LALHOUGHPeak2PHMD()&} 00083 00084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00085 \subsubsection*{Description} 00086 00087 This routine produces a {\sc phmd} at a certain frequency for a given peak-gram and 00088 look-up-table.\\ 00089 00090 The inputs are: 00091 00092 \verb@phmd->fBin@: The frequency bin of this {\sc phmd}. 00093 00094 \verb@*lut@: The look-up-table (of type \verb@HOUGHptfLUT@) 00095 00096 \verb@*pg@: The peak-gram (of type \verb@HOUGHPeakGram@)\\ 00097 00098 00099 The function \verb@LALHOUGHPeak2PHMD@ makes sure that the {\sc lut}, the 00100 peak-gram and also the frequency of the {\sc phmd} 00101 are compatible.\\ 00102 00103 The output \verb@HOUGHphmd *phmd@ is a structure 00104 containing the frequency bin of this {\sc phmd}, 00105 the total number of borders of each type ({\it Left and Right}) to be 00106 marked, the pointers to the borders in the corresponding 00107 look-up-table, plus {\it border} effects of clipping on a finite 00108 patch. 00109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00110 \subsubsection*{Uses} 00111 %\begin{verbatim} 00112 %LALZDestroyVector() 00113 %\end{verbatim} 00114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00115 \subsubsection*{Notes} 00116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00117 \vfill{\footnotesize\input{Peak2PHMDCV}} 00118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00119 </lalLaTeX> */ 00120 00121 #include <lal/PHMD.h> 00122 00123 NRCSID (PEAK2PHMDC, "$Id: Peak2PHMD.c,v 1.10 2007/08/21 11:49:26 badri Exp $"); 00124 00125 /* ******************************* <lalVerbatim file="Peak2PHMDD"> */ 00126 void LALHOUGHPeak2PHMD (LALStatus *status, 00127 HOUGHphmd *phmd, /* partial Hough map derivative */ 00128 HOUGHptfLUT *lut, /* Look up table */ 00129 HOUGHPeakGram *pg) /* peakgram */ 00130 { /* ********************************************* </lalVerbatim> */ 00131 00132 INT2 i,j; 00133 UCHAR *column1P; 00134 INT4 fBinDif,shiftPeak,minPeakBin,maxPeakBin,thisPeak; 00135 INT2 relatIndex; 00136 UINT4 lengthLeft,lengthRight,n, searchIndex; 00137 UINT8 firstBin,lastBin,pgI,pgF; 00138 /* --------------------------------------------- */ 00139 00140 INITSTATUS (status, "LALHOUGHPeak2PHMD", PEAK2PHMDC); 00141 ATTATCHSTATUSPTR (status); 00142 00143 /** lots of error checking of arguments -- asserts have been 00144 replaced by aborts */ 00145 00146 /* Make sure the arguments are not NULL: */ 00147 if (phmd == NULL) { 00148 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00149 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00150 } 00151 /* ASSERT (phmd, status, PHMDH_ENULL, PHMDH_MSGENULL); */ 00152 00153 if (lut == NULL) { 00154 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00155 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00156 } 00157 /* ASSERT (lut, status, PHMDH_ENULL, PHMDH_MSGENULL); */ 00158 00159 if (pg == NULL) { 00160 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00161 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00162 } 00163 /* ASSERT (pg, status, PHMDH_ENULL, PHMDH_MSGENULL); */ 00164 00165 if (phmd->firstColumn == NULL) { 00166 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00167 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00168 } 00169 /* ASSERT (phmd->firstColumn, status, PHMDH_ENULL, PHMDH_MSGENULL); */ 00170 00171 /* Make sure there are elements in firstColumn */ 00172 if (phmd->ySide == 0) { 00173 /* fprintf(stderr,"phmd->ySide should be non-zero [Peak2PHMD.c %d]\n", __LINE__); */ 00174 ABORT( status, PHMDH_ESIZE, PHMDH_MSGESIZE); 00175 } 00176 /* ASSERT (phmd->ySide, status, PHMDH_ESIZE, PHMDH_MSGESIZE); */ 00177 00178 /* Make sure peakgram and lut have same frequency discretization */ 00179 if ( fabs((REAL4)lut->deltaF - (REAL4)pg->deltaF) > 1.0e-6) { 00180 ABORT( status, PHMDH_EVAL, PHMDH_MSGEVAL); 00181 } 00182 /* ASSERT ( fabs((REAL4)lut->deltaF - (REAL4)pg->deltaF) < 1.0e-6, status, PHMDH_EVAL, PHMDH_MSGEVAL); */ 00183 00184 /* Make sure phmd.fBin and lut are compatible */ 00185 fBinDif = abs( (phmd->fBin) - (lut->f0Bin) ); 00186 if ( fBinDif > lut->nFreqValid ) { 00187 /* fprintf(stderr,"fBinDif > nFreqValid [Peak2PHMD.c %d]\n", __LINE__); */ 00188 ABORT( status, PHMDH_EFREQ, PHMDH_MSGEFREQ); 00189 } 00190 /* ASSERT (fBinDif < lut->nFreqValid, status, PHMDH_EFREQ, PHMDH_MSGEFREQ); */ 00191 00192 00193 pgI = pg->fBinIni; 00194 pgF = pg->fBinFin; 00195 /* bounds of interval to look at in the peakgram */ 00196 firstBin = (phmd->fBin) + (lut->iniBin) + (lut->offset); 00197 lastBin = firstBin + (lut->nBin)-1; 00198 00199 /* Make sure peakgram f-interval and phmd.fBin+lut are compatible */ 00200 /* ASSERT ( pgI <= firstBin, status, PHMDH_EINT, PHMDH_MSGEINT); */ 00201 /* ASSERT ( pgF >= lastBin, status, PHMDH_EINT, PHMDH_MSGEINT); */ 00202 if ( pgI > firstBin ) { 00203 ABORT( status, PHMDH_EINT, PHMDH_MSGEINT); 00204 } 00205 if ( pgF < lastBin ) { 00206 ABORT( status, PHMDH_EINT, PHMDH_MSGEINT); 00207 } 00208 00209 00210 /* ------------------------------------------------------------------- */ 00211 /* initialization */ 00212 /* ------------------------------------------------------------------- */ 00213 n= pg->length; 00214 00215 lengthLeft = 0; 00216 lengthRight= 0; 00217 00218 column1P = &(phmd->firstColumn[0]); 00219 00220 for(i=0; i< phmd->ySide; ++i ){ 00221 *column1P = 0; 00222 ++column1P; 00223 } 00224 00225 minPeakBin = firstBin - pgI; 00226 maxPeakBin = lastBin - pgI; 00227 00228 /* ------------------------------------------------------------------- */ 00229 /* ------------------------------------------- */ 00230 if(n){ /* only if there are peaks present */ 00231 /* ------------------------------------------- */ 00232 INT2 lb1,rb1,lb2,rb2; 00233 INT2 max1,min1,max2,min2; 00234 INT2 nBinPos; 00235 UCHAR test1; 00236 00237 nBinPos = (lut->iniBin) + (lut->nBin) -1; 00238 shiftPeak = pgI - (phmd->fBin) - (lut->offset); 00239 00240 /* ------------------------------------------------------------------- */ 00241 /* searching for the initial peak to look at */ 00242 /* ------------------------------------------------------------------- */ 00243 00244 searchIndex = (n * minPeakBin ) /(pgF-pgI+1); 00245 if (searchIndex >= n) { searchIndex = n-1;} 00246 00247 /* moving backwards */ 00248 /* -----------------*/ 00249 00250 test1=1; 00251 while (searchIndex >0 && test1) { 00252 if ( pg->peak[searchIndex -1] >= minPeakBin ) { 00253 --searchIndex; 00254 } 00255 else { 00256 test1=0; 00257 } 00258 } 00259 00260 /* moving forwards */ 00261 /* -----------------*/ 00262 00263 test1=1; 00264 while (searchIndex < n-1 && test1) { 00265 if ( pg->peak[searchIndex] < minPeakBin ) { 00266 ++searchIndex; 00267 } 00268 else { 00269 test1=0; 00270 } 00271 } 00272 00273 /* ------------------------------------------------------------------- */ 00274 /* for all the interesting peaks (or none) */ 00275 /* ------------------------------------------------------------------- */ 00276 00277 test1=1; 00278 00279 while (searchIndex < n && test1) { 00280 thisPeak = pg->peak[searchIndex]; 00281 00282 if (thisPeak > maxPeakBin) { 00283 test1=0; 00284 } else { 00285 if ( thisPeak >= minPeakBin) { /* we got a peak */ 00286 /* relative Index */ 00287 relatIndex = thisPeak + shiftPeak; 00288 00289 i = relatIndex; 00290 if( relatIndex < 0 ) i = nBinPos - relatIndex; 00291 00292 00293 if ( i >= lut->nBin ) { 00294 fprintf(stderr,"current index i=%d not lesser than nBin=%d\n [Peak2PHMD.c %d]\n", i,lut->nBin, __LINE__); 00295 } 00296 00297 00298 /* Reading the bin information */ 00299 lb1 = lut->bin[i].leftB1; 00300 rb1 = lut->bin[i].rightB1; 00301 lb2 = lut->bin[i].leftB2; 00302 rb2 = lut->bin[i].rightB2; 00303 00304 max1 = lut->bin[i].piece1max; 00305 min1 = lut->bin[i].piece1min; 00306 max2 = lut->bin[i].piece2max; 00307 min2 = lut->bin[i].piece2min; 00308 00309 /* border selection from lut */ 00310 00311 if(lb1){ 00312 if ( lut->border + lb1 == NULL ) { 00313 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00314 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00315 } 00316 phmd->leftBorderP[lengthLeft] = &( lut->border[lb1] ); 00317 ++lengthLeft; 00318 } 00319 00320 00321 if(lb2){ 00322 if ( lut->border + lb2 == NULL ) { 00323 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00324 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00325 } 00326 phmd->leftBorderP[lengthLeft] = &( lut->border[lb2] ); 00327 ++lengthLeft; 00328 } 00329 00330 if(rb1){ 00331 if ( lut->border + rb1 == NULL ) { 00332 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00333 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00334 } 00335 phmd->rightBorderP[lengthRight] = &( lut->border[rb1] ); 00336 ++lengthRight; 00337 } 00338 00339 if(rb2){ 00340 if ( lut->border + rb2 == NULL ) { 00341 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00342 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00343 } 00344 phmd->rightBorderP[lengthRight] = &( lut->border[rb2] ); 00345 ++lengthRight; 00346 } 00347 00348 /* correcting 1st column */ 00349 for(j=min1; j<=max1; ++j) { 00350 if (phmd->firstColumn + j == NULL) { 00351 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00352 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00353 } 00354 phmd->firstColumn[j] = 1; 00355 } 00356 00357 for(j=min2; j<=max2; ++j) { 00358 if (phmd->firstColumn + j == NULL) { 00359 /* fprintf(stderr,"null pointer found [Peak2PHMD.c %d]\n", __LINE__); */ 00360 ABORT( status, PHMDH_ENULL, PHMDH_MSGENULL); 00361 } 00362 phmd->firstColumn[j] = 1; 00363 } 00364 00365 } 00366 ++searchIndex; 00367 } 00368 /* ------------------------------------------------------------------- */ 00369 00370 } 00371 } 00372 00373 /* ------------------------------------------------------------------- */ 00374 00375 phmd->lengthLeft = lengthLeft; 00376 phmd->lengthRight= lengthRight; 00377 /* ------------------------------------------- */ 00378 00379 DETATCHSTATUSPTR (status); 00380 00381 /* normal exit */ 00382 RETURN (status); 00383 }
1.5.2