From 9a920a79c664dce4b697052225542fa15222ea01 Mon Sep 17 00:00:00 2001 From: Nathan Bowler Date: Wed, 23 Jul 2014 08:11:12 -0400 Subject: [PATCH] Omaha #3392 Adding unmodified, existing a2acars scripts in order to maintain history. Change-Id: Ifd853cec4a97d7008e58e6beee40a90731d16e12 Former-commit-id: 43d9e401af05e950429bd330aead8b5d59905407 [formerly 43d9e401af05e950429bd330aead8b5d59905407 [formerly 86d82d1942f6c8c85eda7ba5fb16b75740a2d972]] Former-commit-id: 97d38c86cf0b4576fc458a8486bdb90b93550e10 Former-commit-id: 104fecf1f27008a0d8d4e5787495184a89b160d2 --- pythonPackages/msaslaps/acars/a2acars.csh | 96 +++++++++++++++++++ pythonPackages/msaslaps/acars/a2acarsStub.py | 84 ++++++++++++++++ pythonPackages/msaslaps/common/UEngine.cshsrc | 28 ++++++ 3 files changed, 208 insertions(+) create mode 100644 pythonPackages/msaslaps/acars/a2acars.csh create mode 100644 pythonPackages/msaslaps/acars/a2acarsStub.py create mode 100755 pythonPackages/msaslaps/common/UEngine.cshsrc diff --git a/pythonPackages/msaslaps/acars/a2acars.csh b/pythonPackages/msaslaps/acars/a2acars.csh new file mode 100644 index 0000000000..46d2e17f06 --- /dev/null +++ b/pythonPackages/msaslaps/acars/a2acars.csh @@ -0,0 +1,96 @@ +#!/bin/csh +# +# A script wrapper around a UEngine call that is meant to get all available +# acars data in the A-II database over a specified range of times. +# The data is output to stdout as ASCII. Each line is one time/platform +# combination. The individual data items are comma delimited. +# This version can adapt to use a python stub that calls the +# data access framework. +# +# Usage: +# +# a2acars.csh {p} yyyy-mm-dd hh:mm yyyy-mm-dd hh:mm +# +# The literal p flag is optional. The p flag means preserve +# the final version of the python submitted to the UEngine instead of +# cleaning it up. The path to the finalized python is /tmp/a2acarsNNNNN.py +# where NNNNN is a unix process id. +# +# This outputs the following set of variables for each line: +# +# tailNumber,asciitime,latitude,longitude,acarsReceivingStation, +# pressure,flightPhase,rollQuality,temperature,windDir,windSpeed, +# relHumidity,mixRatio +# +set rmpy = yes +if ( "$1" == "p" ) then + set rmpy = no + shift +endif +# +# Identify directory this script is in, will be one of the directories we +# search for other files in. +# +set mydir = `dirname $0` +set d1 = `echo $mydir | cut -c1` +if ( "$mydir" == '.' ) then + set mydir = $PWD +else if ( "$d1" != "/" ) then + set mydir = $PWD/$mydir +endif +set mydir = `(cd $mydir ; pwd)` +if ( ! $?FXA_HOME ) set FXA_HOME = xxxx +# +# Locate python stub that we will modify to create the final python logic. +# +if ( -e ./a2acarsStub.py ) then + set stubpy = ./a2acarsStub.py +else if ( -e $mydir/a2acarsStub.py ) then + set stubpy = $mydir/a2acarsStub.py +else if ( -e $FXA_HOME/src/dm/bufr/acars/a2acarsStub.py ) then + set stubpy = $FXA_HOME/src/dm/bufr/acars/a2acarsStub.py +else if ( -e $FXA_HOME/bin/a2acarsStub.py ) then + set stubpy = $FXA_HOME/bin/a2acarsStub.py +else + bash -c "echo could not find a2acarsStub.py 1>&2" + exit +endif +# +# Determine if we are using the data access framework or the uEngine. +# +grep DataAccessLayer $stubpy >& /dev/null +if ( $status == 0 ) then + set method = "daf" +else + # + # Set up the environment we need to run the UEngine. + # + set method = "uengine" + if ( -e ./UEngine.cshsrc ) then + set ueenv = ./UEngine.cshsrc + else if ( -e $mydir/UEngine.cshsrc ) then + set ueenv = $mydir/UEngine.cshsrc + else if ( -e $FXA_HOME/src/dm/point/UEngine.cshsrc ) then + set ueenv = $FXA_HOME/src/dm/point/UEngine.cshsrc + else if ( -e $FXA_HOME/bin/UEngine.cshsrc ) then + set ueenv = $FXA_HOME/bin/UEngine.cshsrc + else + bash -c "echo could not find UEngine.cshsrc 1>&2" + exit + endif + source $ueenv +endif +# +set specpy = /tmp/a2acars${$}.py +rm -rf $specpy >& /dev/null +touch $specpy +chmod 775 $specpy +cat $stubpy | sed "s/BBBBB/$1 $2/g" | sed "s/EEEEE/$3 $4/g" > $specpy +if ( "$method" == "daf" ) then + /awips2/python/bin/python $specpy +else + cd $UE_BIN_PATH + ( uengine -r python < $specpy ) | grep -v '<' | grep -v Response +endif +if ( "$rmpy" == "yes" ) rm -rf $specpy >& /dev/null +# diff --git a/pythonPackages/msaslaps/acars/a2acarsStub.py b/pythonPackages/msaslaps/acars/a2acarsStub.py new file mode 100644 index 0000000000..20783d50f3 --- /dev/null +++ b/pythonPackages/msaslaps/acars/a2acarsStub.py @@ -0,0 +1,84 @@ +from com.raytheon.uf.common.message.response import ResponseMessageGeneric +import BaseRequest + +br = BaseRequest.BaseRequest( "acars" ) +br.addParameter("dataTime","BBBBB:00.0",">=") +br.addParameter("dataTime","EEEEE:59.9","<=") + +# ArrayList of ResponseMessageGeneric +alrmg = br.execute() +nnn = alrmg.size() +if nnn == 0 : + return ResponseMessageGeneric("No data available.") + +# ResponseMessageGeneric payload is ACARSRecord +msg = "" +i = 0 +while i < nnn : + oneRec = alrmg.get(i).getContents() + i += 1 + mytime = oneRec.getDataURI().split('/',4)[2].split('.',2)[0] + if mytime == "" or mytime == "None" : + continue + mytail = str(oneRec.getTailNumber()).split(' ',2)[0] + myloc = str(oneRec.getLocation().getLocation()).split(' ',4) + mylat = myloc[2].split(')',2)[0] + mylon = myloc[1].split('(',2)[1] + if mylat == "" or mylon == "" or mylat == "None" or mylon == "None" : + continue + mylat = "%.4f"%float(mylat) + mylon = "%.4f"%float(mylon) + myrec = str(oneRec.getReceiver()).split(' ',2)[0] + if myrec == "None" : + myrec = "" + mypres = str(oneRec.getPressure()) + if mypres == "" or mypres == "None" : + mypres = "1e37" + else : + mypres = "%.0f"%(float(mypres)) + myphs = str(oneRec.getFlightPhase()) + if myphs == "" or myphs == "None" : + myphs = "7" + else : + myphs = "%d"%int(myphs) + myrol = str(oneRec.getRollAngleQuality()) + if myrol == "" or myrol == "None" : + myrol = "3" + else : + myrol = "%d"%int(myrol) + mytemp = str(oneRec.getTemp()) + if mytemp == "" or mytemp == "None" : + mytemp = "1e37" + else : + mytemp = "%.1f"%float(mytemp) + mydir = str(oneRec.getWindDirection()) + if mydir == "" or mydir == "None" : + mydir = "1e37" + else : + mydir = "%d"%int(mydir) + myspd = str(oneRec.getWindSpeed()) + if myspd == "" or myspd == "None" : + myspd = "1e37" + else : + myspd = "%.1f"%float(myspd) + myhum = str(oneRec.getHumidity()) + if myhum == "" or myhum == "None" : + myhum = "1e37" + else : + myhum = "%.0f"%float(myhum) + mymix = str(oneRec.getMixingRatio()) + if mymix == "" or mymix == "None" : + mymix = "1e37" + else : + mymix = "%.2f"%float(mymix) +# myicg = str(oneRec.getIcing()) +# if myicg == "" or myicg == "None" : +# myicg = "1e37" +# else : +# myicg = "%d"%int(myicg) + msg += mytail + "," + mytime + "," + mylat + "," + mylon + "," + \ + myrec + "," + mypres + "," + myphs + "," + myrol + "," + \ + mytemp + "," + mydir + "," + myspd + "," + myhum + "," + mymix + "\n" + +# pass single RMG back to the uengine. +return ResponseMessageGeneric(msg) diff --git a/pythonPackages/msaslaps/common/UEngine.cshsrc b/pythonPackages/msaslaps/common/UEngine.cshsrc new file mode 100755 index 0000000000..59c98da46f --- /dev/null +++ b/pythonPackages/msaslaps/common/UEngine.cshsrc @@ -0,0 +1,28 @@ +# +# Set up the environment we need to run the UEngine. +# +#set release = "" +#if ( -e /awips2/edex/conf/banner.txt ) then +# set release = `grep Version /awips2/edex/conf/banner.txt | tr '*' ' ' | \ +# sed 's/ *$//g' | sed 's/^.* //g'` +#endif +# +while (1) + if ( $?INSTALL_BASE ) then + if ( -d $INSTALL_BASE/python ) break + endif + setenv INSTALL_BASE /awips2 + break +end +if ( -e $INSTALL_BASE/bin/uengine ) then + setenv UE_BIN_PATH $INSTALL_BASE/bin +else + setenv UE_BIN_PATH $INSTALL_BASE/fxa/bin +endif +if ( ! $?PRE_ADE_PATH ) then + setenv PRE_ADE_PATH ${PATH} +endif +setenv JAVA_HOME $INSTALL_BASE/java +setenv LD_LIBRARY_PATH /usr/lib +setenv PYTHONPATH .:$INSTALL_BASE/bin/src +setenv PATH ${JAVA_HOME}/bin:${UE_BIN_PATH}:${PRE_ADE_PATH}