Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
getMIIseacurrent.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2script=${0##*/}
3
4# Script to request and transform data from the MII instrumented line.
5# 1 - a request is formed to the database storing the data. The order of the fields is
6# fixed and must stay the same for the next steps :
7# time, current speed, error on current speed, current direction, error on current direction
8# A given period can be specified by providing two strings of the form 2019-05-01T12:00:00Z
9# The data are written into a ASCII file (csv text file).
10# 2 - The awk program splits the file in two separated text files with the header dropped for the
11# moment. The angles are converted from degrees with 0 at North and counting clockwise into
12# radians with 0 at East and counting anticlockwise. They are not further reduded to [-pi,+pi]
13# to keep a continuity of values (the current is often directed toward West)
14
15if [ -z $JPP_DIR ]; then
16 echo "Variable JPP_DIR undefined."
17 exit
18fi
19
20source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
21
22set_variable DEBUG 2
23set_variable DIR $JPP_DIR/examples/JAcoustics/
24set_variable WORKDIR ./
25set_variable: FORMAT GRAPHICS_FORMAT gif
26set_variable+ BATCH GRAPHICS_BATCH -B
27
28set_variable MII_ASC $WORKDIR/MII.asc
29set_variable CurSpeed_TXT $WORKDIR/MII_CurrentSpeed.txt
30set_variable CurSpeed_ROOT $WORKDIR/MII_CurrentSpeed.root
31set_variable CurSpeed_GIF $WORKDIR/MII_CurrentSpeed.$FORMAT
32set_variable CurDirec_TXT $WORKDIR/MII_CurrentDirection.txt
33set_variable CurDirec_ROOT $WORKDIR/MII_CurrentDirection.root
34set_variable CurDirec_GIF $WORKDIR/MII_CurrentDirection.$FORMAT
35
36if do_usage $*; then
37 usage "$script <tmin> <tmax> or"\
38 "\n$script clean" \
39 "\nwhere <tmin> and <tmax> are strings of the form 2019-05-01T12:00:00Z" \
40 "\nand clean will remove the output file" \
41 "\n" \
42 "\nScript to request sea current data from the erddap.osupytheas.fr database." \
43 "\nthe validity of the datetimes is not checked by the script."
44fi
45
46case $# in
47 1) set_variable OPTION $argv[1];&
48 2) set_variable TMAX $argv[2];
49 set_variable TMIN $argv[1];;
50 *) fatal "Wrong number of arguments.";;
51esac
52
53function clean()
54{
55 rm -f $MII_ASC
56 rm -f $CurSpeed_TXT
57 rm -f $CurDirec_TXT
58 rm -f $CurSpeed_ROOT
59 rm -f $CurDirec_ROOT
60 rm -f $CurSpeed_GIF
61 rm -f $CurDirec_GIF
62 exit
63}
64
65case "$OPTION" in
66 clean) clean;;
67 "") ;;
68 *) fatal "Wrong option $OPTION.";;
69esac
70
71
72if [[ -n "$TMIN" && -n "$TMAX" ]]; then
73 uTMIN=`date -d $TMIN +%s --utc`
74 uTMAX=`date -d $TMAX +%s --utc`
75 echo "Obtaining sea current speed and direction between" $TMIN "("$uTMIN") and" $TMAX "("$uTMAX")"
76 wget -O $MII_ASC "https://erddap.osupytheas.fr/erddap/tabledap/Emso_Aquadopp_64c7_8059_4af9.asc?time,Speed_mean,Speed_std,Direction_mean,Direction_std&time>=$uTMIN&time<=$uTMAX"
77fi
78
79# The ASCII use the comma as separator. We split the file in two simple space separated text files.
80# One for the strength of the sea current. One for the direction of the sea current.
81# The direction value are converted from deg to rad and inverted from clockwise to anticlockwise
82# The header is dropped for the moment since it has to be correctly handled using awk command.
83# It has currently 11 lines. A smarter way of handling the header and the fields must be found.
84
85if [[ -f $MII_ASC ]]; then
86 awk -F',' '{if ( NR>11 ) {print $1 " " $2 " " $3;};}' $MII_ASC > $CurSpeed_TXT
87 awk -F',' '{if ( NR>11 ) {print $1 " " (90.0 - $4)/57.2958 " " $5/57.2958 ;}}' $MII_ASC > $CurDirec_TXT
88fi
89
90if [[ -f $CurSpeed_TXT ]]; then
91
92 JGraph \
93 -f $CurSpeed_TXT \
94 -o $CurSpeed_ROOT
95
96 JPlot1D \
97 -f $CurSpeed_ROOT:\.\* \
98 -w 2000x500 \
99 -t "$TIMESTAMP" \
100 -> "Date" \
101 -\^ "Current speed [m.s-1]" \
102 -T "Sea current speed at ORCA site " \
103 -o $CurSpeed_GIF $BATCH
104fi
105
106if [[ -f $CurDirec_TXT ]]; then
107
108 JGraph \
109 -f $CurDirec_TXT \
110 -o $CurDirec_ROOT
111
112 JPlot1D \
113 -f $CurDirec_ROOT:\.\* \
114 -w 2000x500 \
115 -t "$TIMESTAMP" \
116 -> "Date" \
117 -\^ "Current direction [rad]" \
118 -T "Sea current direction at ORCA site " \
119 -o $CurDirec_GIF $BATCH
120fi