#!/bin/csh -f
  # script to create a soft link between an lpc analysis file (usually in the
  # user's SFDIR directory) and a link file called lp.#, where # is an integer
  # A.S. 8/94

set PWD = `pwd`
if ($#argv == 0) then
  echo " lplink syntax:   >>  lplink   analysis_file   #   << "
  echo "       where #  is an integer.  "
  echo "  Example:  lplink  myvoice.lpc  3 "
  echo "  Result : Link file >> lp.4 << is created in your current working Unix"
  echo "  directory (currently $PWD). This link file points to lpc"
  echo "  analysis file >> myvoice.lpc << , in directory $SFDIR ."
  echo  " "
 echo "lpc analysis files must be located on the snd disk or in /sflib/anal/lpc ."
  echo "-> If the analysis file is not located in your current working soundfile "
  echo " directory, include its subdirectory name or full path."
  echo "-> If the analysis file is located in /sflib/anal/lpc, you can omit this"
  echo " directory path and give only the analysis file name."
  echo "-> If the analysis file ends with the extension >> .lpc <<< or the"
  echo " extension  >> ,lp << , you can omit this suffix if you wish."
  echo  " "
  echo "-> Several links can be created with a single command line by including"
  echo "  successive pairs of analysis file and link number arguments:"
  echo "  lplink  analfile1  linknum1  analfile1  linknum3  analfile3 linknum3 (etc.)"
  echo "  Example: "
  echo "   lplink myvoice 3   /LPC/voice2  4   vc.p.c3  6 "
  echo " Result: File lp.3 is created and linked to analysis file myvoice3.lpc"
  echo "   File lp.4 is created and linked to analysis file LPC/voice2.lpc"
  echo "  File lp.6 is created and linked to analysis file /sflib/anal/lpc/vc.p.c3.lpc"
  echo "  ----   For more details , type :   man lplink       ----  "
  exit 1
endif

set SFDIR = "$SFDIR"
set SFLIBLPCDIR = "$SFLIB/anal/lpc"
@ i = ( 1 )   # first soundfile argument
@ x = ( 2 )   # first link file argument

while ($i <= $#argv)
      set FILEARG = "$argv[$i]"
      set LINKARG = "$argv[$x]"


   if ( -e $FILEARG ) then
         set ANALFILE = $FILEARG
           else if ( -e $FILEARG.lpc ) then
               set ANALFILE = $FILEARG.lpc
           else if ( -e $FILEARG.lp ) then
               set ANALFILE = $FILEARG.lp

      else if ( -e $SFDIR/$FILEARG ) then
         set ANALFILE = $SFDIR/$FILEARG
           else if ( -e $SFDIR/$FILEARG.lpc ) then
              set ANALFILE = $SFDIR/$FILEARG.lpc
           else if ( -e $SFDIR/$FILEARG.lp ) then
              set ANALFILE = $SFDIR/$FILEARG.lp

      else if ( -e $SFLIBLPCDIR/$FILEARG ) then
         set ANALFILE = $SFLIBLPCDIR/$FILEARG
           else if ( -e $SFLIBLPCDIR/$FILEARG.lpc ) then
              set ANALFILE = $SFLIBLPCDIR/$FILEARG.lpc

      else
         echo " Quitting. No analysis named >> $FILEARG << "
         echo "    (Your current working soundfile directory is $SFDIR )"
         exit 1
   endif

   set  LINKFILE = lp.$LINKARG

   if ( -e $LINKFILE ) then
       echo " WARNING. Link file >> $LINKFILE << already exists : "
       ls -l $LINKFILE
       echo "    --- This link file will now be overwritten : --- "
	   /bin/rm -f $LINKFILE
   endif

   ln -s $ANALFILE $LINKFILE 

   if ( -e $LINKFILE ) then 
      echo "File >> $LINKFILE << linked to lpc analysis file >> $ANALFILE << :"
      ls -l $LINKFILE
      echo "     ------------- "
   endif
 @ i = ( $i + 2 )   # next soundfile argument
 @ x = ( $x + 2 )   # next link file argument
end
      echo "     ------done------- "
