#!/bin/csh
# cnvrt_cfx_csv_to_gp.csh
#
#  2014-01-23  S.J. Ormiston   modified to use sed to add comments for
#                              the first five lines
#
#
# Assumes that the CFX Post written CSV file:
# 1) is for one curve only
# 2) has 5 lines of header text
# 3) has two blank lines at the end of the file after the data
#
#
echo "*---< Converting <$1> to gnuplot-ready format -------*"
if ( -e $1) then
   setenv filename $1
   set tmp_string = `wc -l $filename`
   set line_count = `echo $tmp_string | sed s/$filename//`
#
   @ head_line_count = $line_count - 2
#
   if ( -e $1:r-gr.dat) then
      echo "Deleting previous version of: <$1:r-gr.dat>"
      /bin/rm $1:r-gr.dat
   endif
#
   cat $1 | head -$head_line_count | sed 1,5"s/^\(.\{0\}\)/\1# /" >  $1:r-gr.dat
#
   echo "*---Created: <$1:r-gr.dat>"
#
else
   echo "Couldn't find $1"
endif
#

