Commit 59a56b60 authored by David Keitel's avatar David Keitel

Merge branch 'SFTvalidate-help-output' into 'master'

lalapps_SFTvalidate: output filename to stdout if valid, add help message and version info options

Closes #406

See merge request !1502
parents ceba1949 6dca44e4
Pipeline #184154 passed with stages
in 242 minutes and 30 seconds
......@@ -41,8 +41,18 @@
int main(int argc, char** argv) {
if (argc == 2 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) {
fprintf(stdout, "%s: %s %s\n", argv[0], lalAppsVCSInfo.vcsId, lalAppsVCSInfo.vcsStatus);
fflush(stdout);
return EXIT_SUCCESS;
}
if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
fprintf(stdout, "usage:\n");
fprintf(stdout, " %s *.sft\n", argv[0]);
fprintf(stdout, " ls *.sft | %s\n", argv[0]);
fprintf(stdout, " find -name '*.sft' | %s >valid-sfts.txt 2>errors.log\n", argv[0]);
return EXIT_SUCCESS;
}
int errcode = EXIT_SUCCESS;
......@@ -56,6 +66,9 @@ int main(int argc, char** argv) {
*/
if (ValidateSFTFile(argv[i]) != 0) {
errcode = EXIT_FAILURE;
} else {
fprintf(stdout, "%s\n", argv[i]);
fflush(stdout);
}
}
......@@ -74,6 +87,9 @@ int main(int argc, char** argv) {
*/
if (ValidateSFTFile(line) != 0) {
errcode = EXIT_FAILURE;
} else {
fprintf(stdout, "%s\n", line);
fflush(stdout);
}
}
}
......
......@@ -16,8 +16,8 @@ if ! lalapps_SFTvalidate SFT-good SFT-test*; then
exit 1
fi
echo
echo "printf '%s\n' SFT-good '' SFT-test* | lalapps_SFTvalidate"
if ! printf '%s\n' SFT-good '' SFT-test* | lalapps_SFTvalidate; then
echo "printf '%s\n' SFT-good '' SFT-test* | lalapps_SFTvalidate >valid-sfts.txt"
if ! printf '%s\n' SFT-good '' SFT-test* | lalapps_SFTvalidate >valid-sfts.txt; then
echo "lalapps_SFTvalidate failed SFTs SFT-good SFT-test*; should have passed"
exit 1
fi
......@@ -44,3 +44,15 @@ if printf '%s\n' SFT-bad* | lalapps_SFTvalidate; then
exit 1
fi
echo
echo "printf '%s\n' SFT-good SFT-bad* SFT-test* | lalapps_SFTvalidate >valid-sfts-2.txt"
if printf '%s\n' SFT-good SFT-bad* SFT-test* | lalapps_SFTvalidate >valid-sfts-2.txt; then
echo "lalapps_SFTvalidate passed SFT-good SFT-bad* SFT-test*; should have failed"
exit 1
fi
echo
echo "diff valid-sfts.txt valid-sfts-2.txt"
if ! diff valid-sfts.txt valid-sfts-2.txt; then
echo "valid-sfts.txt and valid-sfts-2.txt should compare equal"
exit 1
fi
echo
......@@ -554,8 +554,8 @@ int ReadSFTHeader(FILE *fp, /* stream to read */
/* check that checksum is consistent */
if (crc != crc64save) {
#ifdef SFTDEVEL
printf("CRC64 computes as %llu\n", crc);
printf("CRC64 in SFT is %llu\n", crc64save);
fprintf(stderr, "%s: CRC64 computes as %llu\n", __func__, crc);
fprintf(stderr, "%s: CRC64 in SFT is %llu\n", __func__, crc64save);
#endif
retval=SFTEBADCRC64;
goto error;
......@@ -833,67 +833,73 @@ ValidateSFTFile ( const char *fname )
{
FILE *fp;
int count;
int err = 0;
float *data = NULL;
/* clear error status */
errno = 0;
/* open the file */
if (!(fp=fopen(fname, "r"))) {
fprintf(stderr,"Unable to open %s", fname);
fprintf(stderr, "%s: Unable to open %s", __func__, fname);
if (errno)
perror(" ");
perror(__func__);
return SFTENULLFP;
}
/* and read successive SFTs blocks from the file and validate CRC
checksums */
for (count=0; 1; count++) {
for (int count=0; 1; count++) {
struct headertag2 info,lastinfo;
int err=0, swapendian, move, j;
int swapendian, move, j;
err=ReadSFTHeader(fp, &info, NULL, &swapendian, 1);
/* at end of SFT file or merged SFT file blocks */
if (err==SFTENONE && count)
if (err==SFTENONE && count) {
err=0;
break;
}
/* SFT was invalid: say why */
if (err) {
fprintf(stderr, "%s is not a valid SFT. %s\n", fname, SFTErrorMessage(err));
fprintf(stderr, "%s: %s is not a valid SFT (%s)\n", __func__, fname, SFTErrorMessage(err));
if (errno)
perror(NULL);
return err;
perror(__func__);
break;
}
/* check that various bits of header information are consistent */
if (count && (err=CheckSFTHeaderConsistency(&lastinfo, &info))) {
fprintf(stderr, "%s is not a valid SFT. %s\n", fname, SFTErrorMessage(err));
fprintf(stderr, "%s: %s is not a valid SFT (%s)\n", __func__, fname, SFTErrorMessage(err));
if (errno)
perror(NULL);
return err;
perror(__func__);
break;
}
/* check that data appears valid */
float *data=NULL;
data = (float *)realloc((void *)data, info.nsamples*4*2);
if (!data) {
errno=SFTENULLPOINTER;
fprintf(stderr, "ran out of memory at %s. %s\n", fname, SFTErrorMessage(err));
fprintf(stderr, "%s: ran out of memory at %s (%s)\n", __func__, fname, SFTErrorMessage(err));
if (errno)
perror(NULL);
return err;
perror(__func__);
break;
}
err=ReadSFTData(fp, data, info.firstfreqindex, info.nsamples, /*comment*/ NULL, /*headerinfo */ NULL);
if (err) {
fprintf(stderr, "%s is not a valid SFT. %s\n", fname, SFTErrorMessage(err));
fprintf(stderr, "%s: %s is not a valid SFT (%s)\n", __func__, fname, SFTErrorMessage(err));
if (errno)
perror(NULL);
return err;
perror(__func__);
break;
}
for (j=0; j<info.nsamples; j++) {
if (!isfinite(data[2*j]) || !isfinite(data[2*j+1])) {
fprintf(stderr, "%s is not a valid SFT (data infinite at freq bin %d)\n", fname, j+info.firstfreqindex);
return SFTNOTFINITE;
fprintf(stderr, "%s: %s is not a valid SFT (data infinite at freq bin %d)\n", __func__, fname, j+info.firstfreqindex);
err=SFTNOTFINITE;
break;
}
}
......@@ -905,7 +911,10 @@ ValidateSFTFile ( const char *fname )
fseek(fp, move, SEEK_CUR);
}
/* cleanup */
fclose(fp);
return ( 0 );
free(data);
return err;
} /* ValidateSFTFile */
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