Commit 1b2922d8 authored by bema's avatar bema

moved splitSFTs.c

Original: fc2bee6f2c48b4aa7178eb2076c5ffcb158110db
parents
lal/test/tools/resamp_10x4.eps filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S5-L1-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/earth00-19-DE421.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/earth00-19-DE414.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/earth98.dat filter=lfs diff=lfs merge=lfs -text
lalsimulation/src/lalsimburst_btlwnbexamples.svg filter=lfs diff=lfs merge=lfs -text
lalapps/src/inspiral/MachoMasses.dat filter=lfs diff=lfs merge=lfs -text
lalapps/src/inspiral/test/HL-INJECTIONS_1234_INJ001-866088014-2633400.xml filter=lfs diff=lfs merge=lfs -text
lalapps/src/pulsar/CreateEphemeris/ephemMLDC.dat filter=lfs diff=lfs merge=lfs -text
lalframe/test/F-TEST-600000000-60.gwf filter=lfs diff=lfs merge=lfs -text
lalframe/test/H-CAL_REF_V03-734073939-64.gwf filter=lfs diff=lfs merge=lfs -text
lalapps/src/inspiral/inspsrcs100Mpc.errors filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S6-V1-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalburst/test/CLRindata.asc filter=lfs diff=lfs merge=lfs -text
lalinspiral/test/SpaceCovering.par filter=lfs diff=lfs merge=lfs -text
lalsimulation/src/lalsimburst_sinegaussianexamples.svg filter=lfs diff=lfs merge=lfs -text
lalapps/src/calibration/S4H1Filters.txt filter=lfs diff=lfs merge=lfs -text
lalapps/src/pulsar/HeterodyneSearch/H-CW_Injection-875206560-120.gwf filter=lfs diff=lfs merge=lfs -text
lalframe/test/H-CAL_FAC_V03-729273600-5094000.gwf filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/earth00-19-DE200.dat.gz filter=lfs diff=lfs merge=lfs -text
lalapps/src/calibration/S5H1_NoiseCompTimes.txt filter=lfs diff=lfs merge=lfs -text
lalapps/src/calibration/S5L1_NoiseCompTimes.txt filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S6-L1-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalframe/test/F-TEST-600000060-60.gwf filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/earth00-19-DE405.dat.gz filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S6-H1-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalframe/test/L-CAL_REF_V03-731488397-64.gwf filter=lfs diff=lfs merge=lfs -text
lalsimulation/test/reviewed_waveforms.asc filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S5-H1H2-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalapps/src/inspiral/BNSMasses.dat filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S5-V1-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalframe/test/F-TEST-600000120-60.gwf filter=lfs diff=lfs merge=lfs -text
lalframe/test/L-CAL_FAC_V03-729273600-5094000.gwf filter=lfs diff=lfs merge=lfs -text
lalapps/src/findchirp/L1response_psd.dat filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S5-H2-cat2.txt filter=lfs diff=lfs merge=lfs -text
lalapps/src/string/S5-L1segments-cat1.txt filter=lfs diff=lfs merge=lfs -text
lalinference/test/data/2016_subset.xml.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/sun00-19-DE200.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/sun00-19-DE405.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/sun00-19-DE414.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/sun00-19-DE421.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/tdb_2000-2019.dat.gz filter=lfs diff=lfs merge=lfs -text
lalpulsar/test/te405_2000-2019.dat.gz filter=lfs diff=lfs merge=lfs -text
/*
- splits a SFTv2 into multiple ones containing narrow frequency bands.
- uses the SFTReferenceLibrary, compile with
gcc -Wall -O2 splitSFTs.c -o splitSFTs libSFTReferenceLibrary.a
Author: Bernd Machenschalk
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SFTReferenceLibrary.h"
/* error if value is nonzero */
#define TRY(v,c) { int r; if((r=(v))) { fprintf(stderr,c " (%d)\n", r); exit(-1); } }
int main(int argc, char**argv) {
unsigned int arg;
unsigned int start, end, width;
unsigned int bin;
struct headertag2 hd;
FILE *fp;
char *oldcomment;
char *cmdline = NULL;
char *comment = NULL;
int swap;
float *data;
char *outname;
char *prefix;
double factor = 1.0;
/* usage error */
if(argc < 6) {
fprintf(stderr, "%s <startbin> <endbin> <sftbins> <outputprefix> <inputfile> ...\n", argv[0]);
exit(-1);
}
/* get parameters from command line */
start = atoi(argv[1]);
end = atoi(argv[2]);
width = atoi(argv[3]);
prefix = argv[4];
/* allocate space for output filename */
TRY((outname = (char*)malloc(strlen(prefix) + 20)) == NULL,
"out of memory allocating outname");
/* record the commandline for the comment */
for(arg = 0; arg < argc; arg++) {
cmdline = realloc((void*)cmdline, strlen(cmdline) + strlen(argv[arg]) + 2);
strcat(cmdline, argv[arg]);
if(arg == argc - 1)
strcat(cmdline, "\n");
else
strcat(cmdline, " ");
}
/* loop over all input files */
for(arg = 5; arg < argc; arg++) {
/* open input SFT */
TRY((fp = fopen(argv[arg], "r")) == NULL,
"could not open SFT file for read");
/* read header */
TRY(ReadSFTHeader(fp, &hd, &oldcomment, &swap, 1),
"could not read SFT header");
/* allocate space for SFT data */
TRY((data = (float*)malloc(hd.nsamples * sizeof(float))) == NULL,
"out of memory allocating data");
/* allocate space for new comment */
TRY((comment = (char*)malloc(hd.comment_length + strlen(cmdline) + 1)) == NULL,
"out of memory allocating comment");
/* append the commandline of this program to the old comment */
strcpy(comment,oldcomment);
strcat(comment,cmdline);
/* read in complete SFT data */
TRY(ReadSFTData(fp, data, 0, hd.nsamples, NULL, NULL),
"could not read SFT data");
/* apply factor */
for(bin = 0; bin < hd.nsamples; bin++)
data[bin] *= factor;
/* cleanup */
fclose(fp);
/* loop over start bins for output SFTs */
for(bin = start; bin < end; bin += width) {
/* construct output SFT filename */
sprintf(outname, "%s%d", prefix, bin);
/* open for appending */
TRY((fp = fopen(outname,"a")) == NULL,
"could not open SFT for writing");
/* append the SFT to the "merged" SFT */
TRY(WriteSFT(fp, hd.gps_sec, hd.gps_nsec, hd.tbase,
bin, width, hd.detector, comment, data),
"could not write SFT data");
/* cleanup */
fclose(fp);
}
/* cleanup */
free(comment);
free(data);
}
/* cleanup */
free(outname);
free(cmdline);
return(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment