#!/bin/sh
#
#dropcandis.sh: Converts the files from netcdf to candis. Fixes the bad data, c#alculates thetae and thetaes and mean latitude and longitude.
#
if test $# != 8
then
    echo "Usage: dropcandis.sh year mon day hr min sec aircraft sondenumber"
else
    filename=D20$1$2$3_$4$5$6.1QCcdf
#   filename=Mission_RF17.20$1$2$3$4$5$6.C-130.QCcdf.cdf
    uniget $filename | \
    cdfextr -rp bad badlim | \
    cdfextr -rs base_time | \
    cdfparams bad 9999 badlim 9998 | \
    cdfmath "tdry -998 > tdry =" | \
    cdfmath "dp -998 > dp =" | \
    cdfmath "rh -998 > rh =" | \
    cdfmath "u_wind -998 > u_wind =" | \
    cdfmath "v_wind -998 > v_wind =" | \
    cdfmath "dz -998 > dz =" | \
#   cdfmath "tdry 1.5 + temp =" | \
    rafthetae -d pres tdry dp thetae satmr | \
#   cdfmath "thetae 9000 < thetae =" | \
    rafthetae -d pres tdry tdry thetaes satmr | \
    cdfentropy -d pres tdry dp entropy satmr1 | \
    cdfentropy -d pres tdry tdry entropys satmr1 | \
    cdfmath "satmr rh * 100 / mr =" | \
    cdfmean time 0 lat| \
    cdfmean time 0 lon| \
    cdfuncat time | \
    cdfcat pres 0 1200 20000 | \
    cdfextr -s pres lat0 lon0 | \
    cdfextr tdry dp rh u_wind v_wind dz thetae thetaes satmr mr entropy| \
    cdfmath "$1 year = $2 month = $3 day = $4 hour = $5 min = $6 sec =" | \
    cdfcomment "$1$2$3_$4$5$6 $7" > drop$8.sonde    
fi







