home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / DataScope 2.0.3 / Datafiles / externs / Mac_externs / genconst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  903 b   |  45 lines  |  [TEXT/MPS ]

  1. #include "DScope.h"
  2. /*
  3.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.     genconst    Given an array and a constant, generate
  5.                 an array where the output dimensions are
  6.                 the same as the input dimensions and 
  7.                 where each element of the array has the
  8.                 value of the constant
  9.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. */
  11. long addon(l,r,a)
  12.     scope_array            *l,*r,*a;
  13. {
  14.     register float        *p,*q;
  15.  
  16.     if (!l || !r)
  17.        {a->kind = DS_ERROR;
  18.         return(0);
  19.        }
  20.        
  21.     if (l->kind == DS_CONSTANT && r->kind == DS_CONSTANT)
  22.        {a->kind = DS_ERROR;
  23.         return(0);
  24.        }
  25.        
  26.     if (l->kind == DS_ARRAY && r->kind == DS_ARRAY)
  27.        {a->kind = DS_ERROR;
  28.         return(0);
  29.        }
  30.        
  31.     p = a->vals;
  32.     q = p + (long)(a->ncols * a->nrows - 1);
  33.        
  34.     if (l->kind == DS_CONSTANT)
  35.        {while (p < q)    *p++ = l->cval;
  36.         *p = l->cval;
  37.         return (0);
  38.        }
  39.     
  40.     while (p < q)    *p++ = r->cval;
  41.     *p = r->cval;
  42.     return (0);
  43. }
  44.  
  45.