#!/bin/csh -f
#
#	$Id: ncargmv.csh,v 1.11 1993/05/10 05:04:46 haley Exp $
#

#**********************************************************#
#                                                          #
# Script file for moving installed pieces of NCAR Graphics # 
# version 3.2.x to other locations.                        #
#                                                          #
#**********************************************************#

onintr cleanup

set vers = "3.2"
set system = "Sun4Solaris"

#******************************************************#
#                                                      #
# Set pointers to the various pieces of NCAR Graphics. #
#                                                      #
#******************************************************#
set bindir_old = `ncargpath bin`
if ($status != 0 ) exit
set libdir_old = `ncargpath lib`
if ($status != 0 ) exit
set incdir_old = `ncargpath include`
if ($status != 0 ) exit
set mandir_old = `ncargpath man`
if ($status != 0 ) exit

set manlpath   = /home/eos1/harry/ncar/man/manl
set man1path   = /home/eos1/harry/ncar/man/man1
set man3path   = /home/eos1/harry/ncar/man/man3
set man5path   = /home/eos1/harry/ncar/man/man5
set man8path   = /home/eos1/harry/ncar/man/man8
set manlsect   = l
set man1sect   = 1
set man3sect   = 3
set man5sect   = 5
set man8sect   = 8
set manl       = $manlpath:t
set man1       = $man1path:t
set man3       = $man3path:t
set man5       = $man5path:t
set man8       = $man8path:t
set manldir_old = $mandir_old/$manl
set man1dir_old = $mandir_old/$man1
set man3dir_old = $mandir_old/$man3
set man5dir_old = $mandir_old/$man5
set man8dir_old = $mandir_old/$man8

set ncarg      = ncarg
set ncargv     = $ncarg.$vers
set db         = database
set doc        = doc
set ex         = examples
set font       = fontcaps
set graph      = graphcaps
set robj       = robj
set test       = tests
set tutor      = tutorial
set xapp       = xapp

set dbdir_old      = $libdir_old/$ncargv/$db
set docdir_old     = $libdir_old/$ncargv/$doc
set exdir_old      = $libdir_old/$ncargv/$ex
set fontdir_old    = $libdir_old/$ncargv/$font
set graphdir_old   = $libdir_old/$ncargv/$graph
set robjdir_old    = $libdir_old/$ncargv/$robj
set testdir_old    = $libdir_old/$ncargv/$test
set tutordir_old   = $libdir_old/$ncargv/$tutor
set xappdir_old    = $libdir_old/$ncargv/$xapp
set LocalMan       = 0

#************************************************************#
#                                                            #
# Move portions of version 3.2.x of NCAR Graphics.           #
#                                                            #
# The user can install NCAR Graphics in a temporary location #
# and then use this script file "ncargmv" to move it to its  #
# permanent location.                                        #
#                                                            #
#************************************************************#


#******************#
#                  #
# Set binary files #
#                  #
#******************#

set bin_files = (\
    cgm2ncgm cgm_edit cgmtrans cgmtrans.hplj cgmtrans.nolj ctlib ctrans \
    fcaps findg fontc ftrans gcaps graphc ictrans idt med ncargcc ncargcex \
    ncargex ncargf77 ncargfile ncargmv ncargpath ncargrun ncargtar \
    ncargversion ncargworld ncarvversion ncgm2cgm ncgmstat nriftohdf plt \
    pre2ncgm pre2ncgm.prog psblack pswhite rascat rasgetpal rasls rassplit \
    rasstat rasview tgks0a tlocal xwdtohdf)

#*******************#
#                   #
# Set library files #
#                   #
#*******************#

set lib_files = (libcgm.a libncarg.a libncargC.a libncarg_c.a \
                 libncarg_gks.a libncarg_gksC.a libncarg_loc.a \
                 libncarg_ras.a)

#********************#
#                    #
# Set man page files #
#                    #
#********************#

set man1_files = (\
	cgm2ncgm cgm_edit cgmtrans ctrans fcaps findg fontc ftrans gcaps \
	graphc ictrans idt med ncargcc ncargcex ncargex ncargf77 ncargfile \
	ncargrun ncargsrc ncargversion ncgm2cgm nriftohdf pre2ncgm psblack \
	pswhite rascat rasgetpal rasls rassplit rasview xwdtohdf)

set man3_files = (\
	agback agbnch agchax agchcu agchil agchnl agcurv agdshn aggetc aggetf \
	aggeti aggetp aggetr agpwrt agrstr agsave agsetc agsetf agseti agsetp \
	agsetr agstup agutol anotat ardbpa ardrln areas areas_params aredam \
	argeti argtai arinam arpram arscam arseti autograph autograph_params \
	bivar cfux cfuy cgm clsgks cmfx cmfy cmux cmuy colconv conop1 conop2 \
	conop3 conop4 conpack conpack_params conran conran_family \
	conran_family_params conraq conras conrec conrec_family \
	conrec_family_params conrecqck conrecquick conrecsmooth conrecspr \
	conrecsuper cpback cpchcf cpchcl cpchhl cpchil cpchll cpcica cpclam \
	cpcldm cpcldr cpcltr cpcnrc cpdrpl cpezct cpfx cpfy cpgetc cpgeti \
	cpgetr cplbam cplbdr cpmpxy cppkcl cppklb cprect cprset cpscae cpsetc \
	cpseti cpsetr cpsprs cpsps1 cpsps2 cpux cpuy cufx cufy curve curve3 \
	curved dandr dashchar dashdb dashdc dashline dashline_params dashsmth \
	dashsupr displa ezcntr ezhftn ezisos ezmap ezmap_params ezmapa ezmxy \
	ezmy ezsrfc ezstrm ezvec ezxy ezy fence3 fl2int frame frst3 frstd \
	frstpt ftitle fx fy gaccum_tran_matrix gacolr gactivate_ws gactm \
	gacwk gagetc gageti gagetr gasetc gaseti gasetr gca gcell_array \
	gclear_ws gclks gclose_gks gclose_seg gclose_ws gclrwk gclsg gclwk \
	gcopy_seg_ws gcreate_seg gcrsg gcsgwk gdawk gdeactivate_ws gdel_seg \
	gdsg gesc gescape getset getsi getusv geval_tran_matrix gevtm gfa \
	gfill_area gflas1 gflas2 gflas3 gflas4 gflash ginq_asfs \
	ginq_char_expan ginq_char_ht ginq_char_space ginq_char_up_vec \
	ginq_clip ginq_colr_rep ginq_cur_norm_tran_num ginq_fill_colr_ind \
	ginq_fill_int_style ginq_fill_style_ind ginq_line_colr_ind \
	ginq_linetype ginq_linewidth ginq_marker_colr_ind ginq_marker_size \
	ginq_marker_type ginq_max_norm_tran_num ginq_name_open_seg \
	ginq_norm_tran ginq_op_st ginq_set_seg_names ginq_text_align \
	ginq_text_colr_ind ginq_text_font_prec ginq_text_path gks gopen_gks \
	gopen_ws gopks gopwk gpl gpm gpolyline gpolymarker gqasf gqchh \
	gqchsp gqchup gqchxp gqclip gqcntn gqcr gqfaci gqfais gqfasi gqln \
	gqlwsc gqmk gqmksc gqmntn gqnt gqops gqopsg gqplci gqpmci gqsgus \
	gqtxal gqtxci gqtxfp gqtxp grid gridal gridall gridall_params gridl \
	gsasf gschh gschsp gschup gschxp gsclip gscr gsel_norm_tran gselnt \
	gset_asfs gset_char_expan gset_char_ht gset_char_space \
	gset_char_up_vec gset_clip_ind gset_colr_rep gset_fill_colr_ind \
	gset_fill_int_style gset_fill_style_ind gset_line_colr_ind \
	gset_linetype gset_linewidth gset_marker_colr_ind gset_marker_size \
	gset_marker_type gset_seg_tran gset_text_align gset_text_colr_ind \
	gset_text_font_prec gset_text_path gset_vp gset_win gsfaci gsfais \
	gsfasi gsln gslwsc gsmk gsmksc gsplci gspmci gssgt gstxal gstxci \
	gstxfp gstxp gsvp gswn gtext gtx gupd_ws guwk hafton halfax halftone \
	histgr histogram histogram_params hlsrgb hstopc hstopi hstopl hstopr \
	hsvrgb idbvip idsfft init3d isgeti isgetr isosrf isosrfhr isosurface \
	isosurface_params isseti issetr kfmx kfmy kfpx kfpy kmpx \
	kmpy kpmx kpmy kumx kumy kupx kupy labelbar labelbar_params labmod \
	lastd lbfill lbgeti lbgetr lblbar lbseti lbsetr line line3 lined \
	mapaci mapbla mapdrw mapeod mapfst mapgci mapgrd mapgrm mapgtc \
	mapgti mapgtl mapgtr mapint mapiq mapiqa mapiqm mapit mapita mapitm \
	maplbl maplmb maplot mappos maproj maprs maprst mapsav mapset mapstc \
	mapsti mapstl mapstr maptra maptri maptrn mapusr mapvec mpgetc mpgeti \
	mpgetl mpgetr mpsetc mpseti mpsetl mpsetr mxmy ncarg_cbind ncarg_gks \
	ncarg_gks_cbind ngdots ngmisc ngpict ngwsym opngks pcdlsc pcgetc \
	pcgeti pcgetr pchiqu pcloqu pcmequ pcmpxy pcpnwi pcsetc pcseti \
	pcsetr perim perim3 periml plchhq plchlq plchmq plotchar \
	plotchar_params plotif plotit point point3 points psym3 pwrit \
	pwrite_family pwritx pwrity pwrz pwrzi pwrzs pwrzt reset rgbhls \
	rgbhsv rgbyiq scrolled_title scrolled_title_params set set3 seti \
	setusv sfgetc sfgeti sfgetp sfgetr sflush sfnorm sfsetc sfseti \
	sfsetp sfsetr sfsgfa sfwrld slgeti slgetr slseti slsetr softfill \
	softfill_params spps spps_converters spps_params srface stgeti \
	stgetr stinit stitle stream streamlines streamlines_params strmln \
	strset stseti stsetr stuixy stumsl stumta stumxy supcon supmap \
	surface surface_params threed tick3 tick4 tick43 ticks vect3 \
	vectd vector vectors vectors_params velvct velvec vvectr vvgetc \
	vvgeti vvgetr vvinit vvrset vvsetc vvseti vvsetr vvudmv vvumxy \
	wtstr yiqrgb)

set man5_files = (\
	fontcap graphcap ncargintro ncarv_spool ras_formats ras_palette)

set man8_files = (ncargmv ncargtar)

#**********************************************************#
#                                                          #
#  On some systems, all man pages installed to "man/manl"  #
#                                                          #
#**********************************************************#

if ( $LocalMan == 1 ) then
  set manl_files = (${man1_files} ${man3_files} ${man5_files} ${man8_files})
endif

#****************************#
#                            #
# Here's where it all begins #
#                            #
#****************************#

begin:

cat <<"EOF"

The interactive command "ncargmv" is executed to move portions of the current
installed version of NCAR Graphics to new positions in the file hierarchy.
It is not intended for general use and should be executed only by whoever
acts as the custodian of NCAR Graphics.

Please make sure the appropriate NCAR Graphics environment variables
are set before running this script.  I.e, either NCARG_ROOT or
NCARG_BIN, NCARG_LIB, NCARG_INCLUDE, and NCARG_MAN must be set.

"EOF"

echo -n "Enter Return (continue), or q (quit) > "
set answer=$<
if ("$answer" == "q") goto cleanup

#**************************#
#                          #
# Get new "bin" directory. #
#                          #
#**************************#

if (! -d "$bindir_old") then
  echo ""
  echo "Warning:  binary directory <$bindir_old> does not exist."
  echo "Will not try to move this directory."
  unset bin_exist
else
set bin_exist

movebin:

set bindir_new = "$bindir_old"

echo ""
echo "Binary directory is <$bindir_old>."
echo -n "Enter Return (no move), directory name, or q (quit) > "
set answer = $<

if ("$answer" == "q") goto cleanup

if ("$answer" != "" && "$answer" != "$bindir_old") then
  set bindir_new = $answer

  if ( $bindir_new:t != "bin" ) then
      echo "Binary directory must end in 'bin'"
      goto movebin
  endif
  if (! -e $bindir_new) then
    mkdir -p $bindir_new
  else
    if  (! -d $bindir_new) then
      echo "<$bindir_new> exists and is not a directory."
      goto movebin
    endif
  endif

  if (! -w $bindir_new) then
    echo "<$bindir_new> is not writable."
    goto movebin
  endif
endif

endif

#**************************#
#                          #
# Get new "lib" directory. #
#                          #
#**************************#

if (! -d "$libdir_old") then
  echo ""
  echo "Warning:  library directory <$libdir_old> does not exist."
  echo "Will not try to move this directory."
  unset lib_exist
else
set lib_exist

movelib:

set libdir_new = "$libdir_old"

echo ""
echo "Library directory is <$libdir_old>."
echo -n "Enter Return (no move), directory name, or q (quit) > "
set answer = $<

if ("$answer" == "q") goto cleanup

if ("$answer" != "" && "$answer" != "$libdir_old") then
  set libdir_new = $answer

  if ( $libdir_new:t != "lib" ) then
      echo "Library directory must end in 'lib'"
      goto movelib
  endif
  if (! -e $libdir_new) then
    mkdir -p $libdir_new
  else
    if  (! -d $libdir_new) then
      echo "<$libdir_new> exists and is not a directory."
      goto movelib
    endif
  endif

  if (-d "$libdir_old/$ncargv") then
    if (! -e $libdir_new/$ncargv) then
      mkdir -p $libdir_new/$ncargv
    else
      if  (! -d $libdir_new/$ncargv) then
        echo "<$libdir_new/$ncargv> exists and is not a directory."
        goto movelib
      endif
    endif
    if (! -w $libdir_new/$ncargv) then
      echo "<$libdir_new/$ncargv> is not writable."
      goto movelib
    endif

    cd $libdir_new
    if (-f $ncarg) then
      echo "<$libdir_new/$ncarg> exists and is not a directory."
      goto movelib
    else
      if (-d $ncarg) then
        /bin/rm -f $ncarg
        if ($status != 0) then
          echo "<$libdir_new/$ncarg> exists and is not a symbolic link,"
          echo "so it cannot be re-linked."
          goto movelib
        endif
      endif
    endif

#********************#
#                    #
# Database directory #
#                    #
#********************#
    if (-d "$dbdir_old") then
      set dbdir_new = $libdir_new/$ncargv/$db

      if (! -e $dbdir_new) then
        mkdir -p $dbdir_new
      else
        if  (! -d $dbdir_new) then
          echo "<$dbdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $dbdir_new) then
        echo "<$dbdir_new> is not writable."
        goto movelib
      endif
    endif
#***************#
#               #
# doc directory #
#               #
#***********#****
    if (-d "$docdir_old") then
      set docdir_new = $libdir_new/$ncargv/$doc

      if (! -e $docdir_new) then
        mkdir -p $docdir_new
      else
        if  (! -d $docdir_new) then
          echo "<$docdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $docdir_new) then
        echo "<$docdir_new> is not writable."
        goto movelib
      endif
    endif
#*******************#
#                   #
# example directory #
#                   #
#*******************#
    if (-d "$exdir_old") then
      set exdir_new = $libdir_new/$ncargv/$ex

      if (! -e $exdir_new) then
        mkdir -p $exdir_new
      else
        if  (! -d $exdir_new) then
          echo "<$exdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $exdir_new) then
        echo "<$exdir_new> is not writable."
        goto movelib
      endif
    endif
#********************#
#                    #
# fontcaps directory #
#                    #
#********************#
    if (-d "$fontdir_old") then
      set fontdir_new = $libdir_new/$ncargv/$font

      if (! -e $fontdir_new) then
        mkdir -p $fontdir_new
      else
        if  (! -d $fontdir_new) then
          echo "<$fontdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $fontdir_new) then
        echo "<$fontdir_new> is not writable."
        goto movelib
      endif
    endif
#********************#
#                    #
# graphcap directory #
#                    #
#********************#
    if (-d "$graphdir_old") then
      set graphdir_new = $libdir_new/$ncargv/$graph

      if (! -e $graphdir_new) then
        mkdir -p $graphdir_new
      else
        if  (! -d $graphdir_new) then
          echo "<$graphdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $graphdir_new) then
        echo "<$graphdir_new> is not writable."
        goto movelib
      endif
    endif
#******************************#
#                              #
# relocatable object directory #
#                              #
#******************************#
    if (-d "$robjdir_old") then
      set robjdir_new = $libdir_new/$ncargv/$robj

      if (! -e $robjdir_new) then
        mkdir -p $robjdir_new
      else
        if  (! -d $robjdir_new) then
          echo "<$robjdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $robjdir_new) then
        echo "<$robjdir_new> is not writable."
        goto movelib
      endif
    endif
#****************#
#                #
# test directory #
#                #
#****************#
    if (-d "$testdir_old") then
      set testdir_new = $libdir_new/$ncargv/$test

      if (! -e $testdir_new) then
        mkdir -p $testdir_new
      else
        if  (! -d $testdir_new) then
          echo "<$testdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $testdir_new) then
        echo "<$testdir_new> is not writable."
        goto movelib
      endif
    endif
#********************#
#                    #
# tutorial directory #
#                    #
#********************#
    if (-d "$tutordir_old") then
      set tutordir_new = $libdir_new/$ncargv/$tutor

      if (! -e $tutordir_new) then
        mkdir -p $tutordir_new
      else
        if  (! -d $tutordir_new) then
          echo "<$tutordir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $tutordir_new) then
        echo "<$tutordir_new> is not writable."
        goto movelib
      endif
    endif
#****************#
#                #
# xapp directory #
#                #
#****************#
    if (-d "$xappdir_old") then
      set xappdir_new = $libdir_new/$ncargv/$xapp

      if (! -e $xappdir_new) then
        mkdir -p $xappdir_new
      else
        if  (! -d $xappdir_new) then
          echo "<$xappdir_new> exists and is not a directory."
          goto movelib
        endif
      endif

      if (! -w $xappdir_new) then
        echo "<$xappdir_new> is not writable."
        goto movelib
      endif
    endif
  endif
endif
endif

#******************************#
#                              #
# Get new "include" directory. #
#                              #
#******************************#
if (! -d "$incdir_old") then
  echo ""
  echo "Warning:  include directory <$incdir_old> does not exist."
  echo "Will not try to move this directory."
  unset inc_exist
else
set inc_exist

moveinc:

set incdir_new = "$incdir_old"

echo ""
echo "Include directory is <$incdir_old>."
echo -n "Enter Return (no move), directory name, or q (quit) > "
set answer = $<

if ("$answer" == "q") goto cleanup

if ("$answer" != "" && "$answer" != "$incdir_old") then
  set incdir_new = $answer

  if ( $incdir_new:t != "include" ) then
      echo "Include directory must end in 'include'"
      goto moveinc
  endif
  if (! -e $incdir_new) then
    mkdir -p $incdir_new
  else
    if  (! -d $incdir_new) then
      echo "<$incdir_new> exists and is not a directory."
      goto moveinc
    endif
  endif

  if (! -w $incdir_new) then
    echo "<$incdir_new> is not writable."
    goto moveinc
  endif

  if (-d "$incdir_old/$ncargv") then
    if (! -e $incdir_new/$ncargv) then
      mkdir -p $incdir_new/$ncargv
    else
      if  (! -d $incdir_new/$ncargv) then
        echo "<$incdir_new/$ncargv> exists and is not a directory."
        goto moveinc
      endif
    endif
    if (! -w $incdir_new/$ncargv) then
      echo "<$incdir_new/$ncargv> is not writable."
      goto moveinc
    endif

    cd $incdir_new
    if (-f $ncarg) then
      echo "<$incdir_new/$ncarg> exists and is not a directory."
      goto moveinc
    else
      if (-d $ncarg) then
        /bin/rm -f $ncarg
        if ($status != 0) then
          echo "<$incdir_new/$ncarg> exists and is not a symbolic link,"
          echo "so it cannot be re-linked."
          goto moveinc
        endif
      endif
    endif
  endif
endif
endif

#**************************#
#                          #
# Get new "man" directory. #
#                          #
#**************************#
if (! -d "$mandir_old") then
  echo ""
  echo "Warning:  man directory <$mandir_old> does not exist."
  echo "Will not try to move this directory."
  unset man_exist
else
set man_exist

moveman:

set mandir_new = "$mandir_old"

echo ""
echo "Man page directory is <$mandir_old>."
echo -n "Enter Return (no move), directory name, or q (quit) > "
set answer = $<

if ("$answer" == "q") goto cleanup

if ("$answer" != "" && "$answer" != "$mandir_old") then
  set mandir_new = $answer

  if ( $mandir_new:t != "man" ) then
      echo "Man page directory must end in 'man'"
      goto moveman
  endif
  if (! -e $mandir_new) then
    mkdir -p $mandir_new
  else
    if  (! -d $mandir_new) then
      echo "<$mandir_new> exists and is not a directory."
      goto moveman
    endif
  endif

  if (! -w $mandir_new) then
    echo "<$mandir_new> is not writable."
    goto moveman
  endif
#**********************************************#
#                                              #
# Check if man pages install to "manl" or not. #
#                                              #
#**********************************************#
  if ($LocalMan == 1) then
  if (-d "$manldir_old") then
    set manldir_new = $mandir_new/$manl

    if (! -e $manldir_new) then
      mkdir -p $manldir_new
    else
      if  (! -d $manldir_new) then
        echo "<$manldir_new> exists and is not a directory."
        goto movelib
      endif
    endif

    if (! -w $manldir_new) then
      echo "<$manldir_new> is not writable."
      goto movelib
    endif
  endif

  else 

#****************#
#                #
# man1 directory #
#                #
#****************#
  if (-d "$man1dir_old") then
    set man1dir_new = $mandir_new/$man1

    if (! -e $man1dir_new) then
      mkdir -p $man1dir_new
    else
      if  (! -d $man1dir_new) then
        echo "<$man1dir_new> exists and is not a directory."
        goto movelib
      endif
    endif

    if (! -w $man1dir_new) then
      echo "<$man1dir_new> is not writable."
      goto movelib
    endif
  endif

#****************#
#                #
# man3 directory #
#                #
#****************#
  if (-d "$man3dir_old") then
    set man3dir_new = $mandir_new/$man3

    if (! -e $man3dir_new) then
      mkdir -p $man3dir_new
    else
      if  (! -d $man3dir_new) then
        echo "<$man3dir_new> exists and is not a directory."
        goto movelib
      endif
    endif

    if (! -w $man3dir_new) then
      echo "<$man3dir_new> is not writable."
      goto movelib
    endif
  endif

#****************#
#                #
# man5 directory #
#                #
#****************#
  if (-d "$man5dir_old") then
    set man5dir_new = $mandir_new/$man5

    if (! -e $man5dir_new) then
      mkdir -p $man5dir_new
    else
      if  (! -d $man5dir_new) then
        echo "<$man5dir_new> exists and is not a directory."
        goto movelib
      endif
    endif

    if (! -w $man5dir_new) then
      echo "<$man5dir_new> is not writable."
      goto movelib
    endif
  endif

#****************#
#                #
# man8 directory #
#                #
#****************#
  if (-d "$man8dir_old") then
    set man8dir_new = $mandir_new/$man8

    if (! -e $man8dir_new) then
      mkdir -p $man8dir_new
    else
      if  (! -d $man8dir_new) then
        echo "<$man8dir_new> exists and is not a directory."
        goto movelib
      endif
    endif

    if (! -w $man8dir_new) then
      echo "<$man8dir_new> is not writable."
      goto movelib
    endif
  endif
  endif
endif
endif

#****************#
#                #
# Move all files #
#                #
#****************#

if (! $?bin_exist && ! $?lib_exist && ! $?inc_exist && ! $?man_exist) then
  echo ""
  echo "Are you sure you have the proper NCAR Graphics environment"
  echo "variables set?"
  goto cleanup
endif

echo ""
echo "You have asked to move the following parts of NCAR Graphics:"
echo ""

if ($?bin_exist) then
  if ($bindir_old != $bindir_new) echo "<$bindir_old> to <$bindir_new>"
endif

if ($?lib_exist) then
  if ($libdir_old != $libdir_new) echo "<$libdir_old> to <$libdir_new>"
endif

if ($?inc_exist) then
  if ($incdir_old != $incdir_new ) echo "<$incdir_old> to <$incdir_new>"
endif

if ($?man_exist) then
  if ($mandir_old != $mandir_new ) echo "<$mandir_old> to <$mandir_new>"
endif

echo ""
echo "Is this correct?"
echo -n "Enter Return (y), n (no), y (yes), or q (quit) >"
set answer = $<
if ("$answer" == "q") goto cleanup
if ("$answer" != "" && "$answer" != "y") goto begin

echo ""
echo "Some files may be overwritten by the move.  Do it anyway?"
echo -n "Enter Return (no), n (no), y (yes), or q (quit) >"
set answer = $<
if ("$answer" == "q") goto cleanup
if ("$answer" != "y") goto begin

if ($?bin_exist) then
  if ("$bindir_old" != "$bindir_new") then
    echo ""
    echo "Moving files from <$bindir_old> to <$bindir_new>."
#****************#
#                #
# Move binaraies #
#                #
#****************#
    cd $bindir_old
    foreach file ($bin_files)
      if (-e $file.$vers && -e $file) then
        /bin/mv $file.$vers $bindir_new
        /bin/rm -f $file
      endif
    end
#**************#
#              #
# Relink files #
#              #
#**************#
    cd $bindir_new
    foreach file ($bin_files)
      if (-e $file.$vers) then
        /bin/rm -f $file
        ln -s $file.$vers $file
      endif
    end
  endif
endif

if ($?lib_exist) then
  if ("$libdir_new" != "$libdir_old") then
    echo ""
    echo "Moving files from <$libdir_old> to <$libdir_new>."
#****************#
#                #
# Move libraries #
#                #
#****************#
    cd $libdir_old
    foreach file ($lib_files)
      if (-e $file && -e $file.$vers) then
        /bin/mv $file.$vers $libdir_new
        /bin/rm -f $file
      endif
    end
#**************#
#              #
# Relink files #
#              #
#**************#
    cd $libdir_new
    foreach file ($lib_files)
      if (-e $file.$vers) then
        /bin/rm -f $file
        ln -s $file.$vers $file
      endif
    end
#****************#
#                #
# Move databases #
#                #
#****************#
    cd $dbdir_old
    foreach file (*)
      /bin/mv $file $dbdir_new
    end
#*******************************#
#                               #
# Remove old database directory #
#                               #
#*******************************#
    cd ..
    rmdir $dbdir_old 
#****************#
#                #
# Move documents #
#                #
#****************#
    cd $docdir_old
    foreach file (*)
      /bin/mv $file $docdir_new
    end
#**************************#
#                          #
# Remove old doc directory #
#                          #
#**************************#
    cd ..
    rmdir $docdir_old 
#***************#
#               #
# Move examples #
#               #
#***************#
    cd $exdir_old
    foreach file (*)
      /bin/mv $file $exdir_new
    end
#*******************************#
#                               #
# Remove old examples directory #
#                               #
#*******************************#
    cd ..
    rmdir $exdir_old
#***************#
#               #
# Move fontcaps #
#               #
#***************#
    cd $fontdir_old
    foreach file (*)
      /bin/mv $file $fontdir_new
    end
#*******************************#
#                               #
# Remove old fontcaps directory #
#                               #
#*******************************#
    cd ..
    rmdir $fontdir_old
#****************#
#                #
# Move graphcaps #
#                #
#****************#
    cd $graphdir_old
    foreach file (*)
      /bin/mv $file $graphdir_new
    end
#********************************#
#                                #
# Remove old graphcaps directory #
#                                #
#********************************#
    cd ..
    rmdir $graphdir_old
#*******************************#
#                               #
# Move relocatable object files #
#                               #
#*******************************#
    cd $robjdir_old
    foreach file (*)
      /bin/mv $file $robjdir_new
    end
#***************************#
#                           #
# Remove old robj directory #
#                           #
#***************************#
    cd ..
    rmdir $robjdir_old
#************#
#            #
# Move tests #
#            #
#************#
    cd $testdir_old
    foreach file (*)
      /bin/mv $file $testdir_new
    end
#****************************#
#                            #
# Remove old tests directory #
#                            #
#****************************#
    cd ..
    rmdir $testdir_old
#************************#
#                        #
# Move tutorial examples #
#                        #
#************************#
    cd $tutordir_old
    foreach file (*)
      /bin/mv $file $tutordir_new
    end
#*******************************#
#                               #
# Remove old tutorial directory #
#                               #
#*******************************#
    cd ..
    rmdir $tutordir_old
#*****************#
#                 #
# Move xapp files #
#                 #
#*****************#
    cd $xappdir_old
    foreach file (*)
      /bin/mv $file $xappdir_new
    end
#***************************#
#                           #
# Remove old xapp directory #
#                           #
#***************************#
    cd ..
    rmdir $xappdir_old
    cd ..
#****************************#
#                            #
# Remove old ncarg directory #
#                            #
#****************************#
    rmdir $libdir_old/$ncargv
    /bin/rm -f $libdir_old/$ncarg
#*****************#
#                 #
# Create new link #
#                 #
#*****************#
    if ( -d $libdir_new/$ncargv ) then
      cd $libdir_new
      ln -s $ncargv $ncarg
  endif
endif

if ($?inc_exist) then
  if ("$incdir_old" != "$incdir_new") then
    echo ""
    echo "Moving files from <$incdir_old> to <$incdir_new>."
    cd $incdir_old/$ncargv
    foreach file (*)
      /bin/mv $file $incdir_new/$ncargv
    end
#************************************#
#                                    #
# Remove old ncarg include directory #
#                                    #
#************************************#
    cd ..
    rmdir $incdir_old/$ncargv
    /bin/rm $incdir_old/$ncarg
#*****************#
#                 #
# Create new link #
#                 #
#*****************#
    if ( -d $incdir_new/$ncargv ) then
      cd $incdir_new
      ln -s $ncargv $ncarg
    endif
  endif
endif

if ($?man_exist) then
  if ($mandir_old != $mandir_new ) then
    echo ""
    echo "Moving files from <$mandir_old> to <$mandir_new>."

    if ( $LocalMan == 0 ) then
#*********************#
#                     #
# Move man1 man pages #
#                     #
#*********************#
      if (-d $man1dir_old ) then
        cd $man1dir_old
        foreach file ($man1_files)
          set file2 = $file.$man1sect
          if (-e $file2) /bin/mv $file2 $man1dir_new
        end
      endif
#*********************#
#                     #
# Move man3 man pages #
#                     #
#*********************#
      if (-d $man3dir_old ) then
        cd $man3dir_old
        foreach file ($man3_files)
          set file2 = $file.$man3sect
          if (-e $file2) /bin/mv $file2 $man3dir_new
        end
      endif
#*********************#
#                     #
# Move man5 man pages #
#                     #
#*********************#
      if (-d $man5dir_old ) then
        cd $man5dir_old
        foreach file ($man5_files)
          set file2 = $file.$man5sect
          if (-e $file2) /bin/mv $file2 $man5dir_new
        end
      endif
#*********************#
#                     #
# Move man8 man pages #
#                     #
#*********************#
      if (-d $man8dir_old ) then
        cd $man8dir_old
        foreach file ($man8_files)
          set file2 = $file.$man8sect
          if (-e $file2) /bin/mv $file2 $man8dir_new
        end
      endif
    else
#*********************#
#                     #
# Move manl man pages #
#                     #
#*********************#
      if (-d $manldir_old ) then
        cd $manldir_old
        foreach file ($manl_files)
          set file2 = $file.$manlsect
          if (-e $file2) /bin/mv $file2 $manldir_new
        end
      endif
    endif
  endif
endif

#*******************#
#                   #
# Done moving files #
#                   #
#*******************#

if ($?bin_exist) then
  if ("$bindir_new" != "$bindir_old") then
    echo ""
    echo "To use the NCAR Graphics executables from the position to"
    echo "which they have just been moved, your search path must now"
    echo "include the following directory:"
    echo ""
    echo "    $bindir_new"
    echo ""
  endif

  if ($?lib_exist) then
    if ("$libdir_new:h" != "$bindir_new:h" || "$libdir_new:h" != "$incdir_new:h" ) then
      echo ""
      echo "Since the NCAR Graphics libraries, binaries, and include"
      echo "files do not reside under the same root path, every user"
      echo "of NCAR Graphics must do the following:"
      echo ""
      echo "    setenv NCARG_LIB $libdir_new"
      echo "    setenv NCARG_BIN $bindir_new"
      echo "    setenv NCARG_INCLUDE $incdir_new"
      echo ""
    else
      echo ""
      echo "Every user of NCAR Graphics must do the following:"
      echo ""
      echo "    setenv NCARG_ROOT $libdir_new:h"
      echo ""
    endif
  endif
endif

#***********#
#           #
# Clean up. #
#           #
#***********#
cleanup:

echo ""
echo "Terminating 'ncargmv'."
exit 0
