GeneralMetricTest.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 David M. Whitbeck, Jolien Creighton, Ian Jones, Benjamin Owen
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 /************************************ <lalVerbatim file="GeneralMetricTestCV">
00021 Author: Jones, D. I.,     Owen, B. J.
00022 $Id: GeneralMetricTest.c,v 1.21 2007/06/08 14:41:52 bema Exp $
00023 ********************************************************** </lalVerbatim> */
00024 
00025 /**************************************************************** <lalLaTeX>
00026 
00027 \subsection{Program \texttt{GeneralMetricTest.c}}
00028 \label{ss:GeneralMetricTest}
00029 
00030 Tests the various LAL metric functions, by outputting the metric at a
00031 point in parameter space, and also producing an array of ellipses of
00032 constant mismatch.
00033 
00034 \subsubsection*{Usage}
00035 \begin{verbatim}
00036 GeneralMetricTest
00037 \end{verbatim}
00038 
00039 \subsubsection*{Description}
00040 
00041 This program computes metric components using a metric function of the
00042 user's specification.  The ordering of the components is $(f_0,
00043 \alpha, \delta, f_1\ldots)$ for the unprojected metric, and $(\alpha,
00044 \delta, f_1\ldots)$ for the metric with $f_0$ projected out.
00045 
00046 With no options, this program displays metric components for a single point
00047 in parameter space for the default parameter values.
00048 
00049 The \texttt{-a} option determines which LAL metric code is used.  The
00050 options are: 
00051 
00052 \hspace{1cm} 1 = PtoleMetric (default), 
00053 
00054 \hspace{1cm} 2 = (CoherentMetric \& DTBaryPtolemaic), 
00055 
00056 \hspace{1cm} 3 = (CoherentMetric \& DTEphemeris).
00057 
00058 The \texttt{-b} option sets the beginning GPS time of integration to
00059 the option argument. (Default is $731265908$ seconds, chosen to lie
00060 within the S2 run).
00061 
00062 The \texttt{-c} option determines the point on the sky where the metric
00063 is evaluated.  This option is hard-coded to use equatorial coordinates
00064 and the argument should be given in hh:mm:ss:dd:mm:ss format.
00065 (Default is the center of the globular cluster 47 Tuc).
00066 
00067 The \texttt{-d} option sets the detector to the option argument. The
00068 options are: 
00069  
00070 \hspace{1cm} 1 = LIGO Hanford 
00071 
00072 \hspace{1cm} 2 = LIGO Livingston
00073 
00074 \hspace{1cm} 3 = VIRGO 
00075 
00076 \hspace{1cm} 4 = GEO600 (default)
00077 
00078 \hspace{1cm} 5 = TAMA300 
00079 
00080 The \texttt{-e} option sets the LAL debug level to 1.  (The default is 0).
00081 
00082 The \texttt{-f} option sets the maximum frequency (in Hz) to search. (The
00083 default is 1000.)
00084 
00085 The \texttt{-l} option determines the limits in right ascension and
00086 declination of the rectangular region over which the mismatch contours
00087 are computed.  The argument should be given in degrees as
00088 RA(min):RA(max):dec(min):dec(max).  (The default is the octant of the
00089 sky defined by $0 < {\rm RA} 90$ and $0< {\rm dec} 85$; this avoids the
00090 coordinate singularity at the poles.)
00091 
00092 The \texttt{-m} option sets the mismatch (default is $0.02$).
00093 
00094 The \texttt{-n} option sets the number of spindown parameters (default 0).
00095 
00096 The \texttt{-p} option is provided for users who wish to view the
00097 power mismatch contours provided by the \texttt{-x} option (see below)
00098 but don't have xmgrace installed.  All necessary data is simply
00099 written to a file ``nongrace.data''; it's probably best to look at the
00100 code to see the exact format.  The user should then write a small
00101 script to convert the data into the format appropriate to their
00102 favorite graphics package.
00103 
00104 The \texttt{-t} option sets the duration of integration in seconds. (The 
00105 default is $39600$ seconds $= 11$ hours, which is chosen because it is of 
00106 the right size for S2 analyses).
00107 
00108 The \texttt{-x} option produces a graph of the 2\% power mismatch
00109 contours on the sky. Dimensions of the ellipses have been exaggerated
00110 by a factor of \texttt{MAGNIFY} (specified within the code) for
00111 legibility. The purpose of the graph is to get a feel for how ellipses
00112 are varying across parameter space. Note that this option makes a
00113 system call to the \texttt{xmgrace} program, and will not work if that
00114 program is not installed on your system.
00115 
00116 
00117 \subsubsection*{Exit Codes}
00118 ************************************************ </lalLaTeX><lalErrTable> */
00119 #define GENERALMETRICTESTC_EMEM 1
00120 #define GENERALMETRICTESTC_ESUB 2
00121 #define GENERALMETRICTESTC_ESYS 3
00122 #define GENERALMETRICTESTC_EMET 4
00123  
00124 #define GENERALMETRICTESTC_MSGEMEM "memory (de)allocation error"
00125 #define GENERALMETRICTESTC_MSGESUB "subroutine failed"
00126 #define GENERALMETRICTESTC_MSGESYS "system call failed"
00127 #define GENERALMETRICTESTC_MSGEMET "determinant of projected metric negative"
00128 
00129 /************************************************** </lalErrTable><lalLaTeX>
00130 \subsubsection*{Algorithm}
00131 
00132 \subsubsection*{Uses}
00133 
00134 \begin{verbatim}
00135 lalDebugLevel
00136 LALCheckMemoryLeaks()
00137 LALCreateVector()
00138 LALDestroyVector()
00139 LALDCreateVector()
00140 LALDDestroyVector()
00141 LALProjectMetric()
00142 LALPtoleMetric()
00143 xmgrace
00144 \end{verbatim}
00145 
00146 \subsubsection*{Notes}
00147 
00148 The code does not yet really work with more than one spindown parameter.
00149 
00150 \vfill{\footnotesize\input{GeneralMetricTestCV}}
00151 
00152 ************************************************************* </lalLaTeX> */
00153 
00154 #include <math.h>
00155 #include <stdio.h>
00156 #include <stdlib.h>
00157 #include <string.h>
00158 #include <sys/types.h>
00159 #include <sys/stat.h>
00160 #include <unistd.h>
00161 #include <lal/AVFactories.h>
00162 #include <lal/LALMalloc.h>
00163 #include <lal/LALStdlib.h>
00164 #include <lal/PtoleMetric.h>
00165 #include <lal/StackMetric.h>
00166 #include <lal/LALBarycenter.h>
00167 #include <lal/LALInitBarycenter.h>
00168 
00169 extern char *optarg;
00170 
00171 NRCSID( GENERALMETRICTESTC, "$Id" );
00172 
00173 #define DEFAULT_DURATION 39600 /* seconds */
00174 #define SPOKES 30
00175 #define MAGNIFY 1.0            /* Magnification factor of ellipses */
00176 
00177 int lalDebugLevel = 0;
00178 
00179 int main( int argc, char *argv[] ) {
00180   static LALStatus status;          /* Status structure */
00181   PtoleMetricIn    in;              /* PtoleMetric() input structure */
00182   REAL8            mismatch;        /* mismatch threshold of mesh */
00183   REAL8Vector     *metric;          /* Parameter-space metric */
00184   int              j, k;            /* Parameter-space indices */
00185   int              opt;             /* Command-line option. */
00186   BOOLEAN          grace;           /* Whether or not we use xmgrace */
00187   BOOLEAN          nongrace;        /* Whether or not to output data to file*/
00188   int              ra, dec, i;      /* Loop variables for xmgrace option */
00189   FILE            *pvc = NULL;      /* Temporary file for xmgrace option */
00190   FILE            *fnongrace = NULL;/* File contaning ellipse coordinates */
00191   int              metric_code;     /* Which metric code to use: */
00192                                     /* 1 = Ptolemetric */
00193                                     /* 2 = CoherentMetric + DTBarycenter */
00194                                     /* 3 = CoherentMetric + DTEphemeris  */
00195   REAL8Vector     *tevlambda;       /* (f, a, d, ...) for CoherentMetric */
00196   MetricParamStruc tevparam;        /* Input structure for CoherentMetric */
00197   PulsarTimesParamStruc tevpulse;   /* Input structure for CoherentMetric */
00198                                     /* (this is a member of tevparam) */
00199   EphemerisData   *eph;             /* To store ephemeris data */
00200   int             detector;         /* Which detector to use: */
00201                                     /* 1 = Hanford,  2 = Livingston,  */
00202                                     /* 3 = Virgo,  4 = GEO,  5 = TAMA */
00203   REAL8           ra_point;         /* RA at which metric is evaluated */
00204   REAL8           dec_point;        /* dec at which metric is evaluated */
00205   float           a,b,c,d,e,f;      /* To input point in standard format */
00206   int             ra_min, ra_max;   /* Min and max RA for ellipse plot */
00207   int             dec_min, dec_max; /* Min and max dec for ellipse plot */
00208   float           f1;               /* The max spindown parameter */
00209   float           tau;              /* The spindown age */
00210   float           c_ellipse;        /* Centers of ellipses */
00211   float           r_ellipse;        /* Radii of ellipses */
00212   REAL8           determinant;      /* Determinant of projected metric */
00213   REAL4           f0;               /* carrier frequency */
00214   UINT2           numSpindown;      /* Number of spindowns */
00215   char earth[] = "earth00-04.dat";
00216   char sun[] = "sun00-04.dat";
00217 
00218   /* Defaults that can be overwritten: */
00219   metric_code = 1;
00220   in.epoch.gpsSeconds = tevpulse.epoch.gpsSeconds = 731265908;
00221   in.epoch.gpsNanoSeconds = tevpulse.epoch.gpsNanoSeconds = 0.0;
00222   mismatch = 0.02;
00223   nongrace = 0;
00224   in.duration = tevparam.deltaT = DEFAULT_DURATION;
00225   grace = 0;
00226   detector = 4;
00227   ra_point  = (24.1/60)*LAL_PI_180;     /* 47 Tuc */
00228   dec_point = -(72+5./60)*LAL_PI_180;
00229   ra_min = 0;
00230   ra_max = 90;
00231   dec_min = 0;
00232   dec_max = 85;
00233   tau=1e10;
00234   f1 = tevparam.deltaT/tau;
00235   f0 = 1000;
00236   numSpindown = 0;
00237 
00238   /* Parse options. */
00239   while ((opt = getopt( argc, argv, "a:b:c:d:ef:l:m:n:pt:s:x" )) != -1) {
00240     switch (opt) {
00241     case 'a':
00242       metric_code = atoi( optarg );
00243       break;
00244     case 'b':
00245       in.epoch.gpsSeconds = tevpulse.epoch.gpsSeconds = atoi( optarg );
00246       break;
00247     case 'c':
00248       if( sscanf( optarg, "%f:%f:%f:%f:%f:%f", &a, &b, &c, &d, &e, &f ) != 6)
00249         {
00250           fprintf( stderr, "coordinates should be hh:mm:ss:dd:mm:ss\n" );
00251         }
00252       ra_point = (15*a+b/4+c/240)*LAL_PI_180;
00253       dec_point = (d+e/60+f/3600)*LAL_PI_180;
00254       break;
00255     case 'd':
00256       detector = atoi( optarg );
00257       break;
00258     case 'e':
00259       lalDebugLevel = 1;
00260       break;
00261     case 'f':
00262       f0 = atof( optarg );
00263       break;
00264     case 'l':
00265       if( sscanf( optarg, "%d:%d:%d:%d", 
00266                   &ra_min, &ra_max, &dec_min, &dec_max) != 4)
00267         {
00268           fprintf( stderr, "coordinates should be ra_min, ra_max, dec_min, dec_max all in degrees" );
00269         }
00270       break;
00271     case 'm':
00272       mismatch = atof( optarg );
00273       break;
00274     case 'n':
00275       numSpindown = atoi( optarg );
00276       break;
00277     case 'p':
00278       nongrace = 1;
00279       break;
00280     case 's':
00281       tau = atof( optarg );
00282       f1 = tevparam.deltaT/tau;
00283       break;
00284     case 't':
00285       in.duration = tevparam.deltaT = atof( optarg );
00286       break;
00287     case 'x':
00288       grace = 1;
00289       break;
00290     }
00291   }
00292 
00293   /* Allocate storage. */
00294   metric = NULL;
00295   LALDCreateVector( &status, &metric, (3+numSpindown)*(4+numSpindown)/2 );
00296   if( status.statusCode )
00297     {
00298       printf( "%s line %d: %s\n", __FILE__, __LINE__,
00299               GENERALMETRICTESTC_MSGEMEM );
00300       return GENERALMETRICTESTC_EMEM;
00301     }
00302   tevlambda = NULL;
00303   LALDCreateVector( &status, &tevlambda, 3+numSpindown );
00304   if( status.statusCode )
00305     {
00306       printf( "%s line %d: %s\n", __FILE__, __LINE__,
00307               GENERALMETRICTESTC_MSGEMEM );
00308       return GENERALMETRICTESTC_EMEM;
00309     }
00310 
00311   /* Position in parameter space (sky, frequency, spindowns) */
00312   in.position.system = COORDINATESYSTEM_EQUATORIAL;
00313   in.position.longitude = tevlambda->data[1] = ra_point;
00314   in.position.latitude = tevlambda->data[2] = dec_point;
00315   in.maxFreq = tevlambda->data[0] = f0;
00316   in.spindown = NULL;
00317   if( numSpindown > 0 ) {
00318     LALCreateVector( &status, &(in.spindown), numSpindown );
00319     if( status.statusCode ) {
00320       printf( "%s line %d: %s\n", __FILE__, __LINE__,
00321               GENERALMETRICTESTC_MSGEMEM );
00322       return GENERALMETRICTESTC_EMEM;
00323     }
00324     for( i=0; i<numSpindown; i++ ) {
00325       in.spindown->data[i] = 0;
00326       tevlambda->data[i+3] = 0;
00327     }
00328   }
00329 
00330   /* Detector site */
00331   if(detector==1)
00332     tevpulse.site = &lalCachedDetectors[LALDetectorIndexLHODIFF];
00333   if(detector==2)
00334     tevpulse.site = &lalCachedDetectors[LALDetectorIndexLLODIFF];
00335   if(detector==3)
00336     tevpulse.site = &lalCachedDetectors[LALDetectorIndexVIRGODIFF];
00337   if(detector==4)
00338     tevpulse.site = &lalCachedDetectors[LALDetectorIndexGEO600DIFF];
00339   if(detector==5)
00340     tevpulse.site = &lalCachedDetectors[LALDetectorIndexTAMA300DIFF];
00341   in.site = tevpulse.site;
00342   tevpulse.latitude = in.site->frDetector.vertexLatitudeRadians;
00343   tevpulse.longitude = in.site->frDetector.vertexLongitudeRadians;
00344 
00345   /* CoherentMetric constants */
00346   tevparam.constants = &tevpulse;
00347   tevparam.n = 1;
00348   tevparam.errors = 0;
00349   tevparam.start = 0; /* start time relative to epoch */
00350   tevpulse.t0 = 0.0;  /* spindown definition time relative to epoch */
00351  
00352   /* Fill in the fields tevpulse.tMidnight & tevpulse.tAutumn: */
00353   LALGetEarthTimes( &status, &tevpulse );
00354   if( status.statusCode )
00355     {
00356       printf( "%s line %d: %s\n", __FILE__, __LINE__,
00357               GENERALMETRICTESTC_MSGESUB );
00358       return GENERALMETRICTESTC_ESUB;
00359     }
00360 
00361    /* Read in ephemeris data from files: */
00362    eph = (EphemerisData *)LALMalloc(sizeof(EphemerisData));
00363    eph->ephiles.earthEphemeris = earth;
00364    eph->ephiles.sunEphemeris = sun;
00365    eph->leap = 13; /* right number for the years 2000-2004 */
00366    LALInitBarycenter( &status, eph );
00367    if( status.statusCode )
00368     {
00369       printf( "%s line %d: %s\n", __FILE__, __LINE__,
00370               GENERALMETRICTESTC_MSGESUB );
00371       return GENERALMETRICTESTC_ESUB;
00372     }
00373    tevpulse.ephemeris = eph;
00374 
00375    /* Choose CoherentMetric timing function */
00376    if( metric_code == 2 ) {
00377      tevpulse.t1 = LALTBaryPtolemaic;
00378      tevpulse.dt1 = LALDTBaryPtolemaic;
00379    }
00380    if( metric_code == 3 ) {
00381      tevpulse.t1 = LALTEphemeris;
00382      tevpulse.dt1 = LALDTEphemeris;
00383    }
00384    tevpulse.t2 = LALTSpin;
00385    tevpulse.dt2 = LALDTSpin;
00386    tevpulse.constants1 = &tevpulse;
00387    tevpulse.constants2 = &tevpulse;
00388    tevpulse.nArgs = 2;
00389    if( numSpindown > 0 ) {
00390      tevparam.dtCanon = LALDTComp;
00391    }
00392    else {
00393      if( metric_code == 2 )
00394        tevparam.dtCanon = LALDTBaryPtolemaic;
00395      if( metric_code == 3 )
00396        tevparam.dtCanon = LALDTEphemeris;
00397    }
00398 
00399    /* Evaluate metric components. */
00400    if(metric_code==1)
00401      {
00402        LALPtoleMetric( &status, metric, &in );
00403        if( status.statusCode )
00404          {
00405            printf( "%s line %d: %s\n", __FILE__, __LINE__,
00406                    GENERALMETRICTESTC_MSGESUB );
00407            return GENERALMETRICTESTC_ESUB;
00408          }
00409      }
00410    if(metric_code==2  || metric_code==3)
00411      {
00412        LALCoherentMetric( &status, metric, tevlambda, &tevparam );
00413        if( status.statusCode )
00414          {
00415            printf( "%s line %d: %s\n", __FILE__, __LINE__,
00416                    GENERALMETRICTESTC_MSGESUB );
00417            return GENERALMETRICTESTC_ESUB;
00418          }
00419      }
00420 
00421    /* Print metric. */
00422    printf("\nmetric (f0, alpha, delta, ...) at the requested point\n");
00423    for (j=0; j<=2+numSpindown; j++) {
00424      for (k=0; k<=j; k++)
00425        printf( "  %+.4e", metric->data[k+j*(j+1)/2] );
00426      printf("\n");
00427    }
00428 
00429    /* Print determinants. */
00430    determinant = metric->data[5]*metric->data[2] - pow(metric->data[4],2);
00431    printf( "\nSky-determinant %e\n", determinant );
00432    if( numSpindown == 1 ) {
00433      determinant = metric->data[2] * metric->data[5] * metric->data[9]
00434                  - metric->data[2] * metric->data[8] * metric->data[8]
00435                  + metric->data[4] * metric->data[8] * metric->data[7]
00436                  - metric->data[4] * metric->data[4] * metric->data[9]
00437                  + metric->data[7] * metric->data[4] * metric->data[8]
00438                  - metric->data[7] * metric->data[7] * metric->data[5];
00439      printf( "S&S determinant %e\n", determinant );
00440    }
00441 
00442    /* Project carrier frequency out of metric. */
00443    LALProjectMetric( &status, metric, 0 );
00444    if( status.statusCode )
00445      {
00446        printf( "%s line %d: %s\n", __FILE__, __LINE__,
00447                GENERALMETRICTESTC_MSGESUB );
00448        return GENERALMETRICTESTC_ESUB;
00449      }
00450 
00451    /* Print projected metric. */
00452    printf("\nf-projected metric (alpha, delta, ...) at the requested point\n");
00453    for (j=1; j<=2+numSpindown; j++) {
00454      for (k=1; k<=j; k++)
00455        printf( "  %+.4e", metric->data[k+j*(j+1)/2] );
00456      printf( "\n" );
00457       }
00458 
00459    /* Print determinants. */
00460    determinant = metric->data[5]*metric->data[2] - pow(metric->data[4],2);
00461    printf( "\nSky-determinant %e\n", determinant );
00462    if( numSpindown == 1 ) {
00463      determinant = metric->data[2] * metric->data[5] * metric->data[9]
00464                  - metric->data[2] * metric->data[8] * metric->data[8]
00465                  + metric->data[4] * metric->data[8] * metric->data[7]
00466                  - metric->data[4] * metric->data[4] * metric->data[9]
00467                  + metric->data[7] * metric->data[4] * metric->data[8]
00468                  - metric->data[7] * metric->data[7] * metric->data[5];
00469      printf( "S&S determinant %e\n", determinant );
00470    }
00471 
00472   /* Here is the code that uses xmgrace with the -x option, */
00473   /* and outputs data to a file with the -t option. */
00474   if (grace || nongrace) {
00475 
00476     /* Take care of preliminaries. */
00477     if(grace)
00478       {
00479         pvc = popen( "xmgrace -pipe", "w" );
00480         if( !pvc )
00481           {
00482             printf( "%s line %d: %s\n", __FILE__, __LINE__,
00483                     GENERALMETRICTESTC_MSGESYS );
00484             return GENERALMETRICTESTC_ESYS;
00485           }
00486         fprintf( pvc, "@xaxis label \"Right ascension (degrees)\"\n" );
00487         fprintf( pvc, "@yaxis label \"Declination (degrees)\"\n" );
00488       }
00489     if(nongrace)
00490       {
00491         fnongrace = fopen( "nongrace.data", "w" );
00492         if( !fnongrace )
00493           {
00494             printf( "%s line %d: %s\n", __FILE__, __LINE__,
00495                     GENERALMETRICTESTC_MSGESYS );
00496             return GENERALMETRICTESTC_ESYS;
00497           }
00498       }
00499 
00500     /* Step around the sky: a grid in ra and dec. */
00501     j = 0;
00502     for (dec=dec_max; dec>=dec_min; dec-=10) {
00503       for (ra=ra_min; ra<=ra_max; ra+=15) {
00504         REAL8 gaa, gad, gdd, angle, smaj, smin;
00505  
00506         /* Get the metric at this ra, dec. */
00507         in.position.longitude = tevlambda->data[1] = ra*LAL_PI_180;
00508         in.position.latitude  = tevlambda->data[2] = dec*LAL_PI_180;
00509         
00510         /* Evaluate metric: */
00511         if(metric_code==1)
00512           {
00513             LALPtoleMetric( &status, metric, &in );
00514             if( status.statusCode )
00515               {
00516                 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00517                         GENERALMETRICTESTC_MSGESUB );
00518                 return GENERALMETRICTESTC_ESUB;
00519               }
00520           }
00521         if(metric_code==2  || metric_code==3)
00522           {
00523             LALCoherentMetric( &status, metric, tevlambda, &tevparam );
00524             if( status.statusCode )
00525               {
00526                 printf( "%s line %d: %s\n", __FILE__, __LINE__,
00527                         GENERALMETRICTESTC_MSGESUB );
00528                 return GENERALMETRICTESTC_ESUB;
00529               }
00530           }
00531 
00532         /*  Project metric: */ 
00533         LALProjectMetric( &status, metric, 0 );
00534         if( status.statusCode )
00535           {
00536           printf( "%s line %d: %s\n", __FILE__, __LINE__,
00537                   GENERALMETRICTESTC_MSGESUB );
00538           return GENERALMETRICTESTC_ESUB;
00539           }
00540         determinant = metric->data[5]*metric->data[2]-pow(metric->data[4],2.0);
00541         if(determinant < 0.0)
00542           {
00543             printf( "%s line %d: %s\n", __FILE__, __LINE__,
00544                     GENERALMETRICTESTC_MSGEMET );
00545             return GENERALMETRICTESTC_EMET;
00546           }
00547 
00548 
00549 
00550         /* Rename \gamma_{\alpha\alpha}. */
00551         gaa = metric->data[2];
00552         /* Rename \gamma_{\alpha\delta}. */
00553         gad = metric->data[4];
00554         /* Rename \gamma_{\delta\delta}. */
00555         gdd = metric->data[5];
00556         /* Semiminor axis from larger eigenvalue of metric. */
00557         smin = gaa+gdd + sqrt( pow(gaa-gdd,2) + pow(2*gad,2) );
00558         smin = sqrt(2*mismatch/smin);
00559         /* Semiminor axis from smaller eigenvalue of metric. */
00560         smaj = gaa+gdd - sqrt( pow(gaa-gdd,2) + pow(2*gad,2) );
00561         /*printf("ra = %d, dec = %d, temp = %g\n", ra, dec, smaj);*/
00562         smaj = sqrt(2*mismatch/smaj);
00563         /* Angle of semimajor axis with "horizontal" (equator). */
00564         angle = atan2( gad, mismatch/smaj/smaj-gdd );
00565         if (angle <= -LAL_PI_2) angle += LAL_PI;
00566         if (angle > LAL_PI_2) angle -= LAL_PI;
00567  
00568         if(grace)
00569           {
00570             /* Print set header. */
00571             fprintf( pvc, "@s%d color (0,0,0)\n", j );
00572             fprintf( pvc, "@target G0.S%d\n@type xy\n", j++ );
00573             /* Print center of patch. */
00574             fprintf( pvc, "%16.8g %16.8g\n", (float)ra, (float)dec );
00575           }
00576         if(nongrace)
00577           /* Print center of patch. */
00578           fprintf( fnongrace, "%16.8g %16.8g\n", (float)ra, (float)dec );   
00579         /* Loop around patch ellipse. */
00580         for (i=0; i<=SPOKES; i++) {
00581           c_ellipse = LAL_TWOPI*i/SPOKES;
00582           r_ellipse = MAGNIFY*LAL_180_PI*smaj*smin / 
00583             sqrt( pow(smaj*sin(c_ellipse),2) + pow(smin*cos(c_ellipse),2) );
00584           if(grace)
00585             fprintf( pvc, "%e %e\n", ra+r_ellipse*cos(angle-c_ellipse), 
00586                      dec+r_ellipse*sin(angle-c_ellipse) );
00587           if(nongrace)
00588             fprintf( fnongrace, "%e %e\n", ra+r_ellipse*cos(angle-c_ellipse), 
00589                      dec+r_ellipse*sin(angle-c_ellipse) );
00590 
00591         } /* for (a...) */
00592  
00593       } /* for (ra...) */
00594     } /* for (dec...) */
00595     if(grace)
00596       fclose( pvc );
00597     if(nongrace)
00598       fclose( fnongrace );
00599   } /* if (grace || nongrace) */
00600 
00601   printf("\nCleaning up and leaving...\n");
00602 
00603   LALFree( eph->ephemE );
00604   if( status.statusCode )
00605   {
00606     printf( "%s line %d: %s\n", __FILE__, __LINE__,
00607             GENERALMETRICTESTC_MSGEMEM );
00608     return GENERALMETRICTESTC_EMEM;
00609   }
00610   LALFree( eph->ephemS );
00611   if( status.statusCode )
00612   {
00613     printf( "%s line %d: %s\n", __FILE__, __LINE__,
00614             GENERALMETRICTESTC_MSGEMEM );
00615     return GENERALMETRICTESTC_EMEM;
00616   }
00617  LALFree( eph );
00618  if( status.statusCode )
00619   {
00620     printf( "%s line %d: %s\n", __FILE__, __LINE__,
00621             GENERALMETRICTESTC_MSGEMEM );
00622     return GENERALMETRICTESTC_EMEM;
00623   }
00624 
00625   LALDDestroyVector( &status, &metric );
00626   if( status.statusCode )
00627   {
00628     printf( "%s line %d: %s\n", __FILE__, __LINE__,
00629             GENERALMETRICTESTC_MSGEMEM );
00630     return GENERALMETRICTESTC_EMEM;
00631   }
00632   LALDDestroyVector( &status, &tevlambda );
00633   if( status.statusCode )
00634   {
00635     printf( "%s line %d: %s\n", __FILE__, __LINE__,
00636             GENERALMETRICTESTC_MSGEMEM );
00637     return GENERALMETRICTESTC_EMEM;
00638   }
00639   if( in.spindown )
00640     LALDestroyVector( &status, &(in.spindown) );
00641 
00642   if( status.statusCode )
00643   {
00644     printf( "%s line %d: %s\n", __FILE__, __LINE__,
00645             GENERALMETRICTESTC_MSGEMEM );
00646     return GENERALMETRICTESTC_EMEM;
00647   }
00648   LALCheckMemoryLeaks();
00649   return 0;
00650 } /* main() */

Generated on Fri Sep 5 03:06:54 2008 for LAL by  doxygen 1.5.2