/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv------------------------------------ */ int main(int argc, char *argv[]){ static LALStatus status; /* LALStatus pointer */ INT4 arg, blkSize; /* Argument counter */ REAL8 bias; /* default values */ blkSize=7; /********************************************************/ /* Parse argument list. i stores the current position. */ /********************************************************/ arg = 1; while ( arg < argc ) { /* Parse debuglevel option. */ if ( !strcmp( argv[arg], "-d" ) ) { if ( argc > arg + 1 ) { arg++; } else { ERROR( RNGMEDBIASTESTC_EARG, RNGMEDBIASTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return RNGMEDBIASTESTC_EARG; } } else if ( !strcmp( argv[arg], "-b" ) ) { if ( argc > arg + 1 ) { arg++; blkSize = atof(argv[arg++]); } else { ERROR( RNGMEDBIASTESTC_EARG, RNGMEDBIASTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return RNGMEDBIASTESTC_EARG; } } /* Unrecognized option. */ else { ERROR( RNGMEDBIASTESTC_EARG, RNGMEDBIASTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return RNGMEDBIASTESTC_EARG; } } /* End of argument parsing loop. */ /******************************************************************/ SUB( LALRngMedBias( &status, &bias, blkSize), &status); printf("The correction factor for block size %d is: %1.15lf\n", blkSize, bias); INFO( RNGMEDBIASTESTC_MSGENORM ); return RNGMEDBIASTESTC_ENORM; }
void *LALCallocLong(size_t m, size_t n, const char *file, int line) { size_t sz; void *p; void *q; if (!(lalDebugLevel & LALMEMDBGBIT)) { return calloc(m, n); } sz = m * n; p = malloc(allocsz(sz)); q = PushAlloc(PadAlloc(p, sz, 1, "LALCalloc"), sz, file, line); lalMemDbgPtr = lalMemDbgRetPtr = q; lalIsMemDbgPtr = lalIsMemDbgRetPtr = (lalMemDbgRetPtr == lalMemDbgUsrPtr); if (!q) { XLALPrintError("LALMalloc: failed to allocate %zd bytes of memory\n", n); XLALPrintError("LALMalloc: %zd bytes of memory already allocated\n", lalMallocTotal); if (lalDebugLevel & LALMEMINFOBIT) { LALPrintError("LALCalloc meminfo: out of memory\n"); } if (p) { free(p); } } return q ? memset(q, 0, sz) : NULL; }
void *LALMallocLong(size_t n, const char *file, int line) { void *p; void *q; if (!(lalDebugLevel & LALMEMDBGBIT)) { return malloc(n); } p = malloc(allocsz(n)); q = PushAlloc(PadAlloc(p, n, 0, "LALMalloc"), n, file, line); lalMemDbgPtr = lalMemDbgRetPtr = q; lalIsMemDbgPtr = lalIsMemDbgRetPtr = (lalMemDbgRetPtr == lalMemDbgUsrPtr); if (!q) { XLALPrintError("LALMalloc: failed to allocate %zd bytes of memory\n", n); XLALPrintError("LALMalloc: %zd bytes of memory already allocated\n", lalMallocTotal); if (lalDebugLevel & LALMEMINFOBIT) { LALPrintError("LALMalloc meminfo: out of memory\n"); } if (p) { free(p); } } return q; }
void LALCheckMemoryLeaks(void) { int leak = 0; if (!(lalDebugLevel & LALMEMDBGBIT)) { return; } /* allocList should be NULL */ if ((lalDebugLevel & LALMEMTRKBIT) && allocList) { struct allocNode *node = allocList; LALPrintError("LALCheckMemoryLeaks: allocation list\n"); while (node) { LALPrintError("%p: %lu bytes (%s:%d)\n", node->addr, (unsigned long) node->size, node->file, node->line); node = node->next; } leak = 1; } /* lalMallocTotal and lalMallocCount should be zero */ if ((lalDebugLevel & LALMEMPADBIT) && (lalMallocTotal || lalMallocCount)) { LALPrintError("LALCheckMemoryLeaks: lalMallocCount = %d allocs, " "lalMallocTotal = %ld bytes\n", lalMallocCount, (long) lalMallocTotal); leak = 1; } if (leak) { lalRaiseHook(SIGSEGV, "LALCheckMemoryLeaks: memory leak\n"); } else if (lalDebugLevel & LALMEMINFOBIT) { LALPrintError ("LALCheckMemoryLeaks meminfo: no memory leaks detected\n"); } return; }
static void *PadAlloc(size_t * p, size_t n, int keep, const char *func) { size_t i; if (!(lalDebugLevel & LALMEMPADBIT)) { return p; } if (!p) { return NULL; } if (lalDebugLevel & LALMEMINFOBIT) { LALPrintError("%s meminfo: allocating %ld bytes at address %p\n", func, n, p + nprefix); } if (lalDebugLevel & LALWARNING && n == 0) { LALPrintError("%s warning: zero size allocation at address %p\n", func, p + nprefix); } /* store the size in a known position */ p[0] = n; p[1] = magic; /* pad the memory */ for (i = keep ? n : 0; i < padFactor * n; ++i) { ((char *) p)[i + prefix] = (char) (i ^ padding); } pthread_mutex_lock(&mut); lalMallocTotal += n; ++lalMallocCount; pthread_mutex_unlock(&mut); return (void *) (((char *) p) + prefix); }
void *LALReallocLong(void *q, size_t n, const char *file, const int line) { void *p; if (!(lalDebugLevel & LALMEMDBGBIT)) { return realloc(q, n); } lalMemDbgPtr = lalMemDbgArgPtr = q; lalIsMemDbgPtr = lalIsMemDbgArgPtr = (lalMemDbgArgPtr == lalMemDbgUsrPtr); if (!q) { p = malloc(allocsz(n)); q = PushAlloc(PadAlloc(p, n, 0, "LALRealloc"), n, file, line); if (!q) { XLALPrintError("LALMalloc: failed to allocate %zd bytes of memory\n", n); XLALPrintError("LALMalloc: %zd bytes of memory already allocated\n", lalMallocTotal); if (lalDebugLevel & LALMEMINFOBIT) { LALPrintError("LALRealloc meminfo: out of memory\n"); } if (p) { free(p); } } return q; } if (!n) { p = UnPadAlloc(PopAlloc(q, "LALRealloc"), 0, "LALRealloc"); if (p) { free(p); } return NULL; } p = UnPadAlloc(q, 1, "LALRealloc"); if (!p) { return NULL; } q = ModAlloc(q, PadAlloc(realloc(p, allocsz(n)), n, 1, "LALRealloc"), n, "LALRealloc", file, line); lalMemDbgPtr = lalMemDbgRetPtr = q; lalIsMemDbgPtr = lalIsMemDbgRetPtr = (lalMemDbgRetPtr == lalMemDbgUsrPtr); return q; }
/** \see See \ref LALInspiralMoments_c for documentation */ void LALGetInspiralMomentsBCV ( LALStatus *status, InspiralMomentsEtcBCV *moments, REAL8FrequencySeries *psd, InspiralTemplate *params ) { UINT4 k; InspiralMomentsIn in; INITSTATUS(status); ATTATCHSTATUSPTR( status ); /* doesn't seem to be needed. thomas, janvier 2004. I prefer to remove it for the moment. * The factor is not important in the case of SPA approximation but is important in BCV * case. Indeed on one hand we use quantity which are a ratio between two moments and * consequently a factor 1 or 2 is not important. Howver in the case of BCV, we might * use a moment alone. Thus a factor in the computation has an effect. */ /* for (i=0; i< psd->data->length ; i++) { psd->data->data[i] = psd->data->data[i] * 1e45; } */ in.shf = psd; in.xmin = params->fLower; in.xmax = params->fCutoff; /* First compute the norm */ in.norm = 1.L; for ( k = 0; k <= 22; ++k ) { if (k <= 17) { /* positive value*/ in.ndx = (REAL8)k / 3.L; } else { /* negative -1,-2 ...-6 */ in.ndx = (17.- (REAL8)k) /3.L; } LALInspiralMoments( status->statusPtr, &moments->i[k], in ); CHECKSTATUSPTR(status); } in.norm = moments->i[7] -2.*moments->alpha * moments->i[5] + moments->alpha * moments->alpha*moments->i[3]; /* 17 */ moments->M1[0][0] = (moments->i[17] -2.*moments->alpha * moments->i[15] + moments->alpha * moments->alpha*moments->i[13]) / in.norm; /* 14 */ moments->M1[0][1] = (moments->i[14] -2.*moments->alpha * moments->i[12] + moments->alpha * moments->alpha*moments->i[10]) / in.norm; /* 11 */ moments->M1[1][1] = (moments->i[11] -2.*moments->alpha * moments->i[9] + moments->alpha * moments->alpha*moments->i[7]) / in.norm; moments->M1[1][0]=moments->M1[0][1] ; /* 12 */ moments->M2[0][0] = (moments->i[12] -2.*moments->alpha * moments->i[10] + moments->alpha * moments->alpha*moments->i[8]) / in.norm; /* 9 */ moments->M2[0][1] = (moments->i[9] -2.*moments->alpha * moments->i[7] + moments->alpha * moments->alpha*moments->i[5]) / in.norm; /* 9 */ moments->M2[1][0] = (moments->i[9] -2.*moments->alpha * moments->i[7] + moments->alpha * moments->alpha*moments->i[5]) / in.norm; /* 6 */ moments->M2[1][1] = (moments->i[6] -2.*moments->alpha * moments->i[4] + moments->alpha * moments->alpha*moments->i[2]) / in.norm; /* 7 */ moments->M3[0][0] = (moments->i[7] -2.*moments->alpha * moments->i[5] + moments->alpha * moments->alpha*moments->i[3]) / in.norm; /* 4 */ moments->M3[0][1] = (moments->i[4] -2.*moments->alpha * moments->i[2] + moments->alpha * moments->alpha*moments->i[0]) / in.norm; /* 1 */ moments->M3[1][1] = (moments->i[1] -2.*moments->alpha * moments->i[18] + moments->alpha * moments->alpha * moments->i[20]) / in.norm; moments->M3[1][0]=moments->M3[0][1] ; if ( lalDebugLevel & LALINFO ) { LALPrintError( "#M1=\n"); LALPrintError( "#%15.12lf %15.12lf \n# %15.12lf %15.12lf\n", moments->M1[0][0], moments->M1[0][1], moments->M1[1][0], moments->M1[1][1] ); LALPrintError( "#M2=\n" ); LALPrintError( "#%15.12lf %15.12lf \n# %15.12lf %15.12lf\n", moments->M2[0][0], moments->M2[0][1], moments->M2[1][0], moments->M2[1][1] ); LALPrintError( "#M3=\n" ); LALPrintError( "#%15.12lf %15.12lf \n# %15.12lf %15.12lf\n", moments->M3[0][0], moments->M3[0][1], moments->M3[1][0], moments->M3[1][1] ); } DETATCHSTATUSPTR( status ); RETURN( status ); }
int main( int argc, char **argv ) { int arg; /* command-line argument counter */ BOOLEAN xyz = 0; /* whether -x, -y, or -z options were given */ INT4 verbosity = 0; /* verbosity level */ REAL8 x_1 = 0.0, x_2 = 0.0, dx; /* range and increment in x */ REAL8 y_1 = 0.0, y_2 = 0.0, dy; /* range and increment in y */ REAL8 z_1 = 0.0, z_2 = 0.0, dz; /* range and increment in z */ INT4 nx = 1, ny = 1, nz = 1; /* number of steps in each direction */ INT4 i, j, k; /* index in each direction */ REAL8 x, y, z, ddx, ddy, ddz; /* position and error in each direction */ REAL8 ddr, ddmax = 0.0; /* overall and maximum position error */ static LALStatus stat; /* status structure */ EarthPosition earth; /* terrestrial coordinates */ /******************************************************************* * PARSE ARGUMENTS (arg stores the current position) * *******************************************************************/ arg = 1; while ( arg < argc ) { /* Parse range options. */ if ( !strcmp( argv[arg], "-x" ) ) { if ( argc > arg + 3 ) { arg++; xyz = 1; x_1 = atof( argv[arg++] ); x_2 = atof( argv[arg++] ); nx = atoi( argv[arg++] ); } else { ERROR( GEOCENTRICGEODETICTESTC_EARG, GEOCENTRICGEODETICTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return GEOCENTRICGEODETICTESTC_EARG; } } else if ( !strcmp( argv[arg], "-y" ) ) { if ( argc > arg + 3 ) { arg++; xyz = 1; y_1 = atof( argv[arg++] ); y_2 = atof( argv[arg++] ); ny = atoi( argv[arg++] ); } else { ERROR( GEOCENTRICGEODETICTESTC_EARG, GEOCENTRICGEODETICTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return GEOCENTRICGEODETICTESTC_EARG; } } else if ( !strcmp( argv[arg], "-z" ) ) { if ( argc > arg + 3 ) { arg++; xyz = 1; z_1 = atof( argv[arg++] ); z_2 = atof( argv[arg++] ); nz = atoi( argv[arg++] ); } else { ERROR( GEOCENTRICGEODETICTESTC_EARG, GEOCENTRICGEODETICTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return GEOCENTRICGEODETICTESTC_EARG; } } /* Parse verbosity option. */ else if ( !strcmp( argv[arg], "-v" ) ) { if ( argc > arg + 1 ) { arg++; verbosity = atoi( argv[arg++] ); } else { ERROR( GEOCENTRICGEODETICTESTC_EARG, GEOCENTRICGEODETICTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return GEOCENTRICGEODETICTESTC_EARG; } } /* Parse debug level option. */ else if ( !strcmp( argv[arg], "-d" ) ) { if ( argc > arg + 1 ) { arg++; } else { ERROR( GEOCENTRICGEODETICTESTC_EARG, GEOCENTRICGEODETICTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return GEOCENTRICGEODETICTESTC_EARG; } } /* Check for unrecognized options. */ else if ( argv[arg][0] == '-' ) { ERROR( GEOCENTRICGEODETICTESTC_EARG, GEOCENTRICGEODETICTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return GEOCENTRICGEODETICTESTC_EARG; } } /* End of argument parsing loop. */ /******************************************************************* * SET PARAMETERS * *******************************************************************/ /* If none of -x, -y, -z were given, generate a random position. */ if ( !xyz ) { REAL4 lon, coslat, sinlat, rad; /* polar coordinates */ RandomParams *rparams = NULL; /* pseudorandom sequence parameters */ SUB( LALCreateRandomParams( &stat, &rparams, 0 ), &stat ); SUB( LALUniformDeviate( &stat, &lon, rparams ), &stat ); lon *= LAL_TWOPI; SUB( LALUniformDeviate( &stat, &sinlat, rparams ), &stat ); coslat = sqrt( 1.0 - sinlat*sinlat ); SUB( LALUniformDeviate( &stat, &rad, rparams ), &stat ); rad = 1.5*rad + 0.5; x_1 = x_2 = rad*coslat*cos( lon ); y_1 = y_2 = rad*coslat*sin( lon ); z_1 = z_2 = rad*sinlat; SUB( LALDestroyRandomParams( &stat, &rparams ), &stat ); } /* Compute stepsizes. */ dx = dy = dz = 0.0; if ( nx > 1 ) dx = ( x_2 - x_1 )/( nx - 1.0 ); if ( ny > 1 ) dy = ( y_2 - y_1 )/( ny - 1.0 ); if ( nz > 1 ) dz = ( z_2 - z_1 )/( nz - 1.0 ); /******************************************************************* * PERFORM TEST * *******************************************************************/ /* Loop over each direction. */ for ( i = 0; i < nx; i++ ) { x = LAL_REARTH_SI*( x_1 + i*dx ); for ( j = 0; j < ny; j++ ) { y = LAL_REARTH_SI*( y_1 + j*dy ); for ( k = 0; k < nz; k++ ) { z = LAL_REARTH_SI*( z_1 + k*dz ); /* Do transformation. */ earth.x = x; earth.y = y; earth.z = z; SUB( LALGeocentricToGeodetic( &stat, &earth ), &stat ); SUB( LALGeodeticToGeocentric( &stat, &earth ), &stat ); /* Compute difference. */ ddx = x - earth.x; ddy = y - earth.y; ddz = z - earth.z; ddr = sqrt( ddx*ddx + ddy*ddy + ddz*ddz ); if ( ddr > ddmax ) ddmax = ddr; if ( verbosity == 1 ) fprintf( stdout, "%+23.16e\n", ddr ); else if ( verbosity == 2 ) fprintf( stdout, "%+23.16e %+23.16e\n", earth.elevation, ddr ); else if ( verbosity == 3 ) fprintf( stdout, "%+23.16e %+23.16e %+23.16e %+23.16e\n", x, y, z, ddr ); else if ( verbosity == 4 ) fprintf( stdout, "%+23.16e %+23.16e %+23.16e" " %+23.16e %+23.16e %+23.16e %+23.16e\n", x, y, z, earth.elevation, LAL_180_PI*earth.geodetic.latitude, LAL_180_PI*earth.geodetic.longitude, ddr ); } } } /* Print maximum. */ fprintf( stdout, "Maximum error: %.16em\n", ddmax ); if ( !xyz && ddmax > 1.0e-6 ) { ERROR( GEOCENTRICGEODETICTESTC_ETEST, GEOCENTRICGEODETICTESTC_MSGETEST, 0 ); return GEOCENTRICGEODETICTESTC_ETEST; } LALCheckMemoryLeaks(); INFO( GEOCENTRICGEODETICTESTC_MSGENORM ); return GEOCENTRICGEODETICTESTC_ENORM; }
int main(int argc, char **argv) { /* Command-line parsing variables. */ int arg; /* command-line argument counter */ static LALStatus stat; /* status structure */ CHAR *sourcefile = NULL; /* name of sourcefile */ CHAR *respfile = NULL; /* name of respfile */ CHAR *infile = NULL; /* name of infile */ CHAR *outfile = NULL; /* name of outfile */ INT4 seed = 0; /* random number seed */ INT4 sec = SEC; /* ouput epoch.gpsSeconds */ INT4 nsec = NSEC; /* ouput epoch.gpsNanoSeconds */ INT4 npt = NPT; /* number of output points */ REAL8 dt = DT; /* output sampling interval */ REAL4 sigma = SIGMA; /* noise amplitude */ /* File reading variables. */ FILE *fp = NULL; /* generic file pointer */ BOOLEAN ok = 1; /* whether input format is correct */ UINT4 i; /* generic index over file lines */ INT8 epoch; /* epoch stored as an INT8 */ /* Other global variables. */ RandomParams *params = NULL; /* parameters of pseudorandom sequence */ DetectorResponse detector; /* the detector in question */ INT2TimeSeries output; /* detector ACD output */ /******************************************************************* * PARSE ARGUMENTS (arg stores the current position) * *******************************************************************/ /* Exit gracefully if no arguments were given. if ( argc <= 1 ) { INFO( "No testing done." ); return 0; } */ arg = 1; while ( arg < argc ) { /* Parse source file option. */ if ( !strcmp( argv[arg], "-s" ) ) { if ( argc > arg + 1 ) { arg++; sourcefile = argv[arg++]; }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Parse response file option. */ else if ( !strcmp( argv[arg], "-r" ) ) { if ( argc > arg + 1 ) { arg++; respfile = argv[arg++]; }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Parse input file option. */ else if ( !strcmp( argv[arg], "-i" ) ) { if ( argc > arg + 1 ) { arg++; infile = argv[arg++]; }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Parse noise output option. */ else if ( !strcmp( argv[arg], "-n" ) ) { if ( argc > arg + 5 ) { arg++; sec = atoi( argv[arg++] ); nsec = atoi( argv[arg++] ); npt = atoi( argv[arg++] ); dt = atof( argv[arg++] ); sigma = atof( argv[arg++] ); }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Parse output file option. */ else if ( !strcmp( argv[arg], "-o" ) ) { if ( argc > arg + 1 ) { arg++; outfile = argv[arg++]; }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Parse debug level option. */ else if ( !strcmp( argv[arg], "-d" ) ) { if ( argc > arg + 1 ) { arg++; }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Parse random seed option. */ else if ( !strcmp( argv[arg], "-e" ) ) { if ( argc > arg + 1 ) { arg++; seed = atoi( argv[arg++] ); }else{ ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* Check for unrecognized options. */ else if ( argv[arg][0] == '-' ) { ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BASICINJECTTESTC_EARG; } } /* End of argument parsing loop. */ /* Check for redundant or bad argument values. */ CHECKVAL( npt, 0, 2147483647 ); CHECKVAL( dt, 0, LAL_REAL4_MAX ); /******************************************************************* * SETUP * *******************************************************************/ /* Set up output, detector, and random parameter structures. */ output.data = NULL; detector.transfer = (COMPLEX8FrequencySeries *) LALMalloc( sizeof(COMPLEX8FrequencySeries) ); if ( !(detector.transfer) ) { ERROR( BASICINJECTTESTC_EMEM, BASICINJECTTESTC_MSGEMEM, 0 ); return BASICINJECTTESTC_EMEM; } detector.transfer->data = NULL; detector.site = NULL; SUB( LALCreateRandomParams( &stat, ¶ms, seed ), &stat ); /* Set up units. */ output.sampleUnits = lalADCCountUnit; if (XLALUnitDivide( &(detector.transfer->sampleUnits), &lalADCCountUnit, &lalStrainUnit ) == NULL) { return LAL_EXLAL; } /* Read response function. */ if ( respfile ) { REAL4VectorSequence *resp = NULL; /* response as vector sequence */ COMPLEX8Vector *response = NULL; /* response as complex vector */ COMPLEX8Vector *unity = NULL; /* vector of complex 1's */ if ( ( fp = fopen( respfile, "r" ) ) == NULL ) { ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE, respfile ); return BASICINJECTTESTC_EFILE; } /* Read header. */ ok &= ( fscanf( fp, "# epoch = %" LAL_INT8_FORMAT "\n", &epoch ) == 1 ); I8ToLIGOTimeGPS( &( detector.transfer->epoch ), epoch ); ok &= ( fscanf( fp, "# f0 = %lf\n", &( detector.transfer->f0 ) ) == 1 ); ok &= ( fscanf( fp, "# deltaF = %lf\n", &( detector.transfer->deltaF ) ) == 1 ); if ( !ok ) { ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT, respfile ); return BASICINJECTTESTC_EINPUT; } /* Read and convert body to a COMPLEX8Vector. */ SUB( LALSReadVectorSequence( &stat, &resp, fp ), &stat ); fclose( fp ); if ( resp->vectorLength != 2 ) { ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT, respfile ); return BASICINJECTTESTC_EINPUT; } SUB( LALCCreateVector( &stat, &response, resp->length ), &stat ); memcpy( response->data, resp->data, 2*resp->length*sizeof(REAL4) ); SUB( LALSDestroyVectorSequence( &stat, &resp ), &stat ); /* Convert response function to a transfer function. */ SUB( LALCCreateVector( &stat, &unity, response->length ), &stat ); for ( i = 0; i < response->length; i++ ) { unity->data[i] = 1.0; } SUB( LALCCreateVector( &stat, &( detector.transfer->data ), response->length ), &stat ); SUB( LALCCVectorDivide( &stat, detector.transfer->data, unity, response ), &stat ); SUB( LALCDestroyVector( &stat, &response ), &stat ); SUB( LALCDestroyVector( &stat, &unity ), &stat ); } /* No response file, so generate a unit response. */ else { I8ToLIGOTimeGPS( &( detector.transfer->epoch ), EPOCH ); detector.transfer->f0 = 0.0; detector.transfer->deltaF = 1.5*FSTOP; SUB( LALCCreateVector( &stat, &( detector.transfer->data ), 2 ), &stat ); detector.transfer->data->data[0] = 1.0; detector.transfer->data->data[1] = 1.0; } /* Read input data. */ if ( infile ) { REAL4VectorSequence *input = NULL; /* input as vector sequence */ if ( ( fp = fopen( infile, "r" ) ) == NULL ) { ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE, infile ); return BASICINJECTTESTC_EFILE; } /* Read header. */ ok &= ( fscanf( fp, "# epoch = %" LAL_INT8_FORMAT "\n", &epoch ) == 1 ); I8ToLIGOTimeGPS( &( output.epoch ), epoch ); ok &= ( fscanf( fp, "# deltaT = %lf\n", &( output.deltaT ) ) == 1 ); if ( !ok ) { ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT, infile ); return BASICINJECTTESTC_EINPUT; } /* Read and convert body. */ SUB( LALSReadVectorSequence( &stat, &input, fp ), &stat ); fclose( fp ); if ( input->vectorLength != 1 ) { ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT, infile ); return BASICINJECTTESTC_EINPUT; } SUB( LALI2CreateVector( &stat, &( output.data ), input->length ), &stat ); for ( i = 0; i < input->length; i++ ) output.data->data[i] = (INT2)( input->data[i] ); SUB( LALSDestroyVectorSequence( &stat, &input ), &stat ); } /* No input file, so generate one randomly. */ else { output.epoch.gpsSeconds = sec; output.epoch.gpsNanoSeconds = nsec; output.deltaT = dt; SUB( LALI2CreateVector( &stat, &( output.data ), npt ), &stat ); if ( sigma == 0 ) { memset( output.data->data, 0, npt*sizeof(INT2) ); } else { REAL4Vector *deviates = NULL; /* unit Gaussian deviates */ SUB( LALSCreateVector( &stat, &deviates, npt ), &stat ); SUB( LALNormalDeviates( &stat, deviates, params ), &stat ); for ( i = 0; i < (UINT4)( npt ); i++ ) output.data->data[i] = (INT2) floor( sigma*deviates->data[i] + 0.5 ); SUB( LALSDestroyVector( &stat, &deviates ), &stat ); } } /******************************************************************* * INJECTION * *******************************************************************/ /* Open sourcefile. */ if ( sourcefile ) { if ( ( fp = fopen( sourcefile, "r" ) ) == NULL ) { ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE, sourcefile ); return BASICINJECTTESTC_EFILE; } } /* For each line in the sourcefile... */ while ( ok ) { PPNParamStruc ppnParams; /* wave generation parameters */ REAL4 m1, m2, dist, inc, phic; /* unconverted parameters */ CoherentGW waveform; /* amplitude and phase structure */ REAL4TimeSeries signalvec; /* GW signal */ REAL8 time; /* length of GW signal */ CHAR timeCode; /* code for signal time alignment */ CHAR message[MSGLEN]; /* warning/info messages */ /* Read and convert input line. */ if ( sourcefile ) { ok &= ( fscanf( fp, "%c %" LAL_INT8_FORMAT " %f %f %f %f %f\n", &timeCode, &epoch, &m1, &m2, &dist, &inc, &phic ) == 7 ); ppnParams.mTot = m1 + m2; ppnParams.eta = m1*m2/( ppnParams.mTot*ppnParams.mTot ); ppnParams.d = dist*LAL_PC_SI*1000.0; ppnParams.inc = inc*LAL_PI/180.0; ppnParams.phi = phic*LAL_PI/180.0; } else { timeCode = 'i'; ppnParams.mTot = M1 + M2; ppnParams.eta = M1*M2/( ppnParams.mTot*ppnParams.mTot ); ppnParams.d = DIST; ppnParams.inc = INC; ppnParams.phi = PHIC; epoch = EPOCH; } if ( ok ) { /* Set up other parameter structures. */ ppnParams.epoch.gpsSeconds = ppnParams.epoch.gpsNanoSeconds = 0; ppnParams.position.latitude = ppnParams.position.longitude = 0.0; ppnParams.position.system = COORDINATESYSTEM_EQUATORIAL; ppnParams.psi = 0.0; ppnParams.fStartIn = FSTART; ppnParams.fStopIn = FSTOP; ppnParams.lengthIn = 0; ppnParams.ppn = NULL; ppnParams.deltaT = DELTAT; memset( &waveform, 0, sizeof(CoherentGW) ); /* Generate waveform at zero epoch. */ SUB( LALGeneratePPNInspiral( &stat, &waveform, &ppnParams ), &stat ); snprintf( message, MSGLEN, "%d: %s", ppnParams.termCode, ppnParams.termDescription ); INFO( message ); if ( ppnParams.dfdt > 2.0 ) { snprintf( message, MSGLEN, "Waveform sampling interval is too large:\n" "\tmaximum df*dt = %f", ppnParams.dfdt ); WARNING( message ); } /* Compute epoch for waveform. */ time = waveform.a->data->length*DELTAT; if ( timeCode == 'f' ) epoch -= (INT8)( 1000000000.0*time ); else if ( timeCode == 'c' ) epoch -= (INT8)( 1000000000.0*ppnParams.tc ); I8ToLIGOTimeGPS( &( waveform.a->epoch ), epoch ); waveform.f->epoch = waveform.phi->epoch = waveform.a->epoch; /* Generate and inject signal. */ signalvec.epoch = waveform.a->epoch; signalvec.epoch.gpsSeconds -= 1; signalvec.deltaT = output.deltaT/4.0; signalvec.f0 = 0; signalvec.data = NULL; time = ( time + 2.0 )/signalvec.deltaT; SUB( LALSCreateVector( &stat, &( signalvec.data ), (UINT4)time ), &stat ); SUB( LALSimulateCoherentGW( &stat, &signalvec, &waveform, &detector ), &stat ); SUB( LALSI2InjectTimeSeries( &stat, &output, &signalvec, params ), &stat ); SUB( LALSDestroyVectorSequence( &stat, &( waveform.a->data ) ), &stat ); SUB( LALSDestroyVector( &stat, &( waveform.f->data ) ), &stat ); SUB( LALDDestroyVector( &stat, &( waveform.phi->data ) ), &stat ); LALFree( waveform.a ); LALFree( waveform.f ); LALFree( waveform.phi ); SUB( LALSDestroyVector( &stat, &( signalvec.data ) ), &stat ); } /* If there is no source file, inject only one source. */ if ( !sourcefile ) ok = 0; } /* Input file is exhausted (or has a badly-formatted line ). */ if ( sourcefile ) fclose( fp ); /******************************************************************* * CLEANUP * *******************************************************************/ /* Print output file. */ if ( outfile ) { if ( ( fp = fopen( outfile, "w" ) ) == NULL ) { ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE, outfile ); return BASICINJECTTESTC_EFILE; } epoch = 1000000000LL*(INT8)( output.epoch.gpsSeconds ); epoch += (INT8)( output.epoch.gpsNanoSeconds ); fprintf( fp, "# epoch = %" LAL_INT8_FORMAT "\n", epoch ); fprintf( fp, "# deltaT = %23.16e\n", output.deltaT ); for ( i = 0; i < output.data->length; i++ ) fprintf( fp, "%8.1f\n", (REAL4)( output.data->data[i] ) ); fclose( fp ); } /* Destroy remaining memory. */ SUB( LALDestroyRandomParams( &stat, ¶ms ), &stat ); SUB( LALI2DestroyVector( &stat, &( output.data ) ), &stat ); SUB( LALCDestroyVector( &stat, &( detector.transfer->data ) ), &stat ); LALFree( detector.transfer ); /* Done! */ LALCheckMemoryLeaks(); INFO( BASICINJECTTESTC_MSGENORM ); return BASICINJECTTESTC_ENORM; }
int main(int argc, char **argv) { static LALStatus stat; /* LALStatus pointer */ CHAR *infile = NULL; /* The input filename */ CHAR *outfile = NULL; /* The output filename */ INT4 arg; /* Argument counter */ UINT4 npts = NPTS; /* Number of points in time series */ UINT4 offset = OFFSET; /* Position of delta function */ REAL8 dt = DT; /* Sampling interval. */ static REAL4TimeSeries series; /* Time series */ static PassBandParamStruc params; /* Filter parameters */ XLALSetErrorHandler( XLALAbortErrorHandler ); /* Set up the default filter parameters. */ params.f1 = F1; params.f2 = F2; params.a1 = A1; params.a2 = A2; params.nMax = ORDER; /* Parse argument list. i stores the current position. */ arg = 1; while ( arg < argc ) { /* Parse debuglevel option. */ if ( !strcmp( argv[arg], "-d" ) ) { if ( argc > arg + 1 ) { arg++; } else { ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BANDPASSTESTC_EARG; } } /* Parse input file option. */ else if ( !strcmp( argv[arg], "-i" ) ) { if ( argc > arg + 1 ) { arg++; infile = argv[arg++]; } else { ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BANDPASSTESTC_EARG; } } /* Parse output file option. */ else if ( !strcmp( argv[arg], "-o" ) ) { if ( argc > arg + 1 ) { arg++; outfile = argv[arg++]; } else { ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BANDPASSTESTC_EARG; } } /* Parse filter options. */ else if ( !strcmp( argv[arg], "-f" ) ) { if ( argc > arg + 5 ) { arg++; params.f1=atof(argv[arg++]); params.f2=atof(argv[arg++]); params.a1=atof(argv[arg++]); params.a2=atof(argv[arg++]); params.nMax=atoi(argv[arg++]); } else { ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BANDPASSTESTC_EARG; } } /* Parse time series options. */ else if ( !strcmp( argv[arg], "-n" ) ) { if ( argc > arg + 3 ) { arg++; npts=atoi(argv[arg++]); dt=atof(argv[arg++]); offset=atoi(argv[arg++]); } else { ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BANDPASSTESTC_EARG; } } /* Unrecognized option. */ else { ERROR( BANDPASSTESTC_EARG, BANDPASSTESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return BANDPASSTESTC_EARG; } } /* End of argument parsing loop. */ /* Check input values. */ if ( !infile ) { if ( offset >= npts ) { ERROR( BANDPASSTESTC_EBAD, BANDPASSTESTC_MSGEBAD, 0 ); LALPrintError( "\toffset=%i must be less than npts=%i\n", offset, npts ); return BANDPASSTESTC_EBAD; } } /* Create the time series. */ if ( infile ) { FILE *fp = fopen( infile, "r" ); if ( !fp ) { ERROR( BANDPASSTESTC_EFILE, BANDPASSTESTC_MSGEFILE, infile ); return BANDPASSTESTC_EFILE; } SUB( LALSReadTSeries( &stat, &series, fp ), &stat ); fclose( fp ); } else { snprintf( series.name, LALNameLength, "%s", "Impulse" ); series.deltaT = dt; SUB( LALSCreateVector( &stat, &(series.data), npts ), &stat ); memset( series.data->data, 0, npts*sizeof(REAL4) ); series.data->data[offset] = 1.0; } /* Filter the time series. */ SUB( LALDButterworthREAL4TimeSeries( &stat, &series, ¶ms ), &stat ); /* Print the output, if the -o option was given. */ if ( outfile ) { FILE *fp = fopen( outfile, "w" ); if ( !fp ){ ERROR( BANDPASSTESTC_EFILE, BANDPASSTESTC_MSGEFILE, outfile ); return BANDPASSTESTC_EFILE; } SUB( LALSWriteTSeries( &stat, fp, &series ), &stat ); fclose( fp ); } /* Free memory and exit. */ SUB( LALSDestroyVector( &stat, &(series.data) ), &stat ); LALCheckMemoryLeaks(); INFO( BANDPASSTESTC_MSGENORM ); return BANDPASSTESTC_ENORM; }
static void *UnPadAlloc(void *p, int keep, const char *func) { size_t n; size_t i; size_t *q; char *s; if (!(lalDebugLevel & LALMEMPADBIT)) { return p; } if (!p || !(q = ((size_t *) p) - nprefix)) { lalRaiseHook(SIGSEGV, "%s error: tried to free NULL pointer\n", func); return NULL; } n = q[0]; s = (char *) q; if (lalDebugLevel & LALMEMINFOBIT) { LALPrintError("%s meminfo: freeing %ld bytes at address %p\n", func, n, p); } if (lalDebugLevel & LALWARNING && n == 0) { LALPrintError ("%s warning: tried to free a freed pointer at address %p\n", func, p); } if (q[1] != magic) { lalRaiseHook(SIGSEGV, "%s error: wrong magic for pointer at address %p\n", func, p); return NULL; } if (((long) n) < 0) { lalRaiseHook(SIGSEGV, "%s error: corrupt size descriptor for pointer at address %p\n", func, p); return NULL; } /* check for writing past end of array: */ for (i = n; i < padFactor * n; ++i) { if (s[i + prefix] != (char) (i ^ padding)) { lalRaiseHook(SIGSEGV, "%s error: array bounds overwritten\n" "Byte %ld past end of array has changed\n" "Corrupted address: %p\nArray address: %p\n", func, i - n + 1, s + i + prefix, s + prefix); return NULL; } } /* see if there is enough allocated memory to be freed */ if (lalMallocTotal < n) { lalRaiseHook(SIGSEGV, "%s error: lalMallocTotal too small\n", func); return NULL; } /* repad the memory */ for (i = keep ? n : 0; i < padFactor * n; ++i) { s[i + prefix] = (char) (i ^ repadding); } q[0] = -1; /* set negative to detect duplicate frees */ q[1] = ~magic; pthread_mutex_lock(&mut); lalMallocTotal -= n; --lalMallocCount; pthread_mutex_unlock(&mut); return q; }
/** * Multi-IFO version of LALGetAMCoeffs(). * Get all antenna-pattern coefficients for all input detector-series. * * NOTE: contrary to LALGetAMCoeffs(), this functions *allocates* the output-vector, * use XLALDestroyMultiAMCoeffs() to free this. */ void LALGetMultiAMCoeffs (LALStatus *status, /**< [in/out] LAL status structure pointer */ MultiAMCoeffs **multiAMcoef, /**< [out] AM-coefficients for all input detector-state series */ const MultiDetectorStateSeries *multiDetStates, /**< [in] detector-states at timestamps t_i */ SkyPosition skypos /**< source sky-position [in equatorial coords!] */ ) { UINT4 X, numDetectors; MultiAMCoeffs *ret = NULL; INITSTATUS(status); ATTATCHSTATUSPTR (status); /* check input */ ASSERT (multiDetStates, status,LALCOMPUTEAMH_ENULL, LALCOMPUTEAMH_MSGENULL); ASSERT (multiDetStates->length, status,LALCOMPUTEAMH_ENULL, LALCOMPUTEAMH_MSGENULL); ASSERT (multiAMcoef, status,LALCOMPUTEAMH_ENULL, LALCOMPUTEAMH_MSGENULL); ASSERT ( *multiAMcoef == NULL, status,LALCOMPUTEAMH_ENONULL, LALCOMPUTEAMH_MSGENONULL); ASSERT ( skypos.system == COORDINATESYSTEM_EQUATORIAL, status, LALCOMPUTEAMH_EINPUT, LALCOMPUTEAMH_MSGEINPUT ); numDetectors = multiDetStates->length; if ( ( ret = LALCalloc( 1, sizeof( *ret ) )) == NULL ) { ABORT (status, LALCOMPUTEAMH_EMEM, LALCOMPUTEAMH_MSGEMEM); } ret->length = numDetectors; if ( ( ret->data = LALCalloc ( numDetectors, sizeof ( *ret->data ) )) == NULL ) { LALFree ( ret ); ABORT (status, LALCOMPUTEAMH_EMEM, LALCOMPUTEAMH_MSGEMEM); } for ( X=0; X < numDetectors; X ++ ) { AMCoeffs *amcoeX = NULL; UINT4 numStepsX = multiDetStates->data[X]->length; ret->data[X] = LALCalloc ( 1, sizeof ( *(ret->data[X]) ) ); amcoeX = ret->data[X]; amcoeX->a = XLALCreateREAL4Vector ( numStepsX ); if ( (amcoeX->b = XLALCreateREAL4Vector ( numStepsX )) == NULL ) { LALPrintError ("\nOut of memory!\n\n"); goto failed; } /* LALGetAMCoeffs (status->statusPtr, amcoeX, multiDetStates->data[X], skypos ); */ LALNewGetAMCoeffs (status->statusPtr, amcoeX, multiDetStates->data[X], skypos ); if ( status->statusPtr->statusCode ) { LALPrintError ( "\nCall to LALNewGetAMCoeffs() has failed ... \n\n"); goto failed; } } /* for X < numDetectors */ goto success; failed: /* free all memory allocated so far */ XLALDestroyMultiAMCoeffs ( ret ); ABORT ( status, -1, "LALGetMultiAMCoeffs() failed" ); success: (*multiAMcoef) = ret; DETATCHSTATUSPTR (status); RETURN(status); } /* LALGetMultiAMCoeffs() */
int main(int argc, char *argv[]) { const char *fn = __func__; LALStatus status = empty_status; SFTCatalog *catalog = NULL; SFTConstraints constraints = empty_constraints; SFTVector *sft_vect = NULL; SFTVector *sft_vect2 = NULL; MultiSFTVector *multsft_vect = NULL; MultiSFTVector *multsft_vect2 = NULL; CHAR detector[2] = "H1"; INT4 crc_check; /* band to read from infile.* SFTs */ REAL8 fMin = 1008.5; REAL8 fMax = 1009.1; if ( argc == 1) /* avoid warning */ argc = 1; /* check that mal-formated SFTs are properly detected */ SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad1", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad2", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad3", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad4", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad5", NULL ), &status); /* the following (SFT-bad6) has a wrong CRC64 checksum. However, this is * not checked in LALSFTdataFind, so it should succeed! */ SHOULD_WORK( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad6", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad7", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad8", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad9", NULL ), &status); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad10", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad11", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad12", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad13", NULL ), &status ); SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-bad14", NULL ), &status ); /* now check some crc-checksums */ SHOULD_WORK( LALCheckSFTs ( &status, &crc_check, TEST_DATA_DIR "SFT-test1", NULL ), &status ); if ( crc_check != 0 ) { XLALPrintError ("\nLALCheckSFTs(): SFT-test1 has correct checksum but LALCheckSFTs claimed it hasn't.\n\n"); return crc_check; } SHOULD_WORK( LALCheckSFTs ( &status, &crc_check, TEST_DATA_DIR "SFT-bad6", NULL ), &status ); if ( crc_check != SFTFILEIO_ECRC64 ) { XLALPrintError ( "\nLALCheckSFTs() failed to catch invalid CRC checksum in SFT-bad6 \n\n"); return SFTFILEIOTESTC_ESUB; } /* check that proper v2-SFTs are read-in properly */ SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test1", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test2", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test3", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test4", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test5", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test6", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test7", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* now completely read-in a v2 merged-SFT */ SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test*", NULL ), &status ); /* skip sft nr 4 with has Tsft=50 instead of Tsft=60 */ SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test[123567]*", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* try the same with a ";" separated list of files and of patterns */ SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test1;" TEST_DATA_DIR "SFT-test2;" TEST_DATA_DIR "SFT-test3;" TEST_DATA_DIR "SFT-test5;" TEST_DATA_DIR "SFT-test6;" TEST_DATA_DIR "SFT-test7", NULL ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); SHOULD_WORK ( LALSFTdataFind ( &status, &catalog, TEST_DATA_DIR "SFT-test[123]*;" TEST_DATA_DIR "SFT-test[5]*", NULL ), &status ); /* load once as a single SFT-vector (mix of detectors) */ SHOULD_WORK ( LALLoadSFTs ( &status, &sft_vect, catalog, -1, -1 ), &status ); /* load once as a multi-SFT vector */ SHOULD_WORK ( LALLoadMultiSFTs ( &status, &multsft_vect, catalog, -1, -1 ), &status ); /* load again, using XLAL API */ if ( ( multsft_vect2 = XLALLoadMultiSFTs ( catalog, -1, -1 )) == NULL ) { XLALPrintError ("%s: XLALLoadMultiSFTs (cat, -1, -1) failed with xlalErrno = %d\n", fn, xlalErrno ); return SFTFILEIOTESTC_ESUB; } SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* 6 SFTs from 2 IFOs should have been read */ if ( (sft_vect->length != 4) /* either as a single SFTVector */ || (multsft_vect->length != 2) /* or separated by detector */ || (multsft_vect->data[0]->length != 3) || ( multsft_vect->data[1]->length != 1 ) ) { XLALPrintError ( "\nFailed to read in multi-SFT from 2 IFOs 'SFT-test*'!\n\n"); return SFTFILEIOTESTC_ESUB; } /* compare results from LALLoadMultiSFTs() and XLALLoadMultiSFTs() */ { UINT4 numIFOs = multsft_vect->length; UINT4 X; for ( X=0; X < numIFOs; X ++ ) { if( CompareSFTVectors ( multsft_vect->data[X], multsft_vect2->data[X] ) ) { XLALPrintError ("%s: comparing (X)LALLoadMultiSFTs(): sft-vectors differ for X=%d\n", fn, X ); return SFTFILEIOTESTC_ESUB; } } /* for X < numIFOs */ } /* ------ */ /* ----- v2 SFT writing ----- */ /* write v2-SFT to disk */ SHOULD_WORK ( LALWriteSFT2file( &status, &(multsft_vect->data[0]->data[0]), "outputsftv2_v2.sft", "A v2-SFT file for testing!"), &status ); SHOULD_WORK ( LALWriteSFTVector2Dir( &status, multsft_vect->data[0], ".", "A v2-SFT file for testing!", "test"), &status); /* write v2-SFT to single file */ { const CHAR *currSingleSFT = NULL; UINT4 i = 0; FILE *fpConcat = NULL, *fpSingle = NULL; int concat = 0, single = 0; xlalErrno = 0; if (XLAL_SUCCESS != XLALWriteSFTVector2File ( multsft_vect->data[0], ".", "A v2-SFT file for testing!", "test_concat" )) { LALPrintError ( "\n XLALWriteSFTVector2File failed to write multi-SFT vector to file!\n\n"); return SFTFILEIOTESTC_ESUB; } /* check that the single file SFT is the same as the single SFTs */ const UINT4 numSingleSFTs = 3; const CHAR *singleSFTs[] = { "H-1_H1_60SFT_test-000012345-61.sft", "H-1_H1_60SFT_test-000012465-61.sft", "H-1_H1_60SFT_test-000012585-61.sft" }; printf("*** Comparing single and concatenated SFTs ***\n"); /* try to open concatenated SFT */ const CHAR *concatSFT = "H-3_H1_60SFT_test_concat-000012345-302.sft"; if ( ( fpConcat = fopen(concatSFT, "rb" ) ) == NULL ) { LALPrintError ( "\n Cound not open SFT '%s'!\n\n", concatSFT); return SFTFILEIOTESTC_ESUB; } /* do loop while concat. SFT has data */ while (!feof(fpConcat)) { /* get character from concat. SFT */ concat = fgetc(fpConcat); if ( ferror(fpConcat) ) { LALPrintError ( "\n IO error reading '%s'!\n\n", concatSFT); return SFTFILEIOTESTC_ESUB; } /* get character from single SFT */ while (1) { /* need to open next single SFT file */ if (fpSingle == NULL) { /* break if we've run out of single SFTs */ if (i == numSingleSFTs) break; /* try to open single SFT */ if ( ( fpSingle = fopen(singleSFTs[i], "rb" ) ) == NULL ) { LALPrintError ( "\n Cound not open SFT '%s'!\n\n", singleSFTs[i]); return SFTFILEIOTESTC_ESUB; } currSingleSFT = singleSFTs[i]; } /* get character from single SFT */ single = fgetc(fpSingle); if ( ferror(fpSingle) ) { LALPrintError ( "\n IO error reading '%s'!\n\n", singleSFTs[i]); return SFTFILEIOTESTC_ESUB; } /* if single SFT is out of data, close it (open next one at beginning of loop) */ if (feof(fpSingle)) { fclose(fpSingle); fpSingle = NULL; ++i; } /* otherwise we have a valid character */ else break; } /* do character-by-character comparison */ if ( concat != single ) { LALPrintError ( "\n Comparison failed between '%s'(last char = %i) and '%s'(last char = %i)!!\n\n", concatSFT, concat, currSingleSFT, single ); return SFTFILEIOTESTC_ESFTDIFF; } } fclose(fpConcat); printf( "*** Comparing was successful!!! ***\n"); } /* write v2-SFt as a v1-SFT to disk (correct normalization) */ multsft_vect->data[0]->data[0].epoch.gpsSeconds += 60; /* shift start-time so they don't look like segmented SFTs! */ SHOULD_WORK ( LALWrite_v2SFT_to_v1file( &status, &(multsft_vect->data[0]->data[0]), "outputsftv2_v1.sft"), &status ); SUB ( LALDestroySFTVector ( &status, &sft_vect ), &status ); SUB ( LALDestroyMultiSFTVector (&status, &multsft_vect ), &status ); SUB ( LALDestroyMultiSFTVector (&status, &multsft_vect2 ), &status ); /* ----- read the previous two SFTs back */ SHOULD_FAIL ( LALSFTdataFind ( &status, &catalog, "outputsftv2_*.sft", NULL ), &status ); /* need to set proper detector! */ constraints.detector = detector; SUB ( LALSFTdataFind ( &status, &catalog, "outputsftv2_*.sft", &constraints ), &status); SUB ( LALLoadSFTs ( &status, &sft_vect, catalog, -1, -1 ), &status ); if ( sft_vect->length != 2 ) { if ( lalDebugLevel ) XLALPrintError ("\nFailed to read back in 'outputsftv2_*.sft'\n\n"); return SFTFILEIOTESTC_ESUB; } sft_vect2 = XLALLoadSFTs ( catalog, -1, -1 ); if (!sft_vect2) { XLALPrintError ( "\nXLALLoadSFTs() call failed (where it should have succeeded)!\n\n"); return SFTFILEIOTESTC_ESUB; } /* compare the SFT vectors just read */ if(CompareSFTVectors(sft_vect, sft_vect2)) return SFTFILEIOTESTC_ESUB; /* the data of 'outputsftv2_v2.sft' and 'outputsftv2_v1.sft' should agree, as the normalization * should be corrected again when reading-in */ { UINT4 i; UINT4 numBins = sft_vect->data[0].data->length; for ( i=0; i < numBins; i++) { COMPLEX8 *data1 = &(sft_vect->data[0].data->data[i]); COMPLEX8 *data2 = &(sft_vect->data[1].data->data[i]); if ( (crealf(*data1) != crealf(*data2)) || (cimagf(*data1) != cimagf(*data2)) ) { XLALPrintError ("\nv1- and v2- SFT differ after writing/reading\n\n"); return SFTFILEIOTESTC_ESFTDIFF; } } /* for i < numBins */ } SUB ( LALDestroySFTVector (&status, &sft_vect2 ), &status ); SUB ( LALDestroySFTVector (&status, &sft_vect ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* `----- v1 SFT writing */ /* read v1-SFTs: 'inputsft.0' and 'inputsft.1' (one is big-endian, the other little-endian!) */ SUB ( LALSFTdataFind (&status, &catalog, TEST_DATA_DIR "inputsft.?", &constraints ), &status ); SUB ( LALLoadSFTs ( &status, &sft_vect, catalog, fMin, fMax ), &status ); if ( sft_vect->length != 2 ) { if ( lalDebugLevel ) XLALPrintError ("\nFailed to read in v1-SFTs 'inputsft.0' and 'inputsft.1'\n\n"); return SFTFILEIOTESTC_ESUB; } /* read with XLALLoadSFTs() */ sft_vect2 = XLALLoadSFTs ( catalog, fMin, fMax ); if (!sft_vect2) { XLALPrintError ( "\nXLALLoadSFTs() call failed (where it should have succeeded)!\n\n"); return SFTFILEIOTESTC_ESUB; } /* compare the SFT vectors just read */ if(CompareSFTVectors(sft_vect, sft_vect2)) return SFTFILEIOTESTC_ESUB; /* write v1-SFT to disk */ SUB ( LALWriteSFTfile (&status, &(sft_vect->data[0]), "outputsft_v1.sft"), &status); /* try to write this v1-SFTs as v2: should fail without detector-info ! */ strncpy( sft_vect->data[0].name, "??", 2 ); SHOULD_FAIL (LALWriteSFT2file( &status, &(sft_vect->data[0]), "outputsft_v2.sft", "Another v2-SFT file for testing!"), &status ); /* put detector there */ strcpy ( sft_vect->data[0].name, "H1" ); SHOULD_WORK (LALWriteSFT2file( &status, &(sft_vect->data[0]), "outputsft_v2.sft", "Another v2-SFT file for testing!"), &status ); SUB ( LALDestroySFTVector (&status, &sft_vect2 ), &status ); SUB ( LALDestroySFTVector (&status, &sft_vect ), &status ); SUB ( LALDestroySFTCatalog( &status, &catalog), &status ); /* ---------- test timestamps-reading functions by comparing LAL- and XLAL-versions against each other ---------- */ { #define TS_FNAME "testTimestamps.dat" LIGOTimeGPSVector *ts1 = NULL, *ts2 = NULL; /* ----- load timestamps with deprecated LAL function */ SUB ( LALReadTimestampsFile ( &status, &ts1, TEST_DATA_DIR TS_FNAME ), &status ); /* ----- load timestamps w new XLAL function */ if ( (ts2 = XLALReadTimestampsFile ( TEST_DATA_DIR TS_FNAME )) == NULL ) { XLALPrintError ("XLALReadTimestampsFile() failed to read timestamps from file '%s'. xlalErrno = %d\n", TS_FNAME ); return SFTFILEIOTESTC_ESUB; } /* ----- compare the two */ if ( ts1->length != ts2->length ) { XLALPrintError ("Read timestamps-lists differ in length %d != %d\n", ts1->length, ts2->length ); return 1; } if ( ts1->deltaT != ts2->deltaT ) { XLALPrintError ("Read timestamps-lists differ in deltaT %g != %g\n", ts1->deltaT, ts2->deltaT ); return 1; } UINT4 i, numTS = ts1->length; for ( i = 0; i < numTS; i ++ ) { if ( XLALGPSDiff( &ts1->data[i], &ts2->data[i]) != 0 ) { XLALPrintError ("Read timestamps-lists differ in entry %d: { %d, %d } != { %d, %d }\n", i + 1, ts1->data[i].gpsSeconds, ts1->data[i].gpsNanoSeconds, ts2->data[i].gpsSeconds, ts2->data[i].gpsNanoSeconds ); return 1; } } /* for i < numTS */ /* free mem */ XLALDestroyTimestampVector ( ts1 ); XLALDestroyTimestampVector ( ts2 ); } /* ------------------------------ */ LALCheckMemoryLeaks(); XLALPrintError ("\n\n--------------------------------------------------------------------------------\n"); XLALPrintError ("\n OK. All tests passed correctly ! (error-messages above are OK!)\n"); XLALPrintError ("\n--------------------------------------------------------------------------------\n"); INFO( SFTFILEIOTESTC_MSGENORM ); return SFTFILEIOTESTC_ENORM; }
int main( int argc, char *argv[] ) { UINT4 i, j, k; const REAL4 tiny = 1e-6; CHAR ifoCode[][3] = { "H1", "L1" }; INT4 calTime[] = { 729331981, 729332039, 729332040, 729332041, 729332099, 800000000 }; CHAR cacheTime[][21] = { "729273600-734367600", "729273600-734367600" }; COMPLEX8 H1AlphaBeta[] = { {0.9883124570783, 0}, {0.9883124570783, 0}, {1.123396433694, 0}, {1.123396433694, 0}, {1.123396433694, 0}, {0, 0} }; COMPLEX8 L1AlphaBeta[] = { {0, 0}, {0, 0}, {0.6041572088741, 0}, {0.6041572088741, 0}, {0.6041572088741, 0}, {0, 0} }; static LALStatus status; const CHAR calCacheName[LALNameLength]; LALCache *calCache = NULL; UINT4 numPoints = 262144; UINT4 sampleRate = 4096; CHAR outFile[LALNameLength]; LIGOTimeGPS duration = {0,0}; COMPLEX8FrequencySeries response; const LALUnit strainPerCount = {0,{0,0,0,0,0,1,-1},{0,0,0,0,0,0,0}}; ParseOptions (argc, argv); /* clear the response function and create storage for the frequency series */ memset( &response, 0, sizeof(COMPLEX8FrequencySeries) ); LALCCreateVector( &status, &(response.data), numPoints / 2 + 1 ); TESTSTATUS( &status ); /* set the parameters of the response function to generate */ response.deltaF = (REAL8) sampleRate / (REAL8) numPoints; response.sampleUnits = strainPerCount; /* loop over the three interferometers */ for ( j = 0; j < sizeof(ifoCode) / sizeof(*ifoCode); ++j ) { snprintf( response.name, LALNameLength * sizeof(CHAR), CHANNEL, ifoCode[j] ); for ( i = 0; i < sizeof(calTime) / sizeof(*calTime); ++i ) { /* set the time of the calibration and the frame cahche file to use */ snprintf( calCacheName, LALNameLength * sizeof(CHAR), CAL_CATALOG, ifoCode[j], cacheTime[i % 2] ); response.epoch.gpsSeconds = calTime[i]; if ( verbose ) { fprintf( stdout, "Calibration for GPS time %d from %s\n", response.epoch.gpsSeconds, calCacheName ); fflush( stdout ); } /* create the response function */ LALExtractFrameResponse( &status, &response, calCacheName, ifoCode[j], &duration ); if ( status.statusCode == -1 && status.statusPtr ) { if ( status.statusPtr->statusCode == FRAMESTREAMH_EDONE && calTime[i] == 800000000 ) { /* no calibration for this time */ if ( verbose ) { fprintf( stderr, "OK: No calibration for 800000000\n" ); LALPrintError( "OK: %s\n", status.statusPtr->statusDescription ); } CLEARSTATUS( status ); } else if ( status.statusPtr->statusCode == CALIBRATIONH_EZERO && ! strncmp( ifoCode[j], "L1", 2 * sizeof(CHAR) ) && (calTime[i] == 729331981 || calTime[i] == 729332039) ) { /* alpha is zero at this time */ if ( verbose ) { fprintf( stderr, "OK: Cal is zero for L1 at 729332039\n" ); LALPrintError( "OK: %s\n", status.statusPtr->statusDescription ); } CLEARSTATUS( status ); } else { /* some other error */ TESTSTATUS( &status ); } } else { TESTSTATUS( &status ); /* FIXME check that the values match the expected ones */ /* H1AlphaBeta[i] and L1AlphaBeta[i] give the correct values */ /* for this i, so we need to check that the returned values */ /* match the expected ones up to tiny. Need to if on j to get */ /* the correct ifo */ /* test that the response does not contain NaN or Inf */ for ( k = 0; k < response.data->length; ++k ) { if ( (! finite( response.data->data[k].re )) || (! finite( response.data->data[k].im )) ) { fprintf( stderr, "ERROR: non-finite value found in response " "at k = %d (%e,%e)\n", k, response.data->data[k].re, response.data->data[k].im ); exit( 1 ); } } /* print out the response function */ if ( verbose ) { fprintf( stdout, "Calibration updated\n" ); fflush( stdout ); } if ( output ) { snprintf( outFile, LALNameLength * sizeof(CHAR), "Response-%s-%d.txt", ifoCode[j], response.epoch.gpsSeconds ); LALCPrintFrequencySeries( &response, outFile ); } } } } /* free memory */ LALCDestroyVector( &status, &(response.data) ); TESTSTATUS( &status ); LALCheckMemoryLeaks(); return 0; }
int main( int argc, char **argv ) { static LALStatus stat; /* status structure */ int arg; /* command-line argument counter */ UINT4 n = SIZE, i, j; /* array size and indecies */ CHAR *infile = NULL; /* input filename */ CHAR *outfile = NULL; /* output filename */ BOOLEAN timing = 0; /* whether -t option was given */ BOOLEAN single = 0; /* whether -s option was given */ BOOLEAN invert = 0; /* whether -v option was given */ REAL4 sDet = 0.0; /* determinant if -s option is given */ REAL8 dDet = 0.0; /* determinant if -s option isn't given */ REAL4Array *sMatrix = NULL; /* matrix if -s option is given */ REAL8Array *dMatrix = NULL; /* matrix if -s option is not given */ REAL4Array *sInverse = NULL; /* inverse if -s option is given */ REAL8Array *dInverse = NULL; /* inverse if -s option isn't given */ UINT4Vector dimLength; /* dimensions used to create matrix */ UINT4 dims[2]; /* dimLength.data array */ clock_t start = 0, stop = 0; /* start and stop times for timing */ FILE *fp = NULL; /* input/output file pointer */ /******************************************************************* * PARSE ARGUMENTS (arg stores the current position) * *******************************************************************/ arg = 1; while ( arg < argc ) { /* Parse matrix size option. */ if ( !strcmp( argv[arg], "-n" ) ) { if ( argc > arg + 1 ) { arg++; n = atoi( argv[arg++] ); } else { ERROR( DETINVERSETESTC_EARG, DETINVERSETESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return DETINVERSETESTC_EARG; } } /* Parse input option. */ else if ( !strcmp( argv[arg], "-i" ) ) { if ( argc > arg + 1 ) { arg++; infile = argv[arg++]; } else { ERROR( DETINVERSETESTC_EARG, DETINVERSETESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return DETINVERSETESTC_EARG; } } /* Parse output option. */ else if ( !strcmp( argv[arg], "-o" ) ) { if ( argc > arg + 1 ) { arg++; outfile = argv[arg++]; } else { ERROR( DETINVERSETESTC_EARG, DETINVERSETESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return DETINVERSETESTC_EARG; } } /* Parse inversion, single-precision, and timing options. */ else if ( !strcmp( argv[arg], "-v" ) ) { arg++; invert = 1; } else if ( !strcmp( argv[arg], "-s" ) ) { arg++; single = 1; } else if ( !strcmp( argv[arg], "-t" ) ) { arg++; timing = 1; } /* Parse debug level option. */ else if ( !strcmp( argv[arg], "-d" ) ) { if ( argc > arg + 1 ) { arg++; }else{ ERROR( DETINVERSETESTC_EARG, DETINVERSETESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return DETINVERSETESTC_EARG; } } /* Check for unrecognized options. */ else { ERROR( DETINVERSETESTC_EARG, DETINVERSETESTC_MSGEARG, 0 ); LALPrintError( USAGE, *argv ); return DETINVERSETESTC_EARG; } } /* End of argument parsing loop. */ /******************************************************************* * GET INPUT MATRIX * *******************************************************************/ /* Set up array creation vector. */ dimLength.length = 2; dimLength.data = dims; /* Read input matrix file. */ if ( infile ) { /* Open input file. */ if ( !strcmp( infile, "stdin" ) ) fp = stdin; else if ( !( fp = fopen( infile, "r" ) ) ) { ERROR( DETINVERSETESTC_EFILE, "- " DETINVERSETESTC_MSGEFILE, infile ); return DETINVERSETESTC_EFILE; } /* Single-precision mode: */ if ( single ) { REAL4Vector *vec = NULL; /* parsed input line */ /* Read first non-comment line and create array. */ do { SUB( LALSReadVector( &stat, &vec, fp, 0 ), &stat ); } while ( ( n = vec->length ) == 0 ); dimLength.data[0] = dimLength.data[1] = n; SUB( LALSCreateArray( &stat, &sMatrix, &dimLength ), &stat ); for ( j = 0; j < n; j++ ) sMatrix->data[j] = vec->data[j]; SUB( LALSDestroyVector( &stat, &vec ), &stat ); /* Read remaining lines. */ for ( i = 1; i < n; i++ ) { SUB( LALSReadVector( &stat, &vec, fp, 1 ), &stat ); if ( vec->length != n ) { ERROR( DETINVERSETESTC_EFMT, DETINVERSETESTC_MSGEFMT, 0 ); return DETINVERSETESTC_EFMT; } for ( j = 0; j < n; j++ ) sMatrix->data[i*n+j] = vec->data[j]; SUB( LALSDestroyVector( &stat, &vec ), &stat ); } } /* Double-precision mode: */ else { REAL8Vector *vec = NULL; /* parsed input line */ /* Read first non-comment line and create array. */ do { SUB( LALDReadVector( &stat, &vec, fp, 0 ), &stat ); } while ( ( n = vec->length ) == 0 ); dimLength.data[0] = dimLength.data[1] = n; SUB( LALDCreateArray( &stat, &dMatrix, &dimLength ), &stat ); for ( j = 0; j < n; j++ ) dMatrix->data[j] = vec->data[j]; SUB( LALDDestroyVector( &stat, &vec ), &stat ); /* Read remaining lines. */ for ( i = 1; i < n; i++ ) { SUB( LALDReadVector( &stat, &vec, fp, 1 ), &stat ); if ( vec->length != n ) { ERROR( DETINVERSETESTC_EFMT, DETINVERSETESTC_MSGEFMT, 0 ); return DETINVERSETESTC_EFMT; } for ( j = 0; j < n; j++ ) dMatrix->data[i*n+j] = vec->data[j]; SUB( LALDDestroyVector( &stat, &vec ), &stat ); } } } /* Generate random matrix. */ else { RandomParams *params = NULL; SUB( LALCreateRandomParams( &stat, ¶ms, 0 ), &stat ); dimLength.data[0] = dimLength.data[1] = n; /* Single-precision mode: */ if ( single ) { SUB( LALSCreateArray( &stat, &sMatrix, &dimLength ), &stat ); for ( i = 0; i < n; i++ ) { REAL4 x; for ( j = 0; j < n; j++ ) { SUB( LALUniformDeviate( &stat, &x, params ), &stat ); sMatrix->data[i*n+j] = 2.0*x - 1.0; } } } /* Double-precision mode: */ else { SUB( LALDCreateArray( &stat, &dMatrix, &dimLength ), &stat ); for ( i = 0; i < n; i++ ) { REAL4 x; for ( j = 0; j < n; j++ ) { SUB( LALUniformDeviate( &stat, &x, params ), &stat ); dMatrix->data[i*n+j] = 2.0*(REAL8)( x ) - 1.0; } } } SUB( LALDestroyRandomParams( &stat, ¶ms ), &stat ); } /* Write input matrix to output file. */ if ( outfile ) { /* Open output file. */ if ( !strcmp( outfile, "stdout" ) ) fp = stdout; else if ( !strcmp( outfile, "stderr" ) ) fp = stderr; else if ( !( fp = fopen( outfile, "r" ) ) ) { ERROR( DETINVERSETESTC_EFILE, "- " DETINVERSETESTC_MSGEFILE, outfile ); return DETINVERSETESTC_EFILE; } /* Single-precision mode: */ if ( single ) { for ( i = 0; i < n; i++ ) { fprintf( fp, "%16.9e", sMatrix->data[i*n] ); for ( j = 1; j < n; j++ ) fprintf( fp, " %16.9e", sMatrix->data[i*n+j] ); fprintf( fp, "\n" ); } } /* Double-precision mode: */ else { for ( i = 0; i < n; i++ ) { fprintf( fp, "%25.17e", dMatrix->data[i*n] ); for ( j = 1; j < n; j++ ) fprintf( fp, " %25.17e", dMatrix->data[i*n+j] ); fprintf( fp, "\n" ); } } } /******************************************************************* * COMPUTE INVERSE * *******************************************************************/ if ( timing ) start = clock(); /* Single-precision mode: */ if ( single ) { if ( invert ) { SUB( LALSCreateArray( &stat, &sInverse, &dimLength ), &stat ); SUB( LALSMatrixInverse( &stat, &sDet, sMatrix, sInverse ), &stat ); } } /* Double-precision mode: */ else { if ( invert ) { SUB( LALDCreateArray( &stat, &dInverse, &dimLength ), &stat ); SUB( LALDMatrixInverse( &stat, &dDet, dMatrix, dInverse ), &stat ); } else { SUB( LALDMatrixDeterminant( &stat, &dDet, dMatrix ), &stat ); } } if ( timing ) { stop = clock(); fprintf( stderr, "Elapsed time: %.2f s\n", (double)( stop - start )/CLOCKS_PER_SEC ); } /* Write output. */ if ( outfile ) { /* Write determinant. */ fprintf( fp, "\n" ); if ( single ) fprintf( fp, "%16.9e\n", sDet ); else fprintf( fp, "%25.17e\n", dDet ); /* Write inverse. */ if ( invert ) { fprintf( fp, "\n" ); if ( single ) { for ( i = 0; i < n; i++ ) { fprintf( fp, "%16.9e", sInverse->data[i*n] ); for ( j = 1; j < n; j++ ) fprintf( fp, " %16.9e", sInverse->data[i*n+j] ); fprintf( fp, "\n" ); } } else { for ( i = 0; i < n; i++ ) { fprintf( fp, "%25.17e", dInverse->data[i*n] ); for ( j = 1; j < n; j++ ) fprintf( fp, " %25.17e", dInverse->data[i*n+j] ); fprintf( fp, "\n" ); } } } /* Finished output. */ if ( fp != stdout && fp != stderr ) fclose( fp ); } /* Clean up and exit. */ if ( single ) { SUB( LALSDestroyArray( &stat, &sMatrix ), &stat ); if ( invert ) { SUB( LALSDestroyArray( &stat, &sInverse ), &stat ); } } else { SUB( LALDDestroyArray( &stat, &dMatrix ), &stat ); if ( invert ) { SUB( LALDDestroyArray( &stat, &dInverse ), &stat ); } } LALCheckMemoryLeaks(); INFO( DETINVERSETESTC_MSGENORM ); return DETINVERSETESTC_ENORM; }