#!/usr/bin/ksh

# If the stats.short file from the uncoupled GFDL model could
# not be found, then this script creates a fake stats.short 
# file by taking the latest position and speed & direction of
# storm and just extrapolating forward in time.

PS4='+ gfdl_pre_ocean_mkstats.sh line $LINENO: '

grep `echo ${YYMMDD} | cut -c1-6` track | tail -1 |
awk '
{
  a=int($6)/10.  #latitude
  o=int($7)/10.  #longitude
  d=int($8)      #direction
  s=int($9)/100. #speed
  p=int($10)     #central pressure
  v=int($13)     #max wind speed
  for (i=1; i<=12; i++) {
    if (d>=0 && s>=0) {
      a=a+cos(d*3.1415/180)*s*3600*6*i/110000
      o=o-sin(d*3.1415/180)*s*3600*6*i/110000
      printf("%7.2f %7.2f %7.2f %7.2f %7.2f\n", i*6.0, o*-1, a, p, s)
    }
    else {
      printf("%7.2f %7.2f %7.2f %7.2f %7.2f\n", i*6.0, o*-1, a, p, s)
    }
  }
} '
