#!/bin/sh
# Sunearcsv_test4 - for program SUNEARCSV
# Author: Andre Latour, Oct  2022
#
  echo "----------------------------------------------------------------------------"
  echo "---  This test is similar to test1 and test3 (so sx=gx and sy=gy).          "
  echo "---                                                                         "
  echo "---  But unlike test3, the profile created by suprofcsv uses                "
  echo "---  sx,sy key names instead of gx,gy key names.                            "
  echo "---  So, sunearcsv herein uses the dimx=sx dimy=sy options,                 "
  echo "---  which uses the trace sx,sy values and searches for the                 "
  echo "---  nearest sx,sy values in the qin file.                                  "
  echo "---                                                                         "
  echo "---  Since sx=gx and sy=gy                                                  "
  echo "---  this test should produce same cdp,igi,igc values as test1 (and does).  "
  echo "----------------------------------------------------------------------------"
#
 suprofcsv keyx=sx keyy=sy keyp=asis sx=0,1000,1000 sy=0,0,1500 \
           chordi=100 nmaxa=3 nmaxs=3 chordf=100 \
           qout=testout41.csv
#
 sunull nt=4 ntr=10 >tnull41.su
 sushw <tnull41.su >tnull42.su key=sx,sy,gx,gy a=600,-50,600,-50 b=60,125,60,125
#
 sunearcsv qin=testout41.csv <tnull42.su dimx=sx dimy=sy >tnear41.su keyp=cdp okeys=cdp
#
 suchw <tnear41.su >tnear42.su key1=sdel,gdel key2=sx,sy key3=gx,gy b=1,1 c=1,1 d=2,2 
 sugethw <tnear42.su key=sx,sy,gx,gy,sdel,gdel,cdp,igi,igc
#
# Use sed to remove the first lines (C_SU header lines).
# Use cut with a deliminator of comma to retain only fields 3 and 4
# Use sed to replace every comma with a blank.               
# Use a2b to convert ascii to binary                        
# Use sugethw to output x,y values in binary.                                   
# Use cat to combine the 2 sets of XYs into one file.                           
#
# Use xgraph to plot 2 sets of points with marks of Xs and triangles.
#
 sed '/C_SU/d' testout41.csv >testout42.csv
 cut -d, -f3,4 <testout42.csv >testout43.csv
 sed '1,$ s/,/ /g' testout43.csv >testout43.txt
 a2b <testout43.txt >testout43.bin
#
 sugethw <tnear42.su output=binary key=sdel,gdel >testout44.bin
 cat testout43.bin testout44.bin >testout45.bin
#
 xgraph <testout45.bin n=40,10 linecolor=2,3 mark=2,6 marksize=10,10 linewidth=0 \
         width=1000 height=700 x1beg=-800 x1end=1400 x2beg=-100 x2end=2800
