#!/bin/sh
#
 if [ "$1" = "-?" -o "$1" = "/?" -o "$1" = "-h" -o "$1" = "/h" -o "$1" = "--help" ]; then
  echo " " 
  echo "Script trc_imauz_b is supposed to be run inside program TRC_IMAUZ," 
  echo "and shall not be run as a stand-alone script."
  echo " " 
  exit
 fi
#
#
#   Script $gensys/bin/trc_imauz_b translates a Mauzin 
#   registration with the B-end leading into track
#   irregularities written in trax-format.
#   =======================================================
#
#
#   0) Remove the first 8 header lines in the mauz file.
#   ----------------------------------------------------
#obj/copy_mauz.bin
 sed -n '9,$ p' imauz_work/trac_mauzin > imauz_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 = imauz_work/trac_mauz
INTPFI= imauz_work/lat_1     END
+
#
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,40X,f8.2)',
INFIL = imauz_work/trac_mauz
INTPFI= imauz_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 = imauz_work/trac_mauz
INTPFI= imauz_work/vert_1    END
+
#
$gensys/exe/misc/ftrans <<+
SKALAX=1.   YSTART=0.   SKALAY=1.  DX=$1
FORMIN= '(1X,F8.2,8X,f8.2)',
INFIL = imauz_work/trac_mauz
INTPFI= imauz_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 = imauz_work/trac_mauz
INTPFI= imauz_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 = imauz_work/trac_mauz
INTPFI= imauz_work/spv    END
+
#
#
#   5) Average of left and right lateral versine.
#   ---------------------------------------------
$gensys/exe/misc/func <<+
FUNC= MED    DATA = SNGL
INFIL1= imauz_work/lat_1
INFIL2= imauz_work/lat_2
UTFIL = imauz_work/lat_mauz  END
+
#
#
#   6) Average of left and right vertical level.
#   --------------------------------------------
$gensys/exe/misc/func <<+
FUNC= MED    DATA = SNGL
INFIL1= imauz_work/vert_1
INFIL2= imauz_work/vert_2
UTFIL = imauz_work/vert_mauz END
+
#
#
#   7) Translate the lateral versine.
#   ---------------------------------
$gensys/exe/misc/ftrans <<+
HFUNC = IMAUZ    DX=$1
HIN   = .5, .5, 400, .04, 3., 1., 10.,-1, 0.  ,  2, 5, -5
INFIL   imauz_work/lat_mauz
RESFIL  imauz_work/lat
END
+
#
#
#   8) Translate the vertical level.
#   --------------------------------
$gensys/exe/misc/ftrans <<+
HFUNC = IMAUZ  DX=$1
HIN = .25, .25, 400, .04, 3, 1., 13.4, -1., -.675,
        8,  6.71, 4.21, 2.075, .675, -.675, -2.075, -4.21, -6.71
INFIL   imauz_work/vert_mauz
RESFIL  imauz_work/vert
END
+
#
#
#   9) Translate the twist.
#   -----------------------
$gensys/exe/misc/ftrans <<+
HFUNC = IMAUZ  DX=$1
HIN = .25, .25, 400, .1,  3, 1., 13.4,  1.375, 0.675,  1,-2.075,
INFIL   imauz_work/twist_mauz
RESFIL  imauz_work/twist
END
+
#
#
#   10) Add the curves together in file RESFIL.
#   -------------------------------------------
$gensys/exe/track/trc_concat <<+
FORMAT    trax
LATFIL    imauz_work/lat
VERTFIL   imauz_work/vert
TWISTFIL  imauz_work/twist
SPVFIL    imauz_work/spv

RESFIL  = imauz_work/resfil
END
+
