#!/bin/csh -f

set wrkdir = $1
set YEAR0 = $2
set YEAR1 = $3
set diagroot = $4
set PM_CPLLOG = $5
set CPL = $6
set file_name = $7
set hsilogflag = $8
set filepath = $9

setenv TOOLPATH $diagroot/tool_lib

if ($hsilogflag == 0) then
  setenv logpath  $filepath
else
  setenv logpath $wrkdir
endif

if ($PM_CPLLOG == 1) then

   set current = $PWD
   cd $wrkdir

    ${TOOLPATH}/process_cpl6_logfiles_heat.old.awk y0=$YEAR0 y1=$YEAR1 $logpath/cpl.log* >! $wrkdir/cplheatbudget.txt
    if ($CPL == 7) then
      setenv ntailht 21
      setenv ntailfw 16
      ${TOOLPATH}/process_cpl7_logfiles_heat.awk y0=$YEAR0 y1=$YEAR1 $logpath/cpl.log* >! $wrkdir/cplheatbudget.txt
      ${TOOLPATH}/process_cpl7_logfiles_fw.awk y0=$YEAR0 y1=$YEAR1 $logpath/cpl.log* >! $wrkdir/cplfwbudget.txt
    else
      setenv ntailht 16
      setenv ntailfw 16
      ${TOOLPATH}/process_cpl6_logfiles_heat.awk y0=$YEAR0 y1=$YEAR1 $logpath/cpl.log* >! $wrkdir/cplheatbudget.txt
      ${TOOLPATH}/process_cpl6_logfiles_fw.awk y0=$YEAR0 y1=$YEAR1 $logpath/cpl.log* >! $wrkdir/cplfwbudget.txt
    endif
    tail -${ntailfw} cplfwbudget.txt >! $wrkdir/cplfwbudget.asc
    tail -${ntailht} cplheatbudget.txt >! $wrkdir/cplheatbudget.asc

    cd $current
endif


printf " This file was created as a placeholder" > $file_name

