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