-
Notifications
You must be signed in to change notification settings - Fork 19
/
getDAP
executable file
·207 lines (174 loc) · 5.18 KB
/
getDAP
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/sh
export SPACE="catalog"
export REQUESTED_DAP_OBJ="dds"
export RESOURCE_ID="/data/nc/fnoc1.nc"
show_usage () {
echo ""
echo "$0 OPeNDAP"
echo ""
echo "NAME"
echo ""
echo " $0 -- Get a DAP object from a local BES."
echo ""
echo "SYNOPSIS"
echo ""
echo " $0 [-v] [-c bes_conf_file] [-s bes_space_name] [-t dap2_constraint] -d dap_request_type -i resource_id ";
echo ""
echo "DESCRIPTION"
echo ""
echo " Retrieves a DAP object using the besstandalone application."
echo " Because retrieving DAP objects from the BES exercises all of"
echo " machinery of the BES (such as caches) '$0' can easily be used "
echo " to pre-populate caches from a cron job or some other "
echo " programatic activity."
echo ""
echo "OPTIONS"
echo " -h, -? Shows this page."
echo ""
echo " -v file Verbose mode."
echo ""
echo " -i file The data file name relative to the "
echo " BES.Catalog.catalog.RootDirectory property in the"
echo " BES configuration file."
echo ""
echo " -s name The name of the BES 'space' in which the requested data"
echo " can be found. Default: catalog"
echo ""
echo " -d dds|das|dods|dmr|dap "
echo " The type of the DAP object to request. Default: dds"
echo ""
echo " -t ce The DAP2 constraint expression to apply to the request."
echo ""
echo ""
echo " -c file Specifies the BES configuration file"
echo ""
echo ""
echo "OPeNDAP December 9, 2015"
}
OPTIND=1 # Reset in case getopts has been used previously in the shell.
verbose=0
while getopts "h?vd:i:c:s:t:" opt; do
case "$opt" in
h|\?)
show_usage
exit 0
;;
d) REQUESTED_DAP_OBJ=`echo $OPTARG | awk '{print tolower($0)}' -`
;;
i) RESOURCE_ID=$OPTARG
;;
v) verbose=1
;;
c) BES_CONF=$OPTARG
;;
s) SPACE=$OPTARG
;;
t) CE=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ -z $BES_CONF ]
then
echo "BES_CONF is not set trying env variable 'prefix'...";
if [ ! -z $prefix ] # True if var is set and str length != 0
then
test_conf=$prefix/etc/bes/bes.conf
echo "Env var 'prefix' is set. Checking $test_conf";
if [ -r $test_conf ]
then
BES_CONF="$test_conf"
if [ $verbose = 1 ]
then
echo "BES_CONF: " $BES_CONF
fi
fi
fi
fi
if [ -z $BES_CONF ]
then
export BES_CONF=/etc/bes/bes.conf
echo "Last Attempt: Trying $BES_CONF";
if [ -r $BES_CONF ]
then
if [ $verbose = 1 ]
then
echo "BES_CONF: " $BES_CONF
fi
else
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
echo "Unable to locate a BES configuration file."
echo "You may identify your BES configurstion in one of three ways: "
echo ""
echo " 1. Using the command line parameter '-c'"
echo ""
echo " 2. Setting the environment variable $prefix to the install"
echo " location of the BES."
echo ""
echo " 3. Placing the bes.conf file in the "well known" location"
echo " /etc/bes/bes.conf"
echo ""
echo "The command line parameter is the recommended usage."
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
show_usage
echo ""
exit;
fi
fi
# http://cloudydap.s3.amazonaws.com/merra2/MERRA2_100.instM_2d_gas_Nx.198508.nc4
if [ $verbose = 1 ]
then
echo "SPACE: $SPACE"
echo "REQUESTED_DAP_OBJ: $REQUESTED_DAP_OBJ"
echo "RESOURCE_ID: $RESOURCE_ID"
fi
if [ -z ${CE+"true"} ]
then
if [ $verbose = 1 ]
then
echo "CE: Is Not Set";
fi
CONTAINER_ELEMENT=`cat <<EOF
<bes:container name="myContainer" />
EOF
`
else
if [ $verbose = 1 ]
then
echo "CE: $CE";
fi
CONTAINER_ELEMENT=`cat <<EOF
<bes:container name="myContainer">
<bes:constraint>$CE</bes:constraint>
</bes:container>
EOF
`
fi
cmdDoc=`cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<bes:request xmlns:bes="http://xml.opendap.org/ns/bes/1.0#" reqID="[http-bio-8080-exec-1:20:gateway_request]">
<bes:setContext name="bes_timeout">300</bes:setContext>
<bes:setContext name="xdap_accept">2.0</bes:setContext>
<bes:setContext name="dap_explicit_containers">no</bes:setContext>
<bes:setContext name="errors">xml</bes:setContext>
<bes:setContext name="max_response_size">0</bes:setContext>
<bes:setContainer name="myContainer" space="$SPACE">$RESOURCE_ID</bes:setContainer>
<bes:define name="d1" space="default">
$CONTAINER_ELEMENT
</bes:define>
<bes:get type="$REQUESTED_DAP_OBJ" definition="d1" />
</bes:request>
EOF
`
COMMAND_FILE=$(mktemp -t getDAP_XXXXXX)
if [ $verbose = 1 ]
then
echo "COMMAND_FILE: " $COMMAND_FILE
fi
echo $cmdDoc > $COMMAND_FILE
# echo "cmdFile: " `cat $cmdFile`
besstandalone -c $BES_CONF -i $COMMAND_FILE