home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0926.lha / JcGraph / Rexx / Graph_Advantage.rex < prev    next >
OS/2 REXX Batch file  |  1993-10-07  |  8KB  |  246 lines

  1. /********************************************************************/
  2. /* Graph_Advantage.rex                                              */
  3. /* -------------------                                              */
  4. /* This script create a hot-link between JcGraph and Advantage      */
  5. /* so you can enter your data and use Advantage functions and ease  */
  6. /* of use and still have wonderfull JcGraph charts as output!!!     */
  7. /* You just have to execute it from Advantage after having selected */
  8. /* the range of data you want to have a chart from...               */
  9. /* (ARexx -> Execute)                                               */
  10. /* PS You can change the Y ratio in varying the following variable. */
  11. /*    (100 to 1000)                                                 */
  12. /********************************************************************/
  13. UserCtrl=250
  14. NbCotations=10
  15.  
  16. options results
  17.  
  18. address 'Advantage'
  19.  
  20. say '--------'
  21.  
  22. 'DrawMessage'
  23.   "Working. Please wait..."
  24.  
  25. 'Current'                       /* Determine current selected range. */
  26. range = result
  27.  
  28. 'GetValue'
  29. value=result
  30.  
  31. colon_posn = pos(":",range)     /* Look for colon delimiter in range. */
  32.  
  33. if colon_posn = 0 then          /* If no colon, this is not a range. */
  34.    do                           /*  Set the start and end cells to   */
  35.       start_cell = range        /*   the selected cell.              */
  36.       end_cell = range
  37.    end
  38. else                            /* Otherwise, it is a range. */
  39.    /* Extract the start/end cells from the specified range. */
  40.    do
  41.       start_cell = left(range,colon_posn - 1)
  42.       end_cell   = substr(range,colon_posn + 1)
  43.    end
  44.  
  45. start_column = GetColumn(start_cell)    /* Determine range of columns */
  46. end_column   = GetColumn(end_cell)      /*  to be filled.             */
  47.  
  48. start_row = GetRow(start_cell)          /* Determine range of rows */
  49. end_row   = GetRow(end_cell)            /*  to be filled.          */
  50.  
  51. st_etiq1=value(start_row)-1
  52. st_etiq2=d2c(c2d(start_column)-1)
  53.  
  54. if open('tempo','T:Link','W') then do
  55.   writeln('tempo','1002,')
  56.   writeln('tempo',(c2d(end_column)-c2d(start_column)+1) || ',' || (end_row-start_row+1) || ',')
  57.  
  58. 'GetValue'
  59. highest=result
  60.  
  61. 'DrawMessage'
  62.   "First pass. Please wait..."
  63.  
  64. /* First pass. Find the highest values... */
  65. /* -------------------------------------- */
  66. do rownum = start_row to end_row
  67.  
  68.    column = start_column                /* Reset column pointer.  */
  69.  
  70.    do until c2d(column) > c2d(end_column)
  71.       /* Build complete cell name from row and column. */
  72.       next_cell = column || rownum
  73.       /* Select the cell to be modified. */
  74.       'SelectCell'
  75.         value(next_cell)
  76.       'GetValue'
  77.       tempo=result
  78.  
  79.       if value(abs(tempo)) > value(abs(highest)) then do
  80.         highest=tempo
  81.       end
  82.       /* Advance to the next column. */
  83.       column = NextColumn(column)
  84.    end
  85. end rownum
  86.  
  87. rationalfactor=highest
  88. multiplieurdonnees=UserCtrl/rationalfactor
  89.  
  90.   writeln('tempo',abs(UserCtrl/NbCotations) || ',' || (1 / multiplieurdonnees) || ',' )
  91.  
  92. 'DrawMessage'
  93.   "Second pass. Please wait..."
  94.  
  95. /* Second pass. */
  96. /* ------------ */
  97. do rownum = start_row to end_row
  98.  
  99.    column = start_column                /* Reset column pointer.  */
  100.  
  101.    do until c2d(column) > c2d(end_column)
  102.       /* Build complete cell name from row and column. */
  103.       next_cell = column || rownum
  104.       /* Select the cell to be modified. */
  105.       'SelectCell'
  106.          value(next_cell)
  107.       'GetValue'
  108.       tempo=result
  109.       /* Write to the temporary file. */
  110.       writeln('tempo',trunc(tempo * multiplieurdonnees + 0.5) || ',')
  111.  
  112.       /* Advance to the next column. */
  113.       column = NextColumn(column)
  114.    end
  115. end rownum
  116.  
  117. /* Third pass. Label names */
  118. /* ----------------------- */
  119. /* Columns */
  120. /* ------- */
  121.  
  122. column = start_column                /* Reset column pointer.  */
  123.  
  124. do until c2d(column) > c2d(end_column)
  125.    /* Build complete cell name from row and column. */
  126.    next_cell = column || st_etiq1
  127.    /* Select the cell to be modified. */
  128.    'SelectCell'
  129.       value(next_cell)
  130.    'GetLabel'
  131.    tempo=result
  132.    /* Write to the temporary file. */
  133.    writeln('tempo',tempo || ',')
  134.  
  135.    /* Advance to the next column */
  136.    column = NextColumn(column)
  137. end
  138.  
  139. /* Rows */
  140. /* ---- */
  141. do rownum = start_row to end_row
  142.  
  143.       /* Build complete cell name from row and column. */
  144.       next_cell = st_etiq2 || rownum
  145.       /* Select the cell to be modified. */
  146.       'SelectCell'
  147.          value(next_cell)
  148.       'GetLabel'
  149.       tempo=result
  150.       /* Write to the temporary file. */
  151.       writeln('tempo',tempo || ',')
  152.  
  153. end rownum
  154.  
  155. close('tempo')
  156.  
  157. /* Reselect the original range of cells. */
  158. 'SelectRange'
  159.    value(start_cell)
  160.    value(end_cell)
  161.  
  162. 'DrawMessage'
  163.   "Sending to JcGraph. Please wait..."
  164.  
  165. address 'JCGRAPH'
  166.  
  167. 'Open Filename=T:Link'
  168. 'ScreenToFront'
  169. 'requestnotify Your data has been transfered to JcGraph. You can do wathever you want with it now.'
  170.  
  171. end
  172.  
  173. exit                    /* That's all folks! */
  174.  
  175. /* ----------------------------------------------------------------- */
  176. /*            Internal Functions (subroutines)                       */
  177. /* ----------------------------------------------------------------- */
  178.  
  179. /* == GetRow: Extract the row number from a cell name. == */
  180.  
  181. GetRow: procedure
  182.    arg CellName      /* Function expects to be passed a cell name. */
  183.  
  184.    /* Find the first numeric digit in the cell name. */
  185.    start_number = verify(CellName,"0123456789","Match")
  186.  
  187.    /* Extract all characters starting at the first digit and continuing */
  188.    /* to the end of the cell name.                                      */
  189.    rownum = substr(CellName,start_number)
  190.  
  191. return rownum
  192.  
  193. /* == GetColumn: Extract the column label from a cell name. == */
  194.  
  195. GetColumn: procedure
  196.    arg CellName      /* Function expects to be passed a cell name. */
  197.  
  198.    /* Find the first numeric digit in the cell name. */
  199.    start_number = verify(CellName,"0123456789","Match")
  200.  
  201.    /* Extract all characters in the cell name up to the first numeric */
  202.    /* character (start of row number).                                */
  203.    column = left(CellName,start_number-1)
  204.  
  205. return column
  206.  
  207. /* == NextColumn: Given the current column label, determine the label == */
  208. /* ==              for the next sequential column. NOTE: This is a    == */
  209. /* ==              recursive function.                                == */
  210.  
  211. NextColumn: procedure
  212.    arg ThisColumn    /* Function expects to be passed a column label. */
  213.  
  214.    /* If the column label is empty (null string), then we must be */
  215.    /* starting a new group of column labels (for example, going   */
  216.    /* from column ZZ to column AAA. Return an "A".                */
  217.    if length(ThisColumn) = 0 then
  218.       new_column = "A"
  219.  
  220.    /* Otherwise, we must advance the last character in the column */
  221.    /* name to the next sequential alphabetic character.           */
  222.    else
  223.       do
  224.          col_number = ,                 /* Convert last character */
  225.             c2d( right(ThisColumn,1) )  /*  to decimal value.     */
  226.  
  227.          col_number = col_number + 1    /* Increment to next character. */
  228.          new_char = d2c(col_number)     /* Convert back to a character. */
  229.  
  230.          /* If we've gone past 'Z', find the next column for the column */
  231.          /* label minus the last character and then append an "A" to    */
  232.          /* this label (start of a new label set).                      */
  233.          if new_char > "Z" then
  234.             do
  235.                temp_column = left( ThisColumn, length(ThisColumn)-1 )
  236.                new_column = NextColumn(temp_column) || "A"
  237.             end
  238.  
  239.          /* Otherwise, replace the last character of the column label */
  240.          /* with the next sequential character.                       */
  241.          else
  242.             new_column = overlay(new_char,ThisColumn,length(ThisColumn))
  243.       end
  244.  
  245. return new_column
  246.