IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 20, 2010, 2:30:45 PM (16 years ago)
Author:
watersc1
Message:

Attempting to bring branch in sync with trunk

Location:
branches/czw_branch/20101203
Files:
10 deleted
19 edited
6 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/psLib/src/fits/psFitsImage.c

    r28509 r30118  
    900900
    901901    if (nAxis == 2) {
     902        psImage *image = psFitsReadImage(fits, region, 0);
     903        if (!image) {
     904            psFitsError(status, true, "Could not read image into cube");
     905            return NULL;
     906        }
    902907        psArray *images = psArrayAlloc(1); // Single image plane
    903         images->data[0] = psFitsReadImage(fits, region, 0);
     908        images->data[0] = image;
    904909        return images;
    905910    }
  • branches/czw_branch/20101203/psLib/src/imageops

  • branches/czw_branch/20101203/psLib/src/imageops/psImageMapFit.c

    r25753 r30118  
    4848
    4949// map defines the output image dimensions and scaling.
    50 bool psImageMapFit(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
     50bool psImageMapFit(bool *pGoodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
    5151                   const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    5252{
    5353    // XXX Add Asserts
     54
     55    *pGoodFit = false;
    5456
    5557    // dimensions of the output map image
     
    8183        map->map->data.F32[0][0]   = psStatsGetValue(map->stats, mean);
    8284        map->error->data.F32[0][0] = psStatsGetValue(map->stats, stdev);
     85        if (isfinite(map->map->data.F32[0][0]) && isfinite( map->error->data.F32[0][0])) {
     86            *pGoodFit = true;
     87        }
    8388        return true;
    8489    }
     
    8691    if (Nx == 1) {
    8792        bool status;
    88         status = psImageMapFit1DinY (map, mask, maskValue, x, y, f, df);
     93        status = psImageMapFit1DinY (pGoodFit, map, mask, maskValue, x, y, f, df);
    8994        return status;
    9095    }
    9196    if (Ny == 1) {
    9297        bool status;
    93         status = psImageMapFit1DinX (map, mask, maskValue, x, y, f, df);
     98        status = psImageMapFit1DinX (pGoodFit, map, mask, maskValue, x, y, f, df);
    9499        return status;
    95100    }
     
    310315
    311316    if (!psMatrixGJSolve(A, B)) {
    312         psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.  Returning NULL.\n");
    313317        psFree (A);
    314318        psFree (B);
    315         return false;
     319        return true;
    316320    }
    317321
     
    337341    psFree (Empty);
    338342
     343    *pGoodFit = true;
    339344    return true;
    340345}
    341346
    342347// measure residuals on each pass and clip outliers based on stats
    343 bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
     348bool psImageMapClipFit(bool *pGoodFit, psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
    344349                       const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    345350{
     
    351356    psAssert(f, "impossible");
    352357
     358    *pGoodFit = false;
     359
    353360    // the user supplies one of various stats option pairs,
    354361    // determine the desired mean and stdev STATS options:
     
    393400        psTrace("psLib.imageops", 6, "Loop iteration %d.  Calling psImageMapFit()\n", N);
    394401        psS32 Nkeep = 0;
    395         if (!psImageMapFit(map, mask, maskValue, x, y, f, df)) {
     402        if (!psImageMapFit(pGoodFit, map, mask, maskValue, x, y, f, df)) {
    396403            psError(PS_ERR_UNKNOWN, false, "Could not fit image map.\n");
    397404            psFree(resid);
     
    399406            return false;
    400407        }
     408        if (!*pGoodFit) {
     409            psWarning ("bad fit to image map, try something else");
     410            return true;
     411        }
    401412
    402413        psVector *fit = psImageMapEvalVector(map, mask, maskValue, x, y);
     
    454465    psFree(resid);
    455466    if (!inMask) psFree (mask);
     467    *pGoodFit = true; // XXX probably don't need to set this (set by psImageMapFit)
    456468    return true;
    457469}
    458470
    459471// map defines the output image dimensions and scaling.
    460 bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
     472bool psImageMapFit1DinY(bool *pGoodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
    461473                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    462474{
    463475    // XXX Add Asserts
    464476    assert (map->binning->nXruff == 1);
     477
     478    *pGoodFit = false;
    465479
    466480    // dimensions of the output map image
     
    578592
    579593    if (!psMatrixGJSolve(A, B)) {
    580         psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.\n");
    581594        psFree (A);
    582595        psFree (B);
    583596        psFree (Empty);
    584         return false;
     597        return true;
    585598    }
    586599
     
    602615    psFree (Empty);
    603616
     617    *pGoodFit = true;
    604618    return true;
    605619}
    606620
    607621// map defines the output image dimensions and scaling.
    608 bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
     622bool psImageMapFit1DinX(bool *pGoodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
    609623                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    610624{
    611625    // XXX Add Asserts
    612626    assert (map->binning->nYruff == 1);
     627
     628    *pGoodFit = false;
    613629
    614630    // dimensions of the output map image
     
    726742
    727743    if (!psMatrixGJSolve(A, B)) {
    728         psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations..\n");
    729744        psFree (A);
    730745        psFree (B);
    731746        psFree (Empty);
    732         return false;
     747        return true;
    733748    }
    734749
     
    750765    psFree (Empty);
    751766
     767    *pGoodFit = true;
    752768    return true;
    753769}
  • branches/czw_branch/20101203/psLib/src/imageops/psImageMapFit.h

    r25753 r30118  
    88
    99// fit the image map to a set of points
    10 bool psImageMapFit(psImageMap *map,
     10bool psImageMapFit(bool *pGoodFit,
     11                   psImageMap *map,
    1112                   const psVector *mask,
    1213                   psVectorMaskType maskValue, //
     
    1819
    1920// fit the image map to a set of points
    20 bool psImageMapClipFit(psImageMap *map,
     21bool psImageMapClipFit(bool *pGoodFit,
     22                       psImageMap *map,
    2123                       psStats *stats,
    2224                       psVector *mask,  // WARNING: Mask is modified!
     
    2830    );
    2931
    30 bool psImageMapFit1DinY(psImageMap *map,
     32bool psImageMapFit1DinY(bool *pGoodFit,
     33                        psImageMap *map,
    3134                        const psVector *mask,
    3235                        psVectorMaskType maskValue,
     
    3740    );
    3841
    39 bool psImageMapFit1DinX(psImageMap *map,
     42bool psImageMapFit1DinX(bool *pGoodFit,
     43                        psImageMap *map,
    4044                        const psVector *mask,
    4145                        psVectorMaskType maskValue,
  • branches/czw_branch/20101203/psLib/src/jpeg/psImageJpeg.c

    r29542 r30118  
    167167  int dy = image->numRows;
    168168 
    169   bDrawBuffer *bdbuf = bDrawBufferCreate(dx, dy);
     169  int Npalette;
     170  png_color *palette = KapaPNGPalette (&Npalette);
     171
     172  bDrawBuffer *bdbuf = bDrawBufferCreate(dx, dy, 1, palette, Npalette);
    170173
    171174  return bdbuf;
     
    180183  int dy = bdbuf->Ny;
    181184
    182   int Npalette;
    183   png_color *palette = KapaPNGPalette (&Npalette);
     185  png_color *palette = bdbuf->palette;
    184186  bDrawColor white = KapaColorByName ("white");
    185187  for (int j = 0; j < dy; j++) {
     
    336338
    337339    // set the scalebar labels
     340    int Npalette;
     341    png_color *palette = KapaPNGPalette (&Npalette);
     342
    338343    char string[64];
    339     bDrawBuffer *labels = bDrawBufferCreate(dx, PS_JPEG_LABELPAD);
     344    bDrawBuffer *labels = bDrawBufferCreate(dx, PS_JPEG_LABELPAD, 1, palette, Npalette);
    340345    SetRotFont ("helvetica", 8);
    341     bDrawSetBuffer(labels);
    342346    sprint_double (string, options->min);
    343     bDrawRotText(2, 2, string, 2, 0.0);
     347    bDrawRotText(labels, 2, 2, string, 2, 0.0);
    344348    sprint_double (string, options->max);
    345     bDrawRotText(dx - 2, 2, string, 0, 0.0);
     349    bDrawRotText(labels, dx - 2, 2, string, 0, 0.0);
    346350    sprint_double (string, 0.5*(options->min + options->max));
    347     bDrawRotText(0.5*dx, 2, string, 1, 0.0);
     351    bDrawRotText(labels, 0.5*dx, 2, string, 1, 0.0);
    348352    psImageJpegOverlayDraw(jpegImage, labels, 0, offset);
     353    bDrawBufferFree(labels);
    349354  }
    350355   
  • branches/czw_branch/20101203/psLib/src/math/psStats.c

    r28998 r30118  
    827827        // values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
    828828        // bins of that excess bin:
    829         int nMaxBin = 0;
     829        int nMaxBin = histogram->nums->data.F32[0];
    830830        int iMaxBin = 0;
    831831        for (long i = 1; i < histogram->nums->n; i++) {
     
    843843                if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
    844844                bool invalid = false;
    845                 invalid |= (myVector->data.F32[i] <= minKeep);
    846                 invalid |= (myVector->data.F32[i] >= maxKeep);
     845                invalid |= (myVector->data.F32[i] < minKeep);
     846                invalid |= (myVector->data.F32[i] > maxKeep);
    847847                invalid |= (!isfinite(myVector->data.F32[i]));
    848848                if (!invalid) continue;
     
    852852
    853853            if (nInvalid) {
    854               psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
     854              psTrace(TRACE, 6, "data is concentrated in a single bin (%d = %f - %f), masking %d extreme outliers and retrying\n",
     855                      iMaxBin, histogram->bounds->data.F32[iMaxBin], histogram->bounds->data.F32[iMaxBin+1], nInvalid);
    855856              psFree(histogram);
    856857              psFree(cumulative);
     
    11081109    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    11091110    if (isnan(stats->robustMedian)) {
    1110         stats->fittedStdev = NAN;
    1111         stats->fittedStdev = NAN;
     1111        stats->fittedMean = NAN;
     1112        stats->fittedStdev = NAN;
     1113        stats->results |= PS_STAT_FITTED_MEAN;
     1114        stats->results |= PS_STAT_FITTED_STDEV;
     1115        return true;
     1116    }
     1117
     1118    if (stats->robustStdev <= FLT_EPSILON) {
     1119        stats->fittedMean = stats->robustMedian;
     1120        stats->fittedStdev = stats->robustStdev;
     1121        stats->results |= PS_STAT_FITTED_MEAN;
     1122        stats->results |= PS_STAT_FITTED_STDEV;
    11121123        return true;
    11131124    }
     
    12891300    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    12901301    if (isnan(stats->robustMedian)) {
    1291         stats->fittedStdev = NAN;
    1292         stats->fittedStdev = NAN;
    1293         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
     1302        stats->fittedMean = NAN;
     1303        stats->fittedStdev = NAN;
     1304        stats->results |= PS_STAT_FITTED_MEAN_V2;
     1305        stats->results |= PS_STAT_FITTED_STDEV_V2;
     1306        return true;
     1307    }
     1308
     1309    if (stats->robustStdev <= FLT_EPSILON) {
     1310        stats->fittedMean = stats->robustMedian;
     1311        stats->fittedStdev = stats->robustStdev;
     1312        stats->results |= PS_STAT_FITTED_MEAN_V2;
     1313        stats->results |= PS_STAT_FITTED_STDEV_V2;
    12941314        return true;
    12951315    }
     
    14861506    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    14871507    if (isnan(stats->robustMedian)) {
    1488         stats->fittedStdev = NAN;
    1489         stats->fittedStdev = NAN;
    1490         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
     1508        stats->fittedMean = NAN;
     1509        stats->fittedStdev = NAN;
     1510        stats->results |= PS_STAT_FITTED_MEAN_V3;
     1511        stats->results |= PS_STAT_FITTED_STDEV_V3;
     1512        return true;
     1513    }
     1514
     1515    if (stats->robustStdev <= FLT_EPSILON) {
     1516        stats->fittedMean = stats->robustMedian;
     1517        stats->fittedStdev = stats->robustStdev;
     1518        stats->results |= PS_STAT_FITTED_MEAN_V3;
     1519        stats->results |= PS_STAT_FITTED_STDEV_V3;
    14911520        return true;
    14921521    }
     
    17821811
    17831812    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    1784     if (isnan(stats->robustMedian)) goto escape;
     1813    if (isnan(stats->robustMedian)) {
     1814        stats->fittedMean = NAN;
     1815        stats->fittedStdev = NAN;
     1816        stats->results |= PS_STAT_FITTED_MEAN_V4;
     1817        stats->results |= PS_STAT_FITTED_STDEV_V4;
     1818        return true;
     1819    }
     1820
     1821    if (stats->robustStdev <= FLT_EPSILON) {
     1822        stats->fittedMean = stats->robustMedian;
     1823        stats->fittedStdev = stats->robustStdev;
     1824        stats->results |= PS_STAT_FITTED_MEAN_V4;
     1825        stats->results |= PS_STAT_FITTED_STDEV_V4;
     1826        return true;
     1827    }
    17851828
    17861829    float guessStdev = stats->robustStdev;  // pass the guess sigma
  • branches/czw_branch/20101203/psLib/src/sys/psSlurp.c

    r12072 r30118  
    2727#include "psMemory.h"
    2828
    29 #define SLURP_SIZE 4096
     29# define SLURP_SIZE 4096
     30
     31# if (PS_SLURP_GZIP)
     32
     33psString psSlurpFD(int fd) {
     34
     35 gzFile file = gzdopen (fd, "r");
     36 if (file == Z_NULL) {
     37     psError(PS_ERR_IO, true, "Failed to open file\n");
     38     return NULL;
     39 }
     40 
     41 psString str = psSlurpGZIP(file);
     42
     43 return str;
     44}
     45
     46# else
    3047
    3148psString psSlurpFD(int fd)
     
    3855        // increase the allocated string size
    3956        size += SLURP_SIZE;
    40         str = psRealloc(str, size);
     57        str = psStringRealloc(str, size);
    4158
    4259        // read a block from the stream
     
    5976    return str;
    6077}
     78# endif
    6179
     80# if (PS_SLURP_GZIP)
     81psString psSlurpGZIP(gzFile fd)
     82{
     83    psString str = NULL;                // String to which to write
     84    size_t size  = 1;                   // bytes allocated -  make sure there is room for '\0'
     85    size_t used = 0;                    // bytes actually used
     86    ssize_t bytes;                      // Number of bytes read
     87    do {
     88        // increase the allocated string size
     89        size += SLURP_SIZE;
     90        str = psStringRealloc(str, size);
     91
     92        // read a block from the stream
     93        bytes = gzread(fd, str + used, SLURP_SIZE);
     94        if (bytes < 0) {
     95            // it's an error
     96            psError(PS_ERR_IO, true, "slurp failed on read");
     97            psFree(str);
     98            return NULL;
     99        }
     100
     101        // Increase the size of the known string
     102        used += bytes;
     103
     104    } while (bytes != 0);
     105
     106    // append '\0' to the end of the string
     107    str[used] = '\0';
     108
     109    return str;
     110}
     111# endif
    62112
    63113psString psSlurpFile(FILE *stream)
     
    70120{
    71121    PS_ASSERT_PTR_NON_NULL(filename, NULL);
     122   
     123# if (PS_SLURP_GZIP)
     124    gzFile fd = gzopen(filename, "r");
     125    if (fd == Z_NULL) {
     126        psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     127        return NULL;
     128    }
     129    psString text = psSlurpGZIP(fd);
     130
     131    if (gzclose(fd) != Z_OK) {
     132        psError(PS_ERR_IO, true, "Failed to close specified file, %s\n", filename);
     133        psFree(text);
     134        return NULL;
     135    }
     136
     137# else
    72138
    73139    int fd = open(filename, O_RDONLY);
     
    76142        return NULL;
    77143    }
    78 
    79144    psString text = psSlurpFD(fd);
    80145
     
    84149        return NULL;
    85150    }
     151# endif
    86152
    87153    return text;
  • branches/czw_branch/20101203/psLib/src/sys/psSlurp.h

    r15410 r30118  
    1212
    1313#include <psString.h>
     14
     15# define PS_SLURP_GZIP 1
     16
     17# if (PS_SLURP_GZIP)
     18# include <zlib.h>
     19# endif
    1420
    1521/// @addtogroup FileIO Input/Output
     
    3137                    );
    3238
     39# if (PS_SLURP_GZIP)
     40psString psSlurpGZIP(gzFile fd);
     41# endif
     42
    3343/// @}
    3444#endif
  • branches/czw_branch/20101203/psLib/src/sys/psString.c

    r19070 r30118  
    4848    psString string = p_psAlloc(file, lineno, func, nChar + 1);
    4949    psMemSetDeallocator(string, (psFreeFunc)stringFree);
     50
     51    return string;
     52}
     53
     54
     55psString p_psStringRealloc(const char *file,
     56                           unsigned int lineno,
     57                           const char *func,
     58                           psString string,
     59                           size_t nChar)
     60{
     61    if (!string) {
     62        string = p_psAlloc(file, lineno, func, nChar + 1);
     63        psMemSetDeallocator(string, (psFreeFunc)stringFree);
     64    } else {
     65        string = p_psRealloc(file, lineno, func, string, nChar + 1);
     66    }
    5067
    5168    return string;
  • branches/czw_branch/20101203/psLib/src/sys/psString.h

    r15523 r30118  
    4040#define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__)
    4141
    42 
    4342/** Allocates a new psString.
    4443 *
     
    6059#endif // ifdef DOXYGEN
    6160
     61/** Reallocate an existing psString (or alloc if not existent)
     62 *
     63 *  @return psString:       string of length n.
     64 */
     65#ifdef DOXYGEN
     66psString psStringRealloc(
     67    psString string,
     68    size_t nChar                        ///< Size of psString to allocate.
     69);
     70#else // ifdef DOXYGEN
     71psString p_psStringRealloc(
     72    const char *file,                   ///< File of caller
     73    unsigned int lineno,                ///< Line number of caller
     74    const char *func,                   ///< Function name of caller
     75    psString string,                    ///< supplied string or NULL
     76    size_t nChar                        ///< Size of psString to allocate.
     77) PS_ATTR_MALLOC;
     78#define psStringRealloc(string, nChar)                          \
     79    p_psStringRealloc(__FILE__, __LINE__, __func__, string, nChar)
     80#endif // ifdef DOXYGEN
    6281
    6382/** Checks the type of a particular pointer.
  • branches/czw_branch/20101203/psLib/src/types/psMetadata.c

    r29833 r30118  
    13711371            break;
    13721372        case PS_DATA_S64:
    1373             fprintf(fd, "%jd\n", item->data.S64);
     1373            fprintf(fd, "%" PRId64 "\n", item->data.S64);
    13741374            break;
    13751375        case PS_DATA_U8:
     
    13831383            break;
    13841384        case PS_DATA_U64:
    1385             fprintf(fd, "%ju\n", item->data.U64);
     1385            fprintf(fd, "%" PRIu64 "\n", item->data.U64);
    13861386            break;
    13871387        case PS_DATA_F32:
     
    14581458              fprintf(fd, "U64  ");
    14591459              for (int i = 0; i < vector->n; i++) {
    1460                   fprintf(fd, "%ju ", vector->data.U64[i]);
     1460                  fprintf(fd, "%" PRIu64, vector->data.U64[i]);
    14611461              }
    14621462              fprintf(fd, "\n");
     
    14861486              fprintf(fd, "S64  ");
    14871487              for (int i = 0; i < vector->n; i++) {
    1488                   fprintf(fd, "%jd ", vector->data.S64[i]);
     1488                  fprintf(fd, "%" PRId64, vector->data.S64[i]);
    14891489              }
    14901490              fprintf(fd, "\n");
  • branches/czw_branch/20101203/psLib/src/types/psMetadataConfig.c

    r27056 r30118  
    16301630}
    16311631
    1632 
    1633 bool psMetadataConfigWrite(psMetadata *md,
    1634                            const char *filename)
    1635 {
    1636     PS_ASSERT_METADATA_NON_NULL(md, NULL);
    1637     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    1638     FILE *file;
    1639     if ( !(file = fopen(filename, "w")) ) {
    1640         psError(PS_ERR_IO, true,
    1641                 "Failed to open specified file, %s\n", filename);
    1642         return false;
    1643     }
    1644     psString fileString = NULL;
    1645     fileString = psMetadataConfigFormat(md);
    1646     if (fileString == NULL) {
    1647         psError(PS_ERR_BAD_PARAMETER_NULL, false,
    1648                 "psMetadataConfigFormat returned NULL.\n");
    1649         return false;
    1650     }
    1651     if (fprintf(file, "%s", fileString) != strlen(fileString)) {
    1652         psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
    1653         psFree(fileString);
    1654         fclose(file);
    1655         return false;
     1632bool psMetadataConfigWrite(psMetadata *md, const char *filename, const char *compress)
     1633{
     1634  PS_ASSERT_METADATA_NON_NULL(md, NULL);
     1635  PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     1636
     1637  psString fileString = NULL;
     1638  fileString = psMetadataConfigFormat(md);
     1639  if (fileString == NULL) {
     1640    psError(PS_ERR_BAD_PARAMETER_NULL, false, "psMetadataConfigFormat returned NULL.\n");
     1641    return false;
     1642  }
     1643
     1644  if (compress) {
     1645    if (strlen(compress) > 2) {
     1646      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "invalid compression options %s", compress);
     1647      psFree(fileString);
     1648      return false;
     1649    }
     1650    char modeString[4];
     1651    snprintf (modeString, 4, "w%s", compress);
     1652
     1653    gzFile file = gzopen(filename, modeString);
     1654    if (file == Z_NULL) {
     1655      psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     1656      psFree(fileString);
     1657      return false;
     1658    }
     1659
     1660    int nbytes = gzwrite (file, fileString, strlen(fileString));
     1661    if (nbytes != strlen(fileString)) {
     1662      psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
     1663      psFree(fileString);
     1664      gzclose(file);
     1665      return false;
     1666    }
     1667    psFree(fileString);
     1668    if (gzclose(file) != Z_OK) {
     1669      psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1670      return false;
     1671    }
     1672  } else {
     1673    FILE *file = fopen(filename, "w");
     1674    if (file == NULL) {
     1675      psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     1676      psFree(fileString);
     1677      return false;
     1678    }
     1679
     1680    int nbytes = fwrite(fileString, 1, strlen(fileString), file);
     1681    if (nbytes != strlen(fileString)) {
     1682      psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
     1683      psFree(fileString);
     1684      fclose(file);
     1685      return false;
    16561686    }
    16571687    psFree(fileString);
    16581688    if (fclose(file) == EOF) {
    1659         psError(PS_ERR_IO, true,
    1660                 "Failed to close file, %s\n", filename);
    1661         return false;
    1662     }
    1663     return true;
     1689      psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1690      return false;
     1691    }
     1692  }
     1693  return true;
    16641694}
    16651695
  • branches/czw_branch/20101203/psLib/src/types/psMetadataConfig.h

    r11248 r30118  
    3333 *  a string, the formatting command must also be for a string. If the
    3434 *  metadata type is any other data type, printing is not allowed.
     35 *  Currently, this function does not compress the output file
    3536 *
    3637 * @return psMetadataItem* :    Pointer metadata item.
     
    8586bool psMetadataConfigWrite(
    8687    psMetadata *md,                    ///< The metadata to convert
    87     const char *filename               ///< Name of file to write
     88    const char *filename,              ///< Name of file to write
     89    const char *compress               ///< Output compression options
    8890);
    8991
    9092/** Converts a psMetadata structure (including any nested psMetadata) into a
    9193 *  configuration file formatted string that is written a file stream.
     94 *  Currently, this function does not compress the output file
    9295 *
    9396 *  @return bool:       True if successful, otherwise false.
  • branches/czw_branch/20101203/psLib/test/imageops

    • Property svn:ignore
      •  

        old new  
        2727convolutionBench
        2828tap_psImageInterpolate2
         29tap_psImageInterpolate3
        2930tap_psImageGeomManip
        3031tap_psImageMaskOps
  • branches/czw_branch/20101203/psLib/test/imageops/Makefile.am

    r14926 r30118  
    2222        tap_psImagePixelExtract \
    2323        tap_psImageInterpolate2 \
     24        tap_psImageInterpolate3 \
    2425        tap_psImageMap \
    2526        tap_psImageMapFit \
  • branches/czw_branch/20101203/psLib/test/math

  • branches/czw_branch/20101203/psLib/test/math/tap_psStats_Sample_01.c

    r12513 r30118  
    487487                         };
    488488
     489static float yraw_04[] = {
     490    -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, -1.000000, -1.000000,
     491    0.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     492    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.963289,
     493    -1.000000, 0.000000, -1.000000, -1.000000, -0.915174, -1.000000, -1.000000, -1.000000,
     494    -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     495    -1.000000, -1.000000, -1.000000, -0.853025, 0.000000, -1.000000, -1.000000, -1.000000,
     496    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.989926, -1.000000, -1.000000,
     497    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.834902, -1.000000, -1.000000,
     498    -0.942985, -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     499    -1.000000, -1.000000, -0.990081, -1.000000, -0.990456, -0.814654, -1.000000, -1.000000,
     500    -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     501    -0.968021, -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -0.993967, -0.957540,
     502    -0.894533, -0.958363, -1.000000, -1.000000, -1.000000, -0.988915, -1.000000, -1.000000,
     503    -1.000000, -1.000000, -1.000000, -1.000000, -0.985367, -1.000000, -0.972040, -1.000000,
     504    -1.000000, -1.000000, 0.000000, -1.000000, -0.882278, -1.000000, -1.000000, -1.000000,
     505    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     506    -1.000000, -0.962575, -0.976843, -0.998926, -1.000000, -0.914090, 0.000000, -0.957808,
     507    -1.000000, -1.000000, -1.000000, 0.000000, -0.902593, -1.000000, -1.000000, -1.000000,
     508    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.975404,
     509    -1.000000, 0.000000, -0.984627, -1.000000, -0.969547, -0.851295, -1.000000, -0.988146,
     510    -1.000000, 0.000000, -1.000000, -0.993753, -0.861851, -1.000000, -0.980836, -0.979644,
     511    -1.000000, -1.000000, -1.000000, -0.995401, -1.000000, -1.000000, -1.000000, -1.000000,
     512    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     513    0.000000, -1.000000, -0.990123, -0.944934, -1.000000, 0.000000, -1.000000, -0.952198,
     514    -1.000000, -1.000000, -0.960814, -1.000000, -1.000000, -1.000000, -0.956806, -1.000000,
     515    0.000000, -0.991778, -1.000000, -1.000000, -1.000000, -1.000000, 0.000000, -1.000000,
     516    -0.977640, -1.000000, -1.000000, 0.000000, -1.000000, -0.977630, -1.000000, -0.974242,
     517    -1.000000, -1.000000, -0.940085, -0.930729, -1.000000, -1.000000, 0.000000, -1.000000,
     518    -1.000000, -0.933695, -1.000000, -0.932306, -1.000000, -1.000000, -1.000000, -0.836774,
     519    -0.931762, -0.926990, -0.861895, -1.000000, -0.922505, -1.000000, -0.956420, -0.998768,
     520    -0.974626, -0.964573, -1.000000, -0.933995, -1.000000, -0.995117, -1.000000, -1.000000,
     521    0.000000, 0.000000, -1.000000, -0.955537, -0.996360, -0.988015, -1.000000, -1.000000,
     522    -0.963953, -0.920429, -0.955252, -0.950946, -1.000000, -1.000000, -1.000000, -0.979526,
     523    -1.000000, -1.000000, -0.997193, -1.000000, -1.000000, 0.000000, -1.000000, -1.000000,
     524    -1.000000, -0.893445, -1.000000, -1.000000, -0.997704, -1.000000, -1.000000, -0.952295,
     525    -1.000000, 0.000000, -0.928042, -1.000000, -1.000000, -0.994029, -0.919350, -1.000000,
     526    -1.000000, -1.000000, -1.000000, -0.958966, -0.806458, -0.903843, -1.000000, -1.000000,
     527    -1.000000, -1.000000, -1.000000, -1.000000, 0.000000, -0.989002, 0.000000, -0.999874,
     528    -1.000000, 0.000000, -1.000000, 0.000000, -0.923556, -0.906242, -0.923497, -0.997873,
     529    -1.000000, -1.000000, 0.000000, -0.960376, -0.998760, -1.000000, 0.000000, -1.000000,
     530    -0.852141, -1.000000, -0.957442, -0.942000, -1.000000, -1.000000, -1.000000, -1.000000,
     531    -1.000000, -1.000000, -0.996748, -0.997676, -0.976159, -0.951572, -1.000000, -0.993083,
     532    -0.715375, -0.997984, -1.000000, -0.962484, -0.996733, -1.000000, -1.000000, -0.953423,
     533    -1.000000, -0.882232, -1.000000, -1.000000, -0.944493, -1.000000, -0.979617, -1.000000,
     534    -0.990002, -1.000000, -0.844745, -0.945080, -1.000000, -1.000000, -0.904816, -1.000000,
     535    -0.986999, -1.000000, -0.854941, -1.000000, -0.946096, -0.977678, -1.000000, -0.955933,
     536    -0.979545, -1.000000, -1.000000, -0.863616, -0.973953, -0.996599, -0.990304, -0.978263,
     537    -1.000000, -0.967798, -0.912566, 0.000000, -1.000000, -1.000000, -0.990321, -0.995921,
     538    -1.000000, -1.000000, -1.000000, -0.927030, -0.886393, -0.987297, -1.000000, -1.000000,
     539    -0.987206, -0.978084, -1.000000, -0.923876, -0.957539, -0.991587, -0.819295, -1.000000,
     540    -0.985077, -1.000000, 0.000000, -1.000000, -1.000000, -0.822353, -1.000000, -1.000000,
     541    -0.987783, -1.000000, -0.909520, -1.000000, -0.932334, -0.991847, -1.000000, -0.885318,
     542    -0.945695, -0.977144, -0.989444, -0.887085, -0.891662, -0.894193, -1.000000, 0.000000,
     543    -1.000000, -0.917484, -1.000000, -0.892801, -1.000000, -0.963580, -0.869279, -0.965420,
     544    -0.906966, -0.929646, -0.981315, -1.000000, -1.000000, -0.749674, -1.000000, -0.886804,
     545    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.970826, -0.909766,
     546    -1.000000, -0.910406, -0.983636, -1.000000, -0.961209, -0.935273, -1.000000, -0.989806,
     547    0.000000, -0.981563, -0.989701, -0.915626, -0.997493, -0.981429, -1.000000, -0.964583,
     548    -1.000000, -0.930216, -0.737797, -1.000000, -0.944314, -0.999998, -0.999611, -0.945788,
     549    -0.773886, -0.848979, -0.980186, -1.000000, -1.000000, 0.000000, -0.951392, -0.993398,
     550    -0.931889, -0.991680, -0.959021, -0.904240, -1.000000, -0.983561, -0.821324, 0.000000,
     551    0.000000, -1.000000, -0.925782, -0.841267, -1.000000, -0.907313, -1.000000, -0.990704,
     552    -1.000000, -1.000000, -0.936372, -0.885059
     553};
     554
    489555int main (void)
    490556{
    491557    plan_tests(21);
    492558
    493 //    diag("psStats Tests with sample SDSS data from RHL and Megacam from EAM");
    494 //    diag("this file does not yet define a specific test");
    495 //    diag("the fitted mean is currently wrong for these two data sets");
    496 
    497     {
     559    // float **yraw = {yraw_01, yraw_02, yraw_03, yraw_04, NULL};
     560
     561    if (1) {
     562        diag("sample 1 : problem with integer-binned data driven to tiny sigma values");
     563
    498564        psMemId id = psMemGetId();
    499565
    500 //        diag("sample 1 : problem with integer-binned data driven to tiny sigma values");
    501566        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
    502567                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
     
    505570                                       PS_STAT_SAMPLE_STDEV | PS_STAT_USE_BINSIZE);
    506571        stats->binsize = 1.0;
    507 
    508572
    509573        // copy data in static array
     
    533597
    534598
    535     {
     599    if (1) {
    536600        psMemId id = psMemGetId();
    537601
    538 //        diag("sample 2");
     602        diag("sample 2");
    539603        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
    540604                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
     
    568632    }
    569633
    570     {
     634    if (1) {
    571635        psMemId id = psMemGetId();
    572636
    573 //        diag("sample 3");
     637        diag("sample 3");
    574638        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
    575639                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
    576640                                       PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV |
    577641                                       PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN |
    578                                        PS_STAT_SAMPLE_STDEV | PS_STAT_USE_BINSIZE);
    579         stats->binsize = 1.0;
    580 
     642                                       PS_STAT_SAMPLE_STDEV);
    581643
    582644        // copy data in static array
     
    605667    }
    606668
     669    {
     670        psMemId id = psMemGetId();
     671
     672        // psTraceSetLevel("psLib.math.vectorRobustStats", 6);
     673
     674        diag("sample 4");
     675        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
     676                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
     677                                       PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV |
     678                                       PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN |
     679                                       PS_STAT_SAMPLE_STDEV);
     680
     681        // copy data in static array
     682        int nPts = sizeof(yraw_04) / sizeof (float);
     683        psVector *y = psVectorAlloc (nPts, PS_TYPE_F32);
     684        for (int i = 0; i < y->n; i++) {
     685            y->data.F32[i] = yraw_04[i];
     686        }
     687
     688        psVectorStats (stats, y, NULL, NULL, 1);
     689        ok (1, "sample  mean   %f, stdev %f", stats->sampleMean,   stats->sampleStdev);
     690        ok (1, "sample  median %f, stdev %f", stats->sampleMedian, stats->sampleStdev);
     691        ok (1, "clipped mean   %f, stdev %f", stats->clippedMean,  stats->clippedStdev);
     692        ok (1, "robust  median %f, stdev %f", stats->robustMedian, stats->robustStdev);
     693        ok (1, "fitted  mean   %f, stdev %f", stats->fittedMean,   stats->fittedStdev);
     694        psFree (stats);
     695
     696        stats = psStatsAlloc (PS_STAT_FITTED_MEAN_V2 | PS_STAT_FITTED_STDEV_V2 | PS_STAT_USE_BINSIZE);
     697        stats->binsize = 1.0;
     698        psVectorStats (stats, y, NULL, NULL, 1);
     699        ok (1, "fitted  mean v2 %f, stdev %f", stats->fittedMean,   stats->fittedStdev);
     700        psFree (stats);
     701
     702        psFree (y);
     703        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     704    }
     705
    607706    return exit_status();
    608707}
     708
  • branches/czw_branch/20101203/psLib/test/types/tap_psMetadataConfigWrite.c

    r17515 r30118  
    2525    {
    2626        psMemId id = psMemGetId();
    27         ok( !psMetadataConfigWrite(NULL, "mdcfg.wrt"),
     27        ok( !psMetadataConfigWrite(NULL, "mdcfg.wrt", NULL),
    2828            "return false for NULL metadata input.");
    2929        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     
    3535        psMemId id = psMemGetId();
    3636        psMetadata *md = psMetadataAlloc();
    37         ok( !psMetadataConfigWrite(md, NULL),
     37        ok( !psMetadataConfigWrite(md, NULL, NULL),
    3838            "return false for NULL filename input.");
    3939        psFree(md);
     
    4646        psMemId id = psMemGetId();
    4747        psMetadata *md = psMetadataAlloc();
    48         ok( !psMetadataConfigWrite(md, "."),
     48        ok( !psMetadataConfigWrite(md, ".", NULL),
    4949            "return false for invalid filename input.");
    5050        psFree(md);
     
    5757        psMemId id = psMemGetId();
    5858        psMetadata *md = psMetadataAlloc();
    59         ok(psMetadataConfigWrite(md, "mdcfg.wrt"), "return false for empty metadata input.");
     59        ok(psMetadataConfigWrite(md, "mdcfg.wrt", NULL), "return false for empty metadata input.");
    6060        psFree(md);
    6161        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     
    6868        psMetadata *md = psMetadataAlloc();
    6969        psMetadataAddBool(md, PS_LIST_TAIL, "item1-1", 0, "I am a boolean", true);
    70         ok( psMetadataConfigWrite(md, "mdcfg.wrt"),
     70        ok( psMetadataConfigWrite(md, "mdcfg.wrt", NULL),
    7171            "return true for valid inputs.");
    7272        char configTest[61];
Note: See TracChangeset for help on using the changeset viewer.