#!/bin/sh

FILE=$1

if test "$FILE" = "" ; then
   exit
fi

SEGMENT=`../xrmap -grid -tropics -cities -peaks -p 1 \
-mapfile $FILE -seg "mode|1"`

NUMSEG=`echo $SEGMENT | sed -e "/index/s///"`
NUMSEG=`echo $NUMSEG`

if test "$NUMSEG" = "" ; then
   echo "No segment selected. Abort !"
   exit
fi

echo "Correcting $NUMSEG"

../xrmap -p 1 -gridlines -cities -peaks -mapfile $FILE -seg "mode|3" \
-tropics -seg "mark|$NUMSEG" -dump ascii -dump "write|single"

../xrmap -p 1 -gridlines -cities -peaks -mapfile $FILE -seg "mode|2" \
-tropics -seg "mark|$NUMSEG" -dump jpd -dump "write|rest"

emacs -nw single single

echo -n "Where (1, 2 or 3) ?? "
read W

if [ -r $FILE.$W ] ; then
   ../xrmap -mapfile $FILE.$W -arc "read|single" -dump "write|new"
   mv -f $FILE.$W $FILE.$W.bak
else
   ../xrmap -mapfile none -arc "read|single" -dump "write|new"
fi

mv -f new $FILE.$W
mv -f $FILE $FILE.bak
mv -f rest $FILE


