#!/bin/csh
# +-======-+ 
#  Copyright (c) 2003-2018 United States Government as represented by 
#  the Admistrator of the National Aeronautics and Space Administration.  
#  All Rights Reserved.
#  
#  THIS OPEN  SOURCE  AGREEMENT  ("AGREEMENT") DEFINES  THE  RIGHTS  OF USE,
#  REPRODUCTION,  DISTRIBUTION,  MODIFICATION AND REDISTRIBUTION OF CERTAIN 
#  COMPUTER SOFTWARE ORIGINALLY RELEASED BY THE UNITED STATES GOVERNMENT AS 
#  REPRESENTED BY THE GOVERNMENT AGENCY LISTED BELOW ("GOVERNMENT AGENCY").  
#  THE UNITED STATES GOVERNMENT, AS REPRESENTED BY GOVERNMENT AGENCY, IS AN 
#  INTENDED  THIRD-PARTY  BENEFICIARY  OF  ALL  SUBSEQUENT DISTRIBUTIONS OR 
#  REDISTRIBUTIONS  OF THE  SUBJECT  SOFTWARE.  ANYONE WHO USES, REPRODUCES, 
#  DISTRIBUTES, MODIFIES  OR REDISTRIBUTES THE SUBJECT SOFTWARE, AS DEFINED 
#  HEREIN, OR ANY PART THEREOF,  IS,  BY THAT ACTION, ACCEPTING IN FULL THE 
#  RESPONSIBILITIES AND OBLIGATIONS CONTAINED IN THIS AGREEMENT.
#  
#  Government Agency: National Aeronautics and Space Administration
#  Government Agency Original Software Designation: GSC-15354-1
#  Government Agency Original Software Title:  GEOS-5 GCM Modeling Software
#  User Registration Requested.  Please Visit http://opensource.gsfc.nasa.gov
#  Government Agency Point of Contact for Original Software:  
#  			Dale Hithon, SRA Assistant, (301) 286-2691
#  
# +-======-+ 

  set fvroot = $1
  set mydir  = $2

  setenv FVROOT $fvroot
  cd $mydir

# source $FVROOT/bin/g5_modules

  setenv GEOSUTIL $FVROOT/../src/GMAO_Shared/GEOS_Util
  $GEOSUTIL/plots/configure
  source .quickplotrc

# Convert Original ECMWF.nc File to GFIO-Readable nc4 File (Creates:  grads.fwrite.nc4)
# -------------------------------------------------------------------------------------
  /bin/rm -f                                               grads.commands
  touch                                                    grads.commands
  echo \'sdfopen ecmwf.data\'                           >> grads.commands
  echo \'run $GEOSUTIL/plots/grads_util/writegrads.gs\' >> grads.commands
  echo \'q ctlinfo\'                                    >> grads.commands
  echo   write \(ctlinfo,\result\)                      >> grads.commands
  echo \'quit\'                                         >> grads.commands
  # This call assumes that the grads environment includes GEOS_Util/post/grads_utils
  # in the GASCRP setting
  grads    -b -l -c "run grads.commands"

  set failed = 0
  if (! -e grads.fwrite ) set failed = 1
  if (! -e ctlinfo      ) set failed = 1

  /bin/rm sedfile grads.commands grads.txt
  if ($failed) then
     echo "something did not work in grads conversion, aborting ..."
     exit(1)
  endif
  exit(0)

