#!/bin/csh -f
unset echo verbose
set DIAG_RBN = /fis/cgd/home/yeager/ccsm_plots/ncl
echo -n 'Enter casename: '
setenv CASENAME $<
echo -n 'Enter file location (. if this dir): '
setenv LOCATION $<
echo -n 'Process obs? (y/n): '
setenv PROC_OBS $<
echo -n 'Enter first year: '
setenv FIRST $<
echo -n 'Enter last year:  '
setenv LAST $<
if (-e enso.files) then
  rm enso.files
endif

if ($PROC_OBS == 'n') then
    @ yr = $FIRST
    while ($yr <= $LAST)
    if ($yr < 10) then
	ls $LOCATION/$CASENAME.cam2.h0.000{$yr}-??.nc >> enso.files
    else
	if ($yr < 100) then
	ls  $LOCATION/$CASENAME.cam2.h0.00{$yr}-??.nc >> enso.files
	else
	if ($yr < 1000) then
	    ls  $LOCATION/$CASENAME.cam2.h0.0{$yr}-??.nc >> enso.files
	else
	    ls  $LOCATION/$CASENAME.cam2.h0.{$yr}-??.nc >> enso.files
	endif
	endif
    endif
    @ yr++
    end 
    
    ncl $DIAG_RBN/enso.analysis.ncl
    
    convert -crop 0x0+5+5 $CASENAME.ENSO.analysis.ps $CASENAME.ENSO.analysis.png
else
    setenv SFILE /fs/cgd/csm/inputdata/atm/cam2/sst/sst_HadOIBl_bc_1.9x2.5_1949_2004_c050526.nc
    setenv IFILE /fs/cgd/csm/inputdata/atm/cam2/inic/fv/cami_0000-09-01_1.9x2.5_L26_c040809.nc

    ncl $DIAG_RBN/enso.obs.analysis.ncl
    convert -crop 0x0+5+5 $CASENAME.ENSO.obs.analysis.ps $CASENAME.ENSO.obs.analysis.png
endif
