home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncsa.uiuc.edu / ftp.ncsa.uiuc.edu.zip / ftp.ncsa.uiuc.edu / DataScope / misc / dsfns.c < prev    next >
C/C++ Source or Header  |  2017-03-03  |  3KB  |  173 lines

  1.  
  2. #include "DScope.h"
  3.  
  4.  
  5. /*
  6. *  hifilter
  7. *  Given the array (first parameter), and some bounds, either a constant or an
  8. *  array, return in the answer the higher of the two numbers.  This produces a
  9. *  hi-pass filter -- only the larger values get through.
  10. *
  11. */
  12. long exhifilter(l,r,a)
  13.     scope_array *l,*r,*a;
  14. {
  15.     register float *f,*sf,*sf2,hval;
  16.     register int i,j;
  17.     int constyes=0;
  18.  
  19.     if (!l || !r) {
  20.         a->kind = DS_ERROR;
  21.         return(0);
  22.     }
  23.     
  24.     f = a->vals;
  25.     
  26.     if (l->kind == DS_CONSTANT) {        /* is the left a constant? */
  27.         hval = l->cval;
  28.         constyes = 1;
  29.         sf = r->vals;
  30.     }
  31.  
  32.     if (r->kind == DS_CONSTANT) {        /* pass under a constant */
  33.         hval = r->cval;
  34.         if (constyes) {
  35.             a->kind = DS_CONSTANT;
  36.             if (l->cval < r->cval)        /* simple max function */
  37.                 a->cval = r->cval;
  38.             else
  39.                 a->cval = l->cval;
  40.             return;
  41.         }
  42.         constyes = 1;
  43.         sf = l->vals;
  44.     }
  45.     
  46.     if (constyes) {
  47.         
  48.         for (i=0; i< a->nrows; i++) 
  49.             for (j=0; j< a->ncols; j++) {
  50.                 if (*sf < hval) {
  51.                     *f++ = hval;
  52.                     sf++;
  53.                 }
  54.                 else
  55.                     *f++ = *sf++;
  56.             }
  57.     }
  58.  
  59.     else {                                /* compare two arrays */
  60.  
  61.         sf = l->vals;
  62.         sf2    = r->vals;
  63.         
  64.         for (i=0; i< a->nrows; i++) {
  65.             for (j=0; j< a->ncols; j++)
  66.                 if (*sf < *sf2) {
  67.                     *f++ = *sf2++;
  68.                     sf++;
  69.                 }
  70.                 else {
  71.                     *f++ = *sf++;
  72.                     sf2++;
  73.                 }
  74.         }
  75.     }        
  76. }
  77.  
  78. /******************************************************/
  79. /*
  80.  
  81. */
  82. long smooth(l,r,a)
  83.     scope_array *l,*r,*a;
  84. {
  85.     register float *f,*sf,*sf2,hval;
  86.     register int i,j;
  87.     int valfill,times=0;
  88.  
  89.     if (!l || !r) {
  90.         a->kind = DS_ERROR;
  91.         return(0);
  92.     }
  93.  
  94.     if (l->kind != DS_ARRAY
  95.         || r->kind != DS_CONSTANT) {   
  96.         a->kind = DS_ERROR;
  97.         return(0);
  98.     }
  99.  
  100.     hval = r->cval;
  101.     f = a->vals;
  102.     sf = l->vals;
  103.  
  104.     for (i=0; i< a->nrows; i++) 
  105.         for (j=0; j< a->ncols; j++)
  106.             *f++ = *sf++;            /* copy left to answer */
  107.  
  108.  
  109.     do {
  110.         times++;
  111.         valfill = 0;            /* default off, see if one got filled */
  112.  
  113.         f = sf = a->vals;
  114.         
  115.         for (i=1; i< a->nrows-1; i++,f+=2) 
  116.             for (j=1; j< a->ncols-1; j++,f++) {
  117.                 if (*f < hval + 1e-8 && *f > hval - 1e-8) {
  118.                     valfill = 1;
  119.                     *f = (*(f-1) + *(f+1) + *(f-a->ncols) + *(f+a->ncols))/4.0;
  120.                 }
  121.             }
  122.  
  123.  
  124.     } while (valfill && times < 50);
  125.     
  126.  
  127. }
  128.  
  129.  
  130. #include "math.h"
  131.  
  132. scos(l,r,a)
  133.     scope_array *l,*r,*a;
  134.     {
  135.     register int i,j,lim;
  136.     register float f,*sf;
  137.  
  138.     if (!l || !r) {
  139.         a->kind = DS_ERROR;
  140.         return(0);
  141.     }
  142.  
  143.     if (l->kind != DS_ARRAY) {
  144.         a->kind = DS_ERROR;
  145.         return(0);
  146.     }
  147.  
  148.  
  149.     sf = a->vals;
  150.     for (i=0; i<a->nrows; i++)
  151.         for (j=0; j<a->ncols; j++) {
  152.             f = sqrt((double)i*i + j*j)/a->ncols;
  153.  
  154.             *sf++ = sin(20.0*f);
  155.         }
  156. }
  157.  
  158.  
  159. nill(l,r,a)
  160.     scope_array *l,*r,*a;
  161.     {
  162.     char *p,*q;
  163.         int i;
  164.  
  165.     p = (char *)a->vals;
  166.     q = (char *)l->vals;
  167.  
  168.     for (i=0; i<4*a->nrows*a->ncols; i++)
  169.         *p++ = *q++;
  170.  
  171.  
  172. }
  173.