Commit 870bf7bb authored by Vesa Oikonen's avatar Vesa Oikonen
Browse files

continued

parent 5a2647a0
......@@ -35,6 +35,7 @@ static char *info[] = {
" first (-first), or second (-second, default) TAC are saved in",
" combined file, or specified cut time is used.",
" Cut time can also be given in file with keys 'x' or 'time'.",
" By default, overlap will lead to an error.",
" --force",
" Program does not mind if the time or calibration units cannot be",
" converted to match, or if TAC names do not match.",
......@@ -62,7 +63,7 @@ int _dowildcard = -1;
/*****************************************************************************/
/** How to deal with overlap */
enum {OVL_USE_BOTH, OVL_USE_FIRST, OVL_USE_SECOND, OVL_CUTTIME};
enum {OVL_ERROR, OVL_USE_BOTH, OVL_USE_FIRST, OVL_USE_SECOND, OVL_CUTTIME};
/**
* Main
......@@ -72,7 +73,7 @@ int main(int argc, char **argv)
int ai, help=0, version=0, verbose=1;
char tacfile1[FILENAME_MAX], tacfile2[FILENAME_MAX], outfile[FILENAME_MAX];
int forceMode=0;
int overlapMode=OVL_USE_BOTH;
int overlapMode=OVL_ERROR;
double cutTime=nan("");
......@@ -284,14 +285,19 @@ int main(int argc, char **argv)
printf("x range 1 := %g - %g\n", xmin1, xmax1);
printf("x range 2 := %g - %g\n", xmin2, xmax2);
}
if(xmax1>xmin2) isOverlap=1;
else if(!tac1.isframe && xmax1>=xmin2) isOverlap=1;
if(isOverlap && overlapMode==OVL_ERROR) {
fprintf(stderr, "Error: overlapping sample times.\n");
tacFree(&tac1); tacFree(&tac2); return(5);
}
xmin=xmin1; if(xmin2<xmin) xmin=xmin2;
xmax=xmax1; if(xmax2>xmax) xmax=xmax2;
if(overlapMode==OVL_CUTTIME && (cutTime<xmin || cutTime>xmax)) {
fprintf(stderr, "Error: cut time outside of data time range %g - %g\n", xmin, xmax);
tacFree(&tac1); tacFree(&tac2); return(5);
}
if(xmax1>=xmin2) {
isOverlap=1;
if(isOverlap) {
int fail=0;
if(overlapMode==OVL_USE_FIRST && xmin1>xmin2) fail=1;
if(overlapMode==OVL_USE_SECOND && xmin2<=xmin1) fail=2;
......@@ -305,9 +311,9 @@ int main(int argc, char **argv)
if(isOverlap) {
if(overlapMode==OVL_USE_BOTH) {
isOverlap=0;
if(verbose>1) printf("overlap in sample times is ignored.\n");
fprintf(stderr, "Warning: overlap in sample times is ignored.\n");
} else {
if(verbose>1) printf("overlap in sample times will be removed.\n");
fprintf(stderr, "Warning: overlap in sample times will be removed.\n");
}
}
......
#!/bin/bash
#: Title : test_taccat
#: Date : 2021-02-08
#: Date : 2021-02-09
#: Author : "Vesa Oikonen" <vesa.oikonen@utu.fi>
#: Options : None
......@@ -21,7 +21,7 @@ printf "creating test data for %s\n" $PROGRAM
printf "=====================================================================\n"
if [ ! -f test1a.tac ] || [ ! -f test1b.tac ] || [ -f correct_output1.tac ]; then
if [ ! -f test1a.tac ] || [ ! -f test1b.tac ] || [ ! -f correct_output1.tac ]; then
printf "start[minutes] end[Bq/cc] par__All occ__All tem__All cer__All weight\n" > test1a.tac
printf "0.00 1.00 2.410e+02 2.576e+02 2.181e+02 2.203e+02 1.863e+00\n" >> test1a.tac
printf "1.00 2.00 2.888e+03 2.558e+03 2.776e+03 3.518e+03 1.843e-01\n" >> test1a.tac
......@@ -32,15 +32,113 @@ printf "start[minutes] end[Bq/cc] par__All occ__All tem__All cer__All\n" > test1
printf "10.00 20.00 2.010e+04 1.176e+04 6.281e+03 2.293e+03\n" >> test1b.tac
printf "20.00 30.00 2.888e+04 1.555e+04 2.133e+03 8.551e+02\n" >> test1b.tac
printf "start[minutes] end[Bq/cc] par__All occ__All tem__All cer__All weight\n" > correct_output1.tac
printf "0.00 1.00 2.410e+02 2.576e+02 2.181e+02 2.203e+02 1.863e+00\n" >> correct_output1.tac
printf "1.00 2.00 2.888e+03 2.558e+03 2.776e+03 3.518e+03 1.843e-01\n" >> correct_output1.tac
printf "2.00 6.00 7.605e+03 6.306e+03 6.520e+03 8.464e+03 7.599e-02\n" >> correct_output1.tac
printf "6.00 10.00 1.022e+04 9.182e+03 9.171e+03 1.112e+04 5.491e-02\n" >> correct_output1.tac
printf "start[minutes] end[Bq/cc] par__All occ__All tem__All cer__All\n" > correct_output1.tac
printf "0.00 1.00 2.410e+02 2.576e+02 2.181e+02 2.203e+02\n" >> correct_output1.tac
printf "1.00 2.00 2.888e+03 2.558e+03 2.776e+03 3.518e+03\n" >> correct_output1.tac
printf "2.00 6.00 7.605e+03 6.306e+03 6.520e+03 8.464e+03\n" >> correct_output1.tac
printf "6.00 10.00 1.022e+04 9.182e+03 9.171e+03 1.112e+04\n" >> correct_output1.tac
printf "10.00 20.00 2.010e+04 1.176e+04 6.281e+03 2.293e+03\n" >> correct_output1.tac
printf "20.00 30.00 2.888e+04 1.555e+04 2.133e+03 8.551e+02\n" >> correct_output1.tac
fi
if [ ! -f test1a.dft ] || [ ! -f test1b.dft ] || [ ! -f correct_output1.dft ]; then
tacformat -f=DFT test1a.tac
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
tacformat -f=DFT test1b.tac
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
tacformat -f=DFT correct_output1.tac
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
fi
if [ ! -f correct_output1so.tac ]; then
printf "start[minutes] end[Bq/cc] par__All occ__All tem__All cer__All\n" > correct_output1so.tac
printf "2.00 3.00 2.410e+02 2.576e+02 2.181e+02 2.203e+02\n" >> correct_output1so.tac
printf "3.00 4.00 2.888e+03 2.558e+03 2.776e+03 3.518e+03\n" >> correct_output1so.tac
printf "4.00 8.00 7.605e+03 6.306e+03 6.520e+03 8.464e+03\n" >> correct_output1so.tac
printf "8.00 12.00 1.022e+04 9.182e+03 9.171e+03 1.112e+04\n" >> correct_output1so.tac
printf "10.00 20.00 2.010e+04 1.176e+04 6.281e+03 2.293e+03\n" >> correct_output1so.tac
printf "20.00 30.00 2.888e+04 1.555e+04 2.133e+03 8.551e+02\n" >> correct_output1so.tac
fi
if [ ! -f test2a.dat ] || [ ! -f test2b.dat ]; then
printf "# Comment in test2a.dat\n" > test2a.dat
printf "# injection_time := 2006-01-09 16:49:03\n" >> test2a.dat
printf "0 0\n" >> test2a.dat
printf "1 -1\n" >> test2a.dat
printf "2 2\n" >> test2a.dat
printf "3 0\n" >> test2a.dat
printf "4 4\n" >> test2a.dat
printf "5 12\n" >> test2a.dat
printf "6 550\n" >> test2a.dat
printf "7 1009\n" >> test2a.dat
printf "8 1888\n" >> test2a.dat
printf "9 1934\n" >> test2a.dat
printf "10 1878\n" >> test2a.dat
printf "11 1789\n" >> test2a.dat
printf "12 1604\n" >> test2a.dat
printf "13 1557\n" >> test2a.dat
printf "14 1445\n" >> test2a.dat
printf "15 1398\n" >> test2a.dat
printf "16 1313\n" >> test2a.dat
printf "17 1201\n" >> test2a.dat
printf "18 1189\n" >> test2a.dat
printf "19 888\n" >> test2a.dat
printf "20 765\n" >> test2a.dat
printf "21 0\n" >> test2a.dat
printf "22 2\n" >> test2a.dat
printf "23 -1\n" >> test2a.dat
printf "24 7\n" >> test2a.dat
printf "# Comment in test2b.dat\n" > test2b.dat
printf "# unit := kBq/ml\n" >> test2b.dat
printf "# isotope := C-11\n" >> test2b.dat
printf "20.9 655\n" >> test2b.dat
printf "35.1 233\n" >> test2b.dat
printf "47.2 187\n" >> test2b.dat
printf "60.6 165\n" >> test2b.dat
fi
if [ ! -f correct_output2a.dat ]; then
printf "0 0\n" > correct_output2a.dat
printf "1 -1\n" >> correct_output2a.dat
printf "2 2\n" >> correct_output2a.dat
printf "3 0\n" >> correct_output2a.dat
printf "4 4\n" >> correct_output2a.dat
printf "5 12\n" >> correct_output2a.dat
printf "6 550\n" >> correct_output2a.dat
printf "7 1009\n" >> correct_output2a.dat
printf "8 1888\n" >> correct_output2a.dat
printf "9 1934\n" >> correct_output2a.dat
printf "10 1878\n" >> correct_output2a.dat
printf "11 1789\n" >> correct_output2a.dat
printf "12 1604\n" >> correct_output2a.dat
printf "13 1557\n" >> correct_output2a.dat
printf "14 1445\n" >> correct_output2a.dat
printf "15 1398\n" >> correct_output2a.dat
printf "16 1313\n" >> correct_output2a.dat
printf "17 1201\n" >> correct_output2a.dat
printf "18 1189\n" >> correct_output2a.dat
printf "19 888\n" >> correct_output2a.dat
printf "20 765\n" >> correct_output2a.dat
printf "20.9 655\n" >> correct_output2a.dat
printf "21 0\n" >> correct_output2a.dat
printf "22 2\n" >> correct_output2a.dat
printf "23 -1\n" >> correct_output2a.dat
printf "24 7\n" >> correct_output2a.dat
printf "35.1 233\n" >> correct_output2a.dat
printf "47.2 187\n" >> correct_output2a.dat
printf "60.6 165\n" >> correct_output2a.dat
printf "# Comment in test2a.dat\n" >> correct_output2a.dat
printf "# injection_time := 2006-01-09 16:49:03\n" >> correct_output2a.dat
printf "# Comment in test2b.dat\n" >> correct_output2a.dat
printf "# unit := kBq/ml\n" >> correct_output2a.dat
printf "# isotope := C-11\n" >> correct_output2a.dat
fi
printf "\n\n"
......@@ -50,7 +148,7 @@ printf "=====================================================================\n"
printf "\n 1.0.0 \n"
printf " Test case 1: Reasonable data in PMOD TAC format without options. \n"
printf " Test case 1: Reasonable data in PMOD TTAC format without options. \n"
printf " Test case 2: New file name given. \n"
printf " Test case 3: First file contains weights. \n"
printf " Expected result: Correctly catenated data is written in new file. \n"
......@@ -68,18 +166,19 @@ if [ $? -eq 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n 1.0.1 \n"
printf " Test case 1: Output file exists. \n"
printf " Test case: Output file exists. \n"
printf " Test case 2: Option -both. \n"
printf " Expected result: Existing file is overwritten with new file. \n"
cp -f test1a.tac output.tac
$PROGRAM test1a.tac test1b.tac output.tac
$PROGRAM -both test1a.tac test1b.tac output.tac
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output1.tac output.tac
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n 1.1.0 \n"
printf "\n 1.0.2 \n"
printf " Test case 1: Output file name is NOT given. \n"
printf " Expected result: First file is overwritten with catenated data. \n"
......@@ -92,6 +191,59 @@ if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n 1.1.0 \n"
printf " Test case: DFT TTAC format. \n"
printf " Expected result: Correctly catenated data is written in new file. \n\n"
rm -f output.dft
$PROGRAM test1a.dft test1b.dft output.dft
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output1.dft output.dft
if [ $? -ne 0 ] ; then printf "\nFailed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n 1.2.0 \n"
printf " Test case: Slightly overlapping PMOD TTAC data. \n"
printf " Test case 2: Option -BOTH. \n"
printf " Expected result: Warning of overlap. \n"
printf " Expected result 2: Correctly catenated data is written in new file. \n\n"
rm -f output.tac stdout.txt
tactime test1a.tac +2 temp1a.tac
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
$PROGRAM -BOTH temp1a.tac test1b.tac output.tac &> stdout.txt
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
iftisval stdout.txt Warning "overlap in sample times is ignored."
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output1so.tac output.tac
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n 1.2.1 \n"
printf " Test case: Same as before but without option -BOTH. \n"
printf " Expected result: Error. \n\n"
rm -f output.tac stdout.txt
$PROGRAM temp1a.tac test1b.tac output.tac &> stdout.txt
if [ $? -eq 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
iftisval stdout.txt Error "overlapping sample times."
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "=====================================================================\n"
printf " All current tests passed, but more testing needed!\n"
......@@ -186,26 +338,6 @@ printf "\n passed. \n\n"
printf "\n===================================================================\n"
printf "\n1.0.0 output file name is given. Output will be written in there. \n\n"
rm -f stdout.txt output.dft
$PROGRAM test1a.dft test1b.dft output.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output1a.dft output.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n1.1.0 output file name is NOT given. \n"
printf "2nd file will be added to the first one. \n\n"
cp -f test1a.dft temp1a.dft
$PROGRAM temp1a.dft test1b.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output1a.dft temp1a.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n===================================================================\n"
......@@ -231,35 +363,6 @@ if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n2.1.0 combine data with partially overlapping time frames \n\n"
rm -f output.dft stdout.txt
tactime test1a.dft +2 temp1a.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
$PROGRAM temp1a.dft test1b.dft output.dft &> stdout.txt
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
iftisval stdout.txt Warning "times in datafiles overlap."
if [ $? -eq 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output_210.dft output.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n2.1.1 combine data with more overlapping time frames \n\n"
rm -f output2.dft stdout.txt
tactime test1a.dft +8 temp1a.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
$PROGRAM temp1a.dft test1b.dft output2.dft &> stdout.txt
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
iftisval stdout.txt Warning "times in datafiles overlap."
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n ok \n"
tacmatch -abs=0.1 -rel=1 correct_output_211.dft output2.dft
if [ $? -ne 0 ] ; then printf "Failed!\n" ; exit 1 ; fi
printf "\n passed. \n\n"
printf "\n2.2.0 combine overlapping curves with option -first \n\n"
......
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