#!/bin/sh
# 1. creates a file in /jgofsopt/8081/remote_host_name called join-object-1
#    which contains the name of the current object
# 2. creates a file 'parameters' containing the current selections/projections
# 3. creates a file 'from_loc' containing the referring host
# 
port=""
port=${SERVER_PORT}
if test -z $port
then
  $port="8081"
fi
if test \! -d /jgofsopt/$port/$2
then
  /usr/bin/mkdir -m 777 /jgofsopt/$port/$2
fi
echo "$1" >/jgofsopt/$port/$2/join-object-1
#
# referring host is recorded in from_loc (arg 3)
# subselections are saved in parameters (arg 4)
#    if there is no 3rd arg, then there is no 4th. default each.
#
if [ -z "$3" ]
then
  echo "http://optserv1.whoi.edu/jg/otheropt$1" >/jgofsopt/$port/$2/from_loc
  echo "none" >/jgofsopt/$port/$2/parameters
#
# otherwise, is the 3rd arg a valid URL spec?  if not, 
#   probably means that 3rd is empty, 4th is present
#   inclusion of 5th arg on line below is to keep shell happy
#   NO 5TH ARG EXPECTED - TEST REQUIRES A VARIABLE
#
elif [ -z "$5"`echo "$3" | grep "/"` ]
then
  echo "http://optserv1.whoi.edu/jg/otheropt$1" >/jgofsopt/$port/$2/from_loc
  echo "$3" >/jgofsopt/$port/$2/parameters
else 
  echo "$3" >/jgofsopt/$port/$2/from_loc
  if [ -z "$4" ]
  then
    echo "none" >/jgofsopt/$port/$2/parameters
  else
    echo "$4" >/jgofsopt/$port/$2/parameters
  fi
fi
