source: branches/trigger_burst_research/Archive/repairRawFile.sh@ 19914

Last change on this file since 19914 was 12871, checked in by lyard, 13 years ago
added more scripts
  • Property svn:executable set to *
File size: 2.1 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_nfs/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_nfs/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_nfs/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 if [ $filesize > $fitsSize ]
70 then
71 truncate -s $totSize $entry 2>/dev/null
72 truncate -s $fitsSize $entry 2>/dev/null
73 echo "Resized $entry" >> $reportFile
74 fi
75
76 fi
77 fi
78#done
Note: See TracBrowser for help on using the repository browser.