IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

Location:
trunk/psLib/src/collections
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psArray.c

    r1406 r1407  
     1
    12/** @file  psArray.c
    23 *
     
    89 *  @author Ross Harman, MHPCC
    910 *
    10  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-08-06 22:34:05 $
     11 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-08-07 00:06:06 $
    1213 *
    1314 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1516
    1617/******************************************************************************/
     18
    1719/*  INCLUDE FILES                                                             */
     20
    1821/******************************************************************************/
    19 #include<stdlib.h>            // for qsort, etc.
     22#include<stdlib.h>                         // for qsort, etc.
    2023
    2124#include "psMemory.h"
     
    2427#include "psLogMsg.h"
    2528
     29/*****************************************************************************/
     30
     31/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    2632
    2733/*****************************************************************************/
    28 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    29 /*****************************************************************************/
    30 static void arrayFree(psArray *restrict psArr);
     34static void arrayFree(psArray * restrict psArr);
    3135
    3236/*****************************************************************************/
     37
    3338/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
     39
    3440/*****************************************************************************/
    35 psArray* psArrayAlloc(unsigned int nalloc)
     41psArray *psArrayAlloc(unsigned int nalloc)
    3642{
    3743    psArray *psArr = NULL;
    3844
    3945    // Invalid nalloc
    40     if(nalloc < 1) {
     46    if (nalloc < 1) {
    4147        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
    4248        return NULL;
    4349    }
    44 
    4550    // Create vector struct
    46     psArr = (psArray *)psAlloc(sizeof(psArray));
    47     p_psMemSetDeallocator(psArr,(psFreeFcn)arrayFree);
     51    psArr = (psArray *) psAlloc(sizeof(psArray));
     52    p_psMemSetDeallocator(psArr, (psFreeFcn) arrayFree);
    4853
    4954    psArr->nalloc = nalloc;
     
    5156
    5257    // Create vector data array
    53     psArr->data = psAlloc(nalloc*sizeof(psPTR));
     58    psArr->data = psAlloc(nalloc * sizeof(psPTR));
    5459
    5560    return psArr;
    5661}
    5762
    58 psArray *psArrayRealloc(unsigned int nalloc, psArray *restrict in)
     63psArray *psArrayRealloc(unsigned int nalloc, psArray * restrict in)
    5964{
    6065    // Invalid nalloc
    61     if(nalloc < 1) {
     66    if (nalloc < 1) {
    6267        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
    6368        return NULL;
    6469    }
    6570
    66     if(in == NULL) {
     71    if (in == NULL) {
    6772        psError(__func__, "Null input vector\n");
    6873        return NULL;
    69     } else
    70         if(in->nalloc != nalloc) {                    // No need to realloc to same size
    71             if(nalloc < in->n) {
    72                 for (int i = nalloc; i < in->n; i++) {   // For reduction in vector size
    73                     psFree(in->data[i]);
    74                 }
    75                 in->n = nalloc;
     74    } else if (in->nalloc != nalloc) {     // No need to realloc to same size
     75        if (nalloc < in->n) {
     76            for (int i = nalloc; i < in->n; i++) {      // For reduction in vector size
     77                psFree(in->data[i]);
    7678            }
    77 
    78             // Realloc after decrementation to avoid accessing freed array elements
    79             in->data = psRealloc(in->data,nalloc*sizeof(psPTR));
    80             in->nalloc = nalloc;
     79            in->n = nalloc;
    8180        }
     81        // Realloc after decrementation to avoid accessing freed array elements
     82        in->data = psRealloc(in->data, nalloc * sizeof(psPTR));
     83        in->nalloc = nalloc;
     84    }
    8285
    8386    return in;
    8487}
    8588
    86 static void arrayFree(psArray *restrict psArr)
     89static void arrayFree(psArray * restrict psArr)
    8790{
    8891    if (psArr == NULL) {
     
    9598}
    9699
    97 void psArrayElementFree(psArray *restrict psArr)
     100void psArrayElementFree(psArray * restrict psArr)
    98101{
    99102
    100     if(psArr == NULL) {
     103    if (psArr == NULL) {
    101104        return;
    102105    }
    103106
    104     for(int i = 0; i < psArr->n; i++) {
     107    for (int i = 0; i < psArr->n; i++) {
    105108        psFree(psArr->data[i]);
    106109        psArr->data[i] = NULL;
     
    108111}
    109112
    110 psArray* psArraySort(psArray* in, psComparePtrFcn compare)
     113psArray *psArraySort(psArray * in, psComparePtrFcn compare)
    111114{
    112115    if (in == NULL) {
     
    114117    }
    115118
    116     qsort(in->data, in->n, sizeof(psPTR),
    117           (int(*)(const void *, const void *))compare);
    118 
     119    qsort(in->data, in->n, sizeof(psPTR), (int (*)(const void *, const void *))compare);
    119120
    120121    return in;
  • trunk/psLib/src/collections/psArray.h

    r1228 r1407  
     1
    12/** @file  psArray.h
    23 *
     
    1112 *  @author Ross Harman, MHPCC
    1213 *
    13  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-07-15 22:18:02 $
     14 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-07 00:06:06 $
    1516 *
    1617 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1819
    1920#ifndef PS_ARRAY_H
    20 #define PS_ARRAY_H
     21#    define PS_ARRAY_H
    2122
    22 #include "psType.h"
    23 #include "psCompare.h"
     23#    include "psType.h"
     24#    include "psCompare.h"
    2425
    2526/// @addtogroup Array
     
    3334typedef struct
    3435{
    35     unsigned int nalloc;                ///< Total number of elements available.
    36     unsigned int n;                     ///< Number of elements in use.
    37     psPTR* data;                        ///< An Array of pointer elements
     36    unsigned int nalloc;        // /< Total number of elements available.
     37    unsigned int n;             // /< Number of elements in use.
     38    psPTR *data;                // /< An Array of pointer elements
    3839}
    3940psArray;
    4041
    4142/*****************************************************************************/
     43
    4244/* FUNCTION PROTOTYPES                                                       */
     45
    4346/*****************************************************************************/
    4447
     
    5154 *
    5255 */
    53 psArray *psArrayAlloc(
    54     unsigned int nalloc                 ///< Total number of elements to make available.
    55 );
     56psArray *psArrayAlloc(unsigned int nalloc       // /< Total number of elements to make available.
     57                     );
    5658
    5759/** Reallocate an array.
     
    6365 *
    6466 */
    65 psArray *psArrayRealloc(
    66     unsigned int nalloc,                ///< Total number of elements to make available.
    67     psArray *restrict psArr            ///< array to reallocate.
    68 );
     67psArray *psArrayRealloc(unsigned int nalloc,    // /< Total number of elements to make available.
     68                        psArray * restrict psArr        // /< array to reallocate.
     69                       );
    6970
    7071/** Deallocate/Dereference elements of an array.
     
    7576 *
    7677 */
    77 void psArrayElementFree(
    78     psArray *restrict psArr    ///< Void pointer array to destroy.
    79 );
     78void psArrayElementFree(psArray * restrict psArr        // /< Void pointer array to destroy.
     79                       );
    8080
    8181/** Sort the array according to an external compare function.
     
    8686 *  @return psArray*       The sorted array.
    8787 */
    88 psArray* psArraySort(psArray* in, psComparePtrFcn compare);
     88psArray *psArraySort(psArray * in, psComparePtrFcn compare);
    8989
    9090/// @}
  • trunk/psLib/src/collections/psBitSet.c

    r1406 r1407  
     1
    12/** @file  psBitSet.c
    23 *
     
    1011 *  @author Ross Harman, MHPCC
    1112 *
    12  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-06 22:34:05 $
     13 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-07 00:06:06 $
    1415 *
    1516 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1718
    1819/******************************************************************************/
     20
    1921/*  INCLUDE FILES                                                             */
     22
    2023/******************************************************************************/
    2124#include <string.h>
     
    3134
    3235/******************************************************************************/
     36
    3337/*  DEFINE STATEMENTS                                                         */
    34 /******************************************************************************/
    35 
    36 // None
    37 
    38 /******************************************************************************/
     38
     39/******************************************************************************/
     40
     41// None
     42
     43/******************************************************************************/
     44
    3945/*  TYPE DEFINITIONS                                                          */
    40 /******************************************************************************/
    41 
    42 // None
    43 
    44 /*****************************************************************************/
     46
     47/******************************************************************************/
     48
     49// None
     50
     51/*****************************************************************************/
     52
    4553/*  GLOBAL VARIABLES                                                         */
    46 /*****************************************************************************/
    47 
    48 // None
    49 
    50 /*****************************************************************************/
     54
     55/*****************************************************************************/
     56
     57// None
     58
     59/*****************************************************************************/
     60
    5161/*  FILE STATIC VARIABLES                                                    */
    52 /*****************************************************************************/
    53 
    54 // None
    55 
    56 /*****************************************************************************/
     62
     63/*****************************************************************************/
     64
     65// None
     66
     67/*****************************************************************************/
     68
    5769/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    58 /*****************************************************************************/
    59 static void psBitSetFree(psBitSet *restrict inBitSet);
    60 
     70
     71/*****************************************************************************/
     72static void psBitSetFree(psBitSet * restrict inBitSet);
    6173
    6274/** Private function to create a mask.
     
    7082{
    7183    char mask = (char)0x01;
     84
    7285    // Ignore splint warning about negative bit shifts
    73     /*@i@*/
    74     mask = mask << (bit%8);
     86    /* @i@ */
     87    mask = mask << (bit % 8);
    7588
    7689    return mask;
     
    7891
    7992/*****************************************************************************/
     93
    8094/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    81 /*****************************************************************************/
    82 psBitSet* psBitSetAlloc(int n)
     95
     96/*****************************************************************************/
     97psBitSet *psBitSetAlloc(int n)
    8398{
    8499    int numBytes = 0;
    85100    psBitSet *newObj = NULL;
    86101
    87     if(n <= 0) {
     102    if (n <= 0) {
    88103        psError(__func__, " : Line %d - Allocation size must be > 0: size = %d", __LINE__, n);
    89104        return 0;
    90105    }
    91106
    92     numBytes = ceil(n/8.0);
     107    numBytes = ceil(n / 8.0);
    93108    newObj = psAlloc(sizeof(psBitSet));
    94     if(newObj == NULL) {
    95         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    96     }
    97     p_psMemSetDeallocator(newObj,(psFreeFcn)psBitSetFree);
     109    if (newObj == NULL) {
     110        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     111    }
     112    p_psMemSetDeallocator(newObj, (psFreeFcn) psBitSetFree);
    98113    newObj->n = numBytes;
    99114
    100115    // Ignore splint warning about releasing pointer members, since they've not been allocated yet
    101     /*@i@*/
    102     newObj->bits = psAlloc(sizeof(char)*numBytes);
    103     if(newObj->bits == NULL) {
    104         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
     116    /* @i@ */
     117    newObj->bits = psAlloc(sizeof(char) * numBytes);
     118    if (newObj->bits == NULL) {
     119        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
    105120    }
    106121
     
    110125}
    111126
    112 static void psBitSetFree(psBitSet *restrict inBitSet)
    113 {
    114     if(inBitSet == NULL) {
     127static void psBitSetFree(psBitSet * restrict inBitSet)
     128{
     129    if (inBitSet == NULL) {
    115130        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    116131        return;
     
    119134}
    120135
    121 psBitSet* psBitSetSet(psBitSet *inBitSet, int bit)
    122 {
    123     char* byte = NULL;
    124 
    125     if(inBitSet == NULL) {
     136psBitSet *psBitSetSet(psBitSet * inBitSet, int bit)
     137{
     138    char *byte = NULL;
     139
     140    if (inBitSet == NULL) {
    126141        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    127142        return inBitSet;
    128     } else
    129         if(bit < 0) {
    130             psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
    131             return inBitSet;
    132         } else
    133             if(bit > inBitSet->n*8-1) {
    134                 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
    135                 return inBitSet;
    136             }
    137 
     143    } else if (bit < 0) {
     144        psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
     145        return inBitSet;
     146    } else if (bit > inBitSet->n * 8 - 1) {
     147        psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
     148        return inBitSet;
     149    }
    138150    // Variable byte is the byte in the array that contains the bit to be set
    139     byte = inBitSet->bits+bit/8;
     151    byte = inBitSet->bits + bit / 8;
    140152    *byte |= mask(bit);
    141153
     
    143155}
    144156
    145 bool psBitSetTest(const psBitSet *inBitSet, int bit)
    146 {
    147     char* byte = NULL;
    148 
    149     if(inBitSet == NULL) {
    150         psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    151         return 0;
    152     } else
    153         if(bit < 0) {
    154             psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
    155             return 0;
    156         } else
    157             if(bit > inBitSet->n*8-1) {
    158                 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
    159                 return 0;
    160             }
    161 
     157bool psBitSetTest(const psBitSet * inBitSet, int bit)
     158{
     159    char *byte = NULL;
     160
     161    if (inBitSet == NULL) {
     162        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
     163        return 0;
     164    } else if (bit < 0) {
     165        psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
     166        return 0;
     167    } else if (bit > inBitSet->n * 8 - 1) {
     168        psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
     169        return 0;
     170    }
    162171    // Variable byte is the byte in the array that contains the bit to be tested
    163     byte = inBitSet->bits+bit/8;
    164     if((int)(*byte&mask(bit)) == 0) {
     172    byte = inBitSet->bits + bit / 8;
     173    if ((int)(*byte & mask(bit)) == 0) {
    165174        return 0;
    166175    }
     
    169178}
    170179
    171 psBitSet* psBitSetOp(psBitSet *outBitSet, const psBitSet *restrict inBitSet1, char *operator,
    172                      const psBitSet *restrict inBitSet2)
     180psBitSet *psBitSetOp(psBitSet * outBitSet, const psBitSet * restrict inBitSet1, char *operator,
     181                     const psBitSet * restrict inBitSet2)
    173182{
    174183    int i = 0;
     
    179188    char *inBits2 = NULL;
    180189
    181     if(inBitSet1 == NULL) {
     190    if (inBitSet1 == NULL) {
    182191        psError(__func__, " : Line %d - Null psBitSet for inBitSet1 argument", __LINE__);
    183192        return outBitSet;
    184193    }
    185194
    186     if(operator == NULL) {
     195    if (operator == NULL) {
    187196        psError(__func__, " : Line %d - Null input operator\n", __LINE__);
    188197        return outBitSet;
    189198    }
    190199
    191     if(inBitSet2 == NULL) {
     200    if (inBitSet2 == NULL) {
    192201        psError(__func__, " : Line %d - Null psBitSet for inBitSet2 argument", __LINE__);
    193202        return outBitSet;
    194203    }
    195204
    196     if(outBitSet == NULL) {
    197         outBitSet = psBitSetAlloc(inBitSet1->n*8);
    198     }
    199 
    200     if(inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {
     205    if (outBitSet == NULL) {
     206        outBitSet = psBitSetAlloc(inBitSet1->n * 8);
     207    }
     208
     209    if (inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {
    201210        psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__);
    202211        return outBitSet;
     
    209218
    210219    tempChar = toupper(operator[0]);
    211     switch(tempChar) {
     220    switch (tempChar) {
    212221    case 'A':
    213         for(i=0; i<n; i++) {
     222        for (i = 0; i < n; i++) {
    214223            outBits[i] = inBits1[i] & inBits2[i];
    215224        }
    216225        break;
    217226    case 'O':
    218         for(i=0; i<n; i++) {
     227        for (i = 0; i < n; i++) {
    219228            outBits[i] = inBits1[i] | inBits2[i];
    220229        }
    221230        break;
    222231    case 'X':
    223         for(i=0; i<n; i++) {
     232        for (i = 0; i < n; i++) {
    224233            outBits[i] = inBits1[i] ^ inBits2[i];
    225234        }
     
    232241}
    233242
    234 psBitSet* psBitSetNot(psBitSet *outBitSet, const psBitSet *restrict inBitSet)
     243psBitSet *psBitSetNot(psBitSet * outBitSet, const psBitSet * restrict inBitSet)
    235244{
    236245    int i = 0;
     
    239248    char *inBits = NULL;
    240249
    241     if(inBitSet == NULL) {
     250    if (inBitSet == NULL) {
    242251        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    243252        return outBitSet;
     
    245254
    246255    n = inBitSet->n;
    247     if(n == 0) {
     256    if (n == 0) {
    248257        psError(__func__, " : Line %d - No elements in inBitSet", __LINE__);
    249258        return outBitSet;
    250259    }
    251260
    252     if(outBitSet == NULL) {
    253         outBitSet = psBitSetAlloc(n*8);
    254     }
    255 
    256     if(inBitSet->n != outBitSet->n) {
     261    if (outBitSet == NULL) {
     262        outBitSet = psBitSetAlloc(n * 8);
     263    }
     264
     265    if (inBitSet->n != outBitSet->n) {
    257266        psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__);
    258267        return outBitSet;
     
    262271    inBits = inBitSet->bits;
    263272
    264     for(i=0; i<n; i++) {
     273    for (i = 0; i < n; i++) {
    265274        outBits[i] = ~inBits[i];
    266275    }
     
    269278}
    270279
    271 char *psBitSetToString(const psBitSet *restrict inBitSet)
     280char *psBitSetToString(const psBitSet * restrict inBitSet)
    272281{
    273282    int i = 0;
    274     int numBits = inBitSet->n*8;
    275     char* outString = psAlloc((size_t)numBits+1);
    276     if(outString == NULL) {
    277         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    278     }
    279 
    280     for(i=0; i<numBits; i++) {
    281         outString[numBits-i-1] = (psBitSetTest(inBitSet, i) == 1)?'1':'0';
     283    int numBits = inBitSet->n * 8;
     284    char *outString = psAlloc((size_t) numBits + 1);
     285
     286    if (outString == NULL) {
     287        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     288    }
     289
     290    for (i = 0; i < numBits; i++) {
     291        outString[numBits - i - 1] = (psBitSetTest(inBitSet, i) == 1) ? '1' : '0';
    282292    }
    283293
  • trunk/psLib/src/collections/psBitSet.h

    r1172 r1407  
     1
    12/** @file  psBitSet.h
    23 *
     
    1213 *  @author Ross Harman, MHPCC
    1314 *
    14  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-07-01 21:48:11 $
     15 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2004-08-07 00:06:06 $
    1617 *
    1718 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1920
    2021#ifndef PSBITSET_H
    21 #define PSBITSET_H
     22#    define PSBITSET_H
    2223
    2324/// @addtogroup BitSet
     
    2526
    2627/******************************************************************************/
     28
    2729/*  TYPE DEFINITIONS                                                          */
     30
    2831/******************************************************************************/
    2932
     
    3538typedef struct
    3639{
     40
    3741    int n;      /**< Number of bytes in the array */
     42
    3843    char *bits; /**< Aray of bytes holding bits */
    3944}
     
    4146
    4247/*****************************************************************************/
     48
    4349/* FUNCTION PROTOTYPES                                                       */
     50
    4451/*****************************************************************************/
    4552
     
    5158 *  @return  psBitSet*: Pointer to struct containing array of bits and size of array.
    5259 */
     60
    5361/*@null@*/
    54 psBitSet* psBitSetAlloc(
    55     int n   /**< Number of bits in psBitSet array */
    56 );
     62
     63psBitSet *psBitSetAlloc(int n
     64                        /**< Number of bits in psBitSet array */
     65                       );
    5766
    5867/** Set a bit.
     
    6473 *  @return  psBitSet*: Pointer to struct containing psBitSet.
    6574 */
    66 psBitSet* psBitSetSet(
    67     /*@returned@*/psBitSet *restrict inMask,  /**< Pointer to psBitSet to be set. */
    68     int bit                     /**< Bit to be set. */
     75psBitSet *psBitSetSet(
     76
     77    /* @returned@ */ psBitSet * restrict inMask,
     78    /**< Pointer to psBitSet to be set. */
     79
     80    int bit/**< Bit to be set. */
    6981);
    7082
     
    7890 *  @return  int: Value of bit, either one or zero.
    7991 */
    80 bool psBitSetTest(
    81     const psBitSet *restrict inMask,    /**< Pointer psBitSet to be tested. */
    82     int bit                             /**< Bit to be tested. */
    83 );
     92
     93bool psBitSetTest(const psBitSet * restrict inMask,
     94                  /**< Pointer psBitSet to be tested. */
     95
     96                  int bit               /**< Bit to be tested. */
     97                 );
    8498
    8599/** Perform a binary operation on two psBitSets
     
    90104 *  @return  psBitSet*: Pointer to struct containing result of binary operation.
    91105 */
    92 psBitSet* psBitSetOp(
    93     /*@returned@*/psBitSet *restrict outMask,   /**< Resulting psBitSet from binary operation */
    94     const psBitSet *restrict inMask1,           /**< First psBitSet on which to operate */
    95     char *operator,                             /**< Bit operation */
    96     const psBitSet *restrict inMask2            /**< First psBitSet on which to operate */
     106psBitSet *psBitSetOp(
     107
     108    /* @returned@ */ psBitSet * restrict outMask,
     109    /**< Resulting psBitSet from binary operation */
     110
     111    const psBitSet * restrict inMask1,
     112    /**< First psBitSet on which to operate */
     113
     114    char *operator,         /**< Bit operation */
     115
     116    const psBitSet * restrict inMask2
     117    /**< First psBitSet on which to operate */
    97118);
    98119
     
    103124 *  @return  psBitSet*: Pointer to struct containing result of operation.
    104125 */
    105 psBitSet* psBitSetNot(
    106     psBitSet *outBitSet,                /**< Resulting psBitSet from operation */
    107     const psBitSet *restrict inBitSet   /**< Input psBitSet */
    108 );
     126
     127psBitSet *psBitSetNot(psBitSet * outBitSet,
     128                      /**< Resulting psBitSet from operation */
     129
     130                      const psBitSet * restrict inBitSet
     131                      /**< Input psBitSet */
     132                     );
    109133
    110134/** Convert the psBitSet to a string of ones and zeros.
     
    115139 *  @return  char*: Pointer to character array containing string data.
    116140 */
    117 char *psBitSetToString(
    118     const psBitSet *restrict inMask /**< psBitSet to convert */
    119 );
     141
     142char *psBitSetToString(const psBitSet * restrict inMask
     143                       /**< psBitSet to convert */
     144                      );
    120145
    121146/// @}
  • trunk/psLib/src/collections/psCompare.c

    r1393 r1407  
     1
    12/** @file psCompare.c
    23 *  @brief Comparison functions for sorting routines
     
    67 *  @author Robert Daniel DeSonia, MHPCC
    78 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-08-05 19:38:52 $
     9 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-08-07 00:06:06 $
    1011 *
    1112 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/collections/psCompare.h

    r1111 r1407  
    11#if !defined(PS_COMPARE_H)
    2 #define PS_COMPARE_H
     2#    define PS_COMPARE_H
    33
    44/** @file psCompare.h
     
    99 *  @ingroup Compare
    1010 *
    11  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-28 20:36:37 $
     11 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-08-07 00:06:06 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626 *                   than, equal to, or greater than the second.
    2727 */
    28 typedef int (*psComparePtrFcn)(const void** a, const void** b);
     28typedef int (*psComparePtrFcn) (const void **a, const void **b);
    2929
    3030/** A comparison function for sorting.
     
    3434 *                   than, equal to, or greater than the second.
    3535 */
    36 typedef int (*psCompareFcn)(const void* a, const void* b);
     36typedef int (*psCompareFcn) (const void *a, const void *b);
    3737
    3838/** Compare function of psS8 data.  For use with psListSort.
     
    4242 *                   than, equal to, or greater than the second.
    4343 */
    44 int psCompareS8Ptr(const void** a, const void** b);
     44int psCompareS8Ptr(const void **a, const void **b);
    4545
    4646/** Compare function of psS16 data.  For use with psListSort.
     
    5050 *                   than, equal to, or greater than the second.
    5151 */
    52 int psCompareS16Ptr(const void** a, const void** b);
     52int psCompareS16Ptr(const void **a, const void **b);
    5353
    5454/** Compare function of psS32 data.  For use with psListSort.
     
    5858 *                   than, equal to, or greater than the second.
    5959 */
    60 int psCompareS32Ptr(const void** a, const void** b);
     60int psCompareS32Ptr(const void **a, const void **b);
    6161
    6262/** Compare function of psS64 data.  For use with psListSort.
     
    6666 *                   than, equal to, or greater than the second.
    6767 */
    68 int psCompareS64Ptr(const void** a, const void** b);
     68int psCompareS64Ptr(const void **a, const void **b);
    6969
    7070/** Compare function of psU8 data.  For use with psListSort.
     
    7474 *                   than, equal to, or greater than the second.
    7575 */
    76 int psCompareU8Ptr(const void** a, const void** b);
     76int psCompareU8Ptr(const void **a, const void **b);
    7777
    7878/** Compare function of psU16 data.  For use with psListSort.
     
    8282 *                   than, equal to, or greater than the second.
    8383 */
    84 int psCompareU16Ptr(const void** a, const void** b);
     84int psCompareU16Ptr(const void **a, const void **b);
    8585
    8686/** Compare function of psU32 data.  For use with psListSort.
     
    9090 *                   than, equal to, or greater than the second.
    9191 */
    92 int psCompareU32Ptr(const void** a, const void** b);
     92int psCompareU32Ptr(const void **a, const void **b);
    9393
    9494/** Compare function of psU64 data.  For use with psListSort.
     
    9898 *                   than, equal to, or greater than the second.
    9999 */
    100 int psCompareU64Ptr(const void** a, const void** b);
     100int psCompareU64Ptr(const void **a, const void **b);
    101101
    102102/** Compare function of psF32 data.  For use with psListSort.
     
    106106 *                   than, equal to, or greater than the second.
    107107 */
    108 int psCompareF32Ptr(const void** a, const void** b);
     108int psCompareF32Ptr(const void **a, const void **b);
    109109
    110110/** Compare function of psF64 data.  For use with psListSort.
     
    114114 *                   than, equal to, or greater than the second.
    115115 */
    116 int psCompareF64Ptr(const void** a, const void** b);
     116int psCompareF64Ptr(const void **a, const void **b);
    117117
    118118/** Compare function of psS8 data.  For use with psListSort for descending ordering.
     
    122122 *                   than, equal to, or less than the second.
    123123 */
    124 int psCompareDescendingS8Ptr(const void** a, const void** b);
     124int psCompareDescendingS8Ptr(const void **a, const void **b);
    125125
    126126/** Compare function of psS16 data.  For use with psListSort for descending ordering.
     
    130130 *                   than, equal to, or less than the second.
    131131 */
    132 int psCompareDescendingS16Ptr(const void** a, const void** b);
     132int psCompareDescendingS16Ptr(const void **a, const void **b);
    133133
    134134/** Compare function of psS32 data.  For use with psListSort for descending ordering.
     
    138138 *                   than, equal to, or less than the second.
    139139 */
    140 int psCompareDescendingS32Ptr(const void** a, const void** b);
     140int psCompareDescendingS32Ptr(const void **a, const void **b);
    141141
    142142/** Compare function of psS64 data.  For use with psListSort for descending ordering.
     
    146146 *                   than, equal to, or less than the second.
    147147 */
    148 int psCompareDescendingS64Ptr(const void** a, const void** b);
     148int psCompareDescendingS64Ptr(const void **a, const void **b);
    149149
    150150/** Compare function of psU8 data.  For use with psListSort for descending ordering.
     
    154154 *                   than, equal to, or less than the second.
    155155 */
    156 int psCompareDescendingU8Ptr(const void** a, const void** b);
     156int psCompareDescendingU8Ptr(const void **a, const void **b);
    157157
    158158/** Compare function of psU16 data.  For use with psListSort for descending ordering.
     
    162162 *                   than, equal to, or less than the second.
    163163 */
    164 int psCompareDescendingU16Ptr(const void** a, const void** b);
     164int psCompareDescendingU16Ptr(const void **a, const void **b);
    165165
    166166/** Compare function of psU32 data.  For use with psListSort for descending ordering.
     
    170170 *                   than, equal to, or lessg than the second.
    171171 */
    172 int psCompareDescendingU32Ptr(const void** a, const void** b);
     172int psCompareDescendingU32Ptr(const void **a, const void **b);
    173173
    174174/** Compare function of psU64 data.  For use with psListSort for descending ordering.
     
    178178 *                   than, equal to, or lessg than the second.
    179179 */
    180 int psCompareDescendingU64Ptr(const void** a, const void** b);
     180int psCompareDescendingU64Ptr(const void **a, const void **b);
    181181
    182182/** Compare function of psF32 data.  For use with psListSort for descending ordering.
     
    186186 *                   than, equal to, or lessg than the second.
    187187 */
    188 int psCompareDescendingF32Ptr(const void** a, const void** b);
     188int psCompareDescendingF32Ptr(const void **a, const void **b);
    189189
    190190/** Compare function of psF64 data.  For use with psListSort for descending ordering.
     
    194194 *                   than, equal to, or lessg than the second.
    195195 */
    196 int psCompareDescendingF64Ptr(const void** a, const void** b);
     196int psCompareDescendingF64Ptr(const void **a, const void **b);
    197197
    198198/** Compare function of psS8 data.
     
    202202 *                   than, equal to, or greater than the second.
    203203 */
    204 int psCompareS8(const void* a, const void* b);
     204int psCompareS8(const void *a, const void *b);
    205205
    206206/** Compare function of psS16 data.
     
    210210 *                   than, equal to, or greater than the second.
    211211 */
    212 int psCompareS16(const void* a, const void* b);
     212int psCompareS16(const void *a, const void *b);
    213213
    214214/** Compare function of psS32 data.
     
    218218 *                   than, equal to, or greater than the second.
    219219 */
    220 int psCompareS32(const void* a, const void* b);
     220int psCompareS32(const void *a, const void *b);
    221221
    222222/** Compare function of psS64 data.
     
    226226 *                   than, equal to, or greater than the second.
    227227 */
    228 int psCompareS64(const void* a, const void* b);
     228int psCompareS64(const void *a, const void *b);
    229229
    230230/** Compare function of psU8 data.
     
    234234 *                   than, equal to, or greater than the second.
    235235 */
    236 int psCompareU8(const void* a, const void* b);
     236int psCompareU8(const void *a, const void *b);
    237237
    238238/** Compare function of psU16 data.
     
    242242 *                   than, equal to, or greater than the second.
    243243 */
    244 int psCompareU16(const void* a, const void* b);
     244int psCompareU16(const void *a, const void *b);
    245245
    246246/** Compare function of psU32 data.
     
    250250 *                   than, equal to, or greater than the second.
    251251 */
    252 int psCompareU32(const void* a, const void* b);
     252int psCompareU32(const void *a, const void *b);
    253253
    254254/** Compare function of psU64 data.
     
    258258 *                   than, equal to, or greater than the second.
    259259 */
    260 int psCompareU64(const void* a, const void* b);
     260int psCompareU64(const void *a, const void *b);
    261261
    262262/** Compare function of psF32 data.
     
    266266 *                   than, equal to, or greater than the second.
    267267 */
    268 int psCompareF32(const void* a, const void* b);
     268int psCompareF32(const void *a, const void *b);
    269269
    270270/** Compare function of psF64 data.
     
    274274 *                   than, equal to, or greater than the second.
    275275 */
    276 int psCompareF64(const void* a, const void* b);
     276int psCompareF64(const void *a, const void *b);
    277277
    278278/** Compare function of psS8 data.
     
    282282 *                   than, equal to, or less than the second.
    283283 */
    284 int psCompareDescendingS8(const void* a, const void* b);
     284int psCompareDescendingS8(const void *a, const void *b);
    285285
    286286/** Compare function of psS16 data.
     
    290290 *                   than, equal to, or less than the second.
    291291 */
    292 int psCompareDescendingS16(const void* a, const void* b);
     292int psCompareDescendingS16(const void *a, const void *b);
    293293
    294294/** Compare function of psS32 data.
     
    298298 *                   than, equal to, or less than the second.
    299299 */
    300 int psCompareDescendingS32(const void* a, const void* b);
     300int psCompareDescendingS32(const void *a, const void *b);
    301301
    302302/** Compare function of psS64 data.
     
    306306 *                   than, equal to, or less than the second.
    307307 */
    308 int psCompareDescendingS64(const void* a, const void* b);
     308int psCompareDescendingS64(const void *a, const void *b);
    309309
    310310/** Compare function of psU8 data.
     
    314314 *                   than, equal to, or less than the second.
    315315 */
    316 int psCompareDescendingU8(const void* a, const void* b);
     316int psCompareDescendingU8(const void *a, const void *b);
    317317
    318318/** Compare function of psU16 data.
     
    322322 *                   than, equal to, or less than the second.
    323323 */
    324 int psCompareDescendingU16(const void* a, const void* b);
     324int psCompareDescendingU16(const void *a, const void *b);
    325325
    326326/** Compare function of psU32 data.
     
    330330 *                   than, equal to, or lessg than the second.
    331331 */
    332 int psCompareDescendingU32(const void* a, const void* b);
     332int psCompareDescendingU32(const void *a, const void *b);
    333333
    334334/** Compare function of psU64 data.
     
    338338 *                   than, equal to, or lessg than the second.
    339339 */
    340 int psCompareDescendingU64(const void* a, const void* b);
     340int psCompareDescendingU64(const void *a, const void *b);
    341341
    342342/** Compare function of psF32 data.
     
    346346 *                   than, equal to, or lessg than the second.
    347347 */
    348 int psCompareDescendingF32(const void* a, const void* b);
     348int psCompareDescendingF32(const void *a, const void *b);
    349349
    350350/** Compare function of psF64 data.
     
    354354 *                   than, equal to, or lessg than the second.
    355355 */
    356 int psCompareDescendingF64(const void* a, const void* b);
    357 
    358 
     356int psCompareDescendingF64(const void *a, const void *b);
    359357
    360358/// @}
  • trunk/psLib/src/collections/psList.c

    r1406 r1407  
     1
    12/** @file psList.c
    23 *  @brief Support for doubly linked lists
     
    67 *  @author Robert Daniel DeSonia, MHPCC
    78 *
    8  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-08-06 22:34:05 $
     9 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-08-07 00:06:06 $
    1011 *
    1112 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1516#include <stdbool.h>
    1617#include <stdio.h>
    17 #include <pthread.h>                   // we need a mutex to make this stuff thread safe.
     18#include <pthread.h>                       // we need a mutex to make this stuff thread safe.
    1819
    1920#include "psError.h"
     
    2425#include "psLogMsg.h"
    2526
    26 #define ITER_INIT_HEAD ((void *)1) // next iteration should return head
    27 #define ITER_INIT_TAIL ((void *)2) // next iteration should return tail
     27#define ITER_INIT_HEAD ((void *)1)         // next iteration should return head
     28#define ITER_INIT_TAIL ((void *)2)         // next iteration should return tail
    2829
    2930// private functions.
    30 static psListElem* listGetIterator(psList* list);
    31 static int listGetIteratorIndex(psList* list);
    32 static void listSetIterator(psList *list, int where, bool lockList);
    33 static void listFree(psList *list);
    34 
     31static psListElem *listGetIterator(psList * list);
     32static int listGetIteratorIndex(psList * list);
     33static void listSetIterator(psList * list, int where, bool lockList);
     34static void listFree(psList * list);
    3535
    3636psList *psListAlloc(void *data)
    3737{
    3838    psList *list = psAlloc(sizeof(psList));
    39     p_psMemSetDeallocator(list,(psFreeFcn)listFree);
     39
     40    p_psMemSetDeallocator(list, (psFreeFcn) listFree);
    4041
    4142    list->size = 0;
     
    4445    list->iterIndex = PS_LIST_HEAD;
    4546
    46     pthread_mutex_init(&(list->lock),NULL)
     47    pthread_mutex_init(&(list->lock), NULL)
    4748    ;
    4849
     
    5455}
    5556
    56 static void listFree(psList *list)
     57static void listFree(psList * list)
    5758{
    5859    if (list == NULL) {
     
    6364    ;
    6465
    65     for(psListElem *ptr = list->head; ptr != NULL; ) {
     66    for (psListElem * ptr = list->head; ptr != NULL;) {
    6667        psListElem *next = ptr->next;
    6768
     
    8081}
    8182
    82 bool psListAdd(psList *list, void *data, int where)
    83 {
    84     psListElem* position;
    85     psListElem* elem;
     83bool psListAdd(psList * list, void *data, int where)
     84{
     85    psListElem *position;
     86    psListElem *elem;
    8687    int cursorIndex = 0;
    8788
     
    9596
    9697    if (where <= PS_LIST_UNKNOWN) {
    97         /// XXX What is the better way to communicate this failure to the caller?
    98         psLogMsg(__func__,PS_LOG_WARN,
    99                  "The given insert location (%i) for psListAdd is invalid.",
    100                  where);
     98        // / XXX What is the better way to communicate this failure to the caller?
     99        psLogMsg(__func__, PS_LOG_WARN, "The given insert location (%i) for psListAdd is invalid.", where);
    101100        return false;
    102101    }
     
    108107
    109108    if (where > 0 && where > list->size) {
    110         psLogMsg(__func__,PS_LOG_WARN,
    111                  "Invalid index %d (only %d elements in psList); assuming tail.",
    112                  where, list->size);
     109        psLogMsg(__func__, PS_LOG_WARN,
     110                 "Invalid index %d (only %d elements in psList); assuming tail.", where, list->size);
    113111        where = PS_LIST_TAIL;
    114112    }
     
    138136
    139137        if (position == NULL) {
    140             psError(__func__,"%s failed to move cursor to specified location (%d)",__func__,where);
    141             position = list->head; // since we no list->size != 0, this must be non-NULL
    142         }
    143 
     138            psError(__func__, "%s failed to move cursor to specified location (%d)", __func__, where);
     139            position = list->head;         // since we no list->size != 0, this must be non-NULL
     140        }
    144141        // insert our new element in front of the given position
    145142        elem->prev = position->prev;
     
    147144        position->prev = elem;
    148145
    149         if (elem->prev == NULL) { // must be front of list
     146        if (elem->prev == NULL) {          // must be front of list
    150147            list->head = elem;
    151148        } else {
     
    167164
    168165/*****************************************************************************/
     166
    169167/*
    170168 * Remove an element from a list
    171169 */
    172 bool psListRemove(psList *list, void *data, int which)
    173 {
    174     psListElem *elem = NULL;  // element to remove
     170bool psListRemove(psList * list, void *data, int which)
     171{
     172    psListElem *elem = NULL;    // element to remove
    175173    int cursorIndex = 0;
    176174
    177175    if (list == NULL) {
    178         psError(__func__,"list parameter found to be NULL in %s",__func__);
     176        psError(__func__, "list parameter found to be NULL in %s", __func__);
    179177        return false;
    180178    }
    181 
    182179    // get exclusive access to list so that other threads will not get in the way.
    183180    pthread_mutex_lock(&list->lock)
     
    187184        // search list for the data item.
    188185
    189         int i = 0;   // index
    190         for (psListElem *ptr = list->head; ptr != NULL; ptr = ptr->next) {
     186        int i = 0;              // index
     187
     188        for (psListElem * ptr = list->head; ptr != NULL; ptr = ptr->next) {
    191189            if (ptr->data == data) {
    192190                which = i;
     
    201199        }
    202200    }
    203 
    204201    // position the list's cursor to the desired location
    205     listSetIterator(list,which,false);
     202    listSetIterator(list, which, false);
    206203    elem = listGetIterator(list);
    207204    cursorIndex = listGetIteratorIndex(list);
    208205
    209206    if (elem == NULL) {
    210         psError(__func__, "Couldn't position to given index (%d) to remove element from list.",which);
     207        psError(__func__, "Couldn't position to given index (%d) to remove element from list.", which);
    211208        return false;
    212209    }
     
    214211    list->size--;
    215212
    216     if (elem->prev == NULL) { // head of list?
     213    if (elem->prev == NULL) {              // head of list?
    217214        list->head = elem->next;
    218215    } else {
     
    220217    }
    221218
    222     if (elem->next == NULL) { // tail of list?
     219    if (elem->next == NULL) {              // tail of list?
    223220        list->tail = elem->prev;
    224221
     
    246243}
    247244
    248 void psListSetIterator(psList *list, int where)
    249 {
    250     listSetIterator(list,where,true);
    251 }
    252 
    253 void listSetIterator(psList* list, int where, bool lockList)
    254 {
    255     psListElem* cursor;
     245void psListSetIterator(psList * list, int where)
     246{
     247    listSetIterator(list, where, true);
     248}
     249
     250void listSetIterator(psList * list, int where, bool lockList)
     251{
     252    psListElem *cursor;
    256253    int position;
    257254
    258255    if (list == NULL) {
    259         psError(__func__,"Unexpected null pointer for psList parameter (%s:%d).",__FILE__,__LINE__);
     256        psError(__func__, "Unexpected null pointer for psList parameter (%s:%d).", __FILE__, __LINE__);
    260257        return;
    261258    }
     
    291288        if (cursor != NULL) {
    292289            list->iter = cursor->prev;
    293             list->iterIndex = position-1;
     290            list->iterIndex = position - 1;
    294291        }
    295292        break;
     
    301298        if (cursor != NULL) {
    302299            list->iter = cursor->next;
    303             list->iterIndex = position+1;
     300            list->iterIndex = position + 1;
    304301        }
    305302        break;
     
    309306
    310307    default:
    311         if (where <= PS_LIST_HEAD) { // bascially same as PS_LIST_UNKNOWN above
    312             psError(__func__,"Can't move to an unknown position.  Not moving the iterator position.");
     308        if (where <= PS_LIST_HEAD) {   // bascially same as PS_LIST_UNKNOWN above
     309            psError(__func__, "Can't move to an unknown position.  Not moving the iterator position.");
    313310        } else {
    314311            cursor = listGetIterator(list);
    315             if (cursor == NULL) { // reset the iterator if it is invalid
     312            if (cursor == NULL) {      // reset the iterator if it is invalid
    316313                list->iter = ITER_INIT_HEAD;
    317314                list->iterIndex = 0;
     
    321318
    322319            if (where < position) {
    323                 int diff = position-where;
    324                 for (int count=0;count < diff; count++) {
    325                     listSetIterator(list,PS_LIST_PREVIOUS,false);
     320                int diff = position - where;
     321
     322                for (int count = 0; count < diff; count++) {
     323                    listSetIterator(list, PS_LIST_PREVIOUS, false);
    326324                }
    327325            } else {
    328                 int diff = where-position;
    329                 for (int count=0;count < diff; count++) {
    330                     listSetIterator(list,PS_LIST_NEXT,false);
     326                int diff = where - position;
     327
     328                for (int count = 0; count < diff; count++) {
     329                    listSetIterator(list, PS_LIST_NEXT, false);
    331330                }
    332331            }
     
    341340}
    342341
    343 psListElem* listGetIterator(psList* list)
     342psListElem *listGetIterator(psList * list)
    344343{
    345344    if (list == NULL) {
     
    349348    if (list->iter == ITER_INIT_HEAD) {
    350349        return list->head;
    351     } else
    352         if (list->iter == ITER_INIT_TAIL) {
    353             return list->tail;
    354         } else {
    355             return list->iter;
    356         }
    357 }
    358 
    359 int listGetIteratorIndex(psList* list)
     350    } else if (list->iter == ITER_INIT_TAIL) {
     351        return list->tail;
     352    } else {
     353        return list->iter;
     354    }
     355}
     356
     357int listGetIteratorIndex(psList * list)
    360358{
    361359    if (list->iter == ITER_INIT_HEAD) {
    362360        return 0;
    363     } else
    364         if (list->iter == ITER_INIT_TAIL) {
    365             return list->size-1;
    366         } else {
    367             return list->iterIndex;
    368         }
    369 }
    370 
    371 void* psListGet(psList* list,int which)
    372 {
    373     psListElem* element;
    374 
    375     psListSetIterator(list,which);
     361    } else if (list->iter == ITER_INIT_TAIL) {
     362        return list->size - 1;
     363    } else {
     364        return list->iterIndex;
     365    }
     366}
     367
     368void *psListGet(psList * list, int which)
     369{
     370    psListElem *element;
     371
     372    psListSetIterator(list, which);
    376373    element = listGetIterator(list);
    377374
     
    382379    }
    383380}
     381
    384382/*
    385383 * and now return the previous/next element of the list
    386384 */
    387 void *psListGetNext(psList *list)
     385void *psListGetNext(psList * list)
    388386{
    389387    return psListGet(list, PS_LIST_NEXT);
    390388}
    391389
    392 void *psListGetPrevious(psList *list)
     390void *psListGetPrevious(psList * list)
    393391{
    394392    return psListGet(list, PS_LIST_PREVIOUS);
    395393}
    396394
    397 void *psListGetCurrent(psList *list)
     395void *psListGetCurrent(psList * list)
    398396{
    399397    return psListGet(list, PS_LIST_CURRENT);
     
    403401 * Convert a psList to/from a psVoidPtrArray
    404402 */
    405 psArray* psListToArray(psList* restrict list)
    406 {
    407     psListElem* ptr;
     403psArray *psListToArray(psList * restrict list)
     404{
     405    psListElem *ptr;
    408406    unsigned int n;
    409     psArray* restrict arr;
     407    psArray *restrict arr;
    410408
    411409    if (list == NULL) {
     
    431429}
    432430
    433 psList* psArrayToList(psArray* arr)
     431psList *psArrayToList(psArray * arr)
    434432{
    435433    unsigned int n;
    436     psList* list; // list of elements
     434    psList *list;              // list of elements
    437435
    438436    if (arr == NULL) {
     
    443441    n = arr->n;
    444442    for (int i = 0; i < n; i++) {
    445         psListAdd(list,arr->data[i],PS_LIST_TAIL);
     443        psListAdd(list, arr->data[i], PS_LIST_TAIL);
    446444    }
    447445
     
    449447}
    450448
    451 
    452 psList* psListSort(psList* list, psComparePtrFcn compare)
    453 {
    454     psArray* arr;
     449psList *psListSort(psList * list, psComparePtrFcn compare)
     450{
     451    psArray *arr;
     452
    455453    if (list == NULL) {
    456454        return NULL;
    457455    }
    458 
    459456    // convert to indexable vector for use by qsort.
    460457    arr = psListToArray(list);
    461458    psFree(list);
    462459
    463     arr = psArraySort(arr,compare);
     460    arr = psArraySort(arr, compare);
    464461
    465462    // convert back to linked list
  • trunk/psLib/src/collections/psList.h

    r1228 r1407  
    11#if !defined(PS_LIST_H)
    2 #define PS_LIST_H
     2#    define PS_LIST_H
    33
    44/** @file psList.h
     
    1010 *  @ingroup LinkedList
    1111 *
    12  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-15 22:18:02 $
     12 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-07 00:06:06 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1616 */
    1717
    18 #include <pthread.h>                   // we need a mutex to make this stuff thread safe.
    19 #include <stdbool.h>                   // we use the bool type.
     18#    include <pthread.h>                   // we need a mutex to make this stuff thread safe.
     19#    include <stdbool.h>                   // we use the bool type.
    2020
    21 #include "psCompare.h"
    22 #include "psArray.h"
     21#    include "psCompare.h"
     22#    include "psArray.h"
    2323
    2424/** @addtogroup LinkedList
     
    3333 */
    3434enum {
    35     PS_LIST_HEAD = 0,                  ///< at head
    36     PS_LIST_TAIL = -1,                 ///< at tail
    37     PS_LIST_PREVIOUS = -2,             ///< previous element
    38     PS_LIST_CURRENT = -3,              ///< current element
    39     PS_LIST_NEXT = -4,                 ///< next element
    40     PS_LIST_UNKNOWN = -5               ///< unknown position (should be last in enum list)
     35    PS_LIST_HEAD = 0,           // /< at head
     36    PS_LIST_TAIL = -1,                     // /< at tail
     37    PS_LIST_PREVIOUS = -2,                 // /< previous element
     38    PS_LIST_CURRENT = -3,                  // /< current element
     39    PS_LIST_NEXT = -4,                     // /< next element
     40    PS_LIST_UNKNOWN = -5                   // /< unknown position (should be last in enum list)
    4141};
    4242
     
    4444typedef struct psListElem
    4545{
    46     struct psListElem *prev;            ///< previous link in list
    47     struct psListElem *next;            ///< next link in list
    48     void *data;                         ///< real data item
     46    struct psListElem *prev;    // /< previous link in list
     47    struct psListElem *next;    // /< next link in list
     48    void *data;                 // /< real data item
    4949}
    5050psListElem;
     
    5757typedef struct
    5858{
    59     unsigned int size;                  ///< number of elements on list
    60     psListElem* head;                   ///< first element on list (may be NULL)
    61     psListElem* tail;                   ///< last element on list (may be NULL)
    62     psListElem* iter;                   ///< iteration cursor
    63     unsigned int iterIndex;             ///< the numeric position of the iteration cursor in the list
    64     pthread_mutex_t lock;               ///< mutex to lock a node during changes
     59    unsigned int size;          // /< number of elements on list
     60    psListElem *head;           // /< first element on list (may be NULL)
     61    psListElem *tail;           // /< last element on list (may be NULL)
     62    psListElem *iter;           // /< iteration cursor
     63    unsigned int iterIndex;     // /< the numeric position of the iteration cursor in the list
     64    pthread_mutex_t lock;       // /< mutex to lock a node during changes
    6565}
    6666psList;
     
    7070 *  @return psList*     A new psList object.
    7171 */
    72 psList* psListAlloc(
    73     void *data
    74     ///< initial data item; may be NULL if no an empty psList is desired
    75 )
     72psList *psListAlloc(void *data
     73                    // /< initial data item; may be NULL if no an empty psList is desired
     74                   )
    7675;
    7776
     
    8180 *                      NULL, the return value will also be NULL.
    8281 */
    83 bool psListAdd(
    84     psList* restrict list,              ///< list to add to (if NULL, nothing is done)
    85     void* data,                         ///< data item to add.  If NULL, list is not modified.
    86     int where                           ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location.
    87 );
     82bool psListAdd(psList * restrict list,  // /< list to add to (if NULL, nothing is done)
     83               void *data,      // /< data item to add.  If NULL, list is not modified.
     84               int where        // /< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location.
     85              );
    8886
    8987/** Remove an item from a list.  If which parameter is PS_LIST_UNKNOWN,
     
    9189 *  @return bool        TRUE if element is successfully removed, otherwise FALSE.
    9290 */
    93 bool psListRemove(
    94     psList* restrict list,
    95     ///< list to remove element from
    96     void *data,
    97     ///< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored.
    98     int which
    99     ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location.
    100 );
     91bool psListRemove(psList * restrict list,
     92                  // /< list to remove element from
     93                  void *data,
     94                  // /< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored.
     95                  int which
     96                  // /< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location.
     97                 );
    10198
    10299/** Retrieve an item from a list.
     
    107104 *                      NULL is returned.
    108105 */
    109 void* psListGet(
    110     psList* restrict list,             ///< list to retrieve element from
    111     int which                          ///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN
    112 );
     106void *psListGet(psList * restrict list, // /< list to retrieve element from
     107                int which       // /< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN
     108               );
    113109
    114110/** Set the iterator of the list to a given position.  If where is invalid the
     
    116112 *
    117113 */
    118 void psListSetIterator(
    119     psList* restrict list,             ///< list to retrieve element from
    120     int where                           ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
    121 );
     114void psListSetIterator(psList * restrict list,  // /< list to retrieve element from
     115                       int where        // /< index number, PS_LIST_HEAD, or PS_LIST_TAIL
     116                      );
    122117
    123118/** Get next element relative to the iterator.  This also moves the iterator to
     
    128123 *                      parameter was NULL.
    129124 */
    130 void* psListGetNext(
    131     psList* restrict list              ///< list to retrieve element from
    132 );
     125void *psListGetNext(psList * restrict list      // /< list to retrieve element from
     126                   );
    133127
    134128/** Get current element according to the psList's iterator cursor.  This does
     
    139133 *                      iterator is not valid or list parameter was NULL.
    140134 */
    141 void* psListGetCurrent(
    142     psList* restrict list              ///< list to retrieve element from
    143 );
     135void *psListGetCurrent(psList * restrict list   // /< list to retrieve element from
     136                      );
    144137
    145138/** Get previous element relative to list's iterator. This also moves the
     
    150143 *                      parameter was NULL.
    151144 */
    152 void* psListGetPrevious(
    153     psList* restrict list              ///< list to retrieve element from
    154 );
     145void *psListGetPrevious(psList * restrict list  // /< list to retrieve element from
     146                       );
    155147
    156148/** Convert a linked list to an array
     
    159151 *                      or NULL if the given dlist parameter is NULL.
    160152 */
    161 psArray* psListToArray(
    162     psList *dlist                      ///< List to convert
    163 );
     153psArray *psListToArray(psList * dlist   // /< List to convert
     154                      );
    164155
    165156/** Convert array to a doubly-linked list
     
    168159 *                      or NULL is the given arr parameter is NULL.
    169160 */
    170 psList* psArrayToList(
    171     psArray* arr                      ///< vector to convert
    172 );
     161psList *psArrayToList(psArray * arr     // /< vector to convert
     162                     );
    173163
    174 psList* psListSort(psList* list, psComparePtrFcn compare);
     164psList *psListSort(psList * list, psComparePtrFcn compare);
    175165
    176166/// @} End of DataGroup Functions
    177167
    178168#endif
    179 
  • trunk/psLib/src/collections/psMetadata.c

    r1406 r1407  
     1
    12/** @file  psMetadata.c
    23*
     
    1112*  @author Ross Harman, MHPCC
    1213*
    13 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-08-06 22:34:05 $
     14*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2004-08-07 00:06:06 $
    1516*
    1617*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1819
    1920/******************************************************************************/
     21
    2022/*  INCLUDE FILES                                                             */
     23
    2124/******************************************************************************/
    2225#include<stdio.h>
     
    3437#include "psString.h"
    3538
    36 
    3739/******************************************************************************/
     40
    3841/*  DEFINE STATEMENTS                                                         */
     42
    3943/******************************************************************************/
    4044
     
    5660
    5761/******************************************************************************/
     62
    5863/*  TYPE DEFINITIONS                                                          */
     64
    5965/******************************************************************************/
    6066
     
    6268
    6369/*****************************************************************************/
     70
    6471/*  GLOBAL VARIABLES                                                         */
     72
    6573/*****************************************************************************/
    6674
     
    6876
    6977/*****************************************************************************/
     78
    7079/*  FILE STATIC VARIABLES                                                    */
     80
    7181/*****************************************************************************/
    7282
     
    7484
    7585/*****************************************************************************/
     86
    7687/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    77 /*****************************************************************************/
    78 static void metadataItemFree( psMetadataItem *metadataItem )
     88
     89/*****************************************************************************/
     90static void metadataItemFree(psMetadataItem * metadataItem)
    7991{
    8092    psMetadataType type;
     
    8294    type = metadataItem->type;
    8395
    84     if(metadataItem == NULL) {
    85         return ;
    86     }
    87 
    88     psFree( metadataItem->name );
    89     psFree( metadataItem->comment );
    90     psFree( metadataItem->items );
    91 
    92     if(type == PS_META_STR ||
     96    if (metadataItem == NULL) {
     97        return;
     98    }
     99
     100    psFree(metadataItem->name);
     101    psFree(metadataItem->comment);
     102    psFree(metadataItem->items);
     103
     104    if (type == PS_META_STR ||
    93105            type == PS_META_IMG ||
    94             type == PS_META_JPEG ||
    95             type == PS_META_PNG ||
    96             type == PS_META_ASTROM ||
    97             type == PS_META_UNKNOWN) {
    98         psFree( metadataItem->data.V );
    99     }
    100 }
    101 
    102 static void metadataFree( psMetadata *metadata )
    103 {
    104     if(metadata == NULL) {
    105         return ;
    106     }
    107     psFree( metadata->list );
    108     psFree( metadata->table );
    109 }
    110 
    111 /*****************************************************************************/
     106            type == PS_META_JPEG || type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) {
     107        psFree(metadataItem->data.V);
     108    }
     109}
     110
     111static void metadataFree(psMetadata * metadata)
     112{
     113    if (metadata == NULL) {
     114        return;
     115    }
     116    psFree(metadata->list);
     117    psFree(metadata->table);
     118}
     119
     120/*****************************************************************************/
     121
    112122/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    113 /*****************************************************************************/
    114 
    115 psMetadataItem *psMetadataItemAlloc( const char *name, psMetadataType type, const char *comment, ... )
     123
     124/*****************************************************************************/
     125
     126psMetadataItem *psMetadataItemAlloc(const char *name, psMetadataType type, const char *comment, ...)
    116127{
    117128    va_list argPtr;
     
    119130
    120131    // Get the variable list parameters to pass to allocation function
    121     va_start( argPtr, comment );
     132    va_start(argPtr, comment);
    122133
    123134    // Call metadata item allocation
    124     metadataItem = psMetadataItemAllocV( name, type, comment, argPtr );
     135    metadataItem = psMetadataItemAllocV(name, type, comment, argPtr);
    125136
    126137    // Clean up stack after variable arguement has been used
    127     va_end( argPtr );
     138    va_end(argPtr);
    128139
    129140    return metadataItem;
    130141}
    131142
    132 psMetadataItem *psMetadataItemAllocV( const char *name, psMetadataType type, const char *comment, va_list argPtr )
    133 {
    134     psMetadataItem * metadataItem = NULL;
    135 
    136     if(name == NULL) {
    137         psError( __func__, "Null value for name not allowed" );
    138         return NULL;
    139     }
    140 
     143psMetadataItem *psMetadataItemAllocV(const char *name, psMetadataType type, const char *comment,
     144                                     va_list argPtr)
     145{
     146    psMetadataItem *metadataItem = NULL;
     147
     148    if (name == NULL) {
     149        psError(__func__, "Null value for name not allowed");
     150        return NULL;
     151    }
    141152    // Allocate metadata item
    142     metadataItem = ( psMetadataItem * ) psAlloc( sizeof( psMetadataItem ) );
    143     if(metadataItem == NULL) {
    144         psAbort( __func__, "Failed to allocate memory" );
    145     }
    146 
     153    metadataItem = (psMetadataItem *) psAlloc(sizeof(psMetadataItem));
     154    if (metadataItem == NULL) {
     155        psAbort(__func__, "Failed to allocate memory");
     156    }
    147157    // Set deallocator
    148     p_psMemSetDeallocator( metadataItem, ( psFreeFcn ) metadataItemFree );
     158    p_psMemSetDeallocator(metadataItem, (psFreeFcn) metadataItemFree);
    149159
    150160    // Allocate and set metadata item comment
    151     metadataItem->comment = ( char * ) psAlloc( sizeof( char ) * MAX_STRING_LENGTH );
    152     if(comment == NULL) {
     161    metadataItem->comment = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
     162    if (comment == NULL) {
    153163        // Per SDRS, null isn't allowed, must use "" instead
    154         strncpy( metadataItem->comment, "", MAX_STRING_LENGTH );
     164        strncpy(metadataItem->comment, "", MAX_STRING_LENGTH);
    155165    } else {
    156         strncpy( metadataItem->comment, comment, MAX_STRING_LENGTH );
     166        strncpy(metadataItem->comment, comment, MAX_STRING_LENGTH);
    157167    }
    158168
    159169    // Set metadata item unique id
    160     *( int* ) ( &metadataItem->id ) = ++metadataId;
     170    *(int *)(&metadataItem->id) = ++metadataId;
    161171
    162172    // Set metadata item type
     
    164174
    165175    // Set metadata item value
    166     switch(type) {
     176    switch (type) {
    167177    case PS_META_BOOL:
    168         metadataItem->data.B = ( bool ) va_arg( argPtr, int );
     178        metadataItem->data.B = (bool) va_arg(argPtr, int);
     179
    169180        break;
    170181    case PS_META_S32:
    171         metadataItem->data.S32 = va_arg( argPtr, psS32 );
     182        metadataItem->data.S32 = va_arg(argPtr, psS32);
    172183        break;
    173184    case PS_META_F32:
    174         metadataItem->data.F32 = ( psF32 ) va_arg( argPtr, psF64 );
     185        metadataItem->data.F32 = (psF32) va_arg(argPtr, psF64);
    175186        break;
    176187    case PS_META_F64:
    177         metadataItem->data.F64 = va_arg( argPtr, psF64 );
     188        metadataItem->data.F64 = va_arg(argPtr, psF64);
    178189        break;
    179190    case PS_META_STR:
    180         metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
     191        metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH);
     192
    181193        break;
    182194    case PS_META_IMG:
     
    186198    case PS_META_UNKNOWN:
    187199    default:
    188         psError( __func__, "Invalid psMetadataType: %d", type );
     200        psError(__func__, "Invalid psMetadataType: %d", type);
    189201    }
    190202
    191203    // Allocate and set metadata item name
    192     metadataItem->name = ( char * ) psAlloc( sizeof( char ) * MAX_STRING_LENGTH );
    193     vsprintf( metadataItem->name, name, argPtr );
     204    metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
     205    vsprintf(metadataItem->name, name, argPtr);
    194206
    195207    // Allocate metadata items with same name.
    196     metadataItem->items = psListAlloc( NULL );
     208    metadataItem->items = psListAlloc(NULL);
    197209
    198210    return metadataItem;
    199211}
    200212
    201 psMetadata *psMetadataAlloc( void )
    202 {
    203     psList * list = NULL;
     213psMetadata *psMetadataAlloc(void)
     214{
     215    psList *list = NULL;
    204216    psHash *table = NULL;
    205217    psMetadata *metadata = NULL;
    206218
    207219    // Allocate metadata
    208     metadata = ( psMetadata * ) psAlloc( sizeof( psMetadata ) );
    209     if(metadata == NULL) {
    210         psAbort( __func__, "Failed to allocate metadata" );
    211     }
    212 
     220    metadata = (psMetadata *) psAlloc(sizeof(psMetadata));
     221    if (metadata == NULL) {
     222        psAbort(__func__, "Failed to allocate metadata");
     223    }
    213224    // Set deallocator
    214     p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree );
     225    p_psMemSetDeallocator(metadata, (psFreeFcn) metadataFree);
    215226
    216227    // Allocate metadata's internal containers
    217     list = ( psList * ) psListAlloc( NULL );
    218     if(list == NULL) {
    219         psAbort( __func__, "Failed to allocate list" );
    220     }
    221 
    222     table = ( psHash * ) psHashAlloc( 10 );
    223     if(table == NULL) {
    224         psAbort( __func__, "Failed to allocate table" );
     228    list = (psList *) psListAlloc(NULL);
     229    if (list == NULL) {
     230        psAbort(__func__, "Failed to allocate list");
     231    }
     232
     233    table = (psHash *) psHashAlloc(10);
     234    if (table == NULL) {
     235        psAbort(__func__, "Failed to allocate table");
    225236    }
    226237
     
    231242}
    232243
    233 bool psMetadataAddItem( psMetadata *restrict md, int where, psMetadataItem *restrict metadataItem )
    234 {
    235     char * key = NULL;
     244bool psMetadataAddItem(psMetadata * restrict md, int where, psMetadataItem * restrict metadataItem)
     245{
     246    char *key = NULL;
    236247    psHash *mdTable = NULL;
    237248    psList *mdList = NULL;
     
    239250    psMetadataType type = PS_META_ITEM_SET;
    240251
    241     if(md == NULL) {
    242         psError( __func__, "Null metadata collection not allowed" );
    243         return false;
    244     }
    245 
    246     if(metadataItem == NULL) {
    247         psError( __func__, "Null metadata item not allowed" );
     252    if (md == NULL) {
     253        psError(__func__, "Null metadata collection not allowed");
     254        return false;
     255    }
     256
     257    if (metadataItem == NULL) {
     258        psError(__func__, "Null metadata item not allowed");
    248259        return false;
    249260    }
     
    252263
    253264    mdTable = md->table;
    254     if(mdTable == NULL) {
    255         psError( __func__, "Null metadata table not allowed" );
    256         return false;
    257     }
    258 
    259     mdList = md->list;
    260     if(mdList == NULL) {
    261         psError( __func__, "Null metadata list not allowed" );
     265    if (mdTable == NULL) {
     266        psError(__func__, "Null metadata table not allowed");
     267        return false;
     268    }
     269
     270    mdList = md->list;
     271    if (mdList == NULL) {
     272        psError(__func__, "Null metadata list not allowed");
    262273        return false;
    263274    }
    264275
    265276    key = metadataItem->name;
    266     if(key == NULL) {
    267         psError( __func__, "Null key item not allowed" );
    268         return false;
    269     }
    270 
     277    if (key == NULL) {
     278        psError(__func__, "Null key item not allowed");
     279        return false;
     280    }
    271281    // Check if key is already in table
    272     value = ( psMetadataItem* ) psHashLookup( mdTable, key );
    273     if(value != NULL && type != PS_META_ITEM_SET) {
     282    value = (psMetadataItem *) psHashLookup(mdTable, key);
     283    if (value != NULL && type != PS_META_ITEM_SET) {
    274284
    275285        // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so
    276286        // add the new metadata item to hash as a child of the existing metadata item folder node.
    277         if(!psListAdd( value->items, metadataItem, where )) {
    278             psError( __func__, "Couldn't add metadata item to items list. Name: %s",
    279                      metadataItem->name );
     287        if (!psListAdd(value->items, metadataItem, where)) {
     288            psError(__func__, "Couldn't add metadata item to items list. Name: %s", metadataItem->name);
    280289            return false;
    281290        }
    282     } else
    283         if(value != NULL) {
    284 
    285             // The key was found and the new metadata item is a folder node. Don't add new metadata item, since
    286             // it will wipe out existing node.
    287             psError( __func__, "Metadata already exists in metadata collection. Item not added. Name: %s",
    288                      metadataItem->name );
     291    } else if (value != NULL) {
     292
     293        // The key was found and the new metadata item is a folder node. Don't add new metadata item, since
     294        // it will wipe out existing node.
     295        psError(__func__, "Metadata already exists in metadata collection. Item not added. Name: %s",
     296                metadataItem->name);
     297        return false;
     298    } else {
     299
     300        // Duplicate key not found. Add new metadata item to metadata collection's hash
     301        if (!psHashAdd(mdTable, key, metadataItem)) {
     302            psError(__func__, "Couldn't add metadata item to metadata collection table. Name: %s",
     303                    metadataItem->name);
    289304            return false;
    290         } else {
    291 
    292             // Duplicate key not found. Add new metadata item to metadata collection's hash
    293             if(!psHashAdd( mdTable, key, metadataItem )) {
    294                 psError( __func__, "Couldn't add metadata item to metadata collection table. Name: %s",
    295                          metadataItem->name );
    296                 return false;
    297             }
    298         }
     305        }
     306    }
    299307
    300308    // Add all items to metadata collection's list, even if they have the same metadata item names
    301     if(!psListAdd( md->list, metadataItem, where )) {
    302         psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
    303                  metadataItem->name );
     309    if (!psListAdd(md->list, metadataItem, where)) {
     310        psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s",
     311                metadataItem->name);
    304312        return false;
    305313    }
     
    308316}
    309317
    310 bool psMetadataAdd( psMetadata *restrict md, int where, const char *name, psMetadataType type,
    311                     const char *comment, ... )
     318bool psMetadataAdd(psMetadata * restrict md, int where, const char *name, psMetadataType type,
     319                   const char *comment, ...)
    312320{
    313321    va_list argPtr;
    314322    psMetadataItem *metadataItem = NULL;
    315323
    316     va_start( argPtr, comment );
    317     metadataItem = psMetadataItemAllocV( name, type, comment, argPtr );
    318     va_end( argPtr );
    319 
    320     if(!psMetadataAddItem( md, where, metadataItem )) {
    321         psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
    322                  metadataItem->name );
    323         psFree( metadataItem );
    324         return false;
    325     }
    326 
    327     // Decrement reference count, since the metadata item is now in metadata collection and no longer needed here
    328     psMemDecrRefCounter( metadataItem );
     324    va_start(argPtr, comment);
     325    metadataItem = psMetadataItemAllocV(name, type, comment, argPtr);
     326    va_end(argPtr);
     327
     328    if (!psMetadataAddItem(md, where, metadataItem)) {
     329        psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s",
     330                metadataItem->name);
     331        psFree(metadataItem);
     332        return false;
     333    }
     334    // Decrement reference count, since the metadata item is now in metadata collection and no longer needed
     335    // here
     336    psMemDecrRefCounter(metadataItem);
    329337
    330338    return true;
    331339}
    332340
    333 bool psMetadataRemove( psMetadata *restrict md, int where, const char *restrict key )
     341bool psMetadataRemove(psMetadata * restrict md, int where, const char *restrict key)
    334342{
    335343    int numChildren = 0;
     
    340348
    341349    mdList = md->list;
    342     if(mdList == NULL) {
    343         psError( __func__, "Null metadata list not allowed" );
     350    if (mdList == NULL) {
     351        psError(__func__, "Null metadata list not allowed");
    344352        return false;
    345353    }
    346354
    347355    mdTable = md->table;
    348     if(mdTable == NULL) {
    349         psError( __func__, "Null metadata table not allowed" );
    350         return false;
    351     }
    352 
     356    if (mdTable == NULL) {
     357        psError(__func__, "Null metadata table not allowed");
     358        return false;
     359    }
    353360    // Select removal by key or index
    354     if(key != NULL) {
     361    if (key != NULL) {
    355362
    356363        // Remove by key name
    357         entry = ( psMetadataItem* ) psHashLookup( mdTable, key );
    358         if(entry == NULL) {
    359             psError( __func__, "Couldn't find metadata item remove. Name: %s", key );
     364        entry = (psMetadataItem *) psHashLookup(mdTable, key);
     365        if (entry == NULL) {
     366            psError(__func__, "Couldn't find metadata item remove. Name: %s", key);
    360367            return false;
    361368        }
    362369
    363370        numChildren = entry->items->size;
    364         if(entry->type == PS_META_ITEM_SET && numChildren > 0) {
     371        if (entry->type == PS_META_ITEM_SET && numChildren > 0) {
    365372
    366373            // Table entry has children. Entry and children must be removed from metadata collection's list
    367             psListSetIterator( mdList, PS_LIST_HEAD );
    368             entryChild = psListGetCurrent( mdList );
    369             while(entryChild != NULL) {
    370                 if(!psListRemove( entry->items, entryChild, PS_LIST_UNKNOWN )) {
    371                     psError( __func__, "Couldn't remove metadata item from list. Name: %s", key );
     374            psListSetIterator(mdList, PS_LIST_HEAD);
     375            entryChild = psListGetCurrent(mdList);
     376            while (entryChild != NULL) {
     377                if (!psListRemove(entry->items, entryChild, PS_LIST_UNKNOWN)) {
     378                    psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
    372379                    return false;
    373380                }
    374                 entryChild = psListGetNext( entry->items );
     381                entryChild = psListGetNext(entry->items);
    375382            }
    376383        }
    377 
    378384        // Remove entry from metadata collection's list
    379         if(!psListRemove( mdList, entry, PS_LIST_UNKNOWN )) {
    380             psError( __func__, "Couldn't remove metadata item from list. Name: %s", key );
     385        if (!psListRemove(mdList, entry, PS_LIST_UNKNOWN)) {
     386            psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
    381387            return false;
    382388        }
    383 
    384389        // Remove entry from metadata collection's table
    385         if(!psHashRemove( mdTable, key )) {
    386             psError( __func__, "Couldn't remove metadata item from table. Name: %s", key );
     390        if (!psHashRemove(mdTable, key)) {
     391            psError(__func__, "Couldn't remove metadata item from table. Name: %s", key);
    387392            return false;
    388393        }
     
    390395
    391396        // Remove by index
    392         entry = psListGet( mdList, where );
    393         if(entry == NULL) {
    394             psError( __func__, "Couldn't find metadata item from list. Index: %d", where );
     397        entry = psListGet(mdList, where);
     398        if (entry == NULL) {
     399            psError(__func__, "Couldn't find metadata item from list. Index: %d", where);
    395400            return false;
    396401        }
    397402
    398403        key = entry->name;
    399         if(key == NULL) {
    400             psError( __func__, "Null key name not allowed. Index: %d", where );
     404        if (key == NULL) {
     405            psError(__func__, "Null key name not allowed. Index: %d", where);
    401406            return false;
    402407        }
    403 
    404408        // Use recursive remove, now that key is known
    405         psMetadataRemove( md, PS_LIST_UNKNOWN, key );
     409        psMetadataRemove(md, PS_LIST_UNKNOWN, key);
    406410    }
    407411
     
    409413}
    410414
    411 psMetadataItem *psMetadataLookup( psMetadata *restrict md, const char *restrict key )
    412 {
    413     psHash * mdTable = NULL;
     415psMetadataItem *psMetadataLookup(psMetadata * restrict md, const char *restrict key)
     416{
     417    psHash *mdTable = NULL;
    414418    psMetadataItem *entry = NULL;
    415419
    416420    mdTable = md->table;
    417     if(mdTable == NULL) {
    418         psError( __func__, "Null metadata table not allowed" );
    419         return NULL;
    420     }
    421 
    422     if(key == NULL) {
    423         psError( __func__, "Null key name not allowed" );
    424         return NULL;
    425     }
    426 
    427     entry = ( psMetadataItem* ) psHashLookup( mdTable, key );
    428     if(entry == NULL) {
    429         psError( __func__, "Could not find metadata item with given key. Key: %s", key );
     421    if (mdTable == NULL) {
     422        psError(__func__, "Null metadata table not allowed");
     423        return NULL;
     424    }
     425
     426    if (key == NULL) {
     427        psError(__func__, "Null key name not allowed");
     428        return NULL;
     429    }
     430
     431    entry = (psMetadataItem *) psHashLookup(mdTable, key);
     432    if (entry == NULL) {
     433        psError(__func__, "Could not find metadata item with given key. Key: %s", key);
    430434        return NULL;
    431435    }
     
    434438}
    435439
    436 psMetadataItem *psMetadataGet( psMetadata *restrict md, int where )
    437 {
    438     psList * mdList = NULL;
     440psMetadataItem *psMetadataGet(psMetadata * restrict md, int where)
     441{
     442    psList *mdList = NULL;
    439443    psMetadataItem *entry = NULL;
    440444
    441445    mdList = md->list;
    442     if(mdList == NULL) {
    443         psError( __func__, "Null metadata list not allowed" );
    444         return NULL;
    445     }
    446 
    447     entry = ( psMetadataItem* ) psListGet( mdList, where );
    448     if(entry == NULL) {
    449         psError( __func__, "Couldn't find metadata item with given index. Index: %d", where );
     446    if (mdList == NULL) {
     447        psError(__func__, "Null metadata list not allowed");
     448        return NULL;
     449    }
     450
     451    entry = (psMetadataItem *) psListGet(mdList, where);
     452    if (entry == NULL) {
     453        psError(__func__, "Couldn't find metadata item with given index. Index: %d", where);
    450454        return NULL;
    451455    }
     
    454458}
    455459
    456 bool psMetadataSetIterator( psMetadata *restrict md, int where )
    457 {
    458     psList * mdList = NULL;
    459 
    460     mdList = md->list;
    461     if(mdList == NULL) {
    462         psError( __func__, "Null metadata list not allowed" );
    463         return false;
    464     }
    465 
    466     psListSetIterator( mdList, where );
     460bool psMetadataSetIterator(psMetadata * restrict md, int where)
     461{
     462    psList *mdList = NULL;
     463
     464    mdList = md->list;
     465    if (mdList == NULL) {
     466        psError(__func__, "Null metadata list not allowed");
     467        return false;
     468    }
     469
     470    psListSetIterator(mdList, where);
    467471
    468472    return true;
    469473}
    470474
    471 psMetadataItem *psMetadataGetNext( psMetadata *restrict md, const char *restrict match, int which )
    472 {
    473     psList * mdList = NULL;
     475psMetadataItem *psMetadataGetNext(psMetadata * restrict md, const char *restrict match, int which)
     476{
     477    psList *mdList = NULL;
    474478    psMetadataItem *entry = NULL;
    475479
    476480    mdList = md->list;
    477     if(mdList == NULL) {
    478         psError( __func__, "Null metadata list not allowed" );
    479         return NULL;
    480     }
    481 
    482     mdList = md->list;
    483     if(mdList == NULL) {
    484         psError( __func__, "Null metadata list not allowed" );
    485         return NULL;
    486     }
    487 
    488     psListSetIterator( mdList, which );
    489     entry = psListGetCurrent( mdList );
    490     while(entry != NULL) {
    491         if(!strncmp( match, entry->name, strlen( match ) )) {
     481    if (mdList == NULL) {
     482        psError(__func__, "Null metadata list not allowed");
     483        return NULL;
     484    }
     485
     486    mdList = md->list;
     487    if (mdList == NULL) {
     488        psError(__func__, "Null metadata list not allowed");
     489        return NULL;
     490    }
     491
     492    psListSetIterator(mdList, which);
     493    entry = psListGetCurrent(mdList);
     494    while (entry != NULL) {
     495        if (!strncmp(match, entry->name, strlen(match))) {
    492496
    493497            // Match found
    494498            return entry;
    495499        }
    496         entry = psListGetNext( mdList );
     500        entry = psListGetNext(mdList);
    497501    }
    498502
    499503    // Match not found
    500     if(entry == NULL) {
    501         psError( __func__, "Couldn't find metadata item with given match. Match: %s", match );
     504    if (entry == NULL) {
     505        psError(__func__, "Couldn't find metadata item with given match. Match: %s", match);
    502506    }
    503507
     
    505509}
    506510
    507 psMetadataItem *psMetadataGetPrevious( psMetadata *restrict md, const char *restrict match, int which )
    508 {
    509     psList * mdList = NULL;
     511psMetadataItem *psMetadataGetPrevious(psMetadata * restrict md, const char *restrict match, int which)
     512{
     513    psList *mdList = NULL;
    510514    psMetadataItem *entry = NULL;
    511515
    512516    mdList = md->list;
    513     if(mdList == NULL) {
    514         psError( __func__, "Null metadata list not allowed" );
    515         return NULL;
    516     }
    517 
    518     mdList = md->list;
    519     if(mdList == NULL) {
    520         psError( __func__, "Null metadata list not allowed" );
    521         return NULL;
    522     }
    523 
    524     psListSetIterator( mdList, which );
    525     entry = psListGetCurrent( mdList );
    526     while(entry != NULL) {
    527         if(!strncmp( match, entry->name, strlen( match ) )) {
     517    if (mdList == NULL) {
     518        psError(__func__, "Null metadata list not allowed");
     519        return NULL;
     520    }
     521
     522    mdList = md->list;
     523    if (mdList == NULL) {
     524        psError(__func__, "Null metadata list not allowed");
     525        return NULL;
     526    }
     527
     528    psListSetIterator(mdList, which);
     529    entry = psListGetCurrent(mdList);
     530    while (entry != NULL) {
     531        if (!strncmp(match, entry->name, strlen(match))) {
    528532
    529533            // Match found
    530534            return entry;
    531535        }
    532         entry = psListGetPrevious( mdList );
     536        entry = psListGetPrevious(mdList);
    533537    }
    534538
    535539    // Match not found
    536     if(entry == NULL) {
    537         psError( __func__, "Couldn't find metadata item with given match. Match: %s", match );
     540    if (entry == NULL) {
     541        psError(__func__, "Couldn't find metadata item with given match. Match: %s", match);
    538542    }
    539543
     
    541545}
    542546
    543 void psMetadataItemPrint( FILE *fd, const char *format, const psMetadataItem *restrict metadataItem )
     547void psMetadataItemPrint(FILE * fd, const char *format, const psMetadataItem * restrict metadataItem)
    544548{
    545549    psMetadataType type;
    546550
    547     if(fd == NULL) {
    548         psError( __func__, "Null file descriptor not allowed" );
    549         return ;
    550     }
    551 
    552     if(format == NULL) {
    553         psError( __func__, "Null format not allowed" );
    554         return ;
    555     }
    556 
    557     if(metadataItem == NULL) {
    558         psError( __func__, "Null metadata not allowed" );
    559         return ;
     551    if (fd == NULL) {
     552        psError(__func__, "Null file descriptor not allowed");
     553        return;
     554    }
     555
     556    if (format == NULL) {
     557        psError(__func__, "Null format not allowed");
     558        return;
     559    }
     560
     561    if (metadataItem == NULL) {
     562        psError(__func__, "Null metadata not allowed");
     563        return;
    560564    }
    561565
    562566    type = metadataItem->type;
    563567
    564     switch(type) {
     568    switch (type) {
    565569    case PS_META_BOOL:
    566         fprintf( fd, format, metadataItem->data.B );
     570        fprintf(fd, format, metadataItem->data.B);
    567571        break;
    568572    case PS_META_S32:
    569         fprintf( fd, format, metadataItem->data.S32 );
     573        fprintf(fd, format, metadataItem->data.S32);
    570574        break;
    571575    case PS_META_F32:
    572         fprintf( fd, format, metadataItem->data.F32 );
     576        fprintf(fd, format, metadataItem->data.F32);
    573577        break;
    574578    case PS_META_F64:
    575         fprintf( fd, format, metadataItem->data.F64 );
     579        fprintf(fd, format, metadataItem->data.F64);
    576580        break;
    577581    case PS_META_STR:
    578         fprintf( fd, format, metadataItem->data.V );
     582        fprintf(fd, format, metadataItem->data.V);
    579583        break;
    580584    case PS_META_ITEM_SET:
     
    585589    case PS_META_UNKNOWN:
    586590    default:
    587         psError( __func__, " Invalid psMetadataType to print: %d", type );
    588     }
    589 }
    590 
    591 psMetadata *psMetadataFReadHeader( psMetadata *output, char *extName, int extNum, fitsfile *fd )
     591        psError(__func__, " Invalid psMetadataType to print: %d", type);
     592    }
     593}
     594
     595psMetadata *psMetadataFReadHeader(psMetadata * output, char *extName, int extNum, fitsfile * fd)
    592596{
    593597    bool tempBool;
    594598    bool success;
    595599    char keyType;
    596     char keyName[ FITS_LINE_SIZE ];
    597     char keyValue[ FITS_LINE_SIZE ];
    598     char keyComment[ FITS_LINE_SIZE ];
    599     char fitsErr[ MAX_STRING_LENGTH ];
     600    char keyName[FITS_LINE_SIZE];
     601    char keyValue[FITS_LINE_SIZE];
     602    char keyComment[FITS_LINE_SIZE];
     603    char fitsErr[MAX_STRING_LENGTH];
    600604    int i;
    601605    int hduType = 0;
     
    605609    psMetadataType metadataItemType;
    606610
    607     if(fd == NULL) {
    608         psError( __func__, "Null FITS file descriptor not allowed" );
    609         return NULL;
    610     }
    611 
    612     if(extName == NULL && extNum == 0) {
    613         psError( __func__, "Null extName and extNum = 0 not allowed" );
    614         return NULL;
    615     } else
    616         if(extName && extNum) {
    617             psError( __func__, "Both extName and extNum arguments should not have non zero values." );
    618             return NULL;
    619         }
    620 
     611    if (fd == NULL) {
     612        psError(__func__, "Null FITS file descriptor not allowed");
     613        return NULL;
     614    }
     615
     616    if (extName == NULL && extNum == 0) {
     617        psError(__func__, "Null extName and extNum = 0 not allowed");
     618        return NULL;
     619    } else if (extName && extNum) {
     620        psError(__func__, "Both extName and extNum arguments should not have non zero values.");
     621        return NULL;
     622    }
    621623    // Allocate metadata if user didn't
    622     if(output == NULL) {
     624    if (output == NULL) {
    623625        output = psMetadataAlloc();
    624626    }
    625 
    626627    // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one.
    627     if(extName != NULL) {
    628         if(fits_movnam_hdu( fd, ANY_HDU, extName, 0, &status ) != 0) {
     628    if (extName != NULL) {
     629        if (fits_movnam_hdu(fd, ANY_HDU, extName, 0, &status) != 0) {
    629630            FITS_ERROR("FITS error while locating header %s: %s", extName);
    630631        }
    631632    } else {
    632         if(fits_movabs_hdu( fd, extNum, &hduType, &status ) != 0) {
     633        if (fits_movabs_hdu(fd, extNum, &hduType, &status) != 0) {
    633634            FITS_ERROR("FITS error while locating header %d: %s", extNum);
    634635        }
     
    636637
    637638    // Get number of key names
    638     if(fits_get_hdrpos( fd, &numKeys, &keyNum, &status ) != 0) {
     639    if (fits_get_hdrpos(fd, &numKeys, &keyNum, &status) != 0) {
    639640        FITS_ERROR("FITS error while reading key %d: %s", keyNum);
    640641    }
    641 
    642642    // Get each key name. Keywords start at one.
    643     for(i = 1; i <= numKeys; i++) {
    644         if(fits_read_keyn( fd, i, keyName, keyValue, keyComment, &status ) != 0) {
     643    for (i = 1; i <= numKeys; i++) {
     644        if (fits_read_keyn(fd, i, keyName, keyValue, keyComment, &status) != 0) {
    645645            FITS_ERROR("FITS error while reading key %d: %s", keyNum);
    646646        }
    647         if(fits_get_keytype( keyValue, &keyType, &status ) != 0) {
    648             fits_get_errstatus( status, fitsErr );
    649             if(status != VALUE_UNDEFINED) {
     647        if (fits_get_keytype(keyValue, &keyType, &status) != 0) {
     648            fits_get_errstatus(status, fitsErr);
     649            if (status != VALUE_UNDEFINED) {
    650650                FITS_ERROR("FITS error while determining key %d type: %s", keyNum);
    651651            } else {
    652                 // Some keywords are still valid even though they don't have a type, like COMMENTS and HISTORY
     652                // Some keywords are still valid even though they don't have a type, like COMMENTS and
     653                // HISTORY
    653654                keyType = 'C';
    654655                status = 0;
     
    656657        }
    657658
    658         switch(keyType) {
     659        switch (keyType) {
    659660        case 'I':
    660661            metadataItemType = PS_META_S32;
    661             success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, atoi( keyValue ) );
     662            success =
     663                psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,
     664                              atoi(keyValue));
    662665            break;
    663666        case 'F':
    664667            metadataItemType = PS_META_F64;
    665             success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, atof( keyValue ) );
     668            success =
     669                psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,
     670                              atof(keyValue));
    666671            break;
    667672        case 'C':
    668673            metadataItemType = PS_META_STR;
    669             success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue );
     674            success =
     675                psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue);
    670676            break;
    671677        case 'L':
    672678            metadataItemType = PS_META_BOOL;
    673             tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
    674             success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool );
     679            tempBool = (keyValue[0] == 'T') ? 1 : 0;
     680            success =
     681                psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool);
    675682            break;
    676683        case 'U':
    677684        case 'X':
    678685        default:
    679             psError( __func__, "Invalid psMetadataType: %c", keyType );
     686            psError(__func__, "Invalid psMetadataType: %c", keyType);
    680687            return output;
    681688        }
    682689
    683         if(!success) {
    684             psError( __func__, "Failed to add metadata item. Name: %s", keyName );
     690        if (!success) {
     691            psError(__func__, "Failed to add metadata item. Name: %s", keyName);
    685692            return output;
    686693        }
  • trunk/psLib/src/collections/psMetadata.h

    r1394 r1407  
     1
    12/** @file  psMetadata.h
    23*
     
    1011*  @author Ross Harman, MHPCC
    1112*
    12 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-05 20:55:22 $
     13*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-08-07 00:06:06 $
    1415*
    1516*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1617*/
    1718#ifndef PS_METADATA_H
    18 #define PS_METADATA_H
    19 
    20 #include <stdarg.h>
    21 #include <stdio.h>
    22 #include <fitsio.h>
    23 
    24 #include "psHash.h"
    25 #include "psList.h"
     19#    define PS_METADATA_H
     20
     21#    include <stdarg.h>
     22#    include <stdio.h>
     23#    include <fitsio.h>
     24
     25#    include "psHash.h"
     26#    include "psList.h"
    2627
    2728/// @addtogroup Metadata
     
    3334 */
    3435typedef enum {
    35     PS_META_ITEM_SET = 0,                   ///< Null. Metadata is in psMetadataItem.items
    36     PS_META_BOOL,                           ///< Boolean data.
    37     PS_META_S32,                            ///< Signed 32-bit integer data.
    38     PS_META_F32,                            ///< Single-precision float data.
    39     PS_META_F64,                            ///< Double-precision float data.
    40     PS_META_STR,                            ///< String data (Stored in as void *).
    41     PS_META_IMG,                            ///< Image data (Stored in as void *).
    42     PS_META_JPEG,                           ///< JPEG data (Stored in as void .
    43     PS_META_PNG,                            ///< PNG data (Stored in as void *).
    44     PS_META_ASTROM,                         ///< Astrometric coefficients (Stored in as void *).
    45     PS_META_UNKNOWN,                        ///< Other data (Stored in as void *).
    46     PS_META_NTYPE                         ///< Number of types. Must be last.
     36    PS_META_ITEM_SET = 0,       // /< Null. Metadata is in psMetadataItem.items
     37    PS_META_BOOL,                          // /< Boolean data.
     38    PS_META_S32,                           // /< Signed 32-bit integer data.
     39    PS_META_F32,                           // /< Single-precision float data.
     40    PS_META_F64,                           // /< Double-precision float data.
     41    PS_META_STR,                           // /< String data (Stored in as void *).
     42    PS_META_IMG,                           // /< Image data (Stored in as void *).
     43    PS_META_JPEG,                          // /< JPEG data (Stored in as void .
     44    PS_META_PNG,                           // /< PNG data (Stored in as void *).
     45    PS_META_ASTROM,                        // /< Astrometric coefficients (Stored in as void *).
     46    PS_META_UNKNOWN,                       // /< Other data (Stored in as void *).
     47    PS_META_NTYPE                          // /< Number of types. Must be last.
    4748} psMetadataType;
    4849
     
    5455typedef struct psMetadataItem
    5556{
    56     const int id;                       ///< Unique ID for metadata item.
    57     char *restrict name;                ///< Name of metadata item.
    58     psMetadataType type;                ///< Type of metadata item.
    59     union
    60     {
     57    const int id;               // /< Unique ID for metadata item.
     58    char *restrict name;        // /< Name of metadata item.
     59    psMetadataType type;        // /< Type of metadata item.
     60    union {
    6161        bool B;
    62         psS32 S32;                  ///< Signed 32-bit integer data.
    63         psF32 F32;                  ///< Single-precision float data.
    64         psF64 F64;                  ///< Double-precision float data.
    65         psPTR V;                    ///< Pointer to other type of data.
    66     }data;                          ///< Union for data types.
    67     char *comment;                      ///< Optional comment ("", not NULL).
    68     psList *restrict items;             ///< List of psMetadataItems with same name.
     62        psS32 S32;              // /< Signed 32-bit integer data.
     63        psF32 F32;              // /< Single-precision float data.
     64        psF64 F64;              // /< Double-precision float data.
     65        psPTR V;                // /< Pointer to other type of data.
     66    } data;                     // /< Union for data types.
     67    char *comment;              // /< Optional comment ("", not NULL).
     68    psList *restrict items;     // /< List of psMetadataItems with same name.
    6969}
    7070psMetadataItem;
     
    7878typedef struct psMetadata
    7979{
    80     psList* restrict list;
    81     psHash* restrict table;
     80    psList *restrict list;
     81    psHash *restrict table;
    8282}
    8383psMetadata;
    8484
    85 
    8685/*****************************************************************************/
     86
    8787/* FUNCTION PROTOTYPES                                                       */
     88
    8889/*****************************************************************************/
    8990
     
    101102 * @return psMetadataItem*: Pointer metadata item.
    102103 */
    103 psMetadataItem *psMetadataItemAlloc(
    104     const char *name,                       ///< Name of metadata item.
    105     psMetadataType type,                    ///< Type of metadata item.
    106     const char *comment,                    ///< Comment for metadata item.
    107     ...                                 ///< Arguments for name formatting and metadata item data.
    108 );
     104psMetadataItem *psMetadataItemAlloc(const char *name,   // /< Name of metadata item.
     105                                    psMetadataType type,        // /< Type of metadata item.
     106                                    const char *comment,        // /< Comment for metadata item.
     107                                    ... // /< Arguments for name formatting and metadata item data.
     108                                   );
    109109
    110110/** Create a metadata item with va_list.
     
    121121 * @return psMetadataItem*: Pointer metadata item.
    122122 */
    123 psMetadataItem *psMetadataItemAllocV(
    124     const char *name,                       ///< Name of metadata item.
    125     psMetadataType type,                    ///< Type of metadata item.
    126     const char *comment,                    ///< Comment for metadata item.
    127     va_list list                        ///< Arguments for name formatting and metadata item data.
    128 );
     123psMetadataItem *psMetadataItemAllocV(const char *name,  // /< Name of metadata item.
     124                                     psMetadataType type,       // /< Type of metadata item.
     125                                     const char *comment,       // /< Comment for metadata item.
     126                                     va_list list       // /< Arguments for name formatting and metadata item
     127                                     // data.
     128                                    );
    129129
    130130/** Create a metadata collection.
     
    134134 * @return psMetadata*: Pointer metadata.
    135135 */
    136 psMetadata *psMetadataAlloc(
    137     void                                ///< Void.
    138 );
     136psMetadata *psMetadataAlloc(void        // /< Void.
     137                           );
    139138
    140139/** Add existing metadata item to metadata collection.
     
    144143 * @return bool: True for success, false for failure.
    145144 */
    146 bool psMetadataAddItem(
    147     psMetadata *restrict md,                ///< Metadata collection to insert metadat item.
    148     int where,                              ///< Location to be added.
    149     psMetadataItem *restrict item       ///< Metadata item to be added.
    150 );
     145bool psMetadataAddItem(psMetadata * restrict md,        // /< Metadata collection to insert metadat item.
     146                       int where,       // /< Location to be added.
     147                       psMetadataItem * restrict item   // /< Metadata item to be added.
     148                      );
    151149
    152150/** Create and add a metadata item to metadata collection.
     
    156154 * @return bool: True for success, false for failure.
    157155 */
    158 bool psMetadataAdd(
    159     psMetadata *restrict md,                ///< Metadata collection to insert metadat item.
    160     int where,                              ///< Location to be added.
    161     const char *name,                       ///< Name of metadata item.
    162     psMetadataType type,                    ///< Type of metadata item.
    163     const char *comment,                    ///< Comment for metadata item.
    164     ...                                 ///< Arguments for name formatting and metadata item data.
    165 );
     156bool psMetadataAdd(psMetadata * restrict md,    // /< Metadata collection to insert metadat item.
     157                   int where,   // /< Location to be added.
     158                   const char *name,    // /< Name of metadata item.
     159                   psMetadataType type, // /< Type of metadata item.
     160                   const char *comment, // /< Comment for metadata item.
     161                   ...          // /< Arguments for name formatting and metadata item data.
     162                  );
    166163
    167164/** Remove an item from metadata collection.
     
    174171 * @return bool: True for success, false for failure.
    175172 */
    176 bool psMetadataRemove(
    177     psMetadata *restrict md,                ///< Metadata collection to insert metadat item.
    178     int where,                              ///< Location to be removed.
    179     const char *restrict key            ///< Name of metadata key.
    180 );
     173bool psMetadataRemove(psMetadata * restrict md, // /< Metadata collection to insert metadat item.
     174                      int where,        // /< Location to be removed.
     175                      const char *restrict key  // /< Name of metadata key.
     176                     );
    181177
    182178/** Find an item in the metadata collection based on key name.
     
    187183 * @return psMetadataItem*: Pointer metadata item.
    188184 */
    189 psMetadataItem *psMetadataLookup(
    190     psMetadata *restrict md,                ///< Metadata collection to insert metadat item.
    191     const char *restrict key            ///< Name of metadata key.
    192 );
     185psMetadataItem *psMetadataLookup(psMetadata * restrict md,      // /< Metadata collection to insert metadat
     186                                 // item.
     187                                 const char *restrict key       // /< Name of metadata key.
     188                                );
    193189
    194190/** Find an item in the metadata collection based on list index.
     
    198194 * @return psMetadataItem*: Pointer metadata item.
    199195 */
    200 psMetadataItem *psMetadataGet(
    201     psMetadata *restrict md,                ///< Metadata collection to insert metadat item.
    202     int where                           ///< Location to be retrieved.
    203 );
     196psMetadataItem *psMetadataGet(psMetadata * restrict md, // /< Metadata collection to insert metadat item.
     197                              int where // /< Location to be retrieved.
     198                             );
    204199
    205200/** Set or reset metadata iterator.
     
    209204 * @return void: void.
    210205 */
    211 bool psMetadataSetIterator(
    212     psMetadata *restrict md,                ///< Metadata collection to iterate.
    213     int where                           ///< Location of iterator.
    214 );
     206bool psMetadataSetIterator(psMetadata * restrict md,    // /< Metadata collection to iterate.
     207                           int where    // /< Location of iterator.
     208                          );
    215209
    216210/** Get next metadata item.
     
    220214 * @return psMetadataItem*: Pointer metadata item.
    221215 */
    222 psMetadataItem *psMetadataGetNext(
    223     psMetadata *restrict md,                ///< Metadata collection to iterate.
    224     const char *restrict match,             ///< Beginning of key name.
    225     int which                           ///< Iterator to be used.
    226 );
     216psMetadataItem *psMetadataGetNext(psMetadata * restrict md,     // /< Metadata collection to iterate.
     217                                  const char *restrict match,   // /< Beginning of key name.
     218                                  int which     // /< Iterator to be used.
     219                                 );
    227220
    228221/** Get previous metadata item.
     
    232225 * @return psMetadataItem*: Pointer metadata item.
    233226 */
    234 psMetadataItem *psMetadataGetPrevious(
    235     psMetadata *restrict md,                ///< Metadata collection to iterate.
    236     const char *restrict match,             ///< Beginning of key name.
    237     int which                           ///< Iterator to be used.
    238 );
     227psMetadataItem *psMetadataGetPrevious(psMetadata * restrict md, // /< Metadata collection to iterate.
     228                                      const char *restrict match,       // /< Beginning of key name.
     229                                      int which // /< Iterator to be used.
     230                                     );
    239231
    240232/** Print metadata item to file.
     
    248240 * @return psMetadataItem*: Pointer metadata item.
    249241 */
    250 void psMetadataItemPrint(
    251     FILE *fd,                                       ///< Pointer to file to write metadata item.
    252     const char *format,                             ///< Format to print metadata item.
    253     const psMetadataItem *restrict metadataItem     ///< Metadata item to print.
    254 );
     242void psMetadataItemPrint(FILE * fd,     // /< Pointer to file to write metadata item.
     243                         const char *format,    // /< Format to print metadata item.
     244                         const psMetadataItem * restrict metadataItem   // /< Metadata item to print.
     245                        );
    255246
    256247/** Read metadata header.
     
    261252 * @return psMetadata*: Pointer metadata.
    262253 */
    263 psMetadata *psMetadataReadHeader(
    264     psMetadata *output,                     ///< Resulting metadata from read.
    265     char *extname,                          ///< File name extension string.
    266     int extnum,                             ///< File name extension number. Starts at 1.
    267     char *filename                          ///< Name of file to read.
    268 );
     254psMetadata *psMetadataReadHeader(psMetadata * output,   // /< Resulting metadata from read.
     255                                 char *extname, // /< File name extension string.
     256                                 int extnum,    // /< File name extension number. Starts at 1.
     257                                 char *filename // /< Name of file to read.
     258                                );
    269259
    270260/** Read metadata header.
     
    274264 * @return psMetadata*: Pointer metadata.
    275265 */
    276 psMetadata *psMetadataFReadHeader(
    277     psMetadata *output,                     ///< Resulting metadata from read.
    278     char *extName,                          ///< File name extension string.
    279     int extNum,                             ///< File name extension number.
    280     fitsfile *fd                            ///< Pointer to file to read.
    281 );
     266psMetadata *psMetadataFReadHeader(psMetadata * output,  // /< Resulting metadata from read.
     267                                  char *extName,        // /< File name extension string.
     268                                  int extNum,   // /< File name extension number.
     269                                  fitsfile * fd // /< Pointer to file to read.
     270                                 );
     271
    282272/// @}
    283273
  • trunk/psLib/src/collections/psScalar.c

    r1406 r1407  
     1
    12/** @file  psScalar.c
    23 *
     
    89 *  @author Ross Harman, MHPCC
    910 *
    10  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-08-06 22:34:05 $
     11 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-08-07 00:06:06 $
    1213 *
    1314 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1516
    1617/******************************************************************************/
     18
    1719/*  INCLUDE FILES                                                             */
     20
    1821/******************************************************************************/
    1922#include "psMemory.h"
     
    2427
    2528/******************************************************************************/
     29
    2630/*  DEFINE STATEMENTS                                                         */
     31
    2732/******************************************************************************/
    2833
     
    3035
    3136/******************************************************************************/
     37
    3238/*  TYPE DEFINITIONS                                                          */
     39
    3340/******************************************************************************/
    3441
     
    3643
    3744/*****************************************************************************/
     45
    3846/*  GLOBAL VARIABLES                                                         */
     47
    3948/*****************************************************************************/
    4049
     
    4251
    4352/*****************************************************************************/
     53
    4454/*  FILE STATIC VARIABLES                                                    */
     55
    4556/*****************************************************************************/
    4657
     
    4859
    4960/*****************************************************************************/
     61
    5062/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
     63
    5164/*****************************************************************************/
    5265
     
    5467
    5568/*****************************************************************************/
     69
    5670/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
     71
    5772/*****************************************************************************/
    5873psScalar *psScalarAlloc(psC64 value, psElemType dataType)
     
    6176
    6277    // Create scalar
    63     scalar = (psScalar *)psAlloc(sizeof(psScalar));
    64     if(scalar == NULL) {
    65         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
     78    scalar = (psScalar *) psAlloc(sizeof(psScalar));
     79    if (scalar == NULL) {
     80        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
    6681    }
    6782
     
    7186    switch (dataType) {
    7287    case PS_TYPE_S8:
    73         scalar->data.S8 = (psS8)value;
     88        scalar->data.S8 = (psS8) value;
    7489        break;
    7590    case PS_TYPE_U8:
    76         scalar->data.U8 = (psU8)value;
     91        scalar->data.U8 = (psU8) value;
    7792        break;
    7893    case PS_TYPE_S16:
    79         scalar->data.S16 = (psS16)value;
     94        scalar->data.S16 = (psS16) value;
    8095        break;
    8196    case PS_TYPE_U16:
    82         scalar->data.U16 = (psU16)value;
     97        scalar->data.U16 = (psU16) value;
    8398        break;
    8499    case PS_TYPE_S32:
    85         scalar->data.S32 = (psS32)value;
     100        scalar->data.S32 = (psS32) value;
    86101        break;
    87102    case PS_TYPE_U32:
    88         scalar->data.U32 = (psU32)value;
     103        scalar->data.U32 = (psU32) value;
    89104        break;
    90105    case PS_TYPE_S64:
    91         scalar->data.S64 = (psS64)value;
     106        scalar->data.S64 = (psS64) value;
    92107        break;
    93108    case PS_TYPE_U64:
    94         scalar->data.U64 = (psU64)value;
     109        scalar->data.U64 = (psU64) value;
    95110        break;
    96111    case PS_TYPE_F32:
    97         scalar->data.F32 = (psF32)value;
     112        scalar->data.F32 = (psF32) value;
    98113        break;
    99114    case PS_TYPE_F64:
    100         scalar->data.F64 = (psF64)value;
     115        scalar->data.F64 = (psF64) value;
    101116        break;
    102117    case PS_TYPE_C32:
    103         scalar->data.C32 = (psC32)value;
     118        scalar->data.C32 = (psC32) value;
    104119        break;
    105120    case PS_TYPE_C64:
    106         scalar->data.C64 = (psC64)value;
     121        scalar->data.C64 = (psC64) value;
    107122        break;
    108123    default:
     
    110125    }
    111126
    112 
    113127    return scalar;
    114128}
    115129
    116 void psScalarFree(psScalar *restrict scalar)
     130void psScalarFree(psScalar * restrict scalar)
    117131{
    118132    if (scalar == NULL) {
     
    122136    psFree(scalar);
    123137}
    124 
    125 
  • trunk/psLib/src/collections/psScalar.h

    r1406 r1407  
     1
    12/** @file  psScalar.h
    23 *
     
    1011 *  @author Ross Harman, MHPCC
    1112 *
    12  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-06 22:34:05 $
     13 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-07 00:06:06 $
    1415 *
    1516 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1718
    1819#ifndef PS_SCALAR_H
    19 #define PS_SCALAR_H
     20#    define PS_SCALAR_H
    2021
    21 #include "psType.h"
     22#    include "psType.h"
    2223
    2324/// @addtogroup Scalar
     
    3132typedef struct
    3233{
    33     psType type;                       ///< Type of data.
     34    psType type;                // /< Type of data.
    3435
    3536    union {
    36         psU8    U8;                    ///< Unsigned 8-bit integer data.
    37         psU16   U16;                   ///< Unsigned 16-bit integer data.
    38         psU32   U32;                   ///< Unsigned 32-bit integer data.
    39         psU64   U64;                   ///< Unsigned 64-bit integer data.
    40         psS8    S8;                    ///< Signed 8-bit integer data.
    41         psS16   S16;                   ///< Signed 16-bit integer data.
    42         psS32   S32;                   ///< Signed 32-bit integer data.
    43         psS64   S64;                   ///< Signed 64-bit integer data.
    44         psF32   F32;                   ///< Single-precision float data.
    45         psF64   F64;                   ///< Double-precision float data.
    46         psC32   C32;                   ///< Single-precision complex data.
    47         psC64   C64;                   ///< Double-precision complex data.
    48     } data;                            ///< Union for data types.
     37        psU8 U8;                // /< Unsigned 8-bit integer data.
     38        psU16 U16;              // /< Unsigned 16-bit integer data.
     39        psU32 U32;              // /< Unsigned 32-bit integer data.
     40        psU64 U64;              // /< Unsigned 64-bit integer data.
     41        psS8 S8;                // /< Signed 8-bit integer data.
     42        psS16 S16;              // /< Signed 16-bit integer data.
     43        psS32 S32;              // /< Signed 32-bit integer data.
     44        psS64 S64;              // /< Signed 64-bit integer data.
     45        psF32 F32;              // /< Single-precision float data.
     46        psF64 F64;              // /< Double-precision float data.
     47        psC32 C32;              // /< Single-precision complex data.
     48        psC64 C64;              // /< Double-precision complex data.
     49    } data;                     // /< Union for data types.
    4950}
    5051psScalar;
    5152
    5253/*****************************************************************************/
     54
    5355/* FUNCTION PROTOTYPES                                                       */
     56
    5457/*****************************************************************************/
    5558
     
    6265 *
    6366 */
    64 psScalar *psScalarAlloc(
    65     psC64 value,            ///< Data to be put into psScalar.
    66     psElemType dataType     ///< Type of data to be held by psScalar.
    67 );
    68 
     67psScalar *psScalarAlloc(psC64 value,    // /< Data to be put into psScalar.
     68                        psElemType dataType     // /< Type of data to be held by psScalar.
     69                       );
    6970
    7071/** Deallocate a scalar.
     
    7576 *
    7677 */
    77 void psScalarFree(
    78     psScalar *restrict scalar  ///< Scalar to free.
    79 );
     78void psScalarFree(psScalar * restrict scalar    // /< Scalar to free.
     79                 );
    8080
    8181/// @}
  • trunk/psLib/src/collections/psVector.c

    r1406 r1407  
     1
    12/** @file  psVector.c
    23*
     
    89*  @author Ross Harman, MHPCC
    910*
    10 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-08-06 22:34:05 $
     11*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-08-07 00:06:06 $
    1213*
    1314*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1516
    1617/******************************************************************************/
     18
    1719/*  INCLUDE FILES                                                             */
    18 /******************************************************************************/
    19 #include <string.h>        // for memcpy
     20
     21/******************************************************************************/
     22#include <string.h>                        // for memcpy
    2023#include <stdlib.h>
    2124#include <math.h>
     
    2831
    2932/******************************************************************************/
     33
    3034/*  DEFINE STATEMENTS                                                         */
     35
    3136/******************************************************************************/
    3237
     
    3439
    3540/******************************************************************************/
     41
    3642/*  TYPE DEFINITIONS                                                          */
     43
    3744/******************************************************************************/
    3845
     
    4047
    4148/*****************************************************************************/
     49
    4250/*  GLOBAL VARIABLES                                                         */
     51
    4352/*****************************************************************************/
    4453
     
    4655
    4756/*****************************************************************************/
     57
    4858/*  FILE STATIC VARIABLES                                                    */
     59
    4960/*****************************************************************************/
    5061
     
    5263
    5364/*****************************************************************************/
     65
    5466/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    55 /*****************************************************************************/
    56 static void vectorFree( psVector *restrict psVec );
    57 
    58 /*****************************************************************************/
     67
     68/*****************************************************************************/
     69static void vectorFree(psVector * restrict psVec);
     70
     71/*****************************************************************************/
     72
    5973/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    60 /*****************************************************************************/
    61 psVector* psVectorAlloc( unsigned int nalloc, psElemType elemType )
    62 {
    63     psVector * psVec = NULL;
     74
     75/*****************************************************************************/
     76psVector *psVectorAlloc(unsigned int nalloc, psElemType elemType)
     77{
     78    psVector *psVec = NULL;
    6479    int elementSize = 0;
    6580
    6681    // Invalid nalloc
    67     if ( nalloc < 1 ) {
    68         psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
     82    if (nalloc < 1) {
     83        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
    6984        return NULL;
    7085    }
    7186
    72     elementSize = PSELEMTYPE_SIZEOF( elemType );
     87    elementSize = PSELEMTYPE_SIZEOF(elemType);
    7388
    7489    // Create vector struct
    75     psVec = ( psVector * ) psAlloc( sizeof( psVector ) );
    76     p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree );
     90    psVec = (psVector *) psAlloc(sizeof(psVector));
     91    p_psMemSetDeallocator(psVec, (psFreeFcn) vectorFree);
    7792
    7893    psVec->type.dimen = PS_DIMEN_VECTOR;
     
    8297
    8398    // Create vector data array
    84     psVec->data.V = psAlloc( nalloc * elementSize );
     99    psVec->data.V = psAlloc(nalloc * elementSize);
    85100
    86101    return psVec;
    87102}
    88103
    89 psVector *psVectorRealloc( unsigned int nalloc, psVector *restrict in )
     104psVector *psVectorRealloc(unsigned int nalloc, psVector * restrict in)
    90105{
    91106    int elementSize = 0;
     
    93108
    94109    // Invalid nalloc
    95     if ( nalloc < 1 ) {
    96         psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
     110    if (nalloc < 1) {
     111        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
    97112        return NULL;
    98113    }
    99114
    100     if ( in == NULL ) {
    101         psError( __func__, "Null input vector\n" );
     115    if (in == NULL) {
     116        psError(__func__, "Null input vector\n");
    102117        return NULL;
    103     } else
    104         if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
    105             elemType = in->type.type;
    106             elementSize = PSELEMTYPE_SIZEOF( elemType );
    107             if ( nalloc < in->n ) {
    108                 in->n = nalloc;
    109             }
    110 
    111             // Realloc after decrementation to avoid accessing freed array elements
    112             in->data.V = psRealloc( in->data.V, nalloc * elementSize );
    113             in->nalloc = nalloc;
     118    } else if (in->nalloc != nalloc) {     // No need to realloc to same size
     119        elemType = in->type.type;
     120        elementSize = PSELEMTYPE_SIZEOF(elemType);
     121        if (nalloc < in->n) {
     122            in->n = nalloc;
    114123        }
     124        // Realloc after decrementation to avoid accessing freed array elements
     125        in->data.V = psRealloc(in->data.V, nalloc * elementSize);
     126        in->nalloc = nalloc;
     127    }
    115128
    116129    return in;
    117130}
    118131
    119 psVector *psVectorRecycle( psVector *restrict in, unsigned int nalloc, psElemType type )
     132psVector *psVectorRecycle(psVector * restrict in, unsigned int nalloc, psElemType type)
    120133{
    121134    psElemType elemType;
    122135
    123     if ( in == NULL ) {
    124         return psVectorAlloc( nalloc, type );
     136    if (in == NULL) {
     137        return psVectorAlloc(nalloc, type);
    125138    }
    126139
    127140    elemType = in->type.type;
    128141
    129     if ( in->nalloc == nalloc && elemType == type ) {
     142    if (in->nalloc == nalloc && elemType == type) {
    130143        // it is proper size/type already
    131144        return in;
    132145    }
    133 
    134146    // Invalid nalloc
    135     if ( nalloc < 1 ) {
    136         psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
    137         psFree( in );
     147    if (nalloc < 1) {
     148        psError(__func__, "Invalid value for nalloc (%d)\n", nalloc);
     149        psFree(in);
    138150        return NULL;
    139151    }
    140152
    141 
    142     in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) );
     153    in->data.V = psRealloc(in->data.V, nalloc * PSELEMTYPE_SIZEOF(type));
    143154
    144155    in->type.type = type;
     
    149160}
    150161
    151 psVector *psVectorSort( psVector *restrict outVector, const psVector *restrict inVector )
     162psVector *psVectorSort(psVector * restrict outVector, const psVector * restrict inVector)
    152163{
    153164    int inN = 0;
     
    158169    psElemType inType = 0;
    159170
    160     if ( inVector == NULL ) {
    161         psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
     171    if (inVector == NULL) {
     172        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
    162173        return outVector;
    163174    }
     
    166177    inN = inVector->n;
    167178    inVec = inVector->data.V;
    168     elSize = PSELEMTYPE_SIZEOF( inType );
    169 
    170     if ( outVector == NULL ) {
    171         outVector = psVectorAlloc( inN, inType );
     179    elSize = PSELEMTYPE_SIZEOF(inType);
     180
     181    if (outVector == NULL) {
     182        outVector = psVectorAlloc(inN, inType);
    172183        outVector->n = inVector->n;
    173184    }
     
    176187    outVec = outVector->data.V;
    177188
    178     if ( inN != outN ) {
    179         psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
    180                  inN, outN );
    181         return outVector;
    182     }
    183 
    184     if ( inType != outVector->type.type ) {
    185         psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
    186                  inType, outVector->type.type );
    187         return outVector;
    188     }
    189 
    190     if ( inN == 0 ) {
    191         psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
    192         return outVector;
    193     }
    194 
    195     if ( outN == 0 ) {
    196         psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
    197         return outVector;
    198     }
    199 
     189    if (inN != outN) {
     190        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
     191                __LINE__, inN, outN);
     192        return outVector;
     193    }
     194
     195    if (inType != outVector->type.type) {
     196        psError(__func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
     197                inType, outVector->type.type);
     198        return outVector;
     199    }
     200
     201    if (inN == 0) {
     202        psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__);
     203        return outVector;
     204    }
     205
     206    if (outN == 0) {
     207        psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__);
     208        return outVector;
     209    }
    200210    // Copy input vector values into output vector
    201     memcpy( outVec, inVec, elSize * outN );
     211    memcpy(outVec, inVec, elSize * outN);
    202212
    203213    // Sort output vector
    204     switch ( inType ) {
     214    switch (inType) {
    205215    case PS_TYPE_U8:
    206         qsort( outVec, inN, elSize, psCompareU8 );
     216        qsort(outVec, inN, elSize, psCompareU8);
    207217        break;
    208218    case PS_TYPE_U16:
    209         qsort( outVec, inN, elSize, psCompareU16 );
     219        qsort(outVec, inN, elSize, psCompareU16);
    210220        break;
    211221    case PS_TYPE_U32:
    212         qsort( outVec, inN, elSize, psCompareU32 );
     222        qsort(outVec, inN, elSize, psCompareU32);
    213223        break;
    214224    case PS_TYPE_U64:
    215         qsort( outVec, inN, elSize, psCompareU64 );
     225        qsort(outVec, inN, elSize, psCompareU64);
    216226        break;
    217227    case PS_TYPE_S8:
    218         qsort( outVec, inN, elSize, psCompareS8 );
     228        qsort(outVec, inN, elSize, psCompareS8);
    219229        break;
    220230    case PS_TYPE_S16:
    221         qsort( outVec, inN, elSize, psCompareS16 );
     231        qsort(outVec, inN, elSize, psCompareS16);
    222232        break;
    223233    case PS_TYPE_S32:
    224         qsort( outVec, inN, elSize, psCompareS32 );
     234        qsort(outVec, inN, elSize, psCompareS32);
    225235        break;
    226236    case PS_TYPE_S64:
    227         qsort( outVec, inN, elSize, psCompareS64 );
     237        qsort(outVec, inN, elSize, psCompareS64);
    228238        break;
    229239    case PS_TYPE_F32:
    230         qsort( outVec, inN, elSize, psCompareF32 );
     240        qsort(outVec, inN, elSize, psCompareF32);
    231241        break;
    232242    case PS_TYPE_F64:
    233         qsort( outVec, inN, elSize, psCompareF64 );
     243        qsort(outVec, inN, elSize, psCompareF64);
    234244        break;
    235245    default:
    236         psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
     246        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
    237247    }
    238248
     
    251261}
    252262
    253 psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector )
     263psVector *psVectorSortIndex(psVector * restrict outVector, const psVector * restrict inVector)
    254264{
    255265    int inN = 0;
     
    263273    psElemType inType = 0;
    264274
    265     if ( inVector == NULL ) {
    266         psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
     275    if (inVector == NULL) {
     276        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
    267277        return outVector;
    268278    }
     
    272282    inType = inVector->type.type;
    273283
    274     if ( outVector == NULL ) {
    275         outVector = psVectorAlloc( inN, PS_TYPE_U32 );
     284    if (outVector == NULL) {
     285        outVector = psVectorAlloc(inN, PS_TYPE_U32);
    276286        outVector->n = inN;
    277287    }
     
    280290    outVec = outVector->data.V;
    281291
    282     if ( inN != outN ) {
    283         psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
    284                  __LINE__, inN, outN );
    285         return outVector;
    286     }
    287 
    288     if ( outVector->type.type != PS_TYPE_U32 ) {
    289         psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
    290                  __LINE__, outVector->type.type );
    291         return outVector;
    292     }
    293 
    294     tmpVector = psVectorAlloc( inN, inType );
     292    if (inN != outN) {
     293        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
     294                __LINE__, inN, outN);
     295        return outVector;
     296    }
     297
     298    if (outVector->type.type != PS_TYPE_U32) {
     299        psError(__func__, " : Line %d - Output vector is not of type U32: out=%d\n",
     300                __LINE__, outVector->type.type);
     301        return outVector;
     302    }
     303
     304    tmpVector = psVectorAlloc(inN, inType);
    295305    tmpVector->n = inN;
    296     tmpVector = psVectorSort( tmpVector, inVector );
     306    tmpVector = psVectorSort(tmpVector, inVector);
    297307
    298308    // Sort output vector
    299     switch ( inType ) {
     309    switch (inType) {
    300310    case PS_TYPE_U8:
    301         SORT_INDICES( U8 );
     311        SORT_INDICES(U8);
    302312        break;
    303313    case PS_TYPE_U16:
    304         SORT_INDICES( U16 );
     314        SORT_INDICES(U16);
    305315        break;
    306316    case PS_TYPE_U32:
    307         SORT_INDICES( U32 );
     317        SORT_INDICES(U32);
    308318        break;
    309319    case PS_TYPE_U64:
    310         SORT_INDICES( U64 );
     320        SORT_INDICES(U64);
    311321        break;
    312322    case PS_TYPE_S8:
    313         SORT_INDICES( S8 );
     323        SORT_INDICES(S8);
    314324        break;
    315325    case PS_TYPE_S16:
    316         SORT_INDICES( S16 );
     326        SORT_INDICES(S16);
    317327        break;
    318328    case PS_TYPE_S32:
    319         SORT_INDICES( S32 );
     329        SORT_INDICES(S32);
    320330        break;
    321331    case PS_TYPE_S64:
    322         SORT_INDICES( S64 );
     332        SORT_INDICES(S64);
    323333        break;
    324334    case PS_TYPE_F32:
    325         SORT_INDICES( F32 );
     335        SORT_INDICES(F32);
    326336        break;
    327337    case PS_TYPE_F64:
    328         SORT_INDICES( F64 );
     338        SORT_INDICES(F64);
    329339        break;
    330340    default:
    331         psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
     341        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
    332342    }
    333343
    334344    // Free temp memory
    335     psFree( tmpVector );
     345    psFree(tmpVector);
    336346
    337347    return outVector;
    338348}
    339349
    340 static void vectorFree( psVector *restrict psVec )
    341 {
    342     if ( psVec == NULL ) {
    343         return ;
    344     }
    345 
    346     psFree( psVec->data.V );
    347 }
     350static void vectorFree(psVector * restrict psVec)
     351{
     352    if (psVec == NULL) {
     353        return;
     354    }
     355
     356    psFree(psVec->data.V);
     357}
  • trunk/psLib/src/collections/psVector.h

    r1406 r1407  
     1
    12/** @file  psVector.h
    23 *
     
    1112 *  @author Ross Harman, MHPCC
    1213 *
    13  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-08-06 22:34:05 $
     14 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-07 00:06:06 $
    1516 *
    1617 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1819
    1920#ifndef PS_VECTOR_H
    20 #define PS_VECTOR_H
     21#    define PS_VECTOR_H
    2122
    22 #include "psType.h"
     23#    include "psType.h"
    2324
    2425/// @addtogroup Vector
     
    3233typedef struct
    3334{
    34     psType type;                        ///< Type of data.
    35     unsigned int nalloc;                ///< Total number of elements available.
    36     unsigned int n;                     ///< Number of elements in use.
     35    psType type;                // /< Type of data.
     36    unsigned int nalloc;        // /< Total number of elements available.
     37    unsigned int n;             // /< Number of elements in use.
    3738
    3839    union {
    39         psU8    *U8;                    ///< Unsigned 8-bit integer data.
    40         psU16   *U16;                   ///< Unsigned 16-bit integer data.
    41         psU32   *U32;                   ///< Unsigned 32-bit integer data.
    42         psU64   *U64;                   ///< Unsigned 64-bit integer data.
    43         psS8    *S8;                    ///< Signed 8-bit integer data.
    44         psS16   *S16;                   ///< Signed 16-bit integer data.
    45         psS32   *S32;                   ///< Signed 32-bit integer data.
    46         psS64   *S64;                   ///< Signed 64-bit integer data.
    47         psF32   *F32;                   ///< Single-precision float data.
    48         psF64   *F64;                   ///< Double-precision float data.
    49         psC32   *C32;                   ///< Single-precision complex data.
    50         psC64   *C64;                   ///< Double-precision complex data.
    51         psPTR    V;                     ///< Pointer to data.
    52     } data;                             ///< Union for data types.
     40        psU8 *U8;               // /< Unsigned 8-bit integer data.
     41        psU16 *U16;             // /< Unsigned 16-bit integer data.
     42        psU32 *U32;             // /< Unsigned 32-bit integer data.
     43        psU64 *U64;             // /< Unsigned 64-bit integer data.
     44        psS8 *S8;               // /< Signed 8-bit integer data.
     45        psS16 *S16;             // /< Signed 16-bit integer data.
     46        psS32 *S32;             // /< Signed 32-bit integer data.
     47        psS64 *S64;             // /< Signed 64-bit integer data.
     48        psF32 *F32;             // /< Single-precision float data.
     49        psF64 *F64;             // /< Double-precision float data.
     50        psC32 *C32;             // /< Single-precision complex data.
     51        psC64 *C64;             // /< Double-precision complex data.
     52        psPTR V;                // /< Pointer to data.
     53    } data;                     // /< Union for data types.
    5354}
    5455psVector;
    5556
    5657/*****************************************************************************/
     58
    5759/* FUNCTION PROTOTYPES                                                       */
     60
    5861/*****************************************************************************/
    5962
     
    6568 *
    6669 */
    67 psVector *psVectorAlloc(
    68     unsigned int nalloc,                ///< Total number of elements to make available.
    69     psElemType dataType                 ///< Type of data to be held by vector.
    70 );
     70psVector *psVectorAlloc(unsigned int nalloc,    // /< Total number of elements to make available.
     71                        psElemType dataType     // /< Type of data to be held by vector.
     72                       );
    7173
    7274/** Reallocate a vector.
     
    7880 *
    7981 */
    80 psVector *psVectorRealloc(
    81     unsigned int nalloc,                ///< Total number of elements to make available.
    82     psVector *restrict psVec            ///< Vector to reallocate.
    83 );
     82psVector *psVectorRealloc(unsigned int nalloc,  // /< Total number of elements to make available.
     83                          psVector * restrict psVec     // /< Vector to reallocate.
     84                         );
    8485
    8586/** Recycle a vector.
     
    9192 *
    9293 */
    93 psVector *psVectorRecycle(
    94     psVector *restrict psVec,
    95     ///< Vector to recycle.  If NULL, a new vector is created.  No effort taken to preserve the values.
    96 
    97     unsigned int nalloc,                ///< Total number of elements to make available.
    98     psElemType type                     ///< the datatype of the returned vector
    99 );
     94psVector *psVectorRecycle(psVector * restrict psVec,
     95                          // /< Vector to recycle.  If NULL, a new vector is created.  No effort taken to
     96                          // preserve the values.
     97                          unsigned int nalloc,  // /< Total number of elements to make available.
     98                          psElemType type       // /< the datatype of the returned vector
     99                         );
    100100
    101101/** Sort an array of floats.
     
    107107 */
    108108
    109 psVector *psVectorSort(
    110     psVector *restrict outVector,  ///< the output vector to recycle, or NULL if new vector desired.
    111     const psVector *restrict inVector ///< the vector to sort.
    112 );
     109psVector *psVectorSort(psVector * restrict outVector,   // /< the output vector to recycle, or NULL if new
     110                       // vector desired.
     111                       const psVector * restrict inVector       // /< the vector to sort.
     112                      );
    113113
    114114/** Creates an array of indices based on sort odred of float array.
     
    120120 */
    121121
    122 psVector *psVectorSortIndex(
    123     psVector *restrict outVector,
    124     const psVector *restrict inVector
    125 );
    126 
     122psVector *psVectorSortIndex(psVector * restrict outVector, const psVector * restrict inVector);
    127123
    128124/// @}
Note: See TracChangeset for help on using the changeset viewer.