#! /bin/csh -f
#
#  given $1 = a tokamak string, exit w/status 1 (true) if it is "valid"
#                                             0 (false) otherwise
#
#
  set silent = FALSE
  if ( $#argv == 2 ) then
    if ( "$argv[2]" == "silent" ) then
      set silent = TRUE
    else
      echo "?tok_valid:  invalid 2nd argument keyword:  $argv[2]"
      exit 0
    endif
  else if ( $#argv != 1 ) then
    echo "?tok_valid:  wrong number of arguments ($#argv)."
    exit 0
  endif
#
  set string = "$argv[1]"
#

  if (-f TOKAMAK.DAT ) then
    set toklist = `cat TOKAMAK.DAT | awk '{print $1}'`
  else if ( $?CONFIGDIR ) then
    if ( -f $CONFIGDIR/TOKAMAK.DAT ) then
      set toklist = `cat $CONFIGDIR/TOKAMAK.DAT | awk '{print $1}'`
    endif
  else if ( $?NTCC_ROOT ) then
    if (-f $NTCC_ROOT/etc/TOKAMAK.DAT ) then
      set toklist = `cat $NTCC_ROOT/etc/TOKAMAK.DAT | awk '{print $1}'`
    endif
  else if ( $?TRANSP_LOCATION ) then
    if ( -f $TRANSP_LOCATION/TOKAMAK.DAT ) then
      set toklist = `cat $TRANSP_LOCATION/TOKAMAK.DAT | awk '{print $1}'`
    endif
  endif
  if ( ! $?toklist ) then
     echo "?tok_valid: can not find TOKAMAK.DAT"
     exit 0
  endif

#
  @ i = 0
  while ( $i < $#toklist ) 
    @ i++
    if ( "$string" == "$toklist[$i]" ) then
      exit 1
    endif
  end
#
  if ( $silent == FALSE ) then
    echo "tok_valid:  unrecognized tokamak id:  $string"
    echo "...valid list is:  $toklist"
  endif
#
  exit 0
