case $# in
  0) TY="ubv" ; set $1 "ubv" ;;
  1) TY=$1 ;;
  2) TY=$1 ; FT=`nof $2` ; zeT $FT ;;
esac

FS=`nof $TY`
zeT $FS
doll2=".T/ubv.eca"

case $1 in
ubv) TIT="UBV pe" ;;
pgh) TIT="UBV pg" ;;
ccd) TIT="UBV CCD" ;;
sit) TIT="UBV SIT" ;;
ubm) TIT="UBV pe moyenne" ;;
pgm) TIT="UBV pg moyenne" ;;
cor) TIT="UBV corrige" ;;
beta) TIT="BETA" ; doll2=".T/beta.eca" ;;
vsn|vsini) TIT="Vsini" ; doll2=".T/vsini.eca" ;;
uvby) TIT="uvby" ; doll2=".T/uvby.eca" ;;
magv|magV) cmpv ; exit 0 ;;
esac

clear
echo ' '
case $# in
0|1) clear ; echo ' '
   case $LNG in
    fr) echo " Comparaison des donnees $TIT " ;;
    eng) echo "m Comparaison of the $TIT data " ;;
   esac
   ntyp=1
   echo "$1_eca div $1 <<Bout" > .T/auto_eca
   echo ' ' ; $1_eca $1 
   echo "Bout" >> .T/auto_eca ; cx .T/auto_eca ;;
2) clear ; echo ' '
   case $LNG in
    fr) echo " Comparaison des donnees $1 et $2 " ;;
    eng) echo " Comparaison of the $1 and $2 data " ;;
   esac
   typ=$2 ; ntyp=2
   echo "$1_eca div $2 <<Bout" > .T/auto_eca
   echo ' ' ; doll3=`nof $2` ; zeT $doll3 ; $1_eca $1 $2 
   echo "Bout" >> .T/auto_eca ; cx .T/auto_eca ;;
esac

echo ' '
echo -n " - suite - "
read suit

while :
do

page $BDA/menus/menu_cmp.$LNG

case $LNG in
  fr) echo -n "	Donnez votre choix:  " ;;
 eng) echo -n "	Enter your choice:  " ;;
esac
read cho

case $cho in
 1) case $# in
     1) $1_eca $1 ;;
     2) $1_eca $1 $2 ;;
    esac 
    echo -n " - suite - "
    read suit ;;

 2) $1_eca $1
    echo -n " - suite - "
    read suit ;;

 3) echo ' '
    case $LNG in
     fr) echo -n "	Avec quel autre type?  " ;;
     eng) echo -n "	With which other type?  " ;;
    esac
    read typ
    FT=`nof $typ`
    ntyp=2
    zeT $FT
    $1_eca $1 $typ 
    echo -n " - suite - "
    read suit ;;

 4) clear ; more $doll2 ; echo ' ' 
    echo -n " - suite - " ; read suit ;;

 5) echo ' ' ; echo ' '
    case $1 in
     beta) def="0.020" ; pos="26" ; index="beta" ;;
     vsn|vsini) def=80 ; pos=18 ; index="Vsini" ;;
     uvby) ;;
     ubv|pgh|ccd|sit|ubm|pgm|cor)
      case $LNG in
       fr) echo -n " Pour quel parametre (v b u b-v u-b)?  " ;;
       eng) echo -n " For which parameter (v b u b-v u-b)?  " ;;
      esac
      read dif
      case $dif in
       v) def="0.10" ; pos="57" ; index="V" ;;
       b) def="0.10" ; pos="63" ; index="B" ;;
       u) def="0.10" ; pos="69" ; index="U" ;;
       b-v) def="0.05" ; pos="45" ; index="B-V" ;;
       u-b) def="0.05" ; pos="51" ; index="U-B" ;;
      esac ;;
     esac
    echo ' '
    case $LNG in
     fr) echo -n " Donnez la limite [$def]:  " ;;
    eng) echo -n " Enter the limit [$def]:  " ;;
    esac
    read lim
    case $lim in
     "") lim=$def ;;
      *) ;;
    esac
    clear
    echo ' '
   case $LNG in
    fr) echo " Etoiles avec des ecarts plus grands que $lim sur $index ";;
   eng) echo " Stars with differences larger than $lim on $index " ;;
   esac
   case $1 in
   beta) echo "
    No     ref1    ref2   delta 
  -------------------------------
    " ;;
   ubv|pgh|ccd|sit|ubm|pgm) echo "
   No R    V     B-V   U-B    B      U       dB-V  dU-B   dV    dB    dU
   " ;;
    esac

    awkabs $pos 6 $lim < $doll2
    echo ' '
    echo -n " - suite - "
    read suit ;;

 6) case $PLOT in
       sm) Plt_eca.$1 $1 ;;
      mgo) plt_eca.$1 $1 ;;
    esac ;;

 7) TITRE=`setit` ; export TITRE
    mgo_eca.w30 5 15 .3 -.3 
    read suit ;;
 
 8) TITRE=`setit` ; export TITRE
    mgo_eca.v30 5 15 .3 -.3 
    read suit ;;

 9) case $ntyp in
     1) FZ=".T/$FS" ; FTY=$1 ;;
     2) echo ' ' 
        case $LNG in
         fr) echo -n " Quel type ($1 ou $typ: 1/2)?  " ;;
        eng) echo -n " Which datatype ($1 or $typ: 1/2)?  " ;;
        esac
        read rty 
        case $rty in
         1) FZ=".T/$FS" ; FTY=$1 ;;
         2) FZ=".T/$FT" ; FTY=$typ ;;
        esac ;;
    esac
   
    old_ref="9999"

    while :
    do

    echo ' ' 
    case $LNG in
     fr) echo -n "	Quelle reference?  " ;;
    eng) echo -n "	Which reference?  " ;;
    esac
    read ref 
    if test $ref != old_ref
    then
      sed 's/$old_ref/$ref/' .T/auto_eca > .T/tmp
      mv .T/tmp .T/auto_eca
    fi
    old_ref=$ref

    echo ' '
    case $LNG in
     fr) echo -n "	Quel parametre (v b u b-v u-b)?  " ;; 
    eng) echo -n "	Which parameter (v b u b-v u-b)?  " ;;
    esac
    read parm
    case $parm in
     v) par=1 ;;
     b) par=2 ;;
     u) par=3 ;;
     b-v) par=4 ;;
     u-b) par=5 ;;
    esac

    echo ' '
    case $LNG in
     fr) echo -n "	Correction constante ou lineaire (c/l)?  " ;;
    eng) echo -n "	Constant or linear correction (c/l)?  " ;;
    esac
    read cor ; echo ' '
    case $cor in
     c) case $LNG in
         fr) echo -n "	Quelle constante?  " ;; 
        eng) echo -n "	Which constant?  " ;;
        esac
        read cons
        if test -f .T/$FTY.cor
        then
          mv .T/$FTY.cor .T/$FTY.fs 
          FZ=".T/$FTY.fs"
        fi
        awkorcte $ref $par $cons < $FZ > .T/$FTY.cor ;;
     l) case $LNG in
         fr) echo -n "	Pente et ordonnee:  " ;; 
        eng) echo -n "	Slope and ordinate:  " ;;
        esac
        read pent ordo
        test -f .T/$FTY.cor && ( mv .T/$1.cor .T/$1.fs ; FZ=".T/$1.fs")
        awkorlin $ref $par $pent $ordo < $FZ > .T/$FTY.cor ;;
    esac

    echo ' '
    case $LNG in
     fr) echo -n "	Voulez-vous verifier les corrections (o/n) [o]?  " ;;
    eng) echo -n "	Do you want to check the corrections (y/n) [y]?  " ;;
    esac
    read ver
    case $ver in
    ""|o|y) clear ; .T/auto_eca ; echo ' '
       echo -n ' - suite - ' ; read suit ;;
    n) ;;
    esac

    echo ' '
    case $LNG in
     fr) echo -n "	Voulez-vous conserver le fichier corrige (o/n) [o]?  " ;;
    eng) echo -n "	Do you want to keep the corrected file (y/n) [y]?  " ;;
    esac
    read conse
    case $conse in
    ""|o|y) ;;
    n) rm .T/$1.cor ;;
    esac 

    echo ' '
    case $LNG in
      fr) echo -n "	Voulez-vous faire une autre correction (o/n) [n]?  " ;;
     eng) echo -n "	Do you want to do another correction (y/n) [n]?  " ;;
    esac
    read corr
    case $corr in
    o|y) ;;
    ""|n) break ;;
    esac
    done ;;

10) echo ' '
    case $LNG in
      fr) echo -n "	Quel type de donnees ($1 ou cor) ?  " ;;
     eng) echo -n "	Which datatype ($1 or cor) ?  " ;;
    esac
    read tydo
    case $tydo in
    cor) Moyen cor 5 ;;
      *) Moyen $1 5
    esac
    echo ' '
    echo -n " - suite - "
    read suit ;;

11) echo ' '  
    case $LNG in
     fr) echo -n " Donnez le nom du fichier resultant:  " ;;
    eng) echo -n " Enter the output filename:  " ;;
    esac
    read fires
    join -j1 1 -a3 $FS $FZ | \
    awk ' { printf" %04d %4d %6s %6s %6s\n",$1,$2,$3,$4,$5 } ' | \
    cut -c1-40 > $fires ;;

 f) rm .T/$FS ; rm .T/*.eca 
    test -f .T/graph.mod && rm .T/graph.mod .T/noet.lst .T/carte.xy
    test -f .T/$FT && rm .T/$FT
    rm .T/auto_eca .T/label.str
    clear ; break ;;
esac

done
