home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff386.lzh / XLispStat / src1.lzh / IView / iviewdata.c < prev    next >
C/C++ Source or Header  |  1990-10-04  |  44KB  |  1,665 lines

  1. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  2. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  3. /* You may give out copies of this software; for conditions see the    */
  4. /* file COPYING included with this distribution.                       */
  5.  
  6. #include <string.h>
  7. #include "xlisp.h"
  8. #include "osdef.h"
  9. #ifdef ANSI
  10. #include "iviewproto.h"
  11. #include "Stproto.h"
  12. #else
  13. #include "iviewfun.h"
  14. #include "Stfun.h"
  15. #endif ANSI
  16.  
  17. typedef long Fixed;
  18.  
  19. /* forward declarations */
  20. #ifdef ANSI
  21. Fixed FixInnerProduct(int,Fixed *,Fixed *,int *);
  22. IViewBasicPoints IViewNewBasicPoints(int,double *,double *);
  23. double TransformedValue(IViewBasicPoints,unsigned,unsigned),
  24.        IViewBasicPointValue(IViewBasicPoints,unsigned,unsigned);
  25. void IViewFreeBasicPoints(IViewBasicPoints),
  26.      IViewAddBasicPoints(IViewBasicPoints,int),
  27.      IViewClearBasicPoints(IViewBasicPoints),
  28.      IViewBasicPointsSetRecalculate(IViewBasicPoints,int),
  29.      SetScreenValue(IViewBasicPoints,unsigned,unsigned),
  30.      RecalculateScreenPoints(IViewBasicPoints),
  31.      IViewBasicPointsSetTransformation(IViewBasicPoints,double **),
  32.      IViewBasicPointsApplyTransformation(IViewBasicPoints,double **,int *),
  33.      IViewBasicPointSetValue(IViewBasicPoints,unsigned,unsigned,double),
  34.      IViewBasicPointsGetScreenValues(IViewBasicPoints,unsigned,int *);
  35. int IViewBasicPointsNumPoints(IViewBasicPoints),
  36.     IViewBasicPointsNumVariables(IViewBasicPoints),
  37.     IViewBasicPointScreenValue(IViewBasicPoints,unsigned,unsigned),
  38.     CalculateLocationScale(IViewDATA),
  39.     PerspScreenValue(IViewBasicPoints,unsigned,unsigned);
  40. #else
  41. Fixed FixInnerProduct();
  42. IViewBasicPoints IViewNewBasicPoints();
  43. double TransformedValue(),
  44.        IViewBasicPointValue();
  45. void IViewFreeBasicPoints(),
  46.      IViewAddBasicPoints(),
  47.      IViewClearBasicPoints(),
  48.      IViewBasicPointsSetRecalculate(),
  49.      SetScreenValue(),
  50.      RecalculateScreenPoints(),
  51.      IViewBasicPointsSetTransformation(),
  52.      IViewBasicPointsApplyTransformation(),
  53.      IViewBasicPointSetValue),
  54.      IViewBasicPointsGetScreenValues();
  55. int IViewBasicPointsNumPoints(),
  56.     IViewBasicPointsNumVariables(),
  57.     IViewBasicPointScreenValue(),
  58.     CalculateLocationScale(),
  59.     PerspScreenValue();
  60. #endif
  61.  
  62. #define IViewReallocData StReallocData
  63.  
  64. /**************************************************************************/
  65. /**************************************************************************/
  66. /**                                                                      **/
  67. /**                      Fixed Point Arithmetic Package                  **/
  68. /**                                                                      **/
  69. /**************************************************************************/
  70. /**************************************************************************/
  71.  
  72. #define SCALE 65536
  73.  
  74. #ifdef MACINTOSH
  75.  
  76. #include "xmath.h"
  77.  
  78. typedef long Fixed;
  79. typedef struct { short h; unsigned short v; } fixed_struct;
  80. static FixRound(x) fixed_struct x; { return(x.h); }
  81.  
  82. #ifdef MPWC
  83. #ifdef _MC68881_
  84. #undef _MC68881_
  85. #endif _MC68881_
  86. #endif MPWC
  87.  
  88. #ifdef DODO_MC68881_
  89. static Fixed FixInnerProduct(vars, x, y, inbasis)
  90.     int vars, *inbasis;
  91.     Fixed *x, *y;
  92. {
  93.   double result = 0.0;
  94.   
  95.   for (; vars-- > 0; x++, y++) 
  96.     if (*inbasis++) result += ((double) *x) * ((double) *y);
  97.     
  98.   return((Fixed) (result / SCALE));
  99. }
  100. #else /* _MC68881_ */
  101. #define INTPART(x)  (((fixed_struct *) (x))->h)
  102. #define FRACPART(x) (((fixed_struct *) (x))->v)
  103.  
  104. static Fixed FixInnerProduct(vars, x, y, inbasis)
  105.     int vars, *inbasis;
  106.     Fixed *x, *y;
  107. {
  108.   register Fixed result = 0, hx, lx, hy, ly;
  109.   
  110.   for (; vars-- > 0; x++, y++) 
  111.     if (*inbasis++) {
  112.       hx = INTPART(x); lx = FRACPART(x);
  113.       hy = INTPART(y); ly = FRACPART(y);
  114.       if (hx == 0) result += *x * hy + ((*x * (ly >> 2)) >> 14);
  115.       else result += *x * hy + hx * ly + ((lx * (ly >> 2)) >> 14);
  116.     }
  117.     
  118.   return(result);
  119. }
  120. #endif /* _MC68881_ */
  121.  
  122. #else
  123. typedef long Fixed;
  124.  
  125. #define FixRound(x) ((int) ((x) / SCALE))
  126.  
  127. static Fixed FixInnerProduct(vars, x, y, inbasis)
  128.     int vars, *inbasis;
  129.     Fixed *x, *y;
  130. {
  131.   double result = 0.0;
  132.   
  133.   for (; vars-- > 0; x++, y++) 
  134.     if (*inbasis++) result += ((double) *x) * ((double) *y);
  135.     
  136.   return((Fixed) (result / SCALE));
  137. }
  138. #endif MACINTOSH
  139.  
  140. #define Int2Fixed(x) ((Fixed)((x) * SCALE))
  141. #define Double2Fixed(x) ((Fixed) ((x) * SCALE))
  142. #define Fixed2Double(x) (((double) (x)) / SCALE)
  143.  
  144. /**************************************************************************/
  145. /**************************************************************************/
  146. /**                                                                      **/
  147. /**                         IViewBasicPoints Package                     **/
  148. /**                                                                      **/
  149. /**************************************************************************/
  150. /**************************************************************************/
  151. /*   in iviewdef.h JKL 
  152. typedef struct basic_points {
  153.   int num_points, num_variables;
  154.   double *scale, *location, **transformation;
  155.   IViewReallocData *data, *screen_data;
  156.   int recalculateScreenPoints, fixed;
  157. } *IViewBasicPoints;
  158. */
  159. /**************************************************************************/
  160. /**                                                                      **/
  161. /**            Basic Points Creation and Destruction Functions           **/
  162. /**                                                                      **/
  163. /**************************************************************************/
  164.  
  165. static IViewBasicPoints IViewNewBasicPoints(m, scale, location)
  166.     int m;
  167.     double *scale, *location;
  168. {
  169.   IViewBasicPoints p;
  170.   
  171.   p = (IViewBasicPoints) StCalloc(sizeof(struct basic_points), 1);
  172.  
  173.   p->num_points = 0;
  174.   p->num_variables = m;
  175.   p->scale = scale;
  176.   p->location = location;
  177.   p->recalculateScreenPoints = FALSE;
  178.   p->transformation = (double **) nil;
  179.  
  180.   if (m > 0) {
  181.     p->data = (IViewReallocData *) StCalloc(sizeof(IViewReallocData), m);
  182.     p->screen_data = (IViewReallocData *) StCalloc(sizeof(IViewReallocData), m);    
  183.   }
  184.  
  185.   return(p);
  186. }
  187.  
  188. static void IViewFreeBasicPoints(p)
  189.     IViewBasicPoints p;
  190. {
  191.   int i;
  192.   
  193.   for (i = 0; i < p->num_variables; i++) {
  194.     if (p->data != nil) StRFree(p->data[i]);
  195.     if (p->screen_data != nil) StRFree(p->screen_data[i]);
  196.   }
  197.   
  198.   StFree(p->data);
  199.   StFree(p->screen_data);
  200.   StFree(p);
  201. }
  202.  
  203. static void IViewAddBasicPoints(p, n)
  204.     IViewBasicPoints p;
  205.     int n;
  206. {
  207.   int size, i;
  208.  
  209.   size = p->num_points + n;
  210.   if (p->num_variables > 0) {
  211.     if (p->data == nil || p->screen_data == nil) return;
  212.  
  213.     for (i = 0; i < p->num_variables; i++) {
  214.       p->data[i] = StRRealloc(p->data[i], sizeof(double), size);
  215.       p->screen_data[i] = StRRealloc(p->screen_data[i], sizeof(Fixed), size);
  216.     }
  217.   }
  218.   p->num_points += n;
  219. }
  220.  
  221. static void IViewClearBasicPoints(p)
  222.     IViewBasicPoints p;
  223. {
  224.   int i;
  225.   p->num_points = 0;
  226.   if (p->data == nil || p->screen_data == nil) return;
  227.  
  228.   for (i = 0; i < p->num_variables; i++) {
  229.     StRFree(p->data[i]);
  230.     p->data[i] = nil;
  231.     StRFree(p->screen_data[i]);
  232.     p->screen_data[i] = nil;
  233.   }
  234. }
  235.  
  236. /**************************************************************************/
  237. /**                                                                      **/
  238. /**       Basic Points Data Set Access and Modificaiton Functions        **/
  239. /**                                                                      **/
  240. /**************************************************************************/
  241.  
  242. static int IViewBasicPointsNumPoints(p)
  243.     IViewBasicPoints p;
  244. {
  245.   return(p->num_points);
  246. }
  247.  
  248. static int IViewBasicPointsNumVariables(p)
  249.     IViewBasicPoints p;
  250. {
  251.   return(p->num_variables);
  252. }
  253.  
  254. static void IViewBasicPointsSetRecalculate(p, fixed)
  255.     IViewBasicPoints p;
  256.     int fixed;
  257. {
  258.   p->recalculateScreenPoints = TRUE;
  259.   p->fixed = fixed;
  260. }
  261.  
  262. static double TransformedValue(p, var, point)
  263.     IViewBasicPoints p;
  264.     unsigned var, point;
  265. {
  266.   double x, a;
  267.   int i;
  268.   
  269.   if (p->transformation == nil) 
  270.     return(IViewBasicPointValue(p, var, point));
  271.   else {
  272.     for (i = 0, x = 0.0; i < p->num_variables; i++)
  273.       if ((a = p->transformation[var][i]) != 0.0)
  274.         x += IViewBasicPointValue(p, i, point) * a;
  275.     return(x);
  276.   }
  277. }
  278.  
  279. static void SetScreenValue(p, var, point)
  280.     IViewBasicPoints p;
  281.     unsigned var, point;
  282. {
  283.   double x = TransformedValue(p, var, point);
  284.   Fixed screen_x, *screen_data;
  285.   
  286.   if (p->screen_data == nil) return;
  287.   screen_data = (Fixed *) StRPtr(p->screen_data[var]);
  288.   if (screen_data == nil) return;
  289.  
  290.   if (p->location == nil || p->scale == nil) x = 0.0;
  291.   else x = x * p->scale[var] + p->location[var];
  292.   
  293.   screen_x = Double2Fixed(x);
  294.   screen_data[point] = screen_x;
  295. }
  296.  
  297. static void RecalculateScreenPoints(p)
  298.     IViewBasicPoints p;
  299. {
  300.   int var, point;
  301.  
  302.   for (var = 0; var < p->num_variables; var++)
  303.     for (point = 0; point < p->num_points; point++)
  304.       SetScreenValue(p, var, point);
  305.   p->recalculateScreenPoints = FALSE;
  306. }
  307.  
  308. static void IViewBasicPointsSetTransformation(p, a)
  309.     IViewBasicPoints p;
  310.     double **a;
  311. {
  312.   p->transformation = a;
  313.   p->recalculateScreenPoints = TRUE;
  314. }  
  315.  
  316. static void IViewBasicPointsApplyTransformation(p, a, inbasis)
  317.     IViewBasicPoints p;
  318.     double **a;
  319.     int *inbasis;
  320. {
  321.   static maxvars = 0;
  322.   static Fixed **b, *x, **screen_data, *screen_location;
  323.   int vars, n, i, j;
  324.   double *scale = p->scale, *location = p->location;
  325.   if (p->screen_data == nil) return;
  326.  
  327.   vars = p->num_variables;
  328.   n = p->num_points;
  329.  
  330.   /* allocate local working storage */
  331.   if (maxvars < vars) {
  332.     maxvars = vars;
  333.     if (b != nil) StFree(b[0]);
  334.     StFree(b);
  335.     StFree(x);
  336.     StFree(screen_data);
  337.     StFree(screen_location);
  338.     b = (Fixed **) StCalloc(sizeof(Fixed *), maxvars);
  339.     b[0] = (Fixed *) StCalloc(sizeof(Fixed), maxvars * maxvars);
  340.     for (i = 1; i < maxvars; i++) b[i] = b[0] + i * maxvars;
  341.     x = (Fixed *) StCalloc(sizeof(Fixed), maxvars);
  342.     screen_data = (Fixed **) StCalloc(sizeof(Fixed *), maxvars);
  343.     screen_location = (Fixed *) StCalloc(sizeof(Fixed), maxvars);
  344.   }
  345.   
  346.   /* convert transformation to fixed point format*/ 
  347.   if (p->fixed) {
  348.     for (i = 0; i < vars; i++)
  349.       if (inbasis[i])
  350.         for (j = 0; j < vars; j++)
  351.           if (inbasis[j]) b[i][j] = Double2Fixed(a[i][j]);
  352.   }
  353.   else {
  354.     for (i = 0; i < vars; i++)
  355.       if (inbasis[i]) {
  356.         for (j = 0; j < vars; j++)
  357.           if (inbasis[j]) 
  358.             b[i][j] = Double2Fixed(scale[i] * a[i][j] / scale[j]);
  359.         screen_location[i] = Double2Fixed(location[i]);
  360.       }
  361.   }
  362.   
  363.   /* set up array with screen coordinates */
  364.   for (i = 0; i < vars; i++)
  365.     screen_data[i] = (Fixed *) StRPtr(p->screen_data[i]);
  366.   if (! p->fixed)
  367.     for (i = 0; i < vars; i++) 
  368.       if (inbasis[i]) 
  369.         for (j = 0; j < n; j++) screen_data[i][j] -= screen_location[i];
  370.     
  371.   /* apply the transformation */
  372.   for (i = 0; i < n; i++) {
  373.     for (j = 0; j < vars; j++) 
  374.       if (inbasis[j]) x[j] = screen_data[j][i];    
  375.     for (j = 0; j < vars; j++) 
  376.       if (inbasis[j]) {
  377.         screen_data[j][i] = FixInnerProduct(vars, b[j], x, inbasis);
  378.       }
  379.   }
  380.  
  381.   /* adjust origins if scaling is not fixed */
  382.   if (! p->fixed)
  383.     for (i = 0; i < vars; i++) 
  384.       if (inbasis[i]) 
  385.         for (j = 0; j < n; j++) screen_data[i][j] += screen_location[i];
  386. }
  387.  
  388. /**************************************************************************/
  389. /**                                                                      **/
  390. /**         Basic Points Point Access and Modification Functions         **/
  391. /**                                                                      **/
  392. /**************************************************************************/
  393.  
  394. static void IViewBasicPointSetValue(p, var, point, value)
  395.     IViewBasicPoints p;
  396.     unsigned var, point;
  397.     double value;
  398. {
  399.   double *x;
  400.   
  401.   if (var < p->num_variables && point < p->num_points && p->data != nil) {
  402.     x = (double *) StRPtr(p->data[var]);
  403.     if (x != nil) x[point] = value;
  404.   }
  405.   if (p->transformation != nil) p->recalculateScreenPoints = TRUE;
  406.   if (! p->recalculateScreenPoints) SetScreenValue(p, var, point);
  407. }
  408.  
  409. static double IViewBasicPointValue(p, var, point)
  410.     IViewBasicPoints p;
  411.     unsigned var, point;
  412. {
  413.   double *x, value;
  414.   
  415.   if (var < p->num_variables  && point < p->num_points && p->data != nil) {
  416.     x = (double *) StRPtr(p->data[var]);
  417.     value = (x != nil) ? x[point] : 0.0;
  418.     return(value);
  419.   }
  420.   else StPerror("index out of range");
  421. }
  422.  
  423. static int IViewBasicPointScreenValue(p, var, point)
  424.     IViewBasicPoints p;
  425.     unsigned var, point;
  426. {
  427.   Fixed *screen_data;
  428.  
  429.   if (p->recalculateScreenPoints) RecalculateScreenPoints(p);
  430.   
  431.   if (var < p->num_variables && point < p->num_points 
  432.       && p->screen_data != nil) {  /* cast added JKL */
  433.     screen_data = (Fixed *) StRPtr((StReallocData)p->screen_data[var]);
  434. #ifdef PERSPECTIVE
  435.     return(PerspScreenValue(p, var, point));
  436. #else
  437.     return(FixRound(screen_data[point]));
  438. #endif PERSPECTIVE
  439.   }
  440.   else StPerror("index out of range");
  441. }
  442.  
  443. static void IViewBasicPointsGetScreenValues(p, point, x)
  444.     IViewBasicPoints p;
  445.     unsigned point;
  446.     int *x;
  447. {
  448.   int i, n, vars;
  449.   Fixed *screen_data;
  450.   
  451.   n = p->num_points;
  452.   vars = p->num_variables;
  453.  
  454.   if (p->recalculateScreenPoints) RecalculateScreenPoints(p);
  455.   if (p->screen_data == nil || point >= n) return;
  456.   
  457.   for (i = 0; i < vars; i++){
  458.     screen_data = (Fixed *) StRPtr(p->screen_data[i]);
  459.     if (screen_data != nil) x[i] = FixRound(screen_data[point]);
  460.   }
  461. }
  462.  
  463. /**************************************************************************/
  464. /**************************************************************************/
  465. /**                                                                      **/
  466. /**                            IViewData Package                         **/
  467. /**                                                                      **/
  468. /**************************************************************************/
  469. /**************************************************************************/
  470. /*   in iviewdef.h JKL 
  471. typedef char color_index;
  472.  
  473. typedef struct point_symbol {
  474.   int normal, highlighted;
  475. } PointSymbol;
  476.  
  477. typedef struct point_info {
  478.   PointState state, screen_state;
  479.   char marked, masked;
  480.   color_index color;
  481.   PointSymbol symbol;
  482.   char *label;
  483. } PointInfo;
  484.  
  485. typedef struct line_info {
  486.   int next, type;
  487.   char masked, width;
  488.   color_index color;
  489. } LineInfo;
  490.  
  491. #ifdef USESTRINGS
  492. typedef struct string_info {
  493.   char *string;
  494.   char masked, up, h, v;
  495.   color_index color;
  496. } StringInfo;
  497. #endif USESTRINGS
  498.  
  499. typedef struct iview_data {
  500. #ifdef USESTRINGS
  501.   IViewBasicPoints points, lines, strings;
  502.   IViewReallocData pointInfo, lineInfo, stringInfo;
  503. #else
  504.   IViewBasicPoints points, lines;
  505.   IViewReallocData pointInfo, lineInfo;
  506. #endif USESTRINGS
  507.   double *mins, *maxes, *scale, *location;
  508.   int *screen_mins, *screen_maxes;
  509.   char **variableLabels;
  510.   int recalculateScreenPoints, transformed;
  511.   double **transformation;
  512. } *IViewData;
  513. */
  514. /**************************************************************************/
  515. /**                                                                      **/
  516. /**          IView Data Construction and Destruction Functions           **/
  517. /**                                                                      **/
  518. /**************************************************************************/
  519.  
  520. /*char * */ IViewDATA IViewDataNew(vars) /* changed JKL */
  521.     int vars;
  522. {
  523.   IViewDATA p;
  524.   
  525.   p = (IViewDATA) StCalloc(sizeof(struct iview_data), 1);
  526.   if (vars > 0) {
  527.     p->mins = (double *) StCalloc(sizeof(double), vars);
  528.     p->maxes = (double *) StCalloc(sizeof(double), vars);
  529.     p->scale = (double *) StCalloc(sizeof(double), vars);
  530.     p->location = (double *) StCalloc(sizeof(double), vars);
  531.     p->screen_mins = (int *) StCalloc(sizeof(int), vars);
  532.     p->screen_maxes = (int *) StCalloc(sizeof(int), vars);
  533.   }
  534.   
  535.   p->points = IViewNewBasicPoints(vars, p->scale, p->location);
  536.   p->lines = IViewNewBasicPoints(vars, p->scale, p->location);
  537. #ifdef USESTRINGS
  538.   p->strings = IViewNewBasicPoints(vars, p->scale, p->location);
  539. #endif /* USESTRINGS *// * test added - should be moved up to test above JKL */
  540.   if(vars>0)p->variableLabels = (char **) StCalloc(sizeof(char *), vars);
  541.   p->recalculateScreenPoints = FALSE;
  542.   p->transformed = FALSE;
  543.   
  544.   return(/*(char *)*/p);
  545. }
  546.  
  547. void IViewDataFree(p)
  548.     IViewDATA p;
  549. {
  550.   int i;
  551.   PointInfo *pointInfo;
  552. #ifdef USESTRINGS
  553.   StringInfo *stringInfo;
  554. #endif /* USESTRINGS */
  555.   
  556.   StFree(p->mins);
  557.   StFree(p->maxes);
  558.   StFree(p->scale);
  559.   StFree(p->location);
  560.   StFree(p->screen_mins);
  561.   StFree(p->screen_maxes);
  562.  
  563.   for (i = 0; i < p->points->num_points; i++) {
  564.     pointInfo = (PointInfo *) StRPtr(p->pointInfo);
  565.     if (pointInfo[i].label != nil) StFree(pointInfo[i].label);
  566.   }
  567.   StRFree(p->pointInfo);
  568.   
  569.   StRFree(p->lineInfo);
  570.  
  571. #ifdef USESTRINGS
  572.   for (i = 0; i < p->strings->num_points; i++) {
  573.     stringInfo = (StringInfo *) StRPtr(p->stringInfo);
  574.     if (stringInfo[i].string != nil) StFree(stringInfo[i].string);
  575.   }
  576.   StRFree(p->stringInfo);
  577. #endif /* USESTRINGS */
  578.  
  579.   for (i = 0; i < p->points->num_variables; i++) {
  580.     if (p->variableLabels[i] != nil) StFree(p->variableLabels[i]);
  581.   }
  582.   StFree(p->variableLabels);
  583.     
  584.   IViewFreeBasicPoints(p->points);
  585.   IViewFreeBasicPoints(p->lines);
  586. #ifdef USESTRINGS
  587.   IViewFreeBasicPoints(p->strings);
  588. #endif /* USESTRINGS */
  589.   
  590.   if (p->transformation != nil) {
  591.     StFree(p->transformation[0]);
  592.     StFree(p->transformation);
  593.   }
  594.   StFree(p);
  595. }
  596.  
  597. IViewBasicPoints IViewDataPoints(data)
  598.     IViewDATA data;
  599. {
  600.   if (data == nil) StPerror("nil data pointer");
  601.   if (data->points == nil) StPerror("nil point data pointer");
  602.   return(data->points);
  603. }
  604.  
  605. IViewBasicPoints IViewDataLines(data)
  606.     IViewDATA data;
  607. {
  608.   if (data == nil) StPerror("nil data pointer");
  609.   if (data->lines == nil) StPerror("nil line data pointer");
  610.   return(data->lines);
  611. }
  612.  
  613. #ifdef USESTRINGS
  614. IViewBasicPoints IViewDataStrings(data)
  615.     IViewDATA data;
  616. {
  617.   if (data == nil) StPerror("nil data pointer");
  618.   if (data->strings == nil) StPerror("nil string data pointer");
  619.   return(data->strings);
  620. }
  621. #endif /* USESTRINGS */
  622.  
  623. /**************************************************************************/
  624. /**                                                                      **/
  625. /**                        General Data Functions                        **/
  626. /**                                                                      **/
  627. /**************************************************************************/
  628.  
  629. int IViewDataNumVariables(p)
  630.     IViewDATA p;
  631. {
  632.   return(IViewBasicPointsNumVariables(IViewDataPoints(p)));
  633. }
  634.  
  635. void IViewDataSetVariableLabel(p, var, s)
  636.     IViewDATA p;
  637.     unsigned var;
  638.     char *s;
  639. {
  640.   if (p == nil || var >= IViewDataNumVariables(p)) return;
  641.   
  642.   StFree(p->variableLabels[var]);
  643.   p->variableLabels[var] = nil;
  644.   if (s != 0 && strlen(s) > 0) {
  645.     p->variableLabels[var] = StCalloc(sizeof(char), 1 + strlen(s));
  646.     strcpy(p->variableLabels[var], s);
  647.   }
  648. }
  649.  
  650. char *IViewDataVariableLabel(p, var)
  651.     IViewDATA p;
  652.     unsigned var;
  653. {
  654.   if (p == nil || var >= IViewDataNumVariables(p)) return(nil);
  655.   return(p->variableLabels[var]);
  656. }
  657.  
  658. static int CalculateLocationScale(p)
  659.     IViewDATA p;
  660. {
  661.   int i, fixed, vars = IViewDataNumVariables(p);
  662.   double range, screen_range, scale;
  663.   
  664.   for (i = 0; i < vars; i++) {
  665.     range = p->maxes[i] - p->mins[i];
  666.     screen_range = p->screen_maxes[i] - p->screen_mins[i];
  667.     p->scale[i] = (range > 0) ? screen_range / range : 0.0;
  668.     p->location[i] = p->screen_mins[i] - p->mins[i] * p->scale[i];
  669.   }
  670.   if (vars > 0) {
  671.     fixed = (p->location[0] == 0.0) ? TRUE : FALSE;
  672.     scale = p->scale[0];
  673.     for (i = 1; i < vars; i++)
  674.       fixed = (fixed && scale == p->scale[i] && p->location[i] == 0.0);
  675.   }
  676.   return(fixed);
  677. }
  678.  
  679. void IViewDataSetRange(p, var, low, high)
  680.     IViewDATA p;
  681.     unsigned var;
  682.     double low, high;
  683. {
  684.   int fixed;
  685.   
  686.   if (p != nil && var < IViewDataNumVariables(p) && low < high) {
  687.     p->mins[var] = low;
  688.     p->maxes[var] = high;
  689.     fixed = CalculateLocationScale(p);
  690.     IViewBasicPointsSetRecalculate(p->points, fixed);
  691.     IViewBasicPointsSetRecalculate(p->lines, fixed);
  692. #ifdef USESTRINGS
  693.     IViewBasicPointsSetRecalculate(p->strings, fixed);
  694. #endif /* USESTRINGS */
  695.   }
  696. }
  697.  
  698. void IViewDataGetRange(p, var, low, high)
  699.     IViewDATA p;
  700.     unsigned var;
  701.     double *low, *high;
  702. {
  703.   if (p != nil && var < IViewDataNumVariables(p)) {
  704.     if (low != nil) *low = p->mins[var];
  705.     if (high != nil) *high = p->maxes[var];
  706.   }
  707. }
  708.  
  709. void IViewDataSetScreenRange(p, var, low, high)
  710.     IViewDATA p;
  711.     unsigned var;
  712.     int low, high;
  713. {
  714.   int fixed;
  715.   
  716.   if (p != nil && var < IViewDataNumVariables(p) && low < high) {
  717.     p->screen_mins[var] = low;
  718.     p->screen_maxes[var] = high;
  719.     fixed = CalculateLocationScale(p);
  720.     IViewBasicPointsSetRecalculate(IViewDataPoints(p), fixed);
  721.     IViewBasicPointsSetRecalculate(IViewDataLines(p), fixed);
  722. #ifdef USESTRINGS
  723.     IViewBasicPointsSetRecalculate(IViewDataStrings(p), fixed);
  724. #endif /* USESTRINGS */
  725.   }
  726. }
  727.  
  728. void IViewDataGetScreenRange(p, var, low, high)
  729.     IViewDATA p;
  730.     unsigned var;
  731.     int *low, *high;
  732. {
  733.   if (p != nil && var < IViewDataNumVariables(p)) {
  734.     if (low != nil) *low = p->screen_mins[var];
  735.     if (high != nil) *high = p->screen_maxes[var];
  736.   }
  737. }
  738.  
  739. void IViewDataSetIdentityTransformation(data)
  740.      IViewDATA data;
  741. {
  742.   int i, j, vars = IViewDataNumVariables(data);
  743.   double *p;
  744.   
  745.   if (data == nil) return;
  746.   
  747.   data->transformed = FALSE;
  748.   if (data->transformation == nil) {
  749.     data->transformation = (double **) StCalloc(sizeof(double *), vars);
  750.     p = (double *) StCalloc(sizeof(double), vars * vars);
  751.     for (i = 0; i < vars; i++)
  752.       data->transformation[i] = p + i * vars;
  753.   }
  754.   
  755.   for (i = 0; i < vars; i++)
  756.     for (j = 0; j < vars; j++)
  757.       data->transformation[i][j] = (i == j) ? 1.0 : 0.0;
  758.  
  759.   IViewBasicPointsSetTransformation(IViewDataPoints(data), data->transformation);
  760.   IViewBasicPointsSetTransformation(IViewDataLines(data), data->transformation);
  761. #ifdef USESTRINGS
  762.   IViewBasicPointsSetTransformation(IViewDataStrings(data), data->transformation);
  763. #endif /* USESTRINGS */
  764. }
  765.  
  766. void IViewDataSetTransformation(data, a)
  767.      IViewDATA data;
  768.      double **a;
  769. {
  770.   int i, j, vars = IViewDataNumVariables(data);
  771.   double *p;
  772.   
  773.   if (data == nil) return;
  774.   data->transformed = TRUE;
  775.   if (a != nil) {
  776.     if (data->transformation == nil) {
  777.       data->transformation = (double **) StCalloc(sizeof(double *), vars);
  778.       p = (double *) StCalloc(sizeof(double), vars * vars);
  779.       for (i = 0; i < vars; i++)
  780.         data->transformation[i] = p + i * vars;
  781.     }
  782.   
  783.     for (i = 0; i < vars; i++)
  784.       for (j = 0; j < vars; j++)
  785.         data->transformation[i][j] = a[i][j];
  786.   }
  787.   else if (data->transformation != nil) {
  788.     StFree(data->transformation[0]);
  789.     StFree(data->transformation);
  790.   }
  791.  
  792.   IViewBasicPointsSetTransformation(IViewDataPoints(data), data->transformation);
  793.   IViewBasicPointsSetTransformation(IViewDataLines(data), data->transformation);
  794. #ifdef USESTRINGS
  795.   IViewBasicPointsSetTransformation(IViewDataStrings(data), data->transformation);
  796. #endif /* USESTRINGS */
  797. }
  798.  
  799. double **IViewDataTransformation(data)
  800.      IViewDATA data;
  801. {
  802.   if (data == nil) return(nil);
  803.   else return(data->transformation);
  804. }
  805.  
  806. void IViewDataApplyTransformation(data, a, inbasis)
  807.      IViewDATA data;
  808.      double **a;
  809.      int *inbasis;
  810. {
  811.   static int temp_size;
  812.   static double *temp;
  813.   double **b;
  814.   int i, j, k, vars = IViewDataNumVariables(data);
  815.  
  816.   if (data == nil) return;
  817.   
  818.   if (data->transformation == nil) IViewDataSetIdentityTransformation(data);
  819.   data->transformed = TRUE;
  820.   b = data->transformation;
  821.   
  822.   if (temp_size < vars) {
  823.     StFree(temp);
  824.     temp = nil;
  825.   }
  826.   if (temp == nil) {
  827.     temp_size = vars;
  828.     temp = (double *) StCalloc(sizeof(double), temp_size);
  829.   }
  830.  
  831.   for (j = 0; j < vars; j++) {
  832.     for (i = 0; i < vars; i++) 
  833.       if (inbasis[i]){
  834.         temp[i] = 0.0;
  835.         for (k = 0; k < vars; k++)
  836.           if (inbasis[k] && a[i][k] != 0.0 && b[k][j] != 0) 
  837.             temp[i] += a[i][k] * b[k][j];
  838.       }
  839.     for (i = 0; i < vars; i++)
  840.       if (inbasis[i]) b[i][j] = temp[i];
  841.   }
  842.  
  843.   IViewBasicPointsApplyTransformation(IViewDataPoints(data), a, inbasis);
  844.   IViewBasicPointsApplyTransformation(IViewDataLines(data), a, inbasis);
  845. #ifdef USESTRINGS
  846.   IViewBasicPointsApplyTransformation(IViewDataStrings(data), a, inbasis);
  847. #endif /* USESTRINGS */
  848. }
  849.  
  850. int IViewDataIsTransformed(data)
  851.      IViewDATA data;
  852. {
  853.   return (data != nil && data->transformed);
  854. }
  855.  
  856. /**************************************************************************/
  857. /**                                                                      **/
  858. /**                          Point Data Functions                        **/
  859. /**                                                                      **/
  860. /**************************************************************************/
  861.  
  862. void IViewDataAddPoints(p, n)
  863.      IViewDATA p;
  864.      int n;
  865. {
  866.   int i, fixed, old_n = IViewDataNumPoints(p);
  867.     
  868.   IViewAddBasicPoints(IViewDataPoints(p), n);
  869.   n += old_n;  /* cast added JKL */
  870.   p->pointInfo = (IViewReallocData)StRRealloc(p->pointInfo, sizeof(struct point_info), n);
  871.   
  872.   for (i = old_n; i < n; i++) {
  873.     IViewDataSetPointSymbol(p, i, 4, 5);
  874.     IViewDataSetPointState(p, i, pointNormal);
  875.     IViewDataSetPointColor(p, i, -1);
  876.   }
  877.   fixed = CalculateLocationScale(p);
  878.   IViewBasicPointsSetRecalculate(IViewDataPoints(p), fixed);
  879. }
  880.  
  881. void IViewDataClearPoints(p)
  882.     IViewDATA p;
  883. {
  884.   PointInfo *pointInfo;
  885.   int i, n = IViewDataNumPoints(p);
  886.    
  887.   for (i = 0; i < n; i++) {
  888.     pointInfo = (PointInfo *) StRPtr(p->pointInfo);
  889.     if (pointInfo[i].label != nil) StFree(pointInfo[i].label);
  890.   }
  891.   StRFree(p->pointInfo);
  892.   p->pointInfo = nil;
  893.   IViewClearBasicPoints(IViewDataPoints(p));
  894. }
  895.  
  896. int IViewDataNumPoints(p)
  897.     IViewDATA p;
  898. {
  899.   return(IViewBasicPointsNumPoints(IViewDataPoints(p)));
  900. }
  901.  
  902. void IViewDataSetPointValue(p, var, point, value)
  903.     IViewDATA p;
  904.     int var, point;
  905.     double value;
  906. {
  907.   IViewBasicPointSetValue(IViewDataPoints(p), var, point, value);
  908. }
  909.  
  910. double IViewDataPointValue(p, var, point)
  911.     IViewDATA p;
  912.     int var, point;
  913. {
  914.   return(IViewBasicPointValue(IViewDataPoints(p), var, point));
  915. }
  916.  
  917. double IViewDataPointTransformedValue(p, var, point)
  918.     IViewDATA p;
  919.     int var, point;
  920. {
  921.   return(TransformedValue(IViewDataPoints(p), var, point));
  922. }
  923.  
  924. int IViewDataPointScreenValue(p, var, point)
  925.     IViewDATA p;
  926.     int var, point;
  927. {
  928.   return(IViewBasicPointScreenValue(IViewDataPoints(p), var, point));
  929. }
  930.  
  931. void IViewDataGetScreenPointValues(d, point, x)
  932.     IViewDATA d;
  933.     int point, *x;
  934. {
  935.   IViewBasicPointsGetScreenValues(IViewDataPoints(d), point, x);
  936. }
  937.  
  938. void IViewDataSetPointMask(p, point, masked)
  939.      IViewDATA p;
  940.      unsigned point;
  941.      int masked;
  942. {
  943.   PointInfo *info;
  944.   
  945.   if (point >= IViewDataNumPoints(p)) return;
  946.  
  947.   info = (PointInfo *) StRPtr(p->pointInfo);
  948.   info[point].masked = masked;
  949. }
  950.  
  951. int IViewDataPointMasked(p, point)
  952.      IViewDATA p;
  953.      unsigned point;
  954. {
  955.   PointInfo *info;
  956.   
  957.   if (point >= IViewDataNumPoints(p)) return(0);
  958.  
  959.   info = (PointInfo *) StRPtr(p->pointInfo);
  960.   return((int) info[point].masked);
  961. }
  962.  
  963. void IViewDataSetPointColor(p, point, color)
  964.      IViewDATA p;
  965.      unsigned point;
  966.      int color;
  967. {
  968.   PointInfo *info;
  969.   
  970.   if (point >= IViewDataNumPoints(p)) return;
  971.  
  972.   info = (PointInfo *) StRPtr(p->pointInfo);
  973.   info[point].color = color;
  974. }
  975.  
  976. /*int*/ ColorCode IViewDataPointColor(p, point) /* changed JKL */
  977.      IViewDATA p;
  978.      unsigned point;
  979. {
  980.   PointInfo *info;
  981.   
  982.   if (point >= IViewDataNumPoints(p)) return(0);
  983.  
  984.   info = (PointInfo *) StRPtr(p->pointInfo);
  985.   return(/*(int)*/ info[point].color);
  986. }
  987.  
  988. void IViewDataSetPointState(p, point, state)
  989.      IViewDATA p;
  990.      unsigned point;
  991.      PointState state;
  992. {
  993.   PointInfo *info;
  994.   
  995.   if (point >= IViewDataNumPoints(p)) return;
  996.  
  997.   info = (PointInfo *) StRPtr(p->pointInfo);
  998.   info[point].state = state;
  999. }
  1000.  
  1001. PointState IViewDataPointState(p, point)
  1002.      IViewDATA p;
  1003.      unsigned point;
  1004. {
  1005.   PointInfo *info;
  1006.   
  1007.   if (point >= IViewDataNumPoints(p)) return((PointState) 0);
  1008.  
  1009.   info = (PointInfo *) StRPtr(p->pointInfo);
  1010.   return(info[point].state);
  1011. }
  1012.  
  1013. void IViewDataSetPointScreenState(p, point, state)
  1014.      IViewDATA p;
  1015.      unsigned point;
  1016.      PointState state;
  1017. {
  1018.   PointInfo *info;
  1019.   
  1020.   if (point >= IViewDataNumPoints(p)) return;
  1021.  
  1022.   info = (PointInfo *) StRPtr(p->pointInfo);
  1023.   info[point].screen_state = state;
  1024. }
  1025.  
  1026. PointState IViewDataPointScreenState(p, point)
  1027.      IViewDATA p;
  1028.      unsigned point;
  1029. {
  1030.   PointInfo *info;
  1031.   
  1032.   if (point >= IViewDataNumPoints(p)) return((PointState) 0);
  1033.  
  1034.   info = (PointInfo *) StRPtr(p->pointInfo);
  1035.   return(info[point].screen_state);
  1036. }
  1037.  
  1038. void IViewDataResetScreenStates(p)
  1039.      IViewDATA p;
  1040. {
  1041.   int i, n = IViewDataNumPoints(p);
  1042.   PointInfo *info;
  1043.   
  1044.   if (p == nil || p->pointInfo == nil) return;
  1045.  
  1046.   info = (PointInfo *) StRPtr(p->pointInfo);
  1047.   for (i = 0; i < n; i++) info[i].screen_state = info[i].state;
  1048. }
  1049.  
  1050. void IViewDataSetPointMark(p, point, marked)
  1051.      IViewDATA p;
  1052.      unsigned point;
  1053.      int marked;
  1054. {
  1055.   PointInfo *info;
  1056.   
  1057.   if (point >= IViewDataNumPoints(p)) return;
  1058.  
  1059.   info = (PointInfo *) StRPtr(p->pointInfo);
  1060.   info[point].marked = marked;
  1061. }
  1062.  
  1063. int IViewDataPointMarked(p, point)
  1064.      IViewDATA p;
  1065.      unsigned point;
  1066. {
  1067.   PointInfo *info;
  1068.   
  1069.   if (point >= IViewDataNumPoints(p)) return(0);
  1070.  
  1071.   info = (PointInfo *) StRPtr(p->pointInfo);
  1072.   return((int) info[point].marked);
  1073. }
  1074.  
  1075. void IViewDataClearPointMarks(p)
  1076.      IViewDATA p;
  1077. {
  1078.   int i, n = IViewDataNumPoints(p);
  1079.   PointInfo *info;
  1080.   
  1081.   if (p == nil || p->pointInfo == nil) return;
  1082.  
  1083.   info = (PointInfo *) StRPtr(p->pointInfo);
  1084.   for (i = 0; i < n; i++) info[i].marked = FALSE;
  1085. }
  1086.  
  1087. void IViewDataSetPointLabel(p, point, s)
  1088.     IViewDATA p;
  1089.     unsigned point;
  1090.     char *s;
  1091. {
  1092.   PointInfo *info;
  1093.   
  1094.   if (point >= IViewDataNumPoints(p)) return;
  1095.  
  1096.   StRLock(p->pointInfo);
  1097.   info = (PointInfo *) StRPtr(p->pointInfo);
  1098.   
  1099.   StFree(info[point].label);
  1100.   info[point].label = nil;
  1101.   if (s != 0 && strlen(s) > 0) {
  1102.     info[point].label = StCalloc(sizeof(char), 1 + strlen(s));
  1103.     strcpy(info[point].label, s);
  1104.   }
  1105.   StRUnlock(p->pointInfo);
  1106. }
  1107.  
  1108. char *IViewDataPointLabel(p, point)
  1109.     IViewDATA p;
  1110.     unsigned point;
  1111. {
  1112.   PointInfo *info;
  1113.   char label[100];
  1114.   
  1115.   if (point >= IViewDataNumPoints(p)) return(nil);
  1116.  
  1117.   info = (PointInfo *) StRPtr(p->pointInfo);
  1118.   
  1119.   /* only allocate label on demand to save time and space */
  1120.   if (info[point].label == nil) {
  1121.     sprintf(label, "%d", point);
  1122.     IViewDataSetPointLabel(p, point, label);
  1123.   }
  1124.   return(info[point].label);
  1125. }
  1126.  
  1127. void IViewDataSetPointSymbol(p, point, sym, hsym)
  1128.      IViewDATA p;
  1129.      unsigned point;
  1130.      int sym, hsym;
  1131. {
  1132.   PointInfo *info;
  1133.   
  1134.   if (point >= IViewDataNumPoints(p)) return;
  1135.  
  1136.   info = (PointInfo *) StRPtr(p->pointInfo);
  1137.   info[point].symbol.normal = sym;
  1138.   info[point].symbol.highlighted = hsym;
  1139. }
  1140.  
  1141. void IViewDataGetPointSymbol(p, point, sym, hsym)
  1142.      IViewDATA p;
  1143.      unsigned point;
  1144.      int *sym, *hsym;
  1145. {
  1146.   PointInfo *info;
  1147.   
  1148.   if (point >= IViewDataNumPoints(p)) return;
  1149.  
  1150.   info = (PointInfo *) StRPtr(p->pointInfo);
  1151.   if (sym != nil) *sym = info[point].symbol.normal;
  1152.   if (hsym != nil) *hsym = info[point].symbol.highlighted;
  1153. }
  1154.  
  1155. /**************************************************************************/
  1156. /**                                                                      **/
  1157. /**                            Line Data Functions                       **/
  1158. /**                                                                      **/
  1159. /**************************************************************************/
  1160.  
  1161. int IViewDataNumLines(p)
  1162.     IViewDATA p;
  1163. {
  1164.   return(IViewBasicPointsNumPoints(IViewDataLines(p)));
  1165. }
  1166.  
  1167. void IViewDataAddLines(p, n)
  1168.      IViewDATA p;
  1169.      int n;
  1170. {
  1171.   int i, old_n = IViewDataNumLines(p);
  1172.   if (p == nil) return;
  1173.   
  1174.   IViewAddBasicPoints(IViewDataLines(p), n);
  1175.   n += old_n;  /* cast added JKL */
  1176.   p->lineInfo = (IViewReallocData)StRRealloc(p->lineInfo, sizeof(struct line_info), n);
  1177.   
  1178.   for (i = old_n; i < n - 1; i++) {
  1179.     IViewDataSetNextLine(p, i, i + 1);
  1180.     IViewDataSetLineType(p, i, 0);
  1181.     IViewDataSetLineColor(p, i, -1);
  1182.     IViewDataSetLineWidth(p, i, 1);
  1183.   }
  1184.   IViewDataSetNextLine(p, n - 1, -1);
  1185.   IViewDataSetLineType(p, n - 1, 0);  
  1186.   IViewDataSetLineColor(p, n - 1, -1);
  1187.   IViewDataSetLineWidth(p, n - 1, 1);
  1188. }
  1189.  
  1190. void IViewDataClearLines(p)
  1191.     IViewDATA p;
  1192. {
  1193.   StRFree(p->lineInfo);
  1194.   p->lineInfo = nil;
  1195.   IViewClearBasicPoints(IViewDataLines(p));
  1196. }
  1197.  
  1198. void IViewDataSetLineValue(p, var, line, value)
  1199.     IViewDATA p;
  1200.     int var, line;
  1201.     double value;
  1202. {
  1203.   IViewBasicPointSetValue(IViewDataLines(p), var, line, value);
  1204. }
  1205.  
  1206. double IViewDataLineValue(p, var, line)
  1207.     IViewDATA p;
  1208.     int var, line;
  1209. {
  1210.   return(IViewBasicPointValue(IViewDataLines(p), var, line));
  1211. }
  1212.  
  1213. double IViewDataLineTransformedValue(p, var, line)
  1214.     IViewDATA p;
  1215.     int var, line;
  1216. {
  1217.   return(TransformedValue(IViewDataLines(p), var, line));
  1218. }
  1219.  
  1220. IViewDataLineScreenValue(p, var, line)
  1221.     IViewDATA p;
  1222.     int var, line;
  1223. {
  1224.   return(IViewBasicPointScreenValue(IViewDataLines(p), var, line));
  1225. }
  1226.  
  1227. void IViewDataSetLineMask(p, line, masked)
  1228.      IViewDATA p;
  1229.      unsigned line;
  1230.      int masked;
  1231. {
  1232.   LineInfo *info;
  1233.   
  1234.   if (line >= IViewDataNumLines(p)) return;
  1235.  
  1236.   info = (LineInfo *) StRPtr(p->lineInfo);
  1237.   info[line].masked = masked;
  1238. }
  1239.  
  1240. int IViewDataLineMasked(p, line)
  1241.      IViewDATA p;
  1242.      unsigned line;
  1243. {
  1244.   LineInfo *info;
  1245.   
  1246.   if (line >= IViewDataNumLines(p)) return(0);
  1247.  
  1248.   info = (LineInfo *) StRPtr(p->lineInfo);
  1249.   return((int) info[line].masked);
  1250. }
  1251.  
  1252. void IViewDataSetLineColor(p, line, color)
  1253.      IViewDATA p;
  1254.      unsigned line;
  1255.      int color;
  1256. {
  1257.   LineInfo *info;
  1258.   
  1259.   if (line >= IViewDataNumLines(p)) return;
  1260.  
  1261.   info = (LineInfo *) StRPtr(p->lineInfo);
  1262.   info[line].color = color;
  1263. }
  1264.  
  1265. /*int*/ ColorCode IViewDataLineColor(p, line) /* changed JKL */
  1266.      IViewDATA p;
  1267.      unsigned line;
  1268. {
  1269.   LineInfo *info;
  1270.   
  1271.   if (line >= IViewDataNumLines(p)) return(0);
  1272.  
  1273.   info = (LineInfo *) StRPtr(p->lineInfo);
  1274.   return(/*(int)*/ info[line].color);
  1275. }
  1276.  
  1277. void IViewDataSetLineWidth(p, line, width)
  1278.      IViewDATA p;
  1279.      unsigned line, width;
  1280. {
  1281.   LineInfo *info;
  1282.   
  1283.   if (line >= IViewDataNumLines(p)) return;
  1284.  
  1285.   info = (LineInfo *) StRPtr(p->lineInfo);
  1286.   info[line].width = width;
  1287. }
  1288.  
  1289. int IViewDataGetLineWidth(p, line, width)
  1290.      IViewDATA p;
  1291.      unsigned line, *width;
  1292. {
  1293.   LineInfo *info;
  1294.   
  1295.   if (line >= IViewDataNumLines(p)) return(0);
  1296.  
  1297.   info = (LineInfo *) StRPtr(p->lineInfo);
  1298.   if (width != 0) *width = (int) info[line].width;
  1299. }   /* warning : function falls off the end - no return value  JKL */
  1300.  
  1301. void IViewDataSetNextLine(p, line, next)
  1302.      IViewDATA p;
  1303.      unsigned line;
  1304.      int next;
  1305. {
  1306.   LineInfo *info;
  1307.   
  1308.   if (line >= IViewDataNumLines(p) || next >= IViewDataNumLines(p)) return;
  1309.  
  1310.   info = (LineInfo *) StRPtr(p->lineInfo);
  1311.   info[line].next = next;
  1312. }
  1313.  
  1314. int IViewDataNextLine(p, line)
  1315.      IViewDATA p;
  1316.      unsigned line;
  1317. {
  1318.   LineInfo *info;
  1319.   
  1320.   if (line >= IViewDataNumLines(p)) return(0);
  1321.  
  1322.   info = (LineInfo *) StRPtr(p->lineInfo);
  1323.   return(info[line].next);
  1324. }
  1325.  
  1326. void IViewDataSetLineType(p, line, type)
  1327.      IViewDATA p;
  1328.      unsigned line;
  1329.      int type;
  1330. {
  1331.   LineInfo *info;
  1332.   
  1333.   if (line >= IViewDataNumLines(p)) return;
  1334.  
  1335.   info = (LineInfo *) StRPtr(p->lineInfo);
  1336.   info[line].type = type;
  1337. }
  1338.  
  1339. int IViewDataLineType(p, line)
  1340.      IViewDATA p;
  1341.      unsigned line;
  1342. {
  1343.   LineInfo *info;
  1344.   
  1345.   if (line >= IViewDataNumLines(p)) return(0);
  1346.  
  1347.   info = (LineInfo *) StRPtr(p->lineInfo);
  1348.   return(info[line].type);
  1349. }
  1350.  
  1351. #ifdef USESTRINGS
  1352. /**************************************************************************/
  1353. /**                                                                      **/
  1354. /**                           String Data Functions                      **/
  1355. /**                                                                      **/
  1356. /**************************************************************************/
  1357.  
  1358. int IViewDataNumStrings(p)
  1359.     IViewDATA p;
  1360. {
  1361.   return(IViewBasicPointsNumPoints(IViewDataStrings(p)));
  1362. }
  1363.  
  1364. void IViewDataAddStrings(p, n)
  1365.      IViewDATA p;
  1366.      int n;
  1367. {
  1368.   int i, old_n = IViewDataNumStrings(p);
  1369.   if (p == nil) return;
  1370.   
  1371.   IViewAddBasicPoints(IViewDataStrings(p), n);
  1372.   n += old_n;   /* cast added JKL */ 
  1373.   p->stringInfo = (IViewReallocData)StRRealloc(p->stringInfo, sizeof(struct string_info), n);
  1374.   
  1375.   for (i = old_n; i < n; i++) IViewDataSetStringColor(p, i, -1);
  1376. }
  1377.  
  1378. void IViewDataClearStrings(p)
  1379.     IViewDATA p;
  1380. {
  1381.   StringInfo *stringInfo;
  1382.   int i, n = IViewDataNumStrings(p);
  1383.    
  1384.   for (i = 0; i < n; i++) {
  1385.     stringInfo = (StringInfo *) StRPtr(p->stringInfo);
  1386.     if (stringInfo[i].string != nil) StFree(stringInfo[i].string);
  1387.   }
  1388.   StRFree(p->stringInfo);
  1389.   p->stringInfo = nil;
  1390.   IViewClearBasicPoints(IViewDataStrings(p));
  1391. }
  1392.  
  1393. void IViewDataSetStringValue(p, var, string, value)
  1394.     IViewDATA p;
  1395.     int var, string;
  1396.     double value;
  1397. {
  1398.   IViewBasicPointSetValue(IViewDataStrings(p), var, string, value);
  1399. }
  1400.  
  1401. double IViewDataStringValue(p, var, string)
  1402.     IViewDATA p;
  1403.     int var, string;
  1404. {
  1405.   return(IViewBasicPointValue(IViewDataStrings(p), var, string));
  1406. }
  1407.  
  1408. double IViewDataStringTransformedValue(p, var, string)
  1409.     IViewDATA p;
  1410.     int var, string;
  1411. {
  1412.   return(TransformedValue(IViewDataStrings(p), var, string));
  1413. }
  1414.  
  1415. int IViewDataStringScreenValue(p, var, string)
  1416.     IViewDATA p;
  1417.     int var, string;
  1418. {
  1419.   return(IViewBasicPointScreenValue(IViewDataStrings(p), var, string));
  1420. }
  1421.  
  1422. void IViewDataSetStringMask(p, string, masked)
  1423.      IViewDATA p;
  1424.      unsigned string;
  1425.      int masked;
  1426. {
  1427.   StringInfo *info;
  1428.   
  1429.   if (string >= IViewDataNumStrings(p)) return;
  1430.  
  1431.   info = (StringInfo *) StRPtr(p->stringInfo);
  1432.   info[string].masked = masked;
  1433. }
  1434.  
  1435. int IViewDataStringMasked(p, string)
  1436.      IViewDATA p;
  1437.      unsigned string;
  1438. {
  1439.   StringInfo *info;
  1440.   
  1441.   if (string >= IViewDataNumStrings(p)) return(0);
  1442.  
  1443.   info = (StringInfo *) StRPtr(p->stringInfo);
  1444.   return((int) info[string].masked);
  1445. }
  1446.  
  1447. void IViewDataSetStringColor(p, string, color)
  1448.      IViewDATA p;
  1449.      unsigned string;
  1450.      int color;
  1451. {
  1452.   StringInfo *info;
  1453.   
  1454.   if (string >= IViewDataNumStrings(p)) return;
  1455.  
  1456.   info = (StringInfo *) StRPtr(p->stringInfo);
  1457.   info[string].color = color;
  1458. }
  1459.  
  1460. int IViewDataStringColor(p, string)
  1461.      IViewDATA p;
  1462.      unsigned string;
  1463. {
  1464.   StringInfo *info;
  1465.   
  1466.   if (string >= IViewDataNumStrings(p)) return(0);
  1467.  
  1468.   info = (StringInfo *) StRPtr(p->stringInfo);
  1469.   return(/*(int)*/ info[string].color); /* cast removed JKL */
  1470. }
  1471.  
  1472. void IViewDataSetStringString(p, string, s)
  1473.      IViewDATA p;
  1474.      unsigned string;
  1475.      char *s;
  1476. {
  1477.   StringInfo *info;
  1478.   
  1479.   if (string >= IViewDataNumStrings(p)) return;
  1480.  
  1481.   info = (StringInfo *) StRPtr(p->stringInfo);
  1482.   StRLock((StReallocData)p->stringInfo); /* cast added JKL */
  1483.   StFree(info[string].string);
  1484.   info[string].string = nil;
  1485.   if (s != 0 && strlen(s) > 0) {
  1486.     info[string].string = StCalloc(sizeof(char), 1 + strlen(s));
  1487.     strcpy(info[string].string, s);
  1488.   }
  1489.   StRUnlock(p->stringInfo);
  1490. }
  1491.  
  1492. char *IViewDataStringString(p, string)
  1493.      IViewDATA p;
  1494.      unsigned string;
  1495. {
  1496.   StringInfo *info;
  1497.   
  1498.   if (string >= IViewDataNumStrings(p)) return(nil);
  1499.  
  1500.   info = (StringInfo *) StRPtr(p->stringInfo);
  1501.   return(info[string].string);
  1502. }
  1503.  
  1504. void IViewDataSetStringModifiers(p, string, up, h, v)
  1505.      IViewDATA p;
  1506.      unsigned string;
  1507.      int up, h, v;
  1508. {
  1509.   StringInfo *info;
  1510.   
  1511.   if (string >= IViewDataNumStrings(p)) return;
  1512.  
  1513.   info = (StringInfo *) StRPtr(p->stringInfo);
  1514.   info[string].up = up;
  1515.   info[string].h = h;
  1516.   info[string].v = v;
  1517. }
  1518.  
  1519. void IViewDataGetStringModifiers(p, string, up, h, v)
  1520.      IViewDATA p;
  1521.      unsigned string;
  1522.      int *up, *h, *v;
  1523. {
  1524.   StringInfo *info;
  1525.   
  1526.   if (string >= IViewDataNumStrings(p)) return;
  1527.  
  1528.   info = (StringInfo *) StRPtr(p->stringInfo);
  1529.   if (up != nil) *up = info[string].up;
  1530.   if (h != nil) *h = info[string].h;
  1531.   if (v != nil) *v = info[string].v;
  1532. }
  1533. #endif /* USESTRINGS */
  1534.  
  1535. /**************************************************************************/
  1536. /**                                                                      **/
  1537. /**                          Data Drawing Functions                      **/
  1538. /**                                                                      **/
  1539. /**************************************************************************/
  1540.  
  1541. void IViewDataDrawPoints(data, w, var1, var2, m, n, offset)
  1542.      IViewDATA data;
  1543.     IVIEW_WINDOW w;
  1544.     unsigned var1, var2, m, n;
  1545.     int offset;
  1546. {
  1547.   int vars = IViewNumVariables(w);
  1548. /*  int right, bottom; not used below JKL */
  1549.   int point, left, top, width, height, orig_x, orig_y;
  1550.   int showingLabels = IViewShowingLabels(w);
  1551.   int x, y, sym, hsym;
  1552.   PointState state;
  1553.   PointInfo *info;
  1554.   Fixed *screen1, *screen2;
  1555.   /*char*/ StGWWinInfo *gwinfo = IViewWindowWinInfo(w); /* changed JKL */
  1556.   int mode = StGWDrawMode(gwinfo);
  1557.   /* int*/ ColorCode draw_color, use_color = StGWUseColor(gwinfo);
  1558.         /* changed JKL */
  1559.   if (n > IViewNumPoints(w)) return;
  1560.   if (var1 >= vars || var2 >= vars) return;
  1561.   if (data == nil || data->pointInfo == nil || data->points == nil) return;
  1562.   if (data->points->screen_data[var1] == nil 
  1563.       || data->points->screen_data[var2] == nil) return;
  1564.   
  1565.   if (data->points->recalculateScreenPoints)
  1566.     RecalculateScreenPoints(data->points);
  1567.   info = (PointInfo *) StRPtr(data->pointInfo);
  1568.   screen1 = (Fixed *) StRPtr(data->points->screen_data[var1]);
  1569.   screen2 = (Fixed *) StRPtr(data->points->screen_data[var2]);
  1570.  
  1571.   StGrGetContentRect(gwinfo, &left, &top, &width, &height);
  1572.   StGrGetContentOrigin(gwinfo, &orig_x, &orig_y);
  1573. /*  right = left + width;
  1574.   bottom = top + height;  not used below JKL */
  1575.  
  1576.   if (use_color) draw_color = StGWDrawColor(gwinfo);
  1577.   for (point = m; point < n; point++, info++) {
  1578.     state = info->state;
  1579.     sym = info->symbol.normal;
  1580.     hsym = info->symbol.highlighted;
  1581.     if (! info->masked && state != pointInvisible) {
  1582. #ifdef PERSPECTIVE
  1583.       x = orig_x + PerspScreenValue(data->points, var1, point);
  1584.       y = orig_y - PerspScreenValue(data->points, var2, point);
  1585. #else
  1586.       x = orig_x + FixRound(screen1[point]);
  1587.       y = orig_y - FixRound(screen2[point]);
  1588. #endif PERSPECTIVE             /* why not take out this test ?? JKL */
  1589.       if (TRUE /* x >= left && x <= right && y >= top && y <= bottom */) {
  1590.         if (use_color) {
  1591.           if (info->color >= 0) StGWSetDrawColor(gwinfo, info->color);
  1592.           else StGWSetDrawColor(gwinfo, draw_color);
  1593.         }
  1594.         if (state == pointNormal) StGWDrawSymbol(gwinfo, sym, x, y);
  1595.         else {
  1596.           StGWDrawSymbol(gwinfo, hsym, x, y);
  1597.           if (showingLabels) {
  1598.             StGWSetDrawMode(gwinfo, 1);
  1599.             StGWDrawString(gwinfo, info->label, x + offset, y - offset);
  1600.             StGWSetDrawMode(gwinfo, mode);
  1601.           }
  1602.         }
  1603.       }
  1604.     }
  1605.   }
  1606.   if (use_color) StGWSetDrawColor(gwinfo, draw_color);
  1607. }
  1608.  
  1609. void IViewDataCuePoints(data, var, cut1, cut2, cut3, m, n)
  1610.     IViewDATA data;
  1611.     int cut1, cut2, cut3;
  1612.     unsigned var, m, n;
  1613. {
  1614.   int vars;
  1615.   int point;
  1616.   PointInfo *info;
  1617.   Fixed fcut1, fcut2, fcut3;
  1618.   Fixed *screen_z, z;
  1619.   
  1620.   if (data == nil || data->pointInfo == nil || data->points == nil) return;
  1621.   if (data->points->screen_data[var] == nil) return;
  1622.   if (n > IViewDataNumPoints(data)) return;
  1623.   vars = IViewDataNumVariables(data);
  1624.   if (var >= vars) return;
  1625.   
  1626.   if (data->points->recalculateScreenPoints)
  1627.     RecalculateScreenPoints(data->points);
  1628.   info = (PointInfo *) StRPtr(data->pointInfo);
  1629.   screen_z = (Fixed *) StRPtr(data->points->screen_data[var]);
  1630.  
  1631.   fcut1 = Int2Fixed(cut1);
  1632.   fcut2 = Int2Fixed(cut2);
  1633.   fcut3 = Int2Fixed(cut3);
  1634.   for (point = m; point < n; point++, info++) {
  1635.     z = screen_z[point];
  1636.     if (z < fcut1) info->symbol.normal = 0;
  1637.     else if (z < fcut2) info->symbol.normal = 1;
  1638.     else if (z < fcut3) info->symbol.normal = 2;
  1639.     else info->symbol.normal = 3;
  1640.     info->symbol.highlighted = 5;
  1641.   }
  1642. }
  1643.  
  1644. #ifdef PERSPECTIVE
  1645. static int PerspScreenValue(p, var, point)
  1646.     IViewBasicPoints p;
  1647.     unsigned var, point;
  1648. {
  1649.   Fixed screen_x, screen_z, d = 800;
  1650.  
  1651.   if (p->num_variables > 2 && p->num_variables > var) {
  1652.     screen_z = FixRound(((Fixed *) StRPtr(p->screen_data[2]))[point]);
  1653.     /* could create problems if StRPtr return value is zero JKL */
  1654.     screen_x = FixRound(((Fixed *) StRPtr(p->screen_data[var]))[point]);
  1655.     if (screen_z != d) {
  1656.       screen_x = (screen_x * d) / (d - screen_z);
  1657.       return((int) screen_x);
  1658.     }
  1659.     else return(FixRound(screen_x));
  1660.   }
  1661.   else return(0);
  1662. }
  1663. #endif PERSPECTIVE
  1664.  
  1665.