IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 889


Ignore:
Timestamp:
Jun 6, 2004, 2:32:53 PM (22 years ago)
Author:
gusciora
Message:

Lots of bug fixes and such.

Location:
trunk/psLib/src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psFunctions.c

    r845 r889  
    66 *  @author George Gusciora, MHPCC
    77 *
    8  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-04 01:03:11 $
     8 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-07 00:32:53 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7171 routines for generating both uniformly distributed numbers and the
    7272 Gaussian distribution as well.
     73 
     74 GUS: There is no way to seed the random generator.
    7375 *****************************************************************************/
    7476psVector *psGaussianDev(float mean,
     
    8284
    8385    gauss = psVectorAlloc(Npts, PS_TYPE_F32);
     86    gauss->n = Npts;
    8487    gsl_rng_env_setup();
    8588    T = gsl_rng_default;
     
    120123    newPoly->nY = nY;
    121124
    122     newPoly->coeff    = (float **) psAlloc(nX * sizeof(float));
    123     newPoly->coeffErr = (float **) psAlloc(nX * sizeof(float));
    124     newPoly->mask     = (char **)  psAlloc(nX * sizeof(char));
     125    newPoly->coeff    = (float **) psAlloc(nX * sizeof(float *));
     126    newPoly->coeffErr = (float **) psAlloc(nX * sizeof(float *));
     127    newPoly->mask     = (char **)  psAlloc(nX * sizeof(char *));
    125128    for (x=0;x<nX;x++) {
    126129        newPoly->coeff[x]    = (float *) psAlloc(nY * sizeof(float));
     
    129132    }
    130133
     134
    131135    return(newPoly);
    132136}
     
    143147    newPoly->nZ = nZ;
    144148
    145     newPoly->coeff    = (float ***) psAlloc(nX * sizeof(float));
    146     newPoly->coeffErr = (float ***) psAlloc(nX * sizeof(float));
    147     newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char));
     149    newPoly->coeff    = (float ***) psAlloc(nX * sizeof(float **));
     150    newPoly->coeffErr = (float ***) psAlloc(nX * sizeof(float **));
     151    newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char **));
    148152    for (x=0;x<nX;x++) {
    149         newPoly->coeff[x]    = (float **) psAlloc(nY * sizeof(float));
    150         newPoly->coeffErr[x] = (float **) psAlloc(nY * sizeof(float));
    151         newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char));
     153        newPoly->coeff[x]    = (float **) psAlloc(nY * sizeof(float *));
     154        newPoly->coeffErr[x] = (float **) psAlloc(nY * sizeof(float *));
     155        newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char *));
    152156        for (y=0;y<nY;y++) {
    153157            newPoly->coeff[x][y]    = (float *) psAlloc(nZ * sizeof(float));
     
    173177    newPoly->nZ = nZ;
    174178
    175     newPoly->coeff    = (float ****) psAlloc(nW * sizeof(float));
    176     newPoly->coeffErr = (float ****) psAlloc(nW * sizeof(float));
    177     newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char));
     179    newPoly->coeff    = (float ****) psAlloc(nW * sizeof(float ***));
     180    newPoly->coeffErr = (float ****) psAlloc(nW * sizeof(float ***));
     181    newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char ***));
    178182    for (w=0;w<nW;w++) {
    179         newPoly->coeff[w]    = (float ***) psAlloc(nX * sizeof(float));
    180         newPoly->coeffErr[w] = (float ***) psAlloc(nX * sizeof(float));
    181         newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char));
     183        newPoly->coeff[w]    = (float ***) psAlloc(nX * sizeof(float **));
     184        newPoly->coeffErr[w] = (float ***) psAlloc(nX * sizeof(float **));
     185        newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char **));
    182186        for (x=0;x<nX;x++) {
    183             newPoly->coeff[w][x]    = (float **) psAlloc(nY * sizeof(float));
    184             newPoly->coeffErr[w][x] = (float **) psAlloc(nY * sizeof(float));
    185             newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char));
     187            newPoly->coeff[w][x]    = (float **) psAlloc(nY * sizeof(float *));
     188            newPoly->coeffErr[w][x] = (float **) psAlloc(nY * sizeof(float *));
     189            newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char *));
    186190            for (y=0;y<nY;y++) {
    187191                newPoly->coeff[w][x][y]    = (float *) psAlloc(nZ * sizeof(float));
     
    410414    newPoly->nY = nY;
    411415
    412     newPoly->coeff    = (double **) psAlloc(nX * sizeof(double));
    413     newPoly->coeffErr = (double **) psAlloc(nX * sizeof(double));
    414     newPoly->mask     = (char **)  psAlloc(nX * sizeof(char));
     416    newPoly->coeff    = (double **) psAlloc(nX * sizeof(double *));
     417    newPoly->coeffErr = (double **) psAlloc(nX * sizeof(double *));
     418    newPoly->mask     = (char **)  psAlloc(nX * sizeof(char *));
    415419    for (x=0;x<nX;x++) {
    416420        newPoly->coeff[x]    = (double *) psAlloc(nY * sizeof(double));
     
    433437    newPoly->nZ = nZ;
    434438
    435     newPoly->coeff    = (double ***) psAlloc(nX * sizeof(double));
    436     newPoly->coeffErr = (double ***) psAlloc(nX * sizeof(double));
    437     newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char));
     439    newPoly->coeff    = (double ***) psAlloc(nX * sizeof(double **));
     440    newPoly->coeffErr = (double ***) psAlloc(nX * sizeof(double **));
     441    newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char **));
    438442    for (x=0;x<nX;x++) {
    439         newPoly->coeff[x]    = (double **) psAlloc(nY * sizeof(double));
    440         newPoly->coeffErr[x] = (double **) psAlloc(nY * sizeof(double));
    441         newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char));
     443        newPoly->coeff[x]    = (double **) psAlloc(nY * sizeof(double *));
     444        newPoly->coeffErr[x] = (double **) psAlloc(nY * sizeof(double *));
     445        newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char *));
    442446        for (y=0;y<nY;y++) {
    443447            newPoly->coeff[x][y]    = (double *) psAlloc(nZ * sizeof(double));
     
    463467    newPoly->nZ = nZ;
    464468
    465     newPoly->coeff    = (double ****) psAlloc(nW * sizeof(double));
    466     newPoly->coeffErr = (double ****) psAlloc(nW * sizeof(double));
    467     newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char));
     469    newPoly->coeff    = (double ****) psAlloc(nW * sizeof(double ***));
     470    newPoly->coeffErr = (double ****) psAlloc(nW * sizeof(double ***));
     471    newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char ***));
    468472    for (w=0;w<nW;w++) {
    469         newPoly->coeff[w]    = (double ***) psAlloc(nX * sizeof(double));
    470         newPoly->coeffErr[w] = (double ***) psAlloc(nX * sizeof(double));
    471         newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char));
     473        newPoly->coeff[w]    = (double ***) psAlloc(nX * sizeof(double **));
     474        newPoly->coeffErr[w] = (double ***) psAlloc(nX * sizeof(double **));
     475        newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char **));
    472476        for (x=0;x<nX;x++) {
    473             newPoly->coeff[w][x]    = (double **) psAlloc(nY * sizeof(double));
    474             newPoly->coeffErr[w][x] = (double **) psAlloc(nY * sizeof(double));
    475             newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char));
     477            newPoly->coeff[w][x]    = (double **) psAlloc(nY * sizeof(double *));
     478            newPoly->coeffErr[w][x] = (double **) psAlloc(nY * sizeof(double *));
     479            newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char *));
    476480            for (y=0;y<nY;y++) {
    477481                newPoly->coeff[w][x][y]    = (double *) psAlloc(nZ * sizeof(double));
  • trunk/psLib/src/dataManip/psFunctions.h

    r751 r889  
    1818          );
    1919
     20
     21psVector *psGaussianDev(float mean,
     22                        float sigma,
     23                        int Npts);
     24
    2025/*****************************************************************************/
    2126
     
    205210/** Evaluate 1D polynomial (double precision) */
    206211double
    207 psEvalDPolynomial1D(double x,  ///< Value at which to evaluate
     212psDEvalPolynomial1D(double x,  ///< Value at which to evaluate
    208213                    const psDPolynomial1D *myPoly ///< Coefficients for the polynomial
    209214                   );
     
    211216/** Evaluate 2D polynomial (double precision) */
    212217double
    213 psEvalDPolynomial2D(double x,  ///< Value x at which to evaluate
     218psDEvalPolynomial2D(double x,  ///< Value x at which to evaluate
    214219                    double y,  ///< Value y at which to evaluate
    215220                    const psDPolynomial2D *myPoly ///< Coefficients for the polynomial
     
    218223/** Evaluate 3D polynomial (double precision) */
    219224double
    220 psEvalDPolynomial3D(double x,  ///< Value x at which to evaluate
     225psDEvalPolynomial3D(double x,  ///< Value x at which to evaluate
    221226                    double y,  ///< Value y at which to evaluate
    222227                    double z,  ///< Value z at which to evaluate
     
    226231/** Evaluate 4D polynomial (double precision) */
    227232double
    228 psEvalDPolynomial4D(double w,  ///< Value w at which to evaluate
     233psDEvalPolynomial4D(double w,  ///< Value w at which to evaluate
    229234                    double x,  ///< Value x at which to evaluate
    230235                    double y,  ///< Value y at which to evaluate
  • trunk/psLib/src/dataManip/psStats.c

    r831 r889  
    8585    float binSize = 0.0;
    8686
     87    if (n == 0) {
     88        psAbort(__func__, "psHistogram requested with 0 bins");
     89    }
     90
    8791    newHist = (psHistogram *) psAlloc(sizeof(psHistogram));
    8892    newHist->bounds = psVectorAlloc(n+1, PS_TYPE_F32);
     93    newHist->bounds->n = newHist->bounds->nalloc;
     94
    8995    binSize = (upper - lower) / (float) n;
    9096    for (i=0;i<n+1;i++) {
     
    9298    }
    9399    newHist->nums =  psVectorAlloc(n, PS_TYPE_S32);
     100    newHist->nums->n = newHist->nums->nalloc;
     101    for (i=0;i<newHist->nums->n;i++) {
     102        newHist->nums->data.S32[i] = 0;
     103    }
    94104    newHist->minNum = 0;
    95105    newHist->maxNum = 0;
     
    99109}
    100110
    101 
     111// When this is called, the number of data elements in bounds
     112// is n.  Therefore, the number of bins is n-1.
    102113psHistogram *psHistogramAllocGeneric(const psVector *restrict bounds)
    103114{
     
    107118    newHist = (psHistogram *) psAlloc(sizeof(psHistogram));
    108119    newHist->bounds = psVectorAlloc(bounds->n, PS_TYPE_F32);
     120    newHist->bounds->n = newHist->bounds->nalloc;
    109121    for (i=0;i<bounds->n;i++) {
    110122        newHist->bounds->data.F32[i] = bounds->data.F32[i];
    111123    }
    112124    newHist->nums = psVectorAlloc((bounds->n)-1, PS_TYPE_S32);
     125    newHist->nums->n = newHist->nums->nalloc;
     126    for (i=0;i<newHist->nums->n;i++) {
     127        newHist->nums->data.S32[i] = 0;
     128    }
    113129
    114130    newHist->minNum = 0;
     
    119135}
    120136
    121 void psHistogramFree(psHistogram *restrict myHist)
    122 {
     137void psHistogramFree(psHistogram *myHist)
     138{
     139    psVectorFree(myHist->bounds);
     140    psVectorFree(myHist->nums);
    123141    psFree(myHist);
    124142}
     
    150168
    151169    numBins = out->nums->n;
    152     for (i=0;i<in->n;i++) {
    153         // Check if this pixel is masked, and if so, skip it.
    154         if (!(mask->data.S32[i] & maskVal)) {
    155             // Check if this pixel is below the minimum value, and if so
    156             // count it, then skip it.
     170
     171    if (mask != NULL) {
     172        for (i=0;i<in->n;i++) {
     173            // Check if this pixel is masked, and if so, skip it.
     174            if (!(mask->data.U8[i] & maskVal)) {
     175                // Check if this pixel is below the minimum value, and if so
     176                // count it, then skip it.
     177                if (in->data.F32[i] < out->bounds->data.F32[0]) {
     178                    out->minNum++;
     179
     180                    // Check if this pixel is above the maximum value, and if so
     181                    // count it, then skip it.
     182                } else if (in->data.F32[i] > out->bounds->data.F32[numBins]) {
     183                    out->maxNum++;
     184                } else {
     185                    // If this is a uniform histogram, determining the correct
     186                    // number is trivial.
     187                    if (out->uniform == true) {
     188                        binSize = out->bounds->data.F32[1] - out->bounds->data.F32[0];
     189
     190                        binNum = (int) ((in->data.F32[i] - out->bounds->data.F32[0]) /
     191                                        binSize);
     192                        (out->nums->data.S32[binNum])++;
     193                        // If this is a non-uniform histogram, determining the correct
     194                        // bin number requires a bit more work.
     195                    } else {
     196                        // GUS: This is slow.  Put a smarter algorithm here to
     197                        // find the correct bin number (bin search, probably)
     198                        for (j=0;j<(out->bounds->n)-1;j++) {
     199                            if ((out->bounds->data.S32[j] <= in->data.F32[i]) &&
     200                                    (in->data.F32[i] <= out->bounds->data.S32[j+1])) {
     201                                (out->nums->data.S32[j])++;
     202                            }
     203                        }
     204                    }
     205                }
     206            }
     207        }
     208    } else {
     209        for (i=0;i<in->n;i++) {
    157210            if (in->data.F32[i] < out->bounds->data.F32[0]) {
     211                // Check if this pixel is below the minimum value, and if so
     212                // count it, then skip it.
    158213                out->minNum++;
    159 
     214            } else if (in->data.F32[i] > out->bounds->data.F32[numBins]) {
    160215                // Check if this pixel is above the maximum value, and if so
    161216                // count it, then skip it.
    162             } else if (in->data.F32[i] > out->bounds->data.F32[numBins]) {
    163217                out->maxNum++;
    164218            } else {
     
    171225                                    binSize);
    172226                    (out->nums->data.S32[binNum])++;
     227
    173228                    // If this is a non-uniform histogram, determining the correct
    174229                    // bin number requires a bit more work.
     
    185240            }
    186241        }
     242
    187243    }
    188244    return(out);
     
    471527    unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
    472528    unsortedVector->n = unsortedVector->nalloc;
     529
    473530    sortedVector   = psVectorAlloc(nValues, PS_TYPE_F32);
    474531    sortedVector->n = sortedVector->nalloc;
     
    494551                if ((rangeMin <= myVector->data.F32[i]) &&
    495552                        (myVector->data.F32[i] <= rangeMax)) {
    496                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
     553                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
    497554                }
    498555            }
     
    504561            for (i=0;i<myVector->n;i++) {
    505562                if (!(maskVal & maskVector->data.U8[i])) {
    506                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
    507                 }
    508             }
    509         } else {
    510             for (i=0;i<myVector->n;i++) {
    511                 unsortedVector->data.F32[i] = maskVector->data.F32[i];
     563                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
     564                }
     565            }
     566        } else {
     567            for (i=0;i<myVector->n;i++) {
     568                unsortedVector->data.F32[i] = myVector->data.F32[i];
    512569            }
    513570        }
     
    596653    float rangeMin = 0.0;
    597654    float rangeMax = 0.0;
    598     psStats *stats2 = NULL;
    599655
    600656    // Determine if the number of data points exceed a threshold which will
    601657    // cause to generate robust stats, as opposed to exact stats.
    602     if (myVector->n > stats->sampleLimit) {
    603         // Calculate the robust quartiles.
    604         stats2 = psStatsAlloc(PS_STAT_ROBUST_QUARTILE);
    605         p_psVectorRobustStats(myVector, maskVector, maskVal, stats2);
    606 
    607         // Store the robust quartiles into the sample quartile members.
    608         stats->sampleUQ = stats2->robustUQ;
    609         stats->sampleLQ = stats2->robustLQ;
    610 
    611         // Free temporary data buffers.
    612         psStatsFree(stats2);
    613 
    614         // Set the PS_STAT_ROBUST_FOR_SAMPLE bit in the stats structure.
    615         stats->options = stats->options | PS_STAT_ROBUST_FOR_SAMPLE;
    616 
    617         return;
    618     }
     658    /* GUS: When IfA provides the algorithm, insert is here.
     659        if (myVector->n > stats->sampleLimit) {
     660            psStats *stats2 = NULL;
     661            // Calculate the robust quartiles.
     662            stats2 = psStatsAlloc(PS_STAT_ROBUST_QUARTILE);
     663            p_psVectorRobustStats(myVector, maskVector, maskVal, stats2);
     664     
     665            // Store the robust quartiles into the sample quartile members.
     666            stats->sampleUQ = stats2->robustUQ;
     667            stats->sampleLQ = stats2->robustLQ;
     668     
     669            // Free temporary data buffers.
     670            psStatsFree(stats2);
     671     
     672            // Set the PS_STAT_ROBUST_FOR_SAMPLE bit in the stats structure.
     673            stats->options = stats->options | PS_STAT_ROBUST_FOR_SAMPLE;
     674     
     675            return;
     676        }
     677    */
    619678
    620679    // Determine how many data points fit inside this min/max range
     
    640699                        (rangeMin <= myVector->data.F32[i]) &&
    641700                        (myVector->data.F32[i] <= rangeMax)) {
    642                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
     701                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
    643702                }
    644703            }
     
    647706                if ((rangeMin <= myVector->data.F32[i]) &&
    648707                        (myVector->data.F32[i] <= rangeMax)) {
    649                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
     708                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
    650709                }
    651710            }
     
    657716            for (i=0;i<myVector->n;i++) {
    658717                if (!(maskVal & maskVector->data.U8[i])) {
    659                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
    660                 }
    661             }
    662         } else {
    663             for (i=0;i<myVector->n;i++) {
    664                 unsortedVector->data.F32[i] = maskVector->data.F32[i];
     718                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
     719                }
     720            }
     721        } else {
     722            for (i=0;i<myVector->n;i++) {
     723                unsortedVector->data.F32[i] = myVector->data.F32[i];
    665724            }
    666725        }
     
    679738    psVectorFree(unsortedVector);
    680739    psVectorFree(sortedVector);
     740    // GUS: This is the
    681741}
    682742
     
    691751        PS_STAT_ROBUST_QUARTILE
    692752    I have included all that computation in a single function, as opposed to
    693     breaking it across several functions for one primary reason: the all
     753    breaking it across several functions for one primary reason: they all
    694754    require the same basic initial processing steps (calculate the histogram,
    695755    etc.) however there is no currently defined means, in the SDRS, to
     
    719779    // is really required.
    720780
    721     if (0.0 == stats->sampleUQ) {
    722 
    723         // GUS: fix this
    724         //        stats->options = stats->options | PS_STAT_SAMPLE_UQ;
     781    if (isnan(stats->sampleUQ) ||
     782            isnan(stats->sampleLQ)) {
     783        stats->options = stats->options | PS_STAT_SAMPLE_QUARTILE;
    725784        p_psVectorSampleQuartiles(myVector,
    726785                                  maskVector,
     
    729788    }
    730789
    731     if (isnan(stats->sampleLQ)) {
    732         // GUS: fix this
    733         //        stats->options = stats->options | PS_STAT_SAMPLE_LQ;
    734         p_psVectorSampleQuartiles(myVector,
    735                                   maskVector,
    736                                   maskVal,
    737                                   stats);
    738     }
    739 
    740790    // Compute the initial bin size of the robust histogram.
    741791    sigmaE = (stats->sampleUQ - stats->sampleLQ) / 1.34f;
     
    753803    robustHistogram = psHistogramAlloc(stats->min,
    754804                                       stats->max,
    755                                        binSize);
    756     // Populate the histogram arrat.
     805                                       1 + (int) ((stats->max - stats->min) / binSize));
     806
     807
     808    // Populate the histogram array.
    757809    // GUS: fix this
    758810    //    robustHistogram = psHistogramVector(robustHistogram, myVector);
     
    811863        stats->robustLQ = 0.0;
    812864    }
     865    stats->robustNfit = 0.0;
     866    stats->robustN50 = 0.0;
     867    psHistogramFree(robustHistogram);
    813868}
    814869
     
    836891
    837892    if (0 != isnan(stats->sampleMean)) {
    838         psAbort(__func__, "stats->sampleMean == NAN");
     893        p_psVectorSampleMean(myVector, maskVector, maskVal, stats);
    839894    }
    840895    mean = stats->sampleMean;
     
    920975    }
    921976
    922     tmpMask = psVectorAlloc(myVector->nalloc, maskVector->type.type);
    923 
    924     tmpMask->n = maskVector->n;
    925     for (i=0;i<tmpMask->n;i++) {
    926         tmpMask->data.U8[i] = maskVector->data.U8[i];
     977
     978    tmpMask = psVectorAlloc(myVector->n, PS_TYPE_U8);
     979    tmpMask->n = myVector->n;
     980
     981    if (maskVector != NULL) {
     982        for (i=0;i<tmpMask->n;i++) {
     983            tmpMask->data.U8[i] = maskVector->data.U8[i];
     984        }
    927985    }
    928986
    929987    // 1. Compute the sample median.
     988    // GUS: This seems odd.  Verify with IfA that we want to calculate the
     989    // median here, not the mean.
    930990    p_psVectorSampleMedian(myVector, maskVector, maskVal, stats);
    931991
     
    9421002
    9431003    for (i=0;i<stats->clipIter;i++) {
     1004        //        printf("p_psVectorClippedStats(): Iteration %d (%f %f)\n", i,
     1005        //                clippedMean, clippedStdev);
    9441006        for (j=0;j<myVector->n;j++) {
    9451007            // a) Exclude all values x_i for which |x_i - x| > K * stdev
    946             if ( fabs(myVector->data.F32[j] - clippedMean) >
     1008            if (fabs(myVector->data.F32[j] - clippedMean) >
    9471009                    (stats->clipSigma * clippedStdev)) {
    9481010                tmpMask->data.U8[i] = 0xff;
     
    9941056    if (in->type.type != PS_TYPE_F32) {
    9951057        psAbort(__func__,
    996                 "Only data type PS_TYPE_F32 is currently supported.");
    997     }
     1058                "Only data type PS_TYPE_F32 is currently supported (0x%x).",
     1059                in->type.type);
     1060    }
     1061
    9981062    if (mask != NULL) {
    9991063        if (in->n != mask->n) {
     
    10181082
    10191083    // ************************************************************************
     1084    // GUS: The Stdev calculation requires the mean.  Should we assume the
     1085    // mean has already been calculated?  Or should we always calculate it?
    10201086    if (stats->options & PS_STAT_SAMPLE_STDEV) {
     1087        p_psVectorSampleMean(in, mask, maskVal, stats);
    10211088        p_psVectorSampleStdev(in, mask, maskVal, stats);
    10221089    }
  • trunk/psLib/src/dataManip/psStats.h

    r797 r889  
    8181typedef struct
    8282{
    83     const psVector *restrict bounds; ///< Bounds for the bins (type F32)
     83    psVector *bounds;                ///< Bounds for the bins (type F32)
    8484    psVector *nums;                  ///< Number in each of the bins (INT)
    8585    int minNum;                      ///< Number below the minimum
     
    102102
    103103/** Destructor \ingroup MathGroup **/
    104 void psHistogramFree(psHistogram *restrict myHist);          ///< Histogram to destroy
     104void psHistogramFree(psHistogram *myHist);          ///< Histogram to destroy
    105105
    106106
  • trunk/psLib/src/image/psImage.c

    r859 r889  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-04 03:15:47 $
     11 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-07 00:32:53 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 *
     16 *  That is the routine used to generate matrices.
    1517 */
    1618
  • trunk/psLib/src/image/psImageStats.c

    r831 r889  
    1919
    2020/// This routine must determine the various statistics for the image.
     21/*****************************************************************************
     22    GUS: verify that image/mask have the
     23 correct types
     24 sizes
     25 *****************************************************************************/
    2126psStats *psImageStats(psStats *stats,
    2227                      psImage *in,
     
    2631    psVector *junkData=NULL;
    2732    psVector *junkMask=NULL;
     33    int ptr = 0;
     34    int i = 0;
     35    int j = 0;
    2836
    2937    junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type);
    30     junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type);
    31 
    32     // GUS: figure out mask types
    33     junkData->data.F32 = (float *) in->data.F32;
    34     junkMask->data.F32 = (float *) mask->data.F32;
    35     stats = psVectorStats(stats, junkData, junkMask, maskVal);
     38    junkData->n = junkData->nalloc;
     39    ptr=0;
     40    for (i=0;i<in->numRows;i++) {
     41        for (j=0;j<in->numCols;j++) {
     42            junkData->data.F32[ptr++] = in->data.F32[i][j];
     43        }
     44    }
     45
     46    if (mask != NULL) {
     47        // GUS: verify that mask data is PS_TYPE_U8.
     48        // GUS: figure out mask types
     49
     50        junkMask = psVectorAlloc(mask->numRows * mask->numCols,
     51                                 mask->type.type);
     52        junkMask->n = junkMask->nalloc;
     53        // GUS: Is there a more efficient way to do this?
     54        ptr=0;
     55        for (i=0;i<mask->numRows;i++) {
     56            for (j=0;j<mask->numCols;j++) {
     57                junkMask->data.U8[ptr++] = mask->data.U8[i][j];
     58            }
     59        }
     60
     61        stats = psVectorStats(stats, junkData, junkMask, maskVal);
     62        psVectorFree(junkMask);
     63    } else {
     64        stats = psVectorStats(stats, junkData, NULL, 0);
     65    }
    3666
    3767    psVectorFree(junkData);
    38     psVectorFree(junkMask);
    3968
    4069    return(stats);
     
    4473    NOTE: We assume that the psHistogram structure out has already been
    4574    allocated and initialized.
     75 
     76    GUS: verify that image/mask have the
     77 correct types
     78 sizes
    4679 *****************************************************************************/
    4780psHistogram *psImageHistogram(psHistogram *out,
     
    5285    psVector *junkData=NULL;
    5386    psVector *junkMask=NULL;
     87    int ptr = 0;
     88    int i = 0;
     89    int j = 0;
    5490
    5591    junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type);
    56     junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type);
    57 
    58     // GUS: figure out mask types
    59     junkData->data.F32 = (float *) in->data.F32;
    60     junkMask->data.F32 = (float *) mask->data.F32;
    61 
    62     out = psHistogramVector(out, junkData, junkMask, maskVal);
    63 
     92    junkData->n = junkData->nalloc;
     93
     94    // GUS: Is there a more efficient way to do this?  memcopy() won't work.
     95    // Can we trick the junkData structure to use the image buffer, then
     96    // untrick it before we deallocate it (so we won't deallocate that buffer
     97    // twice?
     98
     99    // GUS: Make sure you have the numRows/NumCols in the right place.
     100    ptr=0;
     101    for (i=0;i<in->numRows;i++) {
     102        for (j=0;j<in->numCols;j++) {
     103            junkData->data.F32[ptr++] = in->data.F32[i][j];
     104        }
     105    }
     106
     107    if (mask != NULL) {
     108        // GUS: verify that mask data is PS_TYPE_U8.
     109        // GUS: figure out mask types
     110
     111        junkMask = psVectorAlloc(mask->numRows * mask->numCols,
     112                                 mask->type.type);
     113        junkMask->n = junkMask->nalloc;
     114
     115        // GUS: Is there a more efficient way to do this?
     116        ptr=0;
     117        for (i=0;i<mask->numRows;i++) {
     118            for (j=0;j<mask->numCols;j++) {
     119                junkMask->data.U8[ptr++] = mask->data.U8[i][j];
     120            }
     121        }
     122        out = psHistogramVector(out, junkData, junkMask, maskVal);
     123        psVectorFree(junkMask);
     124    } else {
     125        out = psHistogramVector(out, junkData, NULL, 0);
     126    }
    64127    psVectorFree(junkData);
    65     psVectorFree(junkMask);
    66128
    67129    return(out);
     
    91153    int maxChebyPoly = 0;
    92154
     155
    93156    // Create the sums[][] data structure.  This will hold the LHS of equation
    94157    // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
     158
    95159    sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
    96160    for (i=0;i<coeffs->nX;i++) {
     
    105169    // Determine how many Chebyshev polynomials are needed, then create them.
    106170    maxChebyPoly = coeffs->nX;
    107     if (coeffs->nX > coeffs->nY) {
     171    if (coeffs->nY > coeffs->nX) {
    108172        maxChebyPoly = coeffs->nY;
    109173    }
     
    133197                                 psEvalPolynomial1D((float) x, chebPolys[i]) *
    134198                                 psEvalPolynomial1D((float) y, chebPolys[j]);
     199
    135200                }
    136201            }
     
    160225    }
    161226
    162 
    163227    // Free the Chebyshev polynomials that were created in this routine.
    164228    for (i=0;i<maxChebyPoly;i++) {
    165         psFree(chebPolys[i]);
    166     }
     229        psPolynomial1DFree(chebPolys[i]);
     230    }
     231    psFree(chebPolys);
     232
     233    // Free some data
     234    for (i=0;i<coeffs->nX;i++) {
     235        psFree(sums[i]);
     236    }
     237    psFree(sums);
    167238
    168239    return(coeffs);
     
    199270    // Determine how many Chebyshev polynomials are needed, then create them.
    200271    maxChebyPoly = coeffs->nX;
    201     if (coeffs->nX > coeffs->nY) {
     272    if (coeffs->nY > coeffs->nX) {
    202273        maxChebyPoly = coeffs->nY;
    203274    }
     
    219290        }
    220291    }
    221 
    222292
    223293    for (x=0;x<input->numRows;x++) {
     
    227297                for (j=0;j<coeffs->nY;j++) {
    228298                    polySum+= psEvalPolynomial1D((float)x, chebPolys[i]) *
    229                               psEvalPolynomial1D((float)y, chebPolys[y]) *
     299                              psEvalPolynomial1D((float)y, chebPolys[j]) *
    230300                              coeffs->coeff[i][j];
    231 
    232301                }
    233302            }
     
    236305    }
    237306
    238 
    239307    // Free the Chebyshev polynomials that were created in this routine.
    240308    for (i=0;i<maxChebyPoly;i++) {
    241         psFree(chebPolys[i]);
    242     }
     309        psPolynomial1DFree(chebPolys[i]);
     310    }
     311    psFree(chebPolys);
     312
     313    // Free some data
     314    for (i=0;i<coeffs->nX;i++) {
     315        psFree(sums[i]);
     316    }
     317    psFree(sums);
    243318
    244319    return(0);
  • trunk/psLib/src/imageops/psImageStats.c

    r831 r889  
    1919
    2020/// This routine must determine the various statistics for the image.
     21/*****************************************************************************
     22    GUS: verify that image/mask have the
     23 correct types
     24 sizes
     25 *****************************************************************************/
    2126psStats *psImageStats(psStats *stats,
    2227                      psImage *in,
     
    2631    psVector *junkData=NULL;
    2732    psVector *junkMask=NULL;
     33    int ptr = 0;
     34    int i = 0;
     35    int j = 0;
    2836
    2937    junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type);
    30     junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type);
    31 
    32     // GUS: figure out mask types
    33     junkData->data.F32 = (float *) in->data.F32;
    34     junkMask->data.F32 = (float *) mask->data.F32;
    35     stats = psVectorStats(stats, junkData, junkMask, maskVal);
     38    junkData->n = junkData->nalloc;
     39    ptr=0;
     40    for (i=0;i<in->numRows;i++) {
     41        for (j=0;j<in->numCols;j++) {
     42            junkData->data.F32[ptr++] = in->data.F32[i][j];
     43        }
     44    }
     45
     46    if (mask != NULL) {
     47        // GUS: verify that mask data is PS_TYPE_U8.
     48        // GUS: figure out mask types
     49
     50        junkMask = psVectorAlloc(mask->numRows * mask->numCols,
     51                                 mask->type.type);
     52        junkMask->n = junkMask->nalloc;
     53        // GUS: Is there a more efficient way to do this?
     54        ptr=0;
     55        for (i=0;i<mask->numRows;i++) {
     56            for (j=0;j<mask->numCols;j++) {
     57                junkMask->data.U8[ptr++] = mask->data.U8[i][j];
     58            }
     59        }
     60
     61        stats = psVectorStats(stats, junkData, junkMask, maskVal);
     62        psVectorFree(junkMask);
     63    } else {
     64        stats = psVectorStats(stats, junkData, NULL, 0);
     65    }
    3666
    3767    psVectorFree(junkData);
    38     psVectorFree(junkMask);
    3968
    4069    return(stats);
     
    4473    NOTE: We assume that the psHistogram structure out has already been
    4574    allocated and initialized.
     75 
     76    GUS: verify that image/mask have the
     77 correct types
     78 sizes
    4679 *****************************************************************************/
    4780psHistogram *psImageHistogram(psHistogram *out,
     
    5285    psVector *junkData=NULL;
    5386    psVector *junkMask=NULL;
     87    int ptr = 0;
     88    int i = 0;
     89    int j = 0;
    5490
    5591    junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type);
    56     junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type);
    57 
    58     // GUS: figure out mask types
    59     junkData->data.F32 = (float *) in->data.F32;
    60     junkMask->data.F32 = (float *) mask->data.F32;
    61 
    62     out = psHistogramVector(out, junkData, junkMask, maskVal);
    63 
     92    junkData->n = junkData->nalloc;
     93
     94    // GUS: Is there a more efficient way to do this?  memcopy() won't work.
     95    // Can we trick the junkData structure to use the image buffer, then
     96    // untrick it before we deallocate it (so we won't deallocate that buffer
     97    // twice?
     98
     99    // GUS: Make sure you have the numRows/NumCols in the right place.
     100    ptr=0;
     101    for (i=0;i<in->numRows;i++) {
     102        for (j=0;j<in->numCols;j++) {
     103            junkData->data.F32[ptr++] = in->data.F32[i][j];
     104        }
     105    }
     106
     107    if (mask != NULL) {
     108        // GUS: verify that mask data is PS_TYPE_U8.
     109        // GUS: figure out mask types
     110
     111        junkMask = psVectorAlloc(mask->numRows * mask->numCols,
     112                                 mask->type.type);
     113        junkMask->n = junkMask->nalloc;
     114
     115        // GUS: Is there a more efficient way to do this?
     116        ptr=0;
     117        for (i=0;i<mask->numRows;i++) {
     118            for (j=0;j<mask->numCols;j++) {
     119                junkMask->data.U8[ptr++] = mask->data.U8[i][j];
     120            }
     121        }
     122        out = psHistogramVector(out, junkData, junkMask, maskVal);
     123        psVectorFree(junkMask);
     124    } else {
     125        out = psHistogramVector(out, junkData, NULL, 0);
     126    }
    64127    psVectorFree(junkData);
    65     psVectorFree(junkMask);
    66128
    67129    return(out);
     
    91153    int maxChebyPoly = 0;
    92154
     155
    93156    // Create the sums[][] data structure.  This will hold the LHS of equation
    94157    // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
     158
    95159    sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
    96160    for (i=0;i<coeffs->nX;i++) {
     
    105169    // Determine how many Chebyshev polynomials are needed, then create them.
    106170    maxChebyPoly = coeffs->nX;
    107     if (coeffs->nX > coeffs->nY) {
     171    if (coeffs->nY > coeffs->nX) {
    108172        maxChebyPoly = coeffs->nY;
    109173    }
     
    133197                                 psEvalPolynomial1D((float) x, chebPolys[i]) *
    134198                                 psEvalPolynomial1D((float) y, chebPolys[j]);
     199
    135200                }
    136201            }
     
    160225    }
    161226
    162 
    163227    // Free the Chebyshev polynomials that were created in this routine.
    164228    for (i=0;i<maxChebyPoly;i++) {
    165         psFree(chebPolys[i]);
    166     }
     229        psPolynomial1DFree(chebPolys[i]);
     230    }
     231    psFree(chebPolys);
     232
     233    // Free some data
     234    for (i=0;i<coeffs->nX;i++) {
     235        psFree(sums[i]);
     236    }
     237    psFree(sums);
    167238
    168239    return(coeffs);
     
    199270    // Determine how many Chebyshev polynomials are needed, then create them.
    200271    maxChebyPoly = coeffs->nX;
    201     if (coeffs->nX > coeffs->nY) {
     272    if (coeffs->nY > coeffs->nX) {
    202273        maxChebyPoly = coeffs->nY;
    203274    }
     
    219290        }
    220291    }
    221 
    222292
    223293    for (x=0;x<input->numRows;x++) {
     
    227297                for (j=0;j<coeffs->nY;j++) {
    228298                    polySum+= psEvalPolynomial1D((float)x, chebPolys[i]) *
    229                               psEvalPolynomial1D((float)y, chebPolys[y]) *
     299                              psEvalPolynomial1D((float)y, chebPolys[j]) *
    230300                              coeffs->coeff[i][j];
    231 
    232301                }
    233302            }
     
    236305    }
    237306
    238 
    239307    // Free the Chebyshev polynomials that were created in this routine.
    240308    for (i=0;i<maxChebyPoly;i++) {
    241         psFree(chebPolys[i]);
    242     }
     309        psPolynomial1DFree(chebPolys[i]);
     310    }
     311    psFree(chebPolys);
     312
     313    // Free some data
     314    for (i=0;i<coeffs->nX;i++) {
     315        psFree(sums[i]);
     316    }
     317    psFree(sums);
    243318
    244319    return(0);
  • trunk/psLib/src/math/psPolynomial.c

    r845 r889  
    66 *  @author George Gusciora, MHPCC
    77 *
    8  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-04 01:03:11 $
     8 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-07 00:32:53 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7171 routines for generating both uniformly distributed numbers and the
    7272 Gaussian distribution as well.
     73 
     74 GUS: There is no way to seed the random generator.
    7375 *****************************************************************************/
    7476psVector *psGaussianDev(float mean,
     
    8284
    8385    gauss = psVectorAlloc(Npts, PS_TYPE_F32);
     86    gauss->n = Npts;
    8487    gsl_rng_env_setup();
    8588    T = gsl_rng_default;
     
    120123    newPoly->nY = nY;
    121124
    122     newPoly->coeff    = (float **) psAlloc(nX * sizeof(float));
    123     newPoly->coeffErr = (float **) psAlloc(nX * sizeof(float));
    124     newPoly->mask     = (char **)  psAlloc(nX * sizeof(char));
     125    newPoly->coeff    = (float **) psAlloc(nX * sizeof(float *));
     126    newPoly->coeffErr = (float **) psAlloc(nX * sizeof(float *));
     127    newPoly->mask     = (char **)  psAlloc(nX * sizeof(char *));
    125128    for (x=0;x<nX;x++) {
    126129        newPoly->coeff[x]    = (float *) psAlloc(nY * sizeof(float));
     
    129132    }
    130133
     134
    131135    return(newPoly);
    132136}
     
    143147    newPoly->nZ = nZ;
    144148
    145     newPoly->coeff    = (float ***) psAlloc(nX * sizeof(float));
    146     newPoly->coeffErr = (float ***) psAlloc(nX * sizeof(float));
    147     newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char));
     149    newPoly->coeff    = (float ***) psAlloc(nX * sizeof(float **));
     150    newPoly->coeffErr = (float ***) psAlloc(nX * sizeof(float **));
     151    newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char **));
    148152    for (x=0;x<nX;x++) {
    149         newPoly->coeff[x]    = (float **) psAlloc(nY * sizeof(float));
    150         newPoly->coeffErr[x] = (float **) psAlloc(nY * sizeof(float));
    151         newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char));
     153        newPoly->coeff[x]    = (float **) psAlloc(nY * sizeof(float *));
     154        newPoly->coeffErr[x] = (float **) psAlloc(nY * sizeof(float *));
     155        newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char *));
    152156        for (y=0;y<nY;y++) {
    153157            newPoly->coeff[x][y]    = (float *) psAlloc(nZ * sizeof(float));
     
    173177    newPoly->nZ = nZ;
    174178
    175     newPoly->coeff    = (float ****) psAlloc(nW * sizeof(float));
    176     newPoly->coeffErr = (float ****) psAlloc(nW * sizeof(float));
    177     newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char));
     179    newPoly->coeff    = (float ****) psAlloc(nW * sizeof(float ***));
     180    newPoly->coeffErr = (float ****) psAlloc(nW * sizeof(float ***));
     181    newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char ***));
    178182    for (w=0;w<nW;w++) {
    179         newPoly->coeff[w]    = (float ***) psAlloc(nX * sizeof(float));
    180         newPoly->coeffErr[w] = (float ***) psAlloc(nX * sizeof(float));
    181         newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char));
     183        newPoly->coeff[w]    = (float ***) psAlloc(nX * sizeof(float **));
     184        newPoly->coeffErr[w] = (float ***) psAlloc(nX * sizeof(float **));
     185        newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char **));
    182186        for (x=0;x<nX;x++) {
    183             newPoly->coeff[w][x]    = (float **) psAlloc(nY * sizeof(float));
    184             newPoly->coeffErr[w][x] = (float **) psAlloc(nY * sizeof(float));
    185             newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char));
     187            newPoly->coeff[w][x]    = (float **) psAlloc(nY * sizeof(float *));
     188            newPoly->coeffErr[w][x] = (float **) psAlloc(nY * sizeof(float *));
     189            newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char *));
    186190            for (y=0;y<nY;y++) {
    187191                newPoly->coeff[w][x][y]    = (float *) psAlloc(nZ * sizeof(float));
     
    410414    newPoly->nY = nY;
    411415
    412     newPoly->coeff    = (double **) psAlloc(nX * sizeof(double));
    413     newPoly->coeffErr = (double **) psAlloc(nX * sizeof(double));
    414     newPoly->mask     = (char **)  psAlloc(nX * sizeof(char));
     416    newPoly->coeff    = (double **) psAlloc(nX * sizeof(double *));
     417    newPoly->coeffErr = (double **) psAlloc(nX * sizeof(double *));
     418    newPoly->mask     = (char **)  psAlloc(nX * sizeof(char *));
    415419    for (x=0;x<nX;x++) {
    416420        newPoly->coeff[x]    = (double *) psAlloc(nY * sizeof(double));
     
    433437    newPoly->nZ = nZ;
    434438
    435     newPoly->coeff    = (double ***) psAlloc(nX * sizeof(double));
    436     newPoly->coeffErr = (double ***) psAlloc(nX * sizeof(double));
    437     newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char));
     439    newPoly->coeff    = (double ***) psAlloc(nX * sizeof(double **));
     440    newPoly->coeffErr = (double ***) psAlloc(nX * sizeof(double **));
     441    newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char **));
    438442    for (x=0;x<nX;x++) {
    439         newPoly->coeff[x]    = (double **) psAlloc(nY * sizeof(double));
    440         newPoly->coeffErr[x] = (double **) psAlloc(nY * sizeof(double));
    441         newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char));
     443        newPoly->coeff[x]    = (double **) psAlloc(nY * sizeof(double *));
     444        newPoly->coeffErr[x] = (double **) psAlloc(nY * sizeof(double *));
     445        newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char *));
    442446        for (y=0;y<nY;y++) {
    443447            newPoly->coeff[x][y]    = (double *) psAlloc(nZ * sizeof(double));
     
    463467    newPoly->nZ = nZ;
    464468
    465     newPoly->coeff    = (double ****) psAlloc(nW * sizeof(double));
    466     newPoly->coeffErr = (double ****) psAlloc(nW * sizeof(double));
    467     newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char));
     469    newPoly->coeff    = (double ****) psAlloc(nW * sizeof(double ***));
     470    newPoly->coeffErr = (double ****) psAlloc(nW * sizeof(double ***));
     471    newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char ***));
    468472    for (w=0;w<nW;w++) {
    469         newPoly->coeff[w]    = (double ***) psAlloc(nX * sizeof(double));
    470         newPoly->coeffErr[w] = (double ***) psAlloc(nX * sizeof(double));
    471         newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char));
     473        newPoly->coeff[w]    = (double ***) psAlloc(nX * sizeof(double **));
     474        newPoly->coeffErr[w] = (double ***) psAlloc(nX * sizeof(double **));
     475        newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char **));
    472476        for (x=0;x<nX;x++) {
    473             newPoly->coeff[w][x]    = (double **) psAlloc(nY * sizeof(double));
    474             newPoly->coeffErr[w][x] = (double **) psAlloc(nY * sizeof(double));
    475             newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char));
     477            newPoly->coeff[w][x]    = (double **) psAlloc(nY * sizeof(double *));
     478            newPoly->coeffErr[w][x] = (double **) psAlloc(nY * sizeof(double *));
     479            newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char *));
    476480            for (y=0;y<nY;y++) {
    477481                newPoly->coeff[w][x][y]    = (double *) psAlloc(nZ * sizeof(double));
  • trunk/psLib/src/math/psPolynomial.h

    r751 r889  
    1818          );
    1919
     20
     21psVector *psGaussianDev(float mean,
     22                        float sigma,
     23                        int Npts);
     24
    2025/*****************************************************************************/
    2126
     
    205210/** Evaluate 1D polynomial (double precision) */
    206211double
    207 psEvalDPolynomial1D(double x,  ///< Value at which to evaluate
     212psDEvalPolynomial1D(double x,  ///< Value at which to evaluate
    208213                    const psDPolynomial1D *myPoly ///< Coefficients for the polynomial
    209214                   );
     
    211216/** Evaluate 2D polynomial (double precision) */
    212217double
    213 psEvalDPolynomial2D(double x,  ///< Value x at which to evaluate
     218psDEvalPolynomial2D(double x,  ///< Value x at which to evaluate
    214219                    double y,  ///< Value y at which to evaluate
    215220                    const psDPolynomial2D *myPoly ///< Coefficients for the polynomial
     
    218223/** Evaluate 3D polynomial (double precision) */
    219224double
    220 psEvalDPolynomial3D(double x,  ///< Value x at which to evaluate
     225psDEvalPolynomial3D(double x,  ///< Value x at which to evaluate
    221226                    double y,  ///< Value y at which to evaluate
    222227                    double z,  ///< Value z at which to evaluate
     
    226231/** Evaluate 4D polynomial (double precision) */
    227232double
    228 psEvalDPolynomial4D(double w,  ///< Value w at which to evaluate
     233psDEvalPolynomial4D(double w,  ///< Value w at which to evaluate
    229234                    double x,  ///< Value x at which to evaluate
    230235                    double y,  ///< Value y at which to evaluate
  • trunk/psLib/src/math/psSpline.c

    r845 r889  
    66 *  @author George Gusciora, MHPCC
    77 *
    8  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-04 01:03:11 $
     8 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-07 00:32:53 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7171 routines for generating both uniformly distributed numbers and the
    7272 Gaussian distribution as well.
     73 
     74 GUS: There is no way to seed the random generator.
    7375 *****************************************************************************/
    7476psVector *psGaussianDev(float mean,
     
    8284
    8385    gauss = psVectorAlloc(Npts, PS_TYPE_F32);
     86    gauss->n = Npts;
    8487    gsl_rng_env_setup();
    8588    T = gsl_rng_default;
     
    120123    newPoly->nY = nY;
    121124
    122     newPoly->coeff    = (float **) psAlloc(nX * sizeof(float));
    123     newPoly->coeffErr = (float **) psAlloc(nX * sizeof(float));
    124     newPoly->mask     = (char **)  psAlloc(nX * sizeof(char));
     125    newPoly->coeff    = (float **) psAlloc(nX * sizeof(float *));
     126    newPoly->coeffErr = (float **) psAlloc(nX * sizeof(float *));
     127    newPoly->mask     = (char **)  psAlloc(nX * sizeof(char *));
    125128    for (x=0;x<nX;x++) {
    126129        newPoly->coeff[x]    = (float *) psAlloc(nY * sizeof(float));
     
    129132    }
    130133
     134
    131135    return(newPoly);
    132136}
     
    143147    newPoly->nZ = nZ;
    144148
    145     newPoly->coeff    = (float ***) psAlloc(nX * sizeof(float));
    146     newPoly->coeffErr = (float ***) psAlloc(nX * sizeof(float));
    147     newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char));
     149    newPoly->coeff    = (float ***) psAlloc(nX * sizeof(float **));
     150    newPoly->coeffErr = (float ***) psAlloc(nX * sizeof(float **));
     151    newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char **));
    148152    for (x=0;x<nX;x++) {
    149         newPoly->coeff[x]    = (float **) psAlloc(nY * sizeof(float));
    150         newPoly->coeffErr[x] = (float **) psAlloc(nY * sizeof(float));
    151         newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char));
     153        newPoly->coeff[x]    = (float **) psAlloc(nY * sizeof(float *));
     154        newPoly->coeffErr[x] = (float **) psAlloc(nY * sizeof(float *));
     155        newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char *));
    152156        for (y=0;y<nY;y++) {
    153157            newPoly->coeff[x][y]    = (float *) psAlloc(nZ * sizeof(float));
     
    173177    newPoly->nZ = nZ;
    174178
    175     newPoly->coeff    = (float ****) psAlloc(nW * sizeof(float));
    176     newPoly->coeffErr = (float ****) psAlloc(nW * sizeof(float));
    177     newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char));
     179    newPoly->coeff    = (float ****) psAlloc(nW * sizeof(float ***));
     180    newPoly->coeffErr = (float ****) psAlloc(nW * sizeof(float ***));
     181    newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char ***));
    178182    for (w=0;w<nW;w++) {
    179         newPoly->coeff[w]    = (float ***) psAlloc(nX * sizeof(float));
    180         newPoly->coeffErr[w] = (float ***) psAlloc(nX * sizeof(float));
    181         newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char));
     183        newPoly->coeff[w]    = (float ***) psAlloc(nX * sizeof(float **));
     184        newPoly->coeffErr[w] = (float ***) psAlloc(nX * sizeof(float **));
     185        newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char **));
    182186        for (x=0;x<nX;x++) {
    183             newPoly->coeff[w][x]    = (float **) psAlloc(nY * sizeof(float));
    184             newPoly->coeffErr[w][x] = (float **) psAlloc(nY * sizeof(float));
    185             newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char));
     187            newPoly->coeff[w][x]    = (float **) psAlloc(nY * sizeof(float *));
     188            newPoly->coeffErr[w][x] = (float **) psAlloc(nY * sizeof(float *));
     189            newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char *));
    186190            for (y=0;y<nY;y++) {
    187191                newPoly->coeff[w][x][y]    = (float *) psAlloc(nZ * sizeof(float));
     
    410414    newPoly->nY = nY;
    411415
    412     newPoly->coeff    = (double **) psAlloc(nX * sizeof(double));
    413     newPoly->coeffErr = (double **) psAlloc(nX * sizeof(double));
    414     newPoly->mask     = (char **)  psAlloc(nX * sizeof(char));
     416    newPoly->coeff    = (double **) psAlloc(nX * sizeof(double *));
     417    newPoly->coeffErr = (double **) psAlloc(nX * sizeof(double *));
     418    newPoly->mask     = (char **)  psAlloc(nX * sizeof(char *));
    415419    for (x=0;x<nX;x++) {
    416420        newPoly->coeff[x]    = (double *) psAlloc(nY * sizeof(double));
     
    433437    newPoly->nZ = nZ;
    434438
    435     newPoly->coeff    = (double ***) psAlloc(nX * sizeof(double));
    436     newPoly->coeffErr = (double ***) psAlloc(nX * sizeof(double));
    437     newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char));
     439    newPoly->coeff    = (double ***) psAlloc(nX * sizeof(double **));
     440    newPoly->coeffErr = (double ***) psAlloc(nX * sizeof(double **));
     441    newPoly->mask     = (char ***)  psAlloc(nX * sizeof(char **));
    438442    for (x=0;x<nX;x++) {
    439         newPoly->coeff[x]    = (double **) psAlloc(nY * sizeof(double));
    440         newPoly->coeffErr[x] = (double **) psAlloc(nY * sizeof(double));
    441         newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char));
     443        newPoly->coeff[x]    = (double **) psAlloc(nY * sizeof(double *));
     444        newPoly->coeffErr[x] = (double **) psAlloc(nY * sizeof(double *));
     445        newPoly->mask[x]     = (char **)  psAlloc(nY * sizeof(char *));
    442446        for (y=0;y<nY;y++) {
    443447            newPoly->coeff[x][y]    = (double *) psAlloc(nZ * sizeof(double));
     
    463467    newPoly->nZ = nZ;
    464468
    465     newPoly->coeff    = (double ****) psAlloc(nW * sizeof(double));
    466     newPoly->coeffErr = (double ****) psAlloc(nW * sizeof(double));
    467     newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char));
     469    newPoly->coeff    = (double ****) psAlloc(nW * sizeof(double ***));
     470    newPoly->coeffErr = (double ****) psAlloc(nW * sizeof(double ***));
     471    newPoly->mask     = (char ****)  psAlloc(nW * sizeof(char ***));
    468472    for (w=0;w<nW;w++) {
    469         newPoly->coeff[w]    = (double ***) psAlloc(nX * sizeof(double));
    470         newPoly->coeffErr[w] = (double ***) psAlloc(nX * sizeof(double));
    471         newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char));
     473        newPoly->coeff[w]    = (double ***) psAlloc(nX * sizeof(double **));
     474        newPoly->coeffErr[w] = (double ***) psAlloc(nX * sizeof(double **));
     475        newPoly->mask[w]     = (char ***)  psAlloc(nX * sizeof(char **));
    472476        for (x=0;x<nX;x++) {
    473             newPoly->coeff[w][x]    = (double **) psAlloc(nY * sizeof(double));
    474             newPoly->coeffErr[w][x] = (double **) psAlloc(nY * sizeof(double));
    475             newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char));
     477            newPoly->coeff[w][x]    = (double **) psAlloc(nY * sizeof(double *));
     478            newPoly->coeffErr[w][x] = (double **) psAlloc(nY * sizeof(double *));
     479            newPoly->mask[w][x]     = (char **) psAlloc(nY * sizeof(char *));
    476480            for (y=0;y<nY;y++) {
    477481                newPoly->coeff[w][x][y]    = (double *) psAlloc(nZ * sizeof(double));
  • trunk/psLib/src/math/psSpline.h

    r751 r889  
    1818          );
    1919
     20
     21psVector *psGaussianDev(float mean,
     22                        float sigma,
     23                        int Npts);
     24
    2025/*****************************************************************************/
    2126
     
    205210/** Evaluate 1D polynomial (double precision) */
    206211double
    207 psEvalDPolynomial1D(double x,  ///< Value at which to evaluate
     212psDEvalPolynomial1D(double x,  ///< Value at which to evaluate
    208213                    const psDPolynomial1D *myPoly ///< Coefficients for the polynomial
    209214                   );
     
    211216/** Evaluate 2D polynomial (double precision) */
    212217double
    213 psEvalDPolynomial2D(double x,  ///< Value x at which to evaluate
     218psDEvalPolynomial2D(double x,  ///< Value x at which to evaluate
    214219                    double y,  ///< Value y at which to evaluate
    215220                    const psDPolynomial2D *myPoly ///< Coefficients for the polynomial
     
    218223/** Evaluate 3D polynomial (double precision) */
    219224double
    220 psEvalDPolynomial3D(double x,  ///< Value x at which to evaluate
     225psDEvalPolynomial3D(double x,  ///< Value x at which to evaluate
    221226                    double y,  ///< Value y at which to evaluate
    222227                    double z,  ///< Value z at which to evaluate
     
    226231/** Evaluate 4D polynomial (double precision) */
    227232double
    228 psEvalDPolynomial4D(double w,  ///< Value w at which to evaluate
     233psDEvalPolynomial4D(double w,  ///< Value w at which to evaluate
    229234                    double x,  ///< Value x at which to evaluate
    230235                    double y,  ///< Value y at which to evaluate
  • trunk/psLib/src/math/psStats.c

    r831 r889  
    8585    float binSize = 0.0;
    8686
     87    if (n == 0) {
     88        psAbort(__func__, "psHistogram requested with 0 bins");
     89    }
     90
    8791    newHist = (psHistogram *) psAlloc(sizeof(psHistogram));
    8892    newHist->bounds = psVectorAlloc(n+1, PS_TYPE_F32);
     93    newHist->bounds->n = newHist->bounds->nalloc;
     94
    8995    binSize = (upper - lower) / (float) n;
    9096    for (i=0;i<n+1;i++) {
     
    9298    }
    9399    newHist->nums =  psVectorAlloc(n, PS_TYPE_S32);
     100    newHist->nums->n = newHist->nums->nalloc;
     101    for (i=0;i<newHist->nums->n;i++) {
     102        newHist->nums->data.S32[i] = 0;
     103    }
    94104    newHist->minNum = 0;
    95105    newHist->maxNum = 0;
     
    99109}
    100110
    101 
     111// When this is called, the number of data elements in bounds
     112// is n.  Therefore, the number of bins is n-1.
    102113psHistogram *psHistogramAllocGeneric(const psVector *restrict bounds)
    103114{
     
    107118    newHist = (psHistogram *) psAlloc(sizeof(psHistogram));
    108119    newHist->bounds = psVectorAlloc(bounds->n, PS_TYPE_F32);
     120    newHist->bounds->n = newHist->bounds->nalloc;
    109121    for (i=0;i<bounds->n;i++) {
    110122        newHist->bounds->data.F32[i] = bounds->data.F32[i];
    111123    }
    112124    newHist->nums = psVectorAlloc((bounds->n)-1, PS_TYPE_S32);
     125    newHist->nums->n = newHist->nums->nalloc;
     126    for (i=0;i<newHist->nums->n;i++) {
     127        newHist->nums->data.S32[i] = 0;
     128    }
    113129
    114130    newHist->minNum = 0;
     
    119135}
    120136
    121 void psHistogramFree(psHistogram *restrict myHist)
    122 {
     137void psHistogramFree(psHistogram *myHist)
     138{
     139    psVectorFree(myHist->bounds);
     140    psVectorFree(myHist->nums);
    123141    psFree(myHist);
    124142}
     
    150168
    151169    numBins = out->nums->n;
    152     for (i=0;i<in->n;i++) {
    153         // Check if this pixel is masked, and if so, skip it.
    154         if (!(mask->data.S32[i] & maskVal)) {
    155             // Check if this pixel is below the minimum value, and if so
    156             // count it, then skip it.
     170
     171    if (mask != NULL) {
     172        for (i=0;i<in->n;i++) {
     173            // Check if this pixel is masked, and if so, skip it.
     174            if (!(mask->data.U8[i] & maskVal)) {
     175                // Check if this pixel is below the minimum value, and if so
     176                // count it, then skip it.
     177                if (in->data.F32[i] < out->bounds->data.F32[0]) {
     178                    out->minNum++;
     179
     180                    // Check if this pixel is above the maximum value, and if so
     181                    // count it, then skip it.
     182                } else if (in->data.F32[i] > out->bounds->data.F32[numBins]) {
     183                    out->maxNum++;
     184                } else {
     185                    // If this is a uniform histogram, determining the correct
     186                    // number is trivial.
     187                    if (out->uniform == true) {
     188                        binSize = out->bounds->data.F32[1] - out->bounds->data.F32[0];
     189
     190                        binNum = (int) ((in->data.F32[i] - out->bounds->data.F32[0]) /
     191                                        binSize);
     192                        (out->nums->data.S32[binNum])++;
     193                        // If this is a non-uniform histogram, determining the correct
     194                        // bin number requires a bit more work.
     195                    } else {
     196                        // GUS: This is slow.  Put a smarter algorithm here to
     197                        // find the correct bin number (bin search, probably)
     198                        for (j=0;j<(out->bounds->n)-1;j++) {
     199                            if ((out->bounds->data.S32[j] <= in->data.F32[i]) &&
     200                                    (in->data.F32[i] <= out->bounds->data.S32[j+1])) {
     201                                (out->nums->data.S32[j])++;
     202                            }
     203                        }
     204                    }
     205                }
     206            }
     207        }
     208    } else {
     209        for (i=0;i<in->n;i++) {
    157210            if (in->data.F32[i] < out->bounds->data.F32[0]) {
     211                // Check if this pixel is below the minimum value, and if so
     212                // count it, then skip it.
    158213                out->minNum++;
    159 
     214            } else if (in->data.F32[i] > out->bounds->data.F32[numBins]) {
    160215                // Check if this pixel is above the maximum value, and if so
    161216                // count it, then skip it.
    162             } else if (in->data.F32[i] > out->bounds->data.F32[numBins]) {
    163217                out->maxNum++;
    164218            } else {
     
    171225                                    binSize);
    172226                    (out->nums->data.S32[binNum])++;
     227
    173228                    // If this is a non-uniform histogram, determining the correct
    174229                    // bin number requires a bit more work.
     
    185240            }
    186241        }
     242
    187243    }
    188244    return(out);
     
    471527    unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
    472528    unsortedVector->n = unsortedVector->nalloc;
     529
    473530    sortedVector   = psVectorAlloc(nValues, PS_TYPE_F32);
    474531    sortedVector->n = sortedVector->nalloc;
     
    494551                if ((rangeMin <= myVector->data.F32[i]) &&
    495552                        (myVector->data.F32[i] <= rangeMax)) {
    496                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
     553                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
    497554                }
    498555            }
     
    504561            for (i=0;i<myVector->n;i++) {
    505562                if (!(maskVal & maskVector->data.U8[i])) {
    506                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
    507                 }
    508             }
    509         } else {
    510             for (i=0;i<myVector->n;i++) {
    511                 unsortedVector->data.F32[i] = maskVector->data.F32[i];
     563                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
     564                }
     565            }
     566        } else {
     567            for (i=0;i<myVector->n;i++) {
     568                unsortedVector->data.F32[i] = myVector->data.F32[i];
    512569            }
    513570        }
     
    596653    float rangeMin = 0.0;
    597654    float rangeMax = 0.0;
    598     psStats *stats2 = NULL;
    599655
    600656    // Determine if the number of data points exceed a threshold which will
    601657    // cause to generate robust stats, as opposed to exact stats.
    602     if (myVector->n > stats->sampleLimit) {
    603         // Calculate the robust quartiles.
    604         stats2 = psStatsAlloc(PS_STAT_ROBUST_QUARTILE);
    605         p_psVectorRobustStats(myVector, maskVector, maskVal, stats2);
    606 
    607         // Store the robust quartiles into the sample quartile members.
    608         stats->sampleUQ = stats2->robustUQ;
    609         stats->sampleLQ = stats2->robustLQ;
    610 
    611         // Free temporary data buffers.
    612         psStatsFree(stats2);
    613 
    614         // Set the PS_STAT_ROBUST_FOR_SAMPLE bit in the stats structure.
    615         stats->options = stats->options | PS_STAT_ROBUST_FOR_SAMPLE;
    616 
    617         return;
    618     }
     658    /* GUS: When IfA provides the algorithm, insert is here.
     659        if (myVector->n > stats->sampleLimit) {
     660            psStats *stats2 = NULL;
     661            // Calculate the robust quartiles.
     662            stats2 = psStatsAlloc(PS_STAT_ROBUST_QUARTILE);
     663            p_psVectorRobustStats(myVector, maskVector, maskVal, stats2);
     664     
     665            // Store the robust quartiles into the sample quartile members.
     666            stats->sampleUQ = stats2->robustUQ;
     667            stats->sampleLQ = stats2->robustLQ;
     668     
     669            // Free temporary data buffers.
     670            psStatsFree(stats2);
     671     
     672            // Set the PS_STAT_ROBUST_FOR_SAMPLE bit in the stats structure.
     673            stats->options = stats->options | PS_STAT_ROBUST_FOR_SAMPLE;
     674     
     675            return;
     676        }
     677    */
    619678
    620679    // Determine how many data points fit inside this min/max range
     
    640699                        (rangeMin <= myVector->data.F32[i]) &&
    641700                        (myVector->data.F32[i] <= rangeMax)) {
    642                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
     701                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
    643702                }
    644703            }
     
    647706                if ((rangeMin <= myVector->data.F32[i]) &&
    648707                        (myVector->data.F32[i] <= rangeMax)) {
    649                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
     708                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
    650709                }
    651710            }
     
    657716            for (i=0;i<myVector->n;i++) {
    658717                if (!(maskVal & maskVector->data.U8[i])) {
    659                     unsortedVector->data.F32[count++] = maskVector->data.F32[i];
    660                 }
    661             }
    662         } else {
    663             for (i=0;i<myVector->n;i++) {
    664                 unsortedVector->data.F32[i] = maskVector->data.F32[i];
     718                    unsortedVector->data.F32[count++] = myVector->data.F32[i];
     719                }
     720            }
     721        } else {
     722            for (i=0;i<myVector->n;i++) {
     723                unsortedVector->data.F32[i] = myVector->data.F32[i];
    665724            }
    666725        }
     
    679738    psVectorFree(unsortedVector);
    680739    psVectorFree(sortedVector);
     740    // GUS: This is the
    681741}
    682742
     
    691751        PS_STAT_ROBUST_QUARTILE
    692752    I have included all that computation in a single function, as opposed to
    693     breaking it across several functions for one primary reason: the all
     753    breaking it across several functions for one primary reason: they all
    694754    require the same basic initial processing steps (calculate the histogram,
    695755    etc.) however there is no currently defined means, in the SDRS, to
     
    719779    // is really required.
    720780
    721     if (0.0 == stats->sampleUQ) {
    722 
    723         // GUS: fix this
    724         //        stats->options = stats->options | PS_STAT_SAMPLE_UQ;
     781    if (isnan(stats->sampleUQ) ||
     782            isnan(stats->sampleLQ)) {
     783        stats->options = stats->options | PS_STAT_SAMPLE_QUARTILE;
    725784        p_psVectorSampleQuartiles(myVector,
    726785                                  maskVector,
     
    729788    }
    730789
    731     if (isnan(stats->sampleLQ)) {
    732         // GUS: fix this
    733         //        stats->options = stats->options | PS_STAT_SAMPLE_LQ;
    734         p_psVectorSampleQuartiles(myVector,
    735                                   maskVector,
    736                                   maskVal,
    737                                   stats);
    738     }
    739 
    740790    // Compute the initial bin size of the robust histogram.
    741791    sigmaE = (stats->sampleUQ - stats->sampleLQ) / 1.34f;
     
    753803    robustHistogram = psHistogramAlloc(stats->min,
    754804                                       stats->max,
    755                                        binSize);
    756     // Populate the histogram arrat.
     805                                       1 + (int) ((stats->max - stats->min) / binSize));
     806
     807
     808    // Populate the histogram array.
    757809    // GUS: fix this
    758810    //    robustHistogram = psHistogramVector(robustHistogram, myVector);
     
    811863        stats->robustLQ = 0.0;
    812864    }
     865    stats->robustNfit = 0.0;
     866    stats->robustN50 = 0.0;
     867    psHistogramFree(robustHistogram);
    813868}
    814869
     
    836891
    837892    if (0 != isnan(stats->sampleMean)) {
    838         psAbort(__func__, "stats->sampleMean == NAN");
     893        p_psVectorSampleMean(myVector, maskVector, maskVal, stats);
    839894    }
    840895    mean = stats->sampleMean;
     
    920975    }
    921976
    922     tmpMask = psVectorAlloc(myVector->nalloc, maskVector->type.type);
    923 
    924     tmpMask->n = maskVector->n;
    925     for (i=0;i<tmpMask->n;i++) {
    926         tmpMask->data.U8[i] = maskVector->data.U8[i];
     977
     978    tmpMask = psVectorAlloc(myVector->n, PS_TYPE_U8);
     979    tmpMask->n = myVector->n;
     980
     981    if (maskVector != NULL) {
     982        for (i=0;i<tmpMask->n;i++) {
     983            tmpMask->data.U8[i] = maskVector->data.U8[i];
     984        }
    927985    }
    928986
    929987    // 1. Compute the sample median.
     988    // GUS: This seems odd.  Verify with IfA that we want to calculate the
     989    // median here, not the mean.
    930990    p_psVectorSampleMedian(myVector, maskVector, maskVal, stats);
    931991
     
    9421002
    9431003    for (i=0;i<stats->clipIter;i++) {
     1004        //        printf("p_psVectorClippedStats(): Iteration %d (%f %f)\n", i,
     1005        //                clippedMean, clippedStdev);
    9441006        for (j=0;j<myVector->n;j++) {
    9451007            // a) Exclude all values x_i for which |x_i - x| > K * stdev
    946             if ( fabs(myVector->data.F32[j] - clippedMean) >
     1008            if (fabs(myVector->data.F32[j] - clippedMean) >
    9471009                    (stats->clipSigma * clippedStdev)) {
    9481010                tmpMask->data.U8[i] = 0xff;
     
    9941056    if (in->type.type != PS_TYPE_F32) {
    9951057        psAbort(__func__,
    996                 "Only data type PS_TYPE_F32 is currently supported.");
    997     }
     1058                "Only data type PS_TYPE_F32 is currently supported (0x%x).",
     1059                in->type.type);
     1060    }
     1061
    9981062    if (mask != NULL) {
    9991063        if (in->n != mask->n) {
     
    10181082
    10191083    // ************************************************************************
     1084    // GUS: The Stdev calculation requires the mean.  Should we assume the
     1085    // mean has already been calculated?  Or should we always calculate it?
    10201086    if (stats->options & PS_STAT_SAMPLE_STDEV) {
     1087        p_psVectorSampleMean(in, mask, maskVal, stats);
    10211088        p_psVectorSampleStdev(in, mask, maskVal, stats);
    10221089    }
  • trunk/psLib/src/math/psStats.h

    r797 r889  
    8181typedef struct
    8282{
    83     const psVector *restrict bounds; ///< Bounds for the bins (type F32)
     83    psVector *bounds;                ///< Bounds for the bins (type F32)
    8484    psVector *nums;                  ///< Number in each of the bins (INT)
    8585    int minNum;                      ///< Number below the minimum
     
    102102
    103103/** Destructor \ingroup MathGroup **/
    104 void psHistogramFree(psHistogram *restrict myHist);          ///< Histogram to destroy
     104void psHistogramFree(psHistogram *myHist);          ///< Histogram to destroy
    105105
    106106
  • trunk/psLib/src/mathtypes/psImage.c

    r859 r889  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-04 03:15:47 $
     11 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-07 00:32:53 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 *
     16 *  That is the routine used to generate matrices.
    1517 */
    1618
  • trunk/psLib/src/sys/psLogMsg.c

    r560 r889  
    2929static int logDest = PS_LOG_TO_STDERR; // where to log messages
    3030static int logLevel = PS_LOG_INFO;     // log all messages at this or above
     31//static FILE *p_logFP = NULL;
    3132// The following variables control
    3233// which information is displayed in
  • trunk/psLib/src/sysUtils/psHash.c

    r885 r889  
    1 /******************************************************************************
    2     An interface to hash tables for Pan-STARRS
    3  
    4     Collisions are handled by simple linked lists
    5  *****************************************************************************/
     1/** @file  psHash.c
     2 *
     3 *  @brief Contains support for basic hashing functions.
     4 *
     5 *  This file will hold the functions for defining a hash table with arbitrary
     6 *  data types, allocating/deallocating that has table, adding and removing
     7 *  data from that hash table, and listing all keys defined in the hash table.
     8 *
     9 *  @author Robert Lupton, Princeton University
     10 *  @author George Gusciora, MHPCC
     11 *   
     12 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-07 00:32:53 $
     14 *
     15 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     16 */
    617#include <stdlib.h>
    718#include <stdio.h>
     
    1223#include "psString.h"
    1324#include "psTrace.h"
     25#include "psAbort.h"
    1426
    1527psDlist *psHashKeyList(psHash *table)
     
    142154    // bucket.
    143155    psHashBucket *optr = NULL;
     156    char *tmpchar = NULL;
    144157
    145158    // NOTE: this is NOT a good hash function!  See Knuth.
    146159    //
    147     for (int i = 0, len = strlen(key); i < len; i++) {
    148         hash = (hash << 1) ^ key[i];
    149     }
    150     hash &= (table->nbucket - 1);
     160    //    for (int i = 0, len = strlen(key); i < len; i++) {
     161    //        hash = (hash << 1) ^ key[i];
     162    //    }
     163    //    hash &= (table->nbucket - 1);
     164
     165    // This hash algorithm is from Sedgewick.  NOTE: must reread to ensure that
     166    // the size of the hash table is not required to be a prime number.
     167    tmpchar = (char *) key;
     168    for (hash = 0; *tmpchar != '\0'; tmpchar++) {
     169        hash = (64 * hash + *tmpchar) % (table->nbucket);
     170    }
     171
     172    // NOTE: This should not be necessary, but for now, I'm checking bounds
     173    // anyway.
     174    if ((hash < 0) ||
     175            (hash >= table->nbucket)) {
     176        psAbort(__func__,"Internal hash function out of range (%d)",
     177                hash);
     178    }
    151179
    152180    ptr = table->buckets[hash];
  • trunk/psLib/src/sysUtils/psHash.h

    r886 r889  
     1/** @file  psHash.c
     2 *
     3 *  @brief Contains support for basic hashing functions.
     4 *
     5 *  This file will hold the prototypes for defining a hash table with arbitrary
     6 *  data types, allocating/deallocating that has table, adding and removing
     7 *  data from that hash table, and listing all keys defined in the hash table.
     8 *
     9 *  @author Robert Lupton, Princeton University
     10 *  @author George Gusciora, MHPCC
     11 *   
     12 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-07 00:32:53 $
     14 *
     15 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     16 */
     17
    118#if !defined(PS_HASH_H)
    219#define PS_HASH_H
  • trunk/psLib/src/sysUtils/psLogMsg.c

    r560 r889  
    2929static int logDest = PS_LOG_TO_STDERR; // where to log messages
    3030static int logLevel = PS_LOG_INFO;     // log all messages at this or above
     31//static FILE *p_logFP = NULL;
    3132// The following variables control
    3233// which information is displayed in
Note: See TracChangeset for help on using the changeset viewer.