#!/bin/csh
if ( x$1 == "x-h" ) then
  echo Syntax: getclus \[-e\] \[ecifile\]
  echo extracts, from clusters.out, the cluster sizes, lengths and multiplicities
  echo if ecifile is given, it also prints the eci therein
  echo if -e is specified, it prints eci from eci.out
  exit
endif
if ( x$1 == "x" ) then
   set ecifile=""
else if ( x$1 == "x-e" ) then
   set ecifile="eci.out"
else
   set ecifile=$1
endif

cat clusters.out | awk '{ \
  m=$1; \
  getline; \
  l=$1; \
  getline; \
  n=$1; \
  $1=0; \
  if ('\"$ecifile\"'!="") { \
    getline < '\"$ecifile\"'; \
    e=$1; \
    print n,l,m,e; \
  } \
  else { \
    print n,l,m; \
  } \
  for (i=1; i<=n; i++) {   \
    getline; \
  } \
  getline; \
  if ($1=="tensor") { \
    getline; rank=$1; \
    for (i=1; i<=rank; i++) {getline;} \
    getline; ndata=$1; \
    for (i=1; i<=ndata; i++) {getline;} \
    getline; \
  } \
}'
