mktxt2005.txt

Under:
#!/bin/csh

set sdir = ./StarDb/Calibrations/rhic
set tdir = ./txt
set files = `ls -1 $sdir/*.C`
set vs = (x0 err_x0 y0 err_y0 dxdz err_dxdz dydz err_dydz stats)
set len = 0
set ofile = ""
set dummy = "aa bb"

# Necessary instantiation to make each element of oline a string with spaces
set oline = ( \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" "aa bb" \
  )

set firstTime = 1
set newString = ""
foreach vv ($vs)
  set ofile = $tdir/${vv}.txt
  touch $ofile
  rm $ofile
  touch $ofile
  set va = "row.$vv"
  set fnum = 0
  foreach file ($files)
    @ fnum = $fnum + 1
    set vb = `cat $file | fgrep $va`
    set vc = $vb[3]
    @ len = `echo $vc | wc -c` - 1
    set vd = `echo $vc | colrm $len`
    echo $vd >> $ofile
    if ($firstTime) then
      set newString = "$vd"
    else
      set newString = "${oline[${fnum}]} $vd"
    endif
    set oline[$fnum] = "$newString"
  end
  set firstTime = 0
end


set ff = (date.time days)
set vf
foreach fff ($ff)
  set vg = $tdir/${fff}.txt
  set vf = ($vf $vg)
  touch $vg
  rm $vg
  touch $vg
end

set ofile = ${tdir}/full.txt
touch $ofile
rm $ofile
touch $ofile

set days = 0
set frac = 0
set fnum = 0
foreach file ($files)
  @ len = `echo $file | wc -c` - 18
  set dt = `echo $file | colrm 1 $len | colrm 16`
  set year = `echo $file | colrm 1 $len | colrm 5`
  @ len = $len + 4
  set month = `echo $file | colrm 1 $len | colrm 3`
  @ len = $len + 2
  set day = `echo $file | colrm 1 $len | colrm 3`
  @ len = $len + 3
  set hour = `echo $file | colrm 1 $len | colrm 3`
  @ len = $len + 2
  set min = `echo $file | colrm 1 $len | colrm 3`
  @ len = $len + 2
  set sec = `echo $file | colrm 1 $len | colrm 3`

  set modi = 0
  # Feb has 28 = 31-3 days (this is a leap year)
  if ($month > 2) @ modi += 2
  # Apr,Jun,Sep,Nov have 30 = 31-1 days
  if ($month > 4) @ modi += 1
  if ($month > 6) @ modi += 1
  if ($month > 9) @ modi += 1
  if ($month > 11) @ modi += 1
  echo $modi

# convert to seconds since 01-Jan-2005 EST (5 hours behind GMT)
  @ year = $year - 2005
  @ month = ($month + ($year * 12)) - 1
  @ day = $day + ($month * 31) - $modi
  @ hour = ($hour + ($day * 24)) - 5
  @ min = $min + ($hour * 60)
  @ sec = $sec + ($min * 60)

# convert to days since 01-Jan-2005 EST (5 hours behind GMT)
  @ days = $sec / 86400
  @ sec = $sec - ($days * 86400)
  @ frac = ($sec * 10000) / 864
  set fra = "$frac"
  set len = `echo $fra | wc -c`
  @ len = 7 - $len
  while ($len > 0)
    set fra = "0${fra}"
    @ len = $len - 1
  end
  
  echo $dt >> $vf[1]
  echo ${days}.$fra >> $vf[2]

  @ fnum = $fnum + 1
  echo "${days}.$fra ${oline[${fnum}]} $dt" >> $ofile
end