source: branches/trigger_burst_research/Archive/repairAuxFile.sh@ 19128

Last change on this file since 19128 was 12750, checked in by lyard, 13 years ago
added ingest stuff
  • Property svn:executable set to *
File size: 2.3 KB
Line 
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
18if [ "$#" != "5" ]
19then
20 echo "Error: repairAuxFile.sh should be called with 4 arguments please"
21 exit
22fi
23entry=$1
24errorFile=$2
25wrongMjdFile=$3
26reportFile=$4
27processErrorFile=$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 #is there any extra row that we can keep ?
65 #let RowCheck examine the time markers
66 numrows2=`RowChecker $entry $headerSize $rowWidth 0 $numrows 2>/dev/null`
67 if [ $numrows2 -gt $numrows ]
68 then
69 numrows=$numrows2
70 totSize=`echo " $headerSize + $numrows * $rowWidth " | bc -l`
71 fitsSize=`echo " 2880 - ($totSize % 2880) " | bc`
72 fitsSize=`echo " $totSize + $fitsSize " | bc -l`
73# echo $headerSize" "$numrows" "$rowWidth" "$totSize" "$fitsSize
74# echo " FileSize: "$filesize" should be "$fitsSize
75 truncate -s $totSize $entry 2>/dev/null
76 truncate -s $fitsSize $entry 2>/dev/null
77 echo "Resized $entry" >> $reportFile
78 fi
79 fi
80 fi
81#done
Note: See TracBrowser for help on using the repository browser.