#!/bin/csh NeXtMidas NMD script must be sourced
#
# NeXtMidas source tree directory changer
# @author Jeff Schoen
# @version $Id: nmdir,v 1.7 2012/05/24 20:02:03 ntn Exp $
################################################################################

if ($#args > 0) then
  setenv NM_DIR $args[1]
endif
if ($#args > 1) then
  setenv NM_OPT $args[2]
endif
if ($#args > 0) then
  if (("$NM_DIR" =~ AUX*) || ("$NM_DIR" =~ aux*)) then
    # Change to AUX directory
    set aux_name = `echo "$NM_DIR" | sed /=/s//./`
    set nmd_path = `$NM_OS/nmsf $aux_name`
    if ("$nmd_path" == "NotFound") then
      echo "NMD: $aux_name not defined."
    else
      set nmd_path = `echo "$nmd_path" | sed /+/s//$USER/`
      cd $nmd_path
    endif
    unset aux_name
    unset nmd_path
  else if ("$NM_DIR" == "home") then
    # Change to home directory
    cd `$NM_OS/nmsf aux.home`
  else if ( -e $NMROOT/nxm/$NM_OPT ) then
    # Change to opt/area (try the easy way first)
    cd $NMROOT/nxm/$NM_OPT/$NM_DIR
  else
    # Change to opt/area (do it the hard way)
    set nmd_path = `$NM_OS/nmsf OPT.$NM_OPT`
    if ("$nmd_path" == "NotFound") set nmd_path = $NMROOT
    cd $nmd_path/nxm/$NM_OPT/$NM_DIR
    unset nmd_path
  endif
endif
unset args
# print "current" working directory to display
pwd
