#!/bin/sh
#
prog=`basename $0`
 if [ "$1" = "-?" -o "$1" = "/?" -o "$1" = "-h" -o "$1" = "/h" -o "$1" = "--help" ]; then
  echo " " 
  echo "Script $prog is supposed to be run inside program TRC_IPLAS," 
  echo "and shall not be run as a stand-alone script."
  echo " " 
  exit
 fi
#
#
#   Script $gensys/bin/trc_iplas_b translates a Plasser & Theurer
#   or a Matisa registration with the B-end leading into track
#   irregularities written in trax-format.
#   =================================================================
#
#
#   0) Remove the first 8 header lines in the mauz file.
#   ----------------------------------------------------
 sed -n '9,$ p' iplas_work/trac_mauzin > iplas_work/trac_mauz
#
#
#   1) Interpolate the lateral versines in equidistant steps.
#   ---------------------------------------------------------
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,32X,f8.2)',
INFIL = iplas_work/trac_mauz
INTPFI= iplas_work/lat_1     END
+
#
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,40X,f8.2)',
INFIL = iplas_work/trac_mauz
INTPFI= iplas_work/lat_2    END
+
#
#   2) Interpolate the vertical levels in equidistant steps.
#   --------------------------------------------------------
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,f8.2)',
INFIL = iplas_work/trac_mauz
INTPFI= iplas_work/vert_1    END
+
#
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,8X,f8.2)',
INFIL = iplas_work/trac_mauz
INTPFI= iplas_work/vert_2    END
+
#
#   3) Interpolate the twist in equidistant steps.
#   ----------------------------------------------
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,24X,f8.2)',
INFIL = iplas_work/trac_mauz
INTPFI= iplas_work/twist_mauz END
+
#
#   4) Interpolate the gauge in equidistant steps.
#   ----------------------------------------------
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,48X,f8.2)',
INFIL = iplas_work/trac_mauz
INTPFI= iplas_work/spv    END
+
#
#
#   5) Average of left and right lateral versine.
#   ---------------------------------------------
$gensys/exe/misc/func <<+
FUNC= MED    DATA = SNGL
INFIL1= iplas_work/lat_1
INFIL2= iplas_work/lat_2
UTFIL = iplas_work/lat_mauz  END
+
#
#
#   6) Average of left and right vertical level.
#   --------------------------------------------
$gensys/exe/misc/func <<+
FUNC= MED    DATA = SNGL
INFIL1= iplas_work/vert_1
INFIL2= iplas_work/vert_2
UTFIL = iplas_work/vert_mauz END
+
#
#
#   7) Translate the lateral versine.
#   ---------------------------------
$gensys/exe/misc/ftrans <<+
HFUNC = IPLASSER  DX=$1
HIN = .25,.25,400,.04, 3, 1., 20.,-1,  0., 2, -10, 10
INFIL   iplas_work/lat_mauz
RESFIL  iplas_work/lat
END
+
#
#
#   8) Translate the vertical level.
#   --------------------------------
$gensys/exe/misc/ftrans <<+
HFUNC = IPLASSER  DX=$1
HIN = .25,.25, 400, .04, 3, 1., 10, -1, 3.5, 2, 5,0
INFIL   iplas_work/vert_mauz
RESFIL  iplas_work/vert
END
+
#
#
#   9) Translate the twist.
#   -----------------------
$gensys/exe/misc/ftrans <<+
HFUNC = IMAUZ  DX=$1
HIN = .25, .25, 400, .04, 3, 1., 10., -1, 0, 1, 3.5
INFIL   iplas_work/twist_mauz
RESFIL  iplas_work/twist
END
+
#
#
#   10) Add the curves together in file RESFIL.
#   -------------------------------------------
$gensys/exe/track/trc_concat <<+
FORMAT    trac
LATFIL    iplas_work/lat
VERTFIL   iplas_work/vert
TWISTFIL  iplas_work/twist
SPVFIL    iplas_work/spv

RESFIL  = iplas_work/resfil
END
+
