-
Notifications
You must be signed in to change notification settings - Fork 4
/
cat-l1b.sh
executable file
·159 lines (141 loc) · 3.19 KB
/
cat-l1b.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash -u
# keeping track of where I am
DIR_NOW=$(cd $(dirname $BASH_SOURCE); pwd )
function help_string()
{
echo "\
cat-l1b.sh <date> <product> [ <sat> ] [ <version> ] [ <source> ] ]
Either:
- <date> in YYYYMM[DD]
- <product> name: ACC1B, AHK1B, GNV1B, KBR1B, MAS1B, SCA1B, THR1B, CLK1B, GPS1B, IHK1B, MAG1B, TIM1B, TNK1B, USO1B, VSL1B
Optional argument:
- sat : GRACE A or B or GRACE-FO C or D, defaults to '$SAT' (irrelevant if <product> is 'KBR1B')
- version : release versions, defaults to '$VERSION'
- source : data source institute, defaults to '$SOURCE'
NOTICE:
- if <product> is KBR1B, the third input argument is ignored (effectively replaced with 'X')
Or:
- <dat file>, with complete path
NOTICE: v03 data is available in monthly files; all other versions are available in daily files"
}
#default data characteristics
SOURCE='JPL'
SAT='A'
VERSION=03
DATE=
PRODUCT=
ECHO=
for i in "$@"
do
case "$i" in
-x)
set -x
;;
GFZ|JPL)
SOURCE=$i
;;
0[2-9]*)
VERSION=$i
;;
20*)
DATE=$i
if [ "${#DATE}" -ne 8 ]
then
echo "ERROR:cat-l1b.sh: expecting date to be in YYYYMMDD format, with length equal to 8, not ${#DATE}."
exit 3
fi
;;
*1B)
PRODUCT=$i
;;
[ABDC])
SAT=$i
;;
echo)
ECHO=echo
;;
help|-help|--help|h|-h)
help_string
exit 1
;;
*)
echo "ERROR: cannot handle input argument '$i'"
exit 3
;;
esac
done
#sanity in mandatory inputs
if [ -z "$DATE" ]
then
echo "ERROR: need <date>"
help_string
exit 3
fi
if [ -z "$PRODUCT" ]
then
echo "ERROR: need <product>"
help_string
exit 3
fi
# parsing inputs
YEAR=${DATE:0:4}
MONTH=${DATE:4:2}
DAY=${DATE:6:2}
#resolve GRACE/GRACE-FO
if [ $YEAR -le 2017 ]
then
if [ "$VERSION" == "04" ]
then
echo "WARNING: resetting VERSION to 03, because GRACE does not have later data versions"
VERSION=03
fi
else
if [ "$VERSION" == "02" ] || [ "$VERSION" == "03" ]
then
echo "WARNING: resetting VERSION to 04, because GRACE-FO does not have earlier data versions"
VERSION=04
fi
fi
[ "$PRODUCT" == "KBR1B" ] && SAT="X"
# building package filename
case "$VERSION" in
"02")
DAY=${DATE:6:2}
DAT_FILE=${PRODUCT}_$YEAR-${MONTH}-${DAY}_${SAT}_$VERSION.dat
;;
"03")
DAT_FILE=${PRODUCT}_$YEAR-${MONTH}-${DAY}_${SAT}_$VERSION.dat
;;
"04")
DAY=${DATE:6:2}
#need to translate sate
[ "$SAT" == "A" ] && SAT=C
[ "$SAT" == "B" ] && SAT=D
DAT_FILE=${PRODUCT}_$YEAR-${MONTH}-${DAY}_${SAT}_$VERSION.txt
;;
*)
echo "ERROR: cannot handle VERSION with value '$VERSION'."
exit 3
esac
#define local coordinates
LOCALDIR=$DIR_NOW/L1B/$SOURCE/RL$VERSION/$YEAR
#make sure tar file is extracted
[ -e "$LOCALDIR/$DAT_FILE" ] || "$DIR_NOW/extract-l1b.sh" $@ 1>&2 || exit $?
#double check
if [ ! -e "$LOCALDIR/$DAT_FILE" ]
then
echo "ERROR:cat-l1b.sh: Cannot find file '$LOCALDIR/$DAT_FILE'."
exit 3
fi
#show contents
if [ $YEAR -le 2017 ]
then
# converter
CONV=$DIR_NOW/software/RELEASE_2010-03-31/Bin2AsciiLevel1.e
# need execute perms
chmod u+x $CONV
# use converter to look inside binary data
$CONV -binfile "$LOCALDIR/$DAT_FILE"
else
cat "$LOCALDIR/$DAT_FILE"
fi