#! /usr/local/bin/topaz
#
# name:        "d"
# description: load data from file
#
# Programed by Hisao Kawaura (Sep. 3, 2000)
#          version 1.05
#
# ================= available options ========================
# xlin:         set x-axis linear
# xlog:         set x-axis log
# xinv:         set x-axis inverse
# xloglin:      set x-axis log(linear)
# xinvlin:      set x-axis inverse(linear)
# ylin:         set y-axis linear
# ylog:         set y-axis log
# yinv:         set y-axis inverse
# yloglin:      set y-axis log(linear)
# yinvlin:      set y-axis inverse(linear)
# line:         plot all data only with line
# mark:         plot all data only with marker
# var:          plot data with individual linecolor/linestyle




# get argument length
$len = @ARGV;
if ($len == 0)
{
  print "Error!!: No datafiles given\n";
  exit(1);
}

# check existence of frame object
if ($graph->length('frame') == 0)
{
  # no frame objects exist!
  print "Error!!: No frame exists\n";
  exit(1);
}

# initialize objects
print 'initializing ......   ';
execfile("initparams");
print "done\n";

$lineflag = 0; $markflag = 0; $varflag = 0;
for ($i = 0; $i < $len; $i++)
{

  $opt = $ARGV[$i];

  # axis scaling
  if ($opt eq 'xlin')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 0)]->scaling = 0;
  }
  elsif ($opt eq 'ylin')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 1)]->scaling = 0;
  }
  elsif ($opt eq 'xlog')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 0)]->scaling = 1;
  }
  elsif ($opt eq 'ylog')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 1)]->scaling = 1;
  }
  elsif ($opt eq 'xinv')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 0)]->scaling = 2;
  }
  elsif ($opt eq 'yinv')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 1)]->scaling = 2;
  }
  elsif ($opt eq 'xloglin')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 0)]->scaling = 3;
  }
  elsif ($opt eq 'yloglin')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 1)]->scaling = 3;
  }
  elsif ($opt eq 'xinvlin')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 0)]->scaling = 4;
  }
  elsif ($opt eq 'yinvlin')
  {
    $graph->frame[0]->axis[$graph->frame[0]->getindex('axis', 1)]->scaling = 4;
  }
  elsif ($opt eq 'line')
  {
    $lineflag = 1;
  }
  elsif ($opt eq 'mark')
  {
    $markflag = 1;
  }
  elsif ($opt eq 'var')
  {
    $varflag = 1;
  }
  else
  {
    $no = $graph->frame[0]->new('data') - 1;
    execfile("initdata", 0, $no);
    $graph->frame[0]->data[$no]->filename = appendabspath($ARGV[$i]);
    $graph->frame[0]->data[$no]->loaddata();
   
    if ($lineflag)
    {
      $graph->frame[0]->data[$no]->markerstyle = 0;
      $graph->frame[0]->data[$no]->linestyle = 0;
    }
    elsif ($markflag)
    {
      $graph->frame[0]->data[$no]->markerstyle = 1;
      $graph->frame[0]->data[$no]->linestyle = 7;
    }
    elsif ($varflag)
    {
      $graph->frame[0]->data[$no]->markerstyle = 0;
      $col = $no % 4; $lin = ($no / 4) % 2;
      if ($col == 0)
      {
        $graph->frame[0]->data[$no]->linecolor_red   = 0;
        $graph->frame[0]->data[$no]->linecolor_green = 0;
        $graph->frame[0]->data[$no]->linecolor_blue  = 0;
      }
      elsif ($col == 1)
      {
        $graph->frame[0]->data[$no]->linecolor_red   = 65535;
        $graph->frame[0]->data[$no]->linecolor_green = 0;
        $graph->frame[0]->data[$no]->linecolor_blue  = 0;
      }
      elsif ($col == 2)
      {
        $graph->frame[0]->data[$no]->linecolor_red   = 0;
        $graph->frame[0]->data[$no]->linecolor_green = 65535;
        $graph->frame[0]->data[$no]->linecolor_blue  = 0;
      }
      elsif ($col == 3)
      {
        $graph->frame[0]->data[$no]->linecolor_red   = 0;
        $graph->frame[0]->data[$no]->linecolor_green = 0;
        $graph->frame[0]->data[$no]->linecolor_blue  = 65535;
      }

      if ($lin == 0)
      {
        $graph->frame[0]->data[$no]->linestyle   = 0;
      }
      elsif ($lin == 1)
      {
        $graph->frame[0]->data[$no]->linestyle   = 6;
      }
    }
  }
}

# autoscale all axes with 10% margin
$graph->frame[0]->autoscale($_ALL, '10');

# open a cuimenu and a viewer
execfile("opencui");

# end of "d"










