1 | #!/bin/bash
|
---|
2 | #sourceFolder="./backup"
|
---|
3 | #destFolder="./fixed"
|
---|
4 |
|
---|
5 | #entries=`find $sourceFolder -type f -name '*.fits' | sort`
|
---|
6 |
|
---|
7 | #for entry in ${entries[@]}
|
---|
8 | #do
|
---|
9 | # echo $entry" "$destFolder
|
---|
10 | # cp $entry $destFolder
|
---|
11 | #done
|
---|
12 |
|
---|
13 | #entries=`find $destFolder -type f -name '*.fits' | sort`
|
---|
14 |
|
---|
15 | #for entry in ${entries[@]}
|
---|
16 | #do
|
---|
17 |
|
---|
18 | if [ "$#" != "5" ]
|
---|
19 | then
|
---|
20 | echo "Error: repairAuxFile.sh should be called with 4 arguments please"
|
---|
21 | exit
|
---|
22 | fi
|
---|
23 | entry=$1
|
---|
24 | errorFile=$2
|
---|
25 | wrongMjdFile=$3
|
---|
26 | reportFile=$4
|
---|
27 | processErrorFile=$5
|
---|
28 | #verify file with fverify
|
---|
29 | result=`fverify $entry 2>/dev/null | grep '0 error(s)'`
|
---|
30 | if [ "$result" != "" ]
|
---|
31 | then
|
---|
32 | mjdref=`/home/isdc/lyard/FACT++/fitsdump $entry -h 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]+'`
|
---|
33 | if [ "$mjdref" != 40587 ]
|
---|
34 | then
|
---|
35 | echo "$entry" >> $wrongMjdFile
|
---|
36 | result=""
|
---|
37 | fi
|
---|
38 | else
|
---|
39 | echo "$entry" >> $errorFile
|
---|
40 | fi
|
---|
41 |
|
---|
42 | if [ "$result" == "" ]
|
---|
43 | then
|
---|
44 | #fix it !
|
---|
45 | # echo $entry
|
---|
46 | headerSize=`ENDfixer $entry 2>/dev/null`
|
---|
47 | echo "Fixed END $entry" >> $reportFile
|
---|
48 | if [ "$headerSize" == "Error: header length not acceptable" ] || [ "$headerSize" == "Error: too much header space after END keyword" ]
|
---|
49 | then
|
---|
50 | echo "File "$entry" looks really messed up: "$headerSize >> $errorFile
|
---|
51 | exit
|
---|
52 | else
|
---|
53 | filesize=`stat -c%s $entry`
|
---|
54 | # echo $headerSize" "$filesize
|
---|
55 | numrows=`/home/isdc/lyard/FACT++/fitsdump $entry -h 2>/dev/null | grep 'NAXIS2' | awk '{ print $4 }' | grep -E -o '[0-9]+'`
|
---|
56 | if [ "$numrows" == "" ]
|
---|
57 | then
|
---|
58 | echo "Cannot fitsdump $entry" >> $processErrorFile
|
---|
59 | rm $entry
|
---|
60 | exit
|
---|
61 | fi
|
---|
62 | rowWidth=`/home/isdc/lyard/FACT++/fitsdump $entry -h 2>/dev/null | grep 'NAXIS1' | awk '{ print $4 }' | grep -E -o '[0-9]+'`
|
---|
63 |
|
---|
64 | totSize=`echo " $headerSize + $numrows * $rowWidth " | bc -l`
|
---|
65 | fitsSize=`echo " 2880 - ($totSize % 2880) " | bc`
|
---|
66 | fitsSize=`echo " $totSize + $fitsSize " | bc -l`
|
---|
67 | # echo $headerSize" "$numrows" "$rowWidth" "$totSize" "$fitsSize
|
---|
68 | # echo " FileSize: "$filesize" should be "$fitsSize
|
---|
69 | truncate -s $totSize $entry 2>/dev/null
|
---|
70 | truncate -s $fitsSize $entry 2>/dev/null
|
---|
71 | echo "Resized $entry" >> $reportFile
|
---|
72 | fi
|
---|
73 | fi
|
---|
74 | #done
|
---|