IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8973


Ignore:
Timestamp:
Sep 25, 2006, 4:55:34 PM (20 years ago)
Author:
jhoblitt
Message:

rolling back changes made to these files as these changes basically regressed the code base by two weeks and reintroduced several bugs:

psArguments.c:1.13->1.14
psArray.c:1.52->1.53
psBitSet.c:1.34->1.35
psBitSet.h:1.24->1.25
psHash.c:1.30->1.31
psHash.h:1.16->1.17
psMetadata.c:1.133->1.134
psMetadataConfig.c:1.90->1.91
psPixels.c:1.26->1.27
psPixels.h:1.21->1.22

Location:
trunk/psLib/src/types
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psArguments.c

    r8965 r8973  
    77 *  @author David Robbins, MHPCC
    88 *
    9  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-09-26 01:41:29 $
     9 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-09-26 02:55:34 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 */
    1414
    15 #include<stdio.h>
    16 #include<stdarg.h>
    17 #include<string.h>
     15#include <stdio.h>
     16#include <stdarg.h>
     17#include <string.h>
     18#include <inttypes.h>
     19
    1820#include "psArguments.h"
    1921#include "fitsio.h"
     
    315317        // Print the value
    316318        switch (item->type) {
    317             PRINT_CASE(U8,"%u");
    318             PRINT_CASE(U16,"%u");
    319             PRINT_CASE(U32,"%u");
    320             PRINT_CASE(U64,"%lu");
    321             PRINT_CASE(S8,"%d");
    322             PRINT_CASE(S16,"%d");
    323             PRINT_CASE(S32,"%d");
    324             PRINT_CASE(S64,"%ld");
    325             PRINT_CASE(F32,"%.6e");
    326             PRINT_CASE(F64,"%.6e");
     319            PRINT_CASE(U8, "%u");
     320            PRINT_CASE(U16, "%u");
     321            PRINT_CASE(U32, "%u");
     322            PRINT_CASE(U64, "%" PRIu64);
     323            PRINT_CASE(S8, "%d");
     324            PRINT_CASE(S16, "%d");
     325            PRINT_CASE(S32, "%d");
     326            PRINT_CASE(S64, "%" PRId64);
     327            PRINT_CASE(F32, "%.6e");
     328            PRINT_CASE(F64, "%.6e");
    327329        case PS_DATA_BOOL:
    328330            if (item->data.B) {
  • trunk/psLib/src/types/psArray.c

    r8965 r8973  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-09-26 01:41:29 $
     11 *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-09-26 02:55:34 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    164164    PS_ASSERT_PTR_NON_NULL(array, false);
    165165
    166     if (position > array->n) {
     166    if (position < 0 || position >= array->n) {
    167167        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    168168                _("position > then the number of elements in the array."));
     
    174174    psFree(array->data[i]);
    175175    memmove(&array->data[i], &array->data[i + 1], (n - i - 1) * sizeof(psPtr));
    176     array->n = --i; // reset the array size to indicate the removed item(s)
     176    array->n--;    // reset the array size to indicate the removed item
    177177
    178178    return true;
  • trunk/psLib/src/types/psBitSet.c

    r8965 r8973  
    1111 *  @author Robert DeSonia, MHPCC
    1212 *
    13  *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-09-26 01:41:29 $
     13 *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-09-26 02:55:34 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psAbort.h"
    2828#include "psString.h"
    29 #include "psAssert.h"
    3029
    3130
     
    6160static void bitSetFree(psBitSet* inBitSet)
    6261{
     62    if (inBitSet == NULL) {
     63        return;
     64    }
    6365    psFree(inBitSet->bits);
    6466}
     
    7577psBitSet* psBitSetAlloc(long nalloc)
    7678{
     79    psS32 numBytes = 0;
     80    psBitSet* newObj = NULL;
     81
    7782    if (nalloc < 0) {
    7883        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     
    8186        return NULL;
    8287    }
    83 
    84     psS32 numBytes = 0;
    85     psBitSet* newObj = NULL;
    8688
    8789    numBytes = ceil(nalloc / 8.0);
     
    172174                     const psBitSet* inBitSet2)
    173175{
    174     if (inBitSet1 == NULL) {
    175         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    176                 _("First psBitSet operand can not be NULL."));
    177         psFree(outBitSet);
    178         return NULL;
    179     }
    180     if (operator == NULL) {
    181         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    182                 _("Specified operator is NULL.  Must specify desired operator."));
    183         psFree(outBitSet);
    184         return NULL;
    185     }
    186176    psS32 i = 0;
    187177    psS32 n = 0;
     
    191181    psS32 op = UNKNOWN_OP;
    192182
     183    if (inBitSet1 == NULL) {
     184        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     185                _("First psBitSet operand can not be NULL."));
     186        psFree(outBitSet);
     187        return NULL;
     188    }
    193189    inBits1 = inBitSet1->bits;
    194190
     191    if (operator == NULL) {
     192        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     193                _("Specified operator is NULL.  Must specify desired operator."));
     194        psFree(outBitSet);
     195        return NULL;
     196    }
    195197
    196198    // parse the operator
     
    255257        break;
    256258    case NOT_OP:
    257     default:
    258259        for (i = 0; i < n; i++) {
    259260            outBits[i] = ~inBits1[i];
    260261        }
    261262        break;
     263    default:
     264        psAbort("psBitSetOp",
     265                "Unexpected error - operator parsed successfully but not valid?");
    262266    }
    263267
     
    277281    outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL);
    278282
     283    if (outBitSet == NULL) {
     284        psError(PS_ERR_UNKNOWN, false,
     285                _("Could not perform NOT operation."));
     286    }
     287
    279288    return outBitSet;
    280289}
     
    282291psString psBitSetToString(const psBitSet* bitSet)
    283292{
    284     PS_ASSERT_PTR_NON_NULL(bitSet, NULL);
    285293    psS32 i = 0;
    286294    psS32 numBits = bitSet->n * 8;
    287     //    char *outString = psAlloc((size_t) numBits + 1);
    288     psString outString = psStringAlloc(numBits + 1);
     295    char *outString = psAlloc((size_t) numBits + 1);
    289296
    290297    for (i = 0; i < numBits; i++) {
  • trunk/psLib/src/types/psBitSet.h

    r8965 r8973  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-09-26 01:41:29 $
     14 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-09-26 02:55:34 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232/** Struct containing array of bytes to hold bit data and corresponding array length.
    3333 *
    34  *  The bits in the struct are assembled in as an array of bytes with eight bits per
    35  *  byte. The bits are arranged with the LSB in first (right most) position of the
    36  *  first array element.
     34 *  The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are
     35 *  arranged with the LSB in first (right most) position of the first array element.
    3736 */
    3837typedef struct
     
    5251 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
    5352 *
    54  *  @return bool:     True if the pointer matches a psBitSet structure, false otherwise.
     53 *  @return bool:       True if the pointer matches a psBitSet structure, false otherwise.
    5554 */
    5655bool psMemCheckBitSet(
     
    6160/** Allocate a psBitSet.
    6261 *
    63  *  Create a psBitSet with the number of bits specified by the user. All bits are set
    64  *  to zero upon allocation.
     62 *  Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon
     63 *  allocation.
    6564 *
    6665 *  @return  psBitSet* : Pointer to struct containing array of bits and size of array.
    6766 */
    6867psBitSet* psBitSetAlloc(
    69     long nalloc                        ///< Number of bits in psBitSet array
     68    long nalloc                            ///< Number of bits in psBitSet array
    7069);
    7170
     
    7372 *
    7473 *  Sets a bit at a given bit location. The bit is set based on a zero index with the
    75  *  first bit set in the zero bit slot of the zero element of the byte array. As an
    76  *  example, setting bit 3 in an array with two elements would result in an psBitSet
    77  *  that looks like 00000000 00001000.
     74 *  first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in
     75 *  an array with two elements would result in an psBitSet that looks like 00000000 00001000.
    7876 *
    7977 *  @return  psBitSet* : Pointer to struct containing psBitSet.
     
    9997/** Test the value of a bit.
    10098 *
    101  *  Prints the value of a bit at a given bit location, either one or zero. The resulting
    102  *  bit is based on a zero index format with the first bit set in the zero bit slot of
    103  *  the zero element of the byte array.  As an example, testing bit 3 in a psBitSet with
    104  *  two bytes that looks like 00000000 00001000 would return a value of one, since that
    105  *  is the value that was set.
     99 *  Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a
     100 *  zero index format with the first bit set in the zero bit slot of the zero element of the byte array
     101 *  As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a
     102 *  value of one, since that is the value that was set.
    106103 *
    107104 *  @return  bool:      True if successful, otherwise false
    108105 */
     106
    109107bool psBitSetTest(
    110108    const psBitSet* bitSet,            ///< Pointer psBitSet to be tested.
     
    114112/** Perform a binary operation on two psBitSets
    115113 *
    116  *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size,
    117  *  the operation will not be performed and an error message will be logged.
     114 *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not
     115 *  be performed and an error message will be logged.
    118116 *
    119117 *  @return  psBitSet* : Pointer to struct containing result of binary operation.
    120118 */
    121119psBitSet* psBitSetOp(
    122     psBitSet* outBitSet,               ///< Resulting psBitSet from binary operation
    123     const psBitSet* inBitSet1,         ///< First psBitSet on which to operate
    124     const char *operator,              ///< Bit operation
    125     const psBitSet* inBitSet2          ///< Second psBitSet on which to operate
     120    psBitSet* outBitSet,                 ///< Resulting psBitSet from binary operation
     121    const psBitSet* inBitSet1,           ///< First psBitSet on which to operate
     122    const char *operator,                    ///< Bit operation
     123    const psBitSet* inBitSet2            ///< First psBitSet on which to operate
    126124);
    127125
    128126/** Perform a not operation on a psBitSet
    129127 *
    130  *  Toggles bits in a psBitset. All zero bits are set to one and all one bits are set
    131  *  to zero.
     128 *  Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero.
    132129 *
    133130 *  @return  psBitSet* : Pointer to struct containing result of operation.
    134131 */
     132
    135133psBitSet* psBitSetNot(
    136134    psBitSet* outBitSet,               ///< Resulting psBitSet from operation
     
    140138/** Convert the psBitSet to a string of ones and zeros.
    141139 *
    142  *  Converts the contents of a psBitSet to a string representation of its binary form of
    143  *  ones and zeros. The LSB is the right-most chracter. Each set of eight characters
    144  *  represents one byte.
     140 *  Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The
     141 *  LSB is the right-most chracter. Each set of eight characters represents one byte.
    145142 *
    146  *  @return  psString:      Pointer to character array containing string data.
     143 *  @return  char*: Pointer to character array containing string data.
    147144 */
     145
    148146psString psBitSetToString(
    149     const psBitSet* bitSet             ///< psBitSet to convert
     147    const psBitSet* bitSet             ///< psBitSet to convert */
    150148);
    151149
  • trunk/psLib/src/types/psHash.c

    r8965 r8973  
    1212*  @author GLG, MHPCC
    1313*
    14 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-09-26 01:41:29 $
     14*  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-09-26 02:55:34 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4747psList* psHashKeyList(const psHash* hash)
    4848{
    49     PS_ASSERT_PTR_NON_NULL(hash, NULL);
    5049    psS32 i = 0;                  // Loop index variable
    5150    psList* myLinkList = NULL;  // The output data structure
    5251    psHashBucket* ptr = NULL;   // Used to step thru linked list.
    5352
     53    if (hash == NULL) {
     54        return NULL;
     55    }
    5456    // Create the linked list
    5557    myLinkList = psListAlloc(NULL);
     
    9698    bucket->key = psStringCopy(key);
    9799
    98     //XXX:  Since this function is static and only called by doHashWork,
    99     //data can never be NULL here.
    100     //    if (data == NULL) {
    101     // NOTE: Should we flag a warning message?
    102     //        bucket->data = NULL;
    103     //    } else {
    104     bucket->data = psMemIncrRefCounter(data);
    105     //    }
     100    if (data == NULL) {
     101        // NOTE: Should we flag a warning message?
     102        bucket->data = NULL;
     103    } else {
     104        bucket->data = psMemIncrRefCounter(data);
     105    }
    106106
    107107    bucket->next = next;
     
    120120static void hashBucketFree(psHashBucket* bucket)
    121121{
     122    if (bucket == NULL) {
     123        return;
     124    }
     125
    122126    psFree(bucket->key);
     127
    123128    psFree(bucket->data);
    124129}
     
    134139psHash* psHashAlloc(long nalloc)        // initial number of buckets
    135140{
    136     if (nalloc < 0)
    137     {
    138         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    139                 "Can't allocate a psHash of negative size.");
    140         return NULL;
    141     }
    142141    psS32 i = 0;                  // loop index variable
    143142
     
    186185    psS32 i = 0;                  // Loop index variable.
    187186
     187    if (table == NULL) {
     188        return;
     189    }
    188190    // Loop through each bucket in the hash table.  If that bucket is not
    189191    // NULL, then free the bucket via a function call to hashBucketFree();
     
    223225static psPtr doHashWork(psHash* table,
    224226                        const char *key,
    225                         psPtr data,
    226                         psBool remove
     227                        psPtr data, psBool remove
    227228                           )
    228229{
     
    239240    // function, but I'm checking it anyway since future coders might change
    240241    // the way this procedure is called.
    241     /*    if ((table == NULL) || (key == NULL)) {
    242             psError(PS_ERR_BAD_PARAMETER_NULL, true,
    243                     _("Input key can not be NULL."));
    244             return NULL;
    245         }
    246     */
     242    if ((table == NULL) || (key == NULL)) {
     243        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     244                _("Input key can not be NULL."));
     245        return NULL;
     246    }
    247247    // NOTE: This is the originally supplied hash function.
    248248    // for (psS32 i = 0, len = strlen(key); i < len; i++) {
     
    253253    // This hash algorithm is from Sedgewick.  NOTE: must reread to ensure that
    254254    // the size of the hash table is not required to be a prime number.
    255     if (table->n <= 0)
    256         return NULL;
    257255    tmpchar = (char *)key;
    258256    for (hash = 0; *tmpchar != '\0'; tmpchar++) {
     
    262260    // NOTE: This should not be necessary, but for now, I'm checking bounds
    263261    // anyway.
    264     /*    if ((hash < 0) || (hash >= table->n)) {
    265             psError(PS_ERR_UNKNOWN, true,
    266                     "Internal hash function out of range (%" PRId64 ")", hash);
    267         }
    268     */
     262    if ((hash < 0) || (hash >= table->n)) {
     263        psError(PS_ERR_UNKNOWN, true,
     264                "Internal hash function out of range (%" PRId64 ")", hash);
     265    }
    269266    // ptr will have the correct hash bucket.
    270267    ptr = table->buckets[hash];
     
    400397                  const char *key)
    401398{
     399    psPtr data = NULL;
     400    psBool retVal = false;
     401
    402402    PS_ASSERT_PTR_NON_NULL(hash, false);
    403403    PS_ASSERT_PTR_NON_NULL(key, false);
    404 
    405     psPtr data = NULL;
    406     psBool retVal = false;
    407404
    408405    data = doHashWork(hash, key, NULL, true);
     
    424421    int nElements = 0;
    425422    int nbucket = hash->n;
    426     //XXX:  If we do psArrayAlloc(0) here and use psArrayAdd(result, 1, tmpBucket->data)
    427     //we can eliminate the 2nd for loop below.
    428423    for (int i = 0; i < nbucket; i++) {
    429424        psHashBucket* tmpBucket = hash->buckets[i];
  • trunk/psLib/src/types/psHash.h

    r8965 r8973  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-09-26 01:41:29 $
     13 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-09-26 02:55:34 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/types/psMetadata.c

    r8965 r8973  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.134 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-09-26 01:41:29 $
     14 *  @version $Revision: 1.135 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-09-26 02:55:34 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    605605        // Node doesn't exist - Add new metadata item to metadata collection's hash
    606606        /*  The following is unneeded.  HashAdd can't return false with non-null inputs.
    607          
     607
    608608                if(!psHashAdd(mdTable, key, (psPtr)item)) {
    609609                    psError(PS_ERR_UNKNOWN,false,
     
    13151315            }
    13161316        case PS_DATA_LIST:
    1317             fprintf(fd, "<a list of unknown contents>\n");
     1317            fprintf(fd, "<a list of size %ld>\n", ((psList*)item->data.V)->n);
    13181318            break;
    13191319        case PS_DATA_TIME: {
  • trunk/psLib/src/types/psMetadataConfig.c

    r8965 r8973  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.91 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-09-26 01:41:29 $
     12*  @version $Revision: 1.92 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-09-26 02:55:34 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    11571157    PS_ASSERT_PTR_NON_NULL(filename,NULL);
    11581158
    1159     struct stat buf;
    1160 
    11611159    // Attempt to open specified file
    11621160    int fd = 0;
     
    11641162        // XXX really should return strerror() here
    11651163        psError(PS_ERR_IO, true, _("Failed to open file '%s'. Check if it exists and it has the proper permissions."), filename);
     1164        return NULL;
     1165    }
     1166
     1167    struct stat buf;                    // Results of stat() for file
     1168    if (fstat(fd, &buf) != 0) {
     1169        psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);
     1170        close(fd);
    11661171        return NULL;
    11671172    }
     
    13291334        break;
    13301335    case PS_DATA_BOOL:
    1331         psStringAppend (&content, "%-15s  %-8s  -%15s",
     1336        psStringAppend (&content, "%-15s  %-8s  %-15s",
    13321337                        item->name, "BOOL", item->data.B ? "T" : "F");
    13331338        if (item->comment && strncmp(item->comment, "", 2)) {
     
    13671372        break;
    13681373    case PS_DATA_STRING:
    1369         psStringAppend(&content, "%-15s  %-8s  -%15s",
    1370                        item->name, "STR", item->data.str);
     1374        if (item->data.str && strlen(item->data.str) > 0) {
     1375            psStringAppend(&content, "%-15s  %-8s  %-15s",
     1376                           item->name, "STR", item->data.str);
     1377        } else {
     1378            psStringAppend(&content, "%-15s  %-8s  %-15s",
     1379                           item->name, "STR", "NULL");
     1380        }
    13711381        if (item->comment && strncmp(item->comment,"",2)) {
    13721382            psStringAppend(&content, "  # %s", item->comment);
  • trunk/psLib/src/types/psPixels.c

    r8965 r8973  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-09-26 01:41:29 $
     9 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-09-26 02:55:34 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/types/psPixels.h

    r8965 r8973  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-09-26 01:41:29 $
     9 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-09-26 02:55:34 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
Note: See TracChangeset for help on using the changeset viewer.