Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   graphing in bash (http://www.programmingforums.org/showthread.php?t=12996)

cwl157 Apr 14th, 2007 10:41 AM

graphing in bash
 
I have to make a graph using bash and i have a weird thing going on. If i set the x and y indexes to 0 it will graph the first point, however, if i try to increment them or change them to a different number it doesn't graph anything. The way i have it set up is a while loop that goes through the rows or y values and then a while loop inside of that goes through the x values. It is a 40 by 80 grid so those numbers are set. Here is the function that graphs. If anyone sees any errors as to why it would graph the first point ok, but then not any others, I would appreciate it. I know i am not incrementing the indexes anywhere because if i try that it doesn't graph anything. So i thought it was not graphing all the points because i wasnt incrementing the indexes right, but even if i set the indexes to 1 instead of 0 it won't graph the second point. Anyone see what i'm doing wrong?
:

function graph
{
    rows=40
    cols=1
    yIndexA=0    #go through y array
    xIndexA=0    #go through x array
    #gMinX=$(echo "scale=5 ; $minX - $1" | bc)
  # gMaxY=$(echo "scale=5 ; $maxY + $2" | bc)

############################################################################
    #loop through y values
    while [ "$rows" -gt 0 ]
    do
      #gMaxY=$(echo "scale=5 ; ($gMaxY - $2)" | bc)
    # blankSpacesDown=$(echo "scale=5 ; (${yValues[yIndex]} - $gMaxY - 1)" | bc)
      #printSpacesDown $blankSpacesDown
      #echo -n ${yValues[yIndex]}
      #echo -n $gMaxY

      #(( yIndex++ ))
      echo

      # reset things for innner loop
      cols=1
      xIndexA=0

    ##########################################################################
    #loop through x values
    while [ "$cols" -lt 81 ]
    do
      #gMinX=$(echo "scale=5 ; ($gMinX + $1)" | bc)
      #blankSpaces=$(echo "scale=5 ; (${xValues[xIndex]} - $gMinX - $1)" | bc)
      #printBlankSpaces $blankSpaces
      #printBlankSpaces 4
        #echo -n ${convertedYValues[yIndex]} " "
        #echo -n ${convertedXValues[xIndex]} " "
        #varX=${convertedXValues[xIndex]}
        #varY=${convertedYValues[yIndex]}
        #echo -n $rows " "
        #echo -n $cols " "

      if [ "$cols" == "${convertedXValues[xIndexA]}" ]
      then
        if [ "$rows" == "${convertedYValues[yIndexA]}" ]
        then
          echo -n "X"
        fi
        else
          echo -n " "
      fi
      #echo -n ${xValues[xIndex]} " "
      #echo -n $gMinX

        #(( xIndex++ ))
      #(( yIndex++ ))
      (( cols++ ))
    done  # loop through x
    #(( yIndex++ ))
    (( rows-- ))
  done # loop through y
  echo

}  # end graph function


cwl157 Apr 14th, 2007 11:34 AM

i got it, the comparisons were wrong change them to -le for less than or equal to and make it 80 and then change it to -ge for greater than or equal to and make it 0. This will graph any point i put in. So if i make the indexes 1 then it will print the point at x array is 1 and y array is 1. Now i just have to figure out where to increment the indexes.

cwl157 Apr 14th, 2007 6:16 PM

got it you just have to increment the xIndex and yIndex inside of the if statement when a value is found


All times are GMT -5. The time now is 3:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC