IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2004, 1:37:39 PM (22 years ago)
Author:
desonia
Message:

found the server astyle upgrade was faulty, so the format was reset.

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

Legend:

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

    r1228 r1385  
    88 *  @author Ross Harman, MHPCC
    99 *
    10  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-07-15 22:18:02 $
     10 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-08-04 23:37:39 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6767        psError(__func__, "Null input vector\n");
    6868        return NULL;
    69     } else if(in->nalloc != nalloc) {                    // No need to realloc to same size
    70         if(nalloc < in->n) {
    71             for (int i = nalloc; i < in->n; i++) {   // For reduction in vector size
    72                 psFree(in->data[i]);
     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;
    7376            }
    74             in->n = nalloc;
     77
     78            // Realloc after decrementation to avoid accessing freed array elements
     79            in->data = psRealloc(in->data,nalloc*sizeof(psPTR));
     80            in->nalloc = nalloc;
    7581        }
    76 
    77         // Realloc after decrementation to avoid accessing freed array elements
    78         in->data = psRealloc(in->data,nalloc*sizeof(psPTR));
    79         in->nalloc = nalloc;
    80     }
    8182
    8283    return in;
  • trunk/psLib/src/collections/psBitSet.c

    r1172 r1385  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-01 21:48:11 $
     12 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-04 23:37:39 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    126126        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    127127        return inBitSet;
    128     } else if(bit < 0) {
    129         psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
    130         return inBitSet;
    131     } else if(bit > inBitSet->n*8-1) {
    132         psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
    133         return inBitSet;
    134     }
     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            }
    135137
    136138    // Variable byte is the byte in the array that contains the bit to be set
     
    148150        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    149151        return 0;
    150     } else if(bit < 0) {
    151         psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
    152         return 0;
    153     } else if(bit > inBitSet->n*8-1) {
    154         psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
    155         return 0;
    156     }
     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            }
    157161
    158162    // Variable byte is the byte in the array that contains the bit to be tested
  • trunk/psLib/src/collections/psList.c

    r1228 r1385  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-07-15 22:18:02 $
     8 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-08-04 23:37:39 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    349349    if (list->iter == ITER_INIT_HEAD) {
    350350        return list->head;
    351     } else if (list->iter == ITER_INIT_TAIL) {
    352         return list->tail;
    353     } else {
    354         return list->iter;
    355     }
     351    } else
     352        if (list->iter == ITER_INIT_TAIL) {
     353            return list->tail;
     354        } else {
     355            return list->iter;
     356        }
    356357}
    357358
     
    360361    if (list->iter == ITER_INIT_HEAD) {
    361362        return 0;
    362     } else if (list->iter == ITER_INIT_TAIL) {
    363         return list->size-1;
    364     } else {
    365         return list->iterIndex;
    366     }
     363    } else
     364        if (list->iter == ITER_INIT_TAIL) {
     365            return list->size-1;
     366        } else {
     367            return list->iterIndex;
     368        }
    367369}
    368370
  • trunk/psLib/src/collections/psMetadata.c

    r1381 r1385  
    1111*  @author Ross Harman, MHPCC
    1212*
    13 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-08-04 21:05:24 $
     13*  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-08-04 23:37:39 $
    1515*
    1616*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6565{
    6666    psMetadataType type;
    67    
     67
    6868    type = metadataItem->type;
    69    
     69
    7070    if ( metadataItem == NULL ) {
    71             return ;
    72         }
    73        
     71        return ;
     72    }
     73
    7474    psFree( metadataItem->name );
    7575    psFree( metadataItem->comment );
    7676    psFree( metadataItem->items );
    77    
     77
    7878    if ( type == PS_META_STR ||
    7979            type == PS_META_IMG ||
     
    8282            type == PS_META_ASTROM ||
    8383            type == PS_META_UNKNOWN ) {
    84             psFree( metadataItem->data.V );
    85         }
     84        psFree( metadataItem->data.V );
     85    }
    8686}
    8787
     
    8989{
    9090    if ( metadata == NULL ) {
    91             return ;
    92         }
     91        return ;
     92    }
    9393    psFree( metadata->list );
    9494    psFree( metadata->table );
     
    103103    va_list argPtr;
    104104    psMetadataItem *metadataItem = NULL;
    105    
     105
    106106    // Get the variable list parameters to pass to allocation function
    107107    va_start( argPtr, comment );
    108    
     108
    109109    // Call metadata item allocation
    110110    metadataItem = psMetadataItemAllocV( name, type, comment, argPtr );
    111    
     111
    112112    // Clean up stack after variable arguement has been used
    113113    va_end( argPtr );
    114    
     114
    115115    return metadataItem;
    116116}
     
    119119{
    120120    psMetadataItem * metadataItem = NULL;
    121    
     121
    122122    if ( name == NULL ) {
    123             psError( __func__, "Null value for string not allowed" );
    124             return NULL;
    125         }
    126        
     123        psError( __func__, "Null value for string not allowed" );
     124        return NULL;
     125    }
     126
    127127    // Allocate metadata item
    128128    metadataItem = ( psMetadataItem * ) psAlloc( sizeof( psMetadataItem ) );
    129129    if ( metadataItem == NULL ) {
    130             psAbort( __func__, "Failed to allocate memory" );
    131         }
    132        
     130        psAbort( __func__, "Failed to allocate memory" );
     131    }
     132
    133133    // Set deallocator
    134134    p_psMemSetDeallocator( metadataItem, ( psFreeFcn ) metadataItemFree );
    135    
     135
    136136    // Allocate and set metadata item comment
    137137    metadataItem->comment = ( char * ) psAlloc( sizeof( char ) * MAX_STRING_LENGTH );
    138138    if ( comment == NULL ) {
    139             // Per SDRS, null isn't allowed, must use "" instead
    140             strncpy( metadataItem->comment, "", MAX_STRING_LENGTH );
    141         } else {
    142             strncpy( metadataItem->comment, comment, MAX_STRING_LENGTH );
    143         }
    144        
     139        // Per SDRS, null isn't allowed, must use "" instead
     140        strncpy( metadataItem->comment, "", MAX_STRING_LENGTH );
     141    } else {
     142        strncpy( metadataItem->comment, comment, MAX_STRING_LENGTH );
     143    }
     144
    145145    // Set metadata item unique id
    146146    *( int* ) ( &metadataItem->id ) = ++metadataId;
    147    
     147
    148148    // Set metadata item type
    149149    metadataItem->type = type;
    150    
     150
    151151    // Set metadata item value
    152152    switch ( type ) {
    153             case PS_META_BOOL:
    154             metadataItem->data.B = ( bool ) va_arg( argPtr, int );
    155             break;
    156             case PS_META_S32:
    157             metadataItem->data.S32 = va_arg( argPtr, psS32 );
    158             break;
    159             case PS_META_F32:
    160             metadataItem->data.F32 = ( psF32 ) va_arg( argPtr, psF64 );
    161             break;
    162             case PS_META_F64:
    163             metadataItem->data.F64 = va_arg( argPtr, psF64 );
    164             break;
    165             case PS_META_STR:
    166             metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
    167             break;
    168             case PS_META_IMG:
    169             case PS_META_JPEG:
    170             case PS_META_PNG:
    171             case PS_META_ASTROM:
    172             case PS_META_UNKNOWN:
    173             default:
    174             psError( __func__, "Invalid psMetadataType: %d", type );
    175         }
    176        
     153    case PS_META_BOOL:
     154        metadataItem->data.B = ( bool ) va_arg( argPtr, int );
     155        break;
     156    case PS_META_S32:
     157        metadataItem->data.S32 = va_arg( argPtr, psS32 );
     158        break;
     159    case PS_META_F32:
     160        metadataItem->data.F32 = ( psF32 ) va_arg( argPtr, psF64 );
     161        break;
     162    case PS_META_F64:
     163        metadataItem->data.F64 = va_arg( argPtr, psF64 );
     164        break;
     165    case PS_META_STR:
     166        metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
     167        break;
     168    case PS_META_IMG:
     169    case PS_META_JPEG:
     170    case PS_META_PNG:
     171    case PS_META_ASTROM:
     172    case PS_META_UNKNOWN:
     173    default:
     174        psError( __func__, "Invalid psMetadataType: %d", type );
     175    }
     176
    177177    // Allocate and set metadata item name
    178178    metadataItem->name = ( char * ) psAlloc( sizeof( char ) * MAX_STRING_LENGTH );
    179179    vsprintf( metadataItem->name, name, argPtr );
    180    
     180
    181181    // Allocate metadata items with same name.
    182182    metadataItem->items = psListAlloc( NULL );
    183    
     183
    184184    return metadataItem;
    185185}
     
    190190    psHash *table = NULL;
    191191    psMetadata *metadata = NULL;
    192    
     192
    193193    // Allocate metadata
    194194    metadata = ( psMetadata * ) psAlloc( sizeof( psMetadata ) );
    195195    if ( metadata == NULL ) {
    196             psAbort( __func__, "Failed to allocate metadata" );
    197         }
    198        
     196        psAbort( __func__, "Failed to allocate metadata" );
     197    }
     198
    199199    // Set deallocator
    200200    p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree );
    201    
     201
    202202    // Allocate metadata's internal containers
    203203    list = ( psList * ) psListAlloc( NULL );
    204204    if ( list == NULL ) {
    205             psAbort( __func__, "Failed to allocate list" );
    206         }
    207        
     205        psAbort( __func__, "Failed to allocate list" );
     206    }
     207
    208208    table = ( psHash * ) psHashAlloc( 10 );
    209209    if ( table == NULL ) {
    210             psAbort( __func__, "Failed to allocate table" );
    211         }
    212        
     210        psAbort( __func__, "Failed to allocate table" );
     211    }
     212
    213213    metadata->list = list;
    214214    metadata->table = table;
    215    
     215
    216216    return metadata;
    217217}
     
    224224    psMetadataItem *value = NULL;
    225225    psMetadataType type = PS_META_ITEM_SET;
    226    
     226
    227227    if ( md == NULL ) {
    228             psError( __func__, "Null metadata collection not allowed" );
    229             return false;
    230         }
    231        
     228        psError( __func__, "Null metadata collection not allowed" );
     229        return false;
     230    }
     231
    232232    if ( metadataItem == NULL ) {
    233             psError( __func__, "Null metadata item not allowed" );
    234             return false;
    235         }
    236        
     233        psError( __func__, "Null metadata item not allowed" );
     234        return false;
     235    }
     236
    237237    type = metadataItem->type;
    238    
     238
    239239    mdTable = md->table;
    240240    if ( mdTable == NULL ) {
    241             psError( __func__, "Null metadata table not allowed" );
    242             return false;
    243         }
    244        
    245     mdList = md->list;
    246     if ( mdList == NULL ) {
    247             psError( __func__, "Null metadata list not allowed" );
    248             return false;
    249         }
    250        
     241        psError( __func__, "Null metadata table not allowed" );
     242        return false;
     243    }
     244
     245    mdList = md->list;
     246    if ( mdList == NULL ) {
     247        psError( __func__, "Null metadata list not allowed" );
     248        return false;
     249    }
     250
    251251    key = metadataItem->name;
    252252    if ( key == NULL ) {
    253             psError( __func__, "Null key item not allowed" );
    254             return false;
    255         }
    256        
     253        psError( __func__, "Null key item not allowed" );
     254        return false;
     255    }
     256
    257257    // Check if key is already in table
    258258    value = ( psMetadataItem* ) psHashLookup( mdTable, key );
    259259    if ( value != NULL && type != PS_META_ITEM_SET ) {
    260    
    261             // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so
    262             // add the new metadata item to hash as a child of the existing metadata item folder node.
    263             if ( !psListAdd( value->items, metadataItem, where ) ) {
    264                     psError( __func__, "Couldn't add metadata item to items list. Name: %s",
    265                              metadataItem->name );
    266                     return false;
    267                 }
    268         } else if ( value != NULL ) {
    269        
     260
     261        // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so
     262        // add the new metadata item to hash as a child of the existing metadata item folder node.
     263        if ( !psListAdd( value->items, metadataItem, where ) ) {
     264            psError( __func__, "Couldn't add metadata item to items list. Name: %s",
     265                     metadataItem->name );
     266            return false;
     267        }
     268    } else
     269        if ( value != NULL ) {
     270
    270271            // The key was found and the new metadata item is a folder node. Don't add new metadata item, since
    271272            // it will wipe out existing node.
     
    274275            return false;
    275276        } else {
    276        
     277
    277278            // Duplicate key not found. Add new metadata item to metadata collection's hash
    278279            if ( !psHashAdd( mdTable, key, metadataItem ) ) {
    279                     psError( __func__, "Couldn't add metadata item to metadata collection table. Name: %s",
    280                              metadataItem->name );
    281                     return false;
    282                 }
    283         }
    284        
     280                psError( __func__, "Couldn't add metadata item to metadata collection table. Name: %s",
     281                         metadataItem->name );
     282                return false;
     283            }
     284        }
     285
    285286    // Add all items to metadata collection's list, even if they have the same metadata item names
    286287    if ( !psListAdd( md->list, metadataItem, where ) ) {
    287             psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
    288                      metadataItem->name );
    289             return false;
    290         }
    291        
     288        psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
     289                 metadataItem->name );
     290        return false;
     291    }
     292
    292293    return true;
    293294}
     
    298299    va_list argPtr;
    299300    psMetadataItem *metadataItem = NULL;
    300    
     301
    301302    va_start( argPtr, comment );
    302303    metadataItem = psMetadataItemAllocV( name, type, comment, argPtr );
    303304    va_end( argPtr );
    304    
     305
    305306    if ( !psMetadataAddItem( md, where, metadataItem ) ) {
    306             psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
    307                      metadataItem->name );
    308             psFree( metadataItem );
    309             return false;
    310         }
    311        
     307        psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
     308                 metadataItem->name );
     309        psFree( metadataItem );
     310        return false;
     311    }
     312
    312313    // Decrement reference count, since the metadata item is now in metadata collection and no longer needed here
    313314    psMemDecrRefCounter( metadataItem );
    314    
     315
    315316    return true;
    316317}
     
    323324    psMetadataItem *entry = NULL;
    324325    psMetadataItem *entryChild = NULL;
    325    
    326     mdList = md->list;
    327     if ( mdList == NULL ) {
    328             psError( __func__, "Null metadata list not allowed" );
    329             return false;
    330         }
    331        
     326
     327    mdList = md->list;
     328    if ( mdList == NULL ) {
     329        psError( __func__, "Null metadata list not allowed" );
     330        return false;
     331    }
     332
    332333    mdTable = md->table;
    333334    if ( mdTable == NULL ) {
    334             psError( __func__, "Null metadata table not allowed" );
    335             return false;
    336         }
    337        
     335        psError( __func__, "Null metadata table not allowed" );
     336        return false;
     337    }
     338
    338339    // Select removal by key or index
    339340    if ( key != NULL ) {
    340    
    341             // Remove by key name
    342             entry = ( psMetadataItem* ) psHashLookup( mdTable, key );
    343             if ( entry == NULL ) {
    344                     psError( __func__, "Couldn't find metadata item remove. Name: %s", key );
    345                     return false;
    346                 }
    347                
    348             numChildren = entry->items->size;
    349             if ( entry->type == PS_META_ITEM_SET && numChildren > 0 ) {
    350            
    351                     // Table entry has children. Entry and children must be removed from metadata collection's list
    352                     psListSetIterator( mdList, PS_LIST_HEAD );
    353                     entryChild = psListGetCurrent( mdList );
    354                     while ( entryChild != NULL ) {
    355                             if ( !psListRemove( entry->items, entryChild, PS_LIST_UNKNOWN ) ) {
    356                                     psError( __func__, "Couldn't remove metadata item from list. Name: %s", key );
    357                                     return false;
    358                                 }
    359                             entryChild = psListGetNext( entry->items );
    360                         }
    361                 }
    362                
    363             // Remove entry from metadata collection's list
    364             if ( !psListRemove( mdList, entry, PS_LIST_UNKNOWN ) ) {
     341
     342        // Remove by key name
     343        entry = ( psMetadataItem* ) psHashLookup( mdTable, key );
     344        if ( entry == NULL ) {
     345            psError( __func__, "Couldn't find metadata item remove. Name: %s", key );
     346            return false;
     347        }
     348
     349        numChildren = entry->items->size;
     350        if ( entry->type == PS_META_ITEM_SET && numChildren > 0 ) {
     351
     352            // Table entry has children. Entry and children must be removed from metadata collection's list
     353            psListSetIterator( mdList, PS_LIST_HEAD );
     354            entryChild = psListGetCurrent( mdList );
     355            while ( entryChild != NULL ) {
     356                if ( !psListRemove( entry->items, entryChild, PS_LIST_UNKNOWN ) ) {
    365357                    psError( __func__, "Couldn't remove metadata item from list. Name: %s", key );
    366358                    return false;
    367359                }
    368                
    369             // Remove entry from metadata collection's table
    370             if ( !psHashRemove( mdTable, key ) ) {
    371                     psError( __func__, "Couldn't remove metadata item from table. Name: %s", key );
    372                     return false;
    373                 }
    374         } else {
    375        
    376             // Remove by index
    377             entry = psListGet( mdList, where );
    378             if ( entry == NULL ) {
    379                     psError( __func__, "Couldn't find metadata item from list. Index: %d", where );
    380                     return false;
    381                 }
    382                
    383             key = entry->name;
    384             if ( key == NULL ) {
    385                     psError( __func__, "Null key name not allowed. Index: %d", where );
    386                     return false;
    387                 }
    388                
    389             // Use recursive remove, now that key is known
    390             psMetadataRemove( md, PS_LIST_UNKNOWN, key );
    391         }
    392        
     360                entryChild = psListGetNext( entry->items );
     361            }
     362        }
     363
     364        // Remove entry from metadata collection's list
     365        if ( !psListRemove( mdList, entry, PS_LIST_UNKNOWN ) ) {
     366            psError( __func__, "Couldn't remove metadata item from list. Name: %s", key );
     367            return false;
     368        }
     369
     370        // Remove entry from metadata collection's table
     371        if ( !psHashRemove( mdTable, key ) ) {
     372            psError( __func__, "Couldn't remove metadata item from table. Name: %s", key );
     373            return false;
     374        }
     375    } else {
     376
     377        // Remove by index
     378        entry = psListGet( mdList, where );
     379        if ( entry == NULL ) {
     380            psError( __func__, "Couldn't find metadata item from list. Index: %d", where );
     381            return false;
     382        }
     383
     384        key = entry->name;
     385        if ( key == NULL ) {
     386            psError( __func__, "Null key name not allowed. Index: %d", where );
     387            return false;
     388        }
     389
     390        // Use recursive remove, now that key is known
     391        psMetadataRemove( md, PS_LIST_UNKNOWN, key );
     392    }
     393
    393394    return true;
    394395}
     
    398399    psHash * mdTable = NULL;
    399400    psMetadataItem *entry = NULL;
    400    
     401
    401402    mdTable = md->table;
    402403    if ( mdTable == NULL ) {
    403             psError( __func__, "Null metadata table not allowed" );
    404             return NULL;
    405         }
    406        
     404        psError( __func__, "Null metadata table not allowed" );
     405        return NULL;
     406    }
     407
    407408    if ( key == NULL ) {
    408             psError( __func__, "Null key name not allowed" );
    409             return NULL;
    410         }
    411        
     409        psError( __func__, "Null key name not allowed" );
     410        return NULL;
     411    }
     412
    412413    entry = ( psMetadataItem* ) psHashLookup( mdTable, key );
    413414    if ( entry == NULL ) {
    414             psError( __func__, "Could not find metadata item with given key. Key: %s", key );
    415             return NULL;
    416         }
    417        
     415        psError( __func__, "Could not find metadata item with given key. Key: %s", key );
     416        return NULL;
     417    }
     418
    418419    return entry;
    419420}
     
    423424    psList * mdList = NULL;
    424425    psMetadataItem *entry = NULL;
    425    
    426     mdList = md->list;
    427     if ( mdList == NULL ) {
    428             psError( __func__, "Null metadata list not allowed" );
    429             return NULL;
    430         }
    431        
     426
     427    mdList = md->list;
     428    if ( mdList == NULL ) {
     429        psError( __func__, "Null metadata list not allowed" );
     430        return NULL;
     431    }
     432
    432433    entry = ( psMetadataItem* ) psListGet( mdList, where );
    433434    if ( entry == NULL ) {
    434             psError( __func__, "Couldn't find metadata item with given index. Index: %d", where );
    435             return NULL;
    436         }
    437        
     435        psError( __func__, "Couldn't find metadata item with given index. Index: %d", where );
     436        return NULL;
     437    }
     438
    438439    return entry;
    439440}
     
    442443{
    443444    psList * mdList = NULL;
    444    
    445     mdList = md->list;
    446     if ( mdList == NULL ) {
    447             psError( __func__, "Null metadata list not allowed" );
    448             return false;
    449         }
    450        
     445
     446    mdList = md->list;
     447    if ( mdList == NULL ) {
     448        psError( __func__, "Null metadata list not allowed" );
     449        return false;
     450    }
     451
    451452    psListSetIterator( mdList, where );
    452    
     453
    453454    return true;
    454455}
     
    458459    psList * mdList = NULL;
    459460    psMetadataItem *entry = NULL;
    460    
    461     mdList = md->list;
    462     if ( mdList == NULL ) {
    463             psError( __func__, "Null metadata list not allowed" );
    464             return NULL;
    465         }
    466        
    467     mdList = md->list;
    468     if ( mdList == NULL ) {
    469             psError( __func__, "Null metadata list not allowed" );
    470             return NULL;
    471         }
    472        
     461
     462    mdList = md->list;
     463    if ( mdList == NULL ) {
     464        psError( __func__, "Null metadata list not allowed" );
     465        return NULL;
     466    }
     467
     468    mdList = md->list;
     469    if ( mdList == NULL ) {
     470        psError( __func__, "Null metadata list not allowed" );
     471        return NULL;
     472    }
     473
    473474    psListSetIterator( mdList, which );
    474475    entry = psListGetCurrent( mdList );
    475476    while ( entry != NULL ) {
    476             if ( !strncmp( match, entry->name, strlen( match ) ) ) {
    477            
    478                     // Match found
    479                     return entry;
    480                 }
    481             entry = psListGetNext( mdList );
    482         }
    483        
     477        if ( !strncmp( match, entry->name, strlen( match ) ) ) {
     478
     479            // Match found
     480            return entry;
     481        }
     482        entry = psListGetNext( mdList );
     483    }
     484
    484485    // Match not found
    485486    if ( entry == NULL ) {
    486             psError( __func__, "Couldn't find metadata item with given match. Match: %s", match );
    487         }
    488        
     487        psError( __func__, "Couldn't find metadata item with given match. Match: %s", match );
     488    }
     489
    489490    return entry;
    490491}
     
    494495    psList * mdList = NULL;
    495496    psMetadataItem *entry = NULL;
    496    
    497     mdList = md->list;
    498     if ( mdList == NULL ) {
    499             psError( __func__, "Null metadata list not allowed" );
    500             return NULL;
    501         }
    502        
    503     mdList = md->list;
    504     if ( mdList == NULL ) {
    505             psError( __func__, "Null metadata list not allowed" );
    506             return NULL;
    507         }
    508        
     497
     498    mdList = md->list;
     499    if ( mdList == NULL ) {
     500        psError( __func__, "Null metadata list not allowed" );
     501        return NULL;
     502    }
     503
     504    mdList = md->list;
     505    if ( mdList == NULL ) {
     506        psError( __func__, "Null metadata list not allowed" );
     507        return NULL;
     508    }
     509
    509510    psListSetIterator( mdList, which );
    510511    entry = psListGetCurrent( mdList );
    511512    while ( entry != NULL ) {
    512             if ( !strncmp( match, entry->name, strlen( match ) ) ) {
    513            
    514                     // Match found
    515                     return entry;
    516                 }
    517             entry = psListGetPrevious( mdList );
    518         }
    519        
     513        if ( !strncmp( match, entry->name, strlen( match ) ) ) {
     514
     515            // Match found
     516            return entry;
     517        }
     518        entry = psListGetPrevious( mdList );
     519    }
     520
    520521    // Match not found
    521522    if ( entry == NULL ) {
    522             psError( __func__, "Couldn't find metadata item with given match. Match: %s", match );
    523         }
    524        
     523        psError( __func__, "Couldn't find metadata item with given match. Match: %s", match );
     524    }
     525
    525526    return entry;
    526527}
     
    529530{
    530531    psMetadataType type;
    531    
     532
    532533    if ( fd == NULL ) {
    533             psError( __func__, "Null file descriptor not allowed" );
    534             return ;
    535         }
    536        
     534        psError( __func__, "Null file descriptor not allowed" );
     535        return ;
     536    }
     537
    537538    if ( format == NULL ) {
    538             psError( __func__, "Null format not allowed" );
    539             return ;
    540         }
    541        
     539        psError( __func__, "Null format not allowed" );
     540        return ;
     541    }
     542
    542543    if ( metadataItem == NULL ) {
    543             psError( __func__, "Null metadata not allowed" );
    544             return ;
    545         }
    546        
     544        psError( __func__, "Null metadata not allowed" );
     545        return ;
     546    }
     547
    547548    type = metadataItem->type;
    548    
     549
    549550    switch ( type ) {
    550             case PS_META_BOOL:
    551             fprintf( fd, format, metadataItem->data.B );
    552             break;
    553             case PS_META_S32:
    554             fprintf( fd, format, metadataItem->data.S32 );
    555             break;
    556             case PS_META_F32:
    557             fprintf( fd, format, metadataItem->data.F32 );
    558             break;
    559             case PS_META_F64:
    560             fprintf( fd, format, metadataItem->data.F64 );
    561             break;
    562             case PS_META_STR:
    563             fprintf( fd, format, metadataItem->data.V );
    564             break;
    565             case PS_META_ITEM_SET:
    566             case PS_META_IMG:
    567             case PS_META_JPEG:
    568             case PS_META_PNG:
    569             case PS_META_ASTROM:
    570             case PS_META_UNKNOWN:
    571             default:
    572             psError( __func__, " Invalid psMetadataType to print: %d", type );
    573         }
     551    case PS_META_BOOL:
     552        fprintf( fd, format, metadataItem->data.B );
     553        break;
     554    case PS_META_S32:
     555        fprintf( fd, format, metadataItem->data.S32 );
     556        break;
     557    case PS_META_F32:
     558        fprintf( fd, format, metadataItem->data.F32 );
     559        break;
     560    case PS_META_F64:
     561        fprintf( fd, format, metadataItem->data.F64 );
     562        break;
     563    case PS_META_STR:
     564        fprintf( fd, format, metadataItem->data.V );
     565        break;
     566    case PS_META_ITEM_SET:
     567    case PS_META_IMG:
     568    case PS_META_JPEG:
     569    case PS_META_PNG:
     570    case PS_META_ASTROM:
     571    case PS_META_UNKNOWN:
     572    default:
     573        psError( __func__, " Invalid psMetadataType to print: %d", type );
     574    }
    574575}
    575576
     
    590591    int keyNum = 0;
    591592    psMetadataType metadataItemType;
    592    
     593
    593594    if ( fd == NULL ) {
    594             psError( __func__, "Null FITS file descriptor not allowed" );
    595             return NULL;
    596         }
    597        
     595        psError( __func__, "Null FITS file descriptor not allowed" );
     596        return NULL;
     597    }
     598
    598599    if ( extname == NULL && extnum == 0 ) {
    599             psError( __func__, "Null extname AND extnum = 0 not allowed" );
    600             return NULL;
    601         } else if ( extname && extnum ) {
     600        psError( __func__, "Null extname AND extnum = 0 not allowed" );
     601        return NULL;
     602    } else
     603        if ( extname && extnum ) {
    602604            psError( __func__, "Both extname AND extnum arguments should not have values." );
    603605            return NULL;
    604606        }
    605        
     607
    606608    // Allocate metadata if user didn't
    607609    if ( output == NULL ) {
    608             output = psMetadataAlloc();
    609         }
    610        
     610        output = psMetadataAlloc();
     611    }
     612
    611613    // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one.
    612614    if ( extname == NULL ) {
    613             if ( fits_movabs_hdu( fd, extnum, &hduType, &status ) != 0 ) {
    614                     fits_get_errstatus( status, fitsErr );
    615                     psError( __func__, "FITS error while locating header: %s", fitsErr );
    616                     status = 0;
    617                     return output;
    618                 }
    619         } else if ( extnum > 0 ) {
     615        if ( fits_movabs_hdu( fd, extnum, &hduType, &status ) != 0 ) {
     616            fits_get_errstatus( status, fitsErr );
     617            psError( __func__, "FITS error while locating header: %s", fitsErr );
     618            status = 0;
     619            return output;
     620        }
     621    } else
     622        if ( extnum > 0 ) {
    620623            tempExtname = ( char* ) extname;
    621624            if ( fits_movnam_hdu( fd, ANY_HDU, tempExtname, 0, &status ) != 0 ) {
    622                     fits_get_errstatus( status, fitsErr );
    623                     psError( __func__, "FITS error while locating header: %s", fitsErr );
    624                     status = 0;
    625                     return output;
    626                 }
    627         }
    628        
     625                fits_get_errstatus( status, fitsErr );
     626                psError( __func__, "FITS error while locating header: %s", fitsErr );
     627                status = 0;
     628                return output;
     629            }
     630        }
     631
    629632    // Get number of key names
    630633    if ( fits_get_hdrpos( fd, &numKeys, &keyNum, &status ) != 0 ) {
     634        fits_get_errstatus( status, fitsErr );
     635        psError( __func__, "FITS error while reading keys: %s", fitsErr );
     636        status = 0;
     637        return output;
     638    }
     639
     640    // Get each key name. Keywords start at one.
     641    for ( i = 1; i <= numKeys; i++ ) {
     642        if ( fits_read_keyn( fd, i, keyName, keyValue, keyComment, &status ) != 0 ) {
    631643            fits_get_errstatus( status, fitsErr );
    632             psError( __func__, "FITS error while reading keys: %s", fitsErr );
     644            psError( __func__, "FITS error while reading key number %d: %s", i, fitsErr );
    633645            status = 0;
    634646            return output;
    635647        }
    636        
    637     // Get each key name. Keywords start at one.
    638     for ( i = 1; i <= numKeys; i++ ) {
    639             if ( fits_read_keyn( fd, i, keyName, keyValue, keyComment, &status ) != 0 ) {
    640                     fits_get_errstatus( status, fitsErr );
    641                     psError( __func__, "FITS error while reading key number %d: %s", i, fitsErr );
    642                     status = 0;
    643                     return output;
    644                 }
    645             if ( fits_get_keytype( keyValue, &keyType, &status ) != 0 ) {
    646                     fits_get_errstatus( status, fitsErr );
    647                     if ( status != VALUE_UNDEFINED ) {
    648                             psError( __func__, "FITS error while determining key type: %s", fitsErr );
    649                             status = 0;
    650                             return output;
    651                         } else {
    652                             // Some keywords are still valid even though they don't have a type or value, like COMMENTS
    653                             keyType = 'C';
    654                             status = 0;
    655                         }
    656                 }
    657                
    658             switch ( keyType ) {
    659                     case 'I':
    660                     metadataItemType = PS_META_S32;
    661                     success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, atoi( keyValue ) );
    662                     break;
    663                     case 'F':
    664                     metadataItemType = PS_META_F64;
    665                     success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, atof( keyValue ) );
    666                     break;
    667                     case 'C':
    668                     metadataItemType = PS_META_STR;
    669                     success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, keyValue );
    670                     break;
    671                     case 'L':
    672                     metadataItemType = PS_META_BOOL;
    673                     tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
    674                     success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, tempBool );
    675                     break;
    676                     case 'U':
    677                     case 'X':
    678                     default:
    679                     psError( __func__, "Invalid psMetadataType: %c", keyType );
    680                     return output;
    681                 }
    682                
    683             if ( !success ) {
    684                     psError( __func__, "Failed to add metadata item. Name: %s", keyName );
    685                 }
    686         }
    687        
     648        if ( fits_get_keytype( keyValue, &keyType, &status ) != 0 ) {
     649            fits_get_errstatus( status, fitsErr );
     650            if ( status != VALUE_UNDEFINED ) {
     651                psError( __func__, "FITS error while determining key type: %s", fitsErr );
     652                status = 0;
     653                return output;
     654            } else {
     655                // Some keywords are still valid even though they don't have a type or value, like COMMENTS
     656                keyType = 'C';
     657                status = 0;
     658            }
     659        }
     660
     661        switch ( keyType ) {
     662        case 'I':
     663            metadataItemType = PS_META_S32;
     664            success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, atoi( keyValue ) );
     665            break;
     666        case 'F':
     667            metadataItemType = PS_META_F64;
     668            success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, atof( keyValue ) );
     669            break;
     670        case 'C':
     671            metadataItemType = PS_META_STR;
     672            success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, keyValue );
     673            break;
     674        case 'L':
     675            metadataItemType = PS_META_BOOL;
     676            tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
     677            success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, tempBool );
     678            break;
     679        case 'U':
     680        case 'X':
     681        default:
     682            psError( __func__, "Invalid psMetadataType: %c", keyType );
     683            return output;
     684        }
     685
     686        if ( !success ) {
     687            psError( __func__, "Failed to add metadata item. Name: %s", keyName );
     688        }
     689    }
     690
    688691    return output;
    689692}
  • trunk/psLib/src/collections/psMetadata.h

    r1382 r1385  
    1010*  @author Ross Harman, MHPCC
    1111*
    12 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-04 22:11:09 $
     12*  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-08-04 23:37:39 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5959 */
    6060typedef struct psMetadataItem
     61{
     62    const int id;                       ///< Unique ID for metadata item.
     63    char *restrict name;                ///< Name of metadata item.
     64    psMetadataType type;                ///< Type of metadata item.
     65    union
    6166    {
    62         const int id;                       ///< Unique ID for metadata item.
    63         char *restrict name;                ///< Name of metadata item.
    64         psMetadataType type;                ///< Type of metadata item.
    65         union
    66             {
    67                 bool B;
    68                 psS32 S32;                  ///< Signed 32-bit integer data.
    69                 psF32 F32;                  ///< Single-precision float data.
    70                 psF64 F64;                  ///< Double-precision float data.
    71                 psPTR V;                    ///< Pointer to other type of data.
    72             }data;                          ///< Union for data types.
    73         char *comment;                      ///< Optional comment ("", not NULL).
    74         psList *restrict items;             ///< List of psMetadataItems with same name.
    75     }
     67        bool B;
     68        psS32 S32;                  ///< Signed 32-bit integer data.
     69        psF32 F32;                  ///< Single-precision float data.
     70        psF64 F64;                  ///< Double-precision float data.
     71        psPTR V;                    ///< Pointer to other type of data.
     72    }data;                          ///< Union for data types.
     73    char *comment;                      ///< Optional comment ("", not NULL).
     74    psList *restrict items;             ///< List of psMetadataItems with same name.
     75}
    7676psMetadataItem;
    7777
     
    8383 */
    8484typedef struct psMetadata
    85     {
    86         psList* restrict list;
    87         psHash* restrict table;
    88     }
     85{
     86    psList* restrict list;
     87    psHash* restrict table;
     88}
    8989psMetadata;
    9090
  • trunk/psLib/src/collections/psScalar.c

    r1162 r1385  
    88 *  @author Ross Harman, MHPCC
    99 *
    10  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-07-01 00:14:40 $
     10 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-08-04 23:37:39 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/collections/psScalar.h

    r1060 r1385  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-18 23:36:02 $
     12 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-04 23:37:39 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/collections/psVector.c

    r1360 r1385  
    88*  @author Ross Harman, MHPCC
    99*
    10 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-07-31 02:28:10 $
     10*  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2004-08-04 23:37:39 $
    1212*
    1313*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6363    psVector * psVec = NULL;
    6464    int elementSize = 0;
    65    
     65
    6666    // Invalid nalloc
    6767    if ( nalloc < 1 ) {
    68             psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
    69             return NULL;
    70         }
    71        
     68        psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
     69        return NULL;
     70    }
     71
    7272    elementSize = PSELEMTYPE_SIZEOF( elemType );
    73    
     73
    7474    // Create vector struct
    7575    psVec = ( psVector * ) psAlloc( sizeof( psVector ) );
    7676    p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree );
    77    
     77
    7878    psVec->type.dimen = PS_DIMEN_VECTOR;
    7979    psVec->type.type = elemType;
    8080    psVec->nalloc = nalloc;
    8181    psVec->n = nalloc;
    82    
     82
    8383    // Create vector data array
    8484    psVec->data.V = psAlloc( nalloc * elementSize );
    85    
     85
    8686    return psVec;
    8787}
     
    9191    int elementSize = 0;
    9292    psElemType elemType;
    93    
     93
    9494    // Invalid nalloc
    9595    if ( nalloc < 1 ) {
    96             psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
    97             return NULL;
    98         }
    99        
     96        psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
     97        return NULL;
     98    }
     99
    100100    if ( in == NULL ) {
    101             psError( __func__, "Null input vector\n" );
    102             return NULL;
    103         } else if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
     101        psError( __func__, "Null input vector\n" );
     102        return NULL;
     103    } else
     104        if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
    104105            elemType = in->type.type;
    105106            elementSize = PSELEMTYPE_SIZEOF( elemType );
    106107            if ( nalloc < in->n ) {
    107                     in->n = nalloc;
    108                 }
    109                
     108                in->n = nalloc;
     109            }
     110
    110111            // Realloc after decrementation to avoid accessing freed array elements
    111112            in->data.V = psRealloc( in->data.V, nalloc * elementSize );
    112113            in->nalloc = nalloc;
    113114        }
    114        
     115
    115116    return in;
    116117}
     
    119120{
    120121    psElemType elemType;
    121    
     122
    122123    if ( in == NULL ) {
    123             return psVectorAlloc( nalloc, type );
    124         }
    125        
     124        return psVectorAlloc( nalloc, type );
     125    }
     126
    126127    elemType = in->type.type;
    127    
     128
    128129    if ( in->nalloc == nalloc && elemType == type ) {
    129             // it is proper size/type already
    130             return in;
    131         }
    132        
     130        // it is proper size/type already
     131        return in;
     132    }
     133
    133134    // Invalid nalloc
    134135    if ( nalloc < 1 ) {
    135             psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
    136             psFree( in );
    137             return NULL;
    138         }
    139        
    140        
     136        psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
     137        psFree( in );
     138        return NULL;
     139    }
     140
     141
    141142    in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) );
    142    
     143
    143144    in->type.type = type;
    144145    in->nalloc = nalloc;
    145146    in->n = nalloc;
    146    
     147
    147148    return in;
    148149}
     
    156157    void *outVec = NULL;
    157158    psElemType inType = 0;
    158    
     159
    159160    if ( inVector == NULL ) {
    160             psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
    161             return outVector;
    162         }
    163        
     161        psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
     162        return outVector;
     163    }
     164
    164165    inType = inVector->type.type;
    165166    inN = inVector->n;
    166167    inVec = inVector->data.V;
    167168    elSize = PSELEMTYPE_SIZEOF( inType );
    168    
     169
    169170    if ( outVector == NULL ) {
    170             outVector = psVectorAlloc( inN, inType );
    171             outVector->n = inVector->n;
    172         }
    173        
     171        outVector = psVectorAlloc( inN, inType );
     172        outVector->n = inVector->n;
     173    }
     174
    174175    outN = outVector->n;
    175176    outVec = outVector->data.V;
    176    
     177
    177178    if ( inN != outN ) {
    178             psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
    179                      inN, outN );
    180             return outVector;
    181         }
    182        
     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
    183184    if ( inType != outVector->type.type ) {
    184             psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
    185                      inType, outVector->type.type );
    186             return outVector;
    187         }
    188        
     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
    189190    if ( inN == 0 ) {
    190             psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
    191             return outVector;
    192         }
    193        
     191        psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
     192        return outVector;
     193    }
     194
    194195    if ( outN == 0 ) {
    195             psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
    196             return outVector;
    197         }
    198        
     196        psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
     197        return outVector;
     198    }
     199
    199200    // Copy input vector values into output vector
    200201    memcpy( outVec, inVec, elSize * outN );
    201    
     202
    202203    // Sort output vector
    203204    switch ( inType ) {
    204             case PS_TYPE_U8:
    205             qsort( outVec, inN, elSize, psCompareU8 );
    206             break;
    207             case PS_TYPE_U16:
    208             qsort( outVec, inN, elSize, psCompareU16 );
    209             break;
    210             case PS_TYPE_U32:
    211             qsort( outVec, inN, elSize, psCompareU32 );
    212             break;
    213             case PS_TYPE_U64:
    214             qsort( outVec, inN, elSize, psCompareU64 );
    215             break;
    216             case PS_TYPE_S8:
    217             qsort( outVec, inN, elSize, psCompareS8 );
    218             break;
    219             case PS_TYPE_S16:
    220             qsort( outVec, inN, elSize, psCompareS16 );
    221             break;
    222             case PS_TYPE_S32:
    223             qsort( outVec, inN, elSize, psCompareS32 );
    224             break;
    225             case PS_TYPE_S64:
    226             qsort( outVec, inN, elSize, psCompareS64 );
    227             break;
    228             case PS_TYPE_F32:
    229             qsort( outVec, inN, elSize, psCompareF32 );
    230             break;
    231             case PS_TYPE_F64:
    232             qsort( outVec, inN, elSize, psCompareF64 );
    233             break;
    234             default:
    235             psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
    236         }
    237        
     205    case PS_TYPE_U8:
     206        qsort( outVec, inN, elSize, psCompareU8 );
     207        break;
     208    case PS_TYPE_U16:
     209        qsort( outVec, inN, elSize, psCompareU16 );
     210        break;
     211    case PS_TYPE_U32:
     212        qsort( outVec, inN, elSize, psCompareU32 );
     213        break;
     214    case PS_TYPE_U64:
     215        qsort( outVec, inN, elSize, psCompareU64 );
     216        break;
     217    case PS_TYPE_S8:
     218        qsort( outVec, inN, elSize, psCompareS8 );
     219        break;
     220    case PS_TYPE_S16:
     221        qsort( outVec, inN, elSize, psCompareS16 );
     222        break;
     223    case PS_TYPE_S32:
     224        qsort( outVec, inN, elSize, psCompareS32 );
     225        break;
     226    case PS_TYPE_S64:
     227        qsort( outVec, inN, elSize, psCompareS64 );
     228        break;
     229    case PS_TYPE_F32:
     230        qsort( outVec, inN, elSize, psCompareF32 );
     231        break;
     232    case PS_TYPE_F64:
     233        qsort( outVec, inN, elSize, psCompareF64 );
     234        break;
     235    default:
     236        psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
     237    }
     238
    238239    return outVector;
    239240}
     
    241242#define SORT_INDICES(TYPE)                                                                                   \
    242243for(i=0; i<inN; i++) {                                                                                       \
    243         for(j=0; j<inN; j++) {                                                                                   \
    244                 diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
    245                 if(diff < FLT_EPSILON) {                                                                             \
    246                         outVec[i] = j;                                                                                   \
    247                         break;                                                                                           \
    248                     }                                                                                                    \
    249             }                                                                                                        \
    250     }
    251    
     244    for(j=0; j<inN; j++) {                                                                                   \
     245        diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
     246        if(diff < FLT_EPSILON) {                                                                             \
     247            outVec[i] = j;                                                                                   \
     248            break;                                                                                           \
     249        }                                                                                                    \
     250    }                                                                                                        \
     251}
     252
    252253psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector )
    253254{
     
    261262    psVector *tmpVector = NULL;
    262263    psElemType inType = 0;
    263    
     264
    264265    if ( inVector == NULL ) {
    265             psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
    266             return outVector;
    267         }
    268        
     266        psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
     267        return outVector;
     268    }
     269
    269270    inN = inVector->n;
    270271    inVec = inVector->data.V;
    271272    inType = inVector->type.type;
    272    
     273
    273274    if ( outVector == NULL ) {
    274             outVector = psVectorAlloc( inN, PS_TYPE_U32 );
    275             outVector->n = inN;
    276         }
    277        
     275        outVector = psVectorAlloc( inN, PS_TYPE_U32 );
     276        outVector->n = inN;
     277    }
     278
    278279    outN = outVector->n;
    279280    outVec = outVector->data.V;
    280    
     281
    281282    if ( inN != outN ) {
    282             psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
    283                      __LINE__, inN, outN );
    284             return outVector;
    285         }
    286        
     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
    287288    if ( outVector->type.type != PS_TYPE_U32 ) {
    288             psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
    289                      __LINE__, outVector->type.type );
    290             return outVector;
    291         }
    292        
     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
    293294    tmpVector = psVectorAlloc( inN, inType );
    294295    tmpVector->n = inN;
    295296    tmpVector = psVectorSort( tmpVector, inVector );
    296    
     297
    297298    // Sort output vector
    298299    switch ( inType ) {
    299             case PS_TYPE_U8:
    300             SORT_INDICES( U8 );
    301             break;
    302             case PS_TYPE_U16:
    303             SORT_INDICES( U16 );
    304             break;
    305             case PS_TYPE_U32:
    306             SORT_INDICES( U32 );
    307             break;
    308             case PS_TYPE_U64:
    309             SORT_INDICES( U64 );
    310             break;
    311             case PS_TYPE_S8:
    312             SORT_INDICES( S8 );
    313             break;
    314             case PS_TYPE_S16:
    315             SORT_INDICES( S16 );
    316             break;
    317             case PS_TYPE_S32:
    318             SORT_INDICES( S32 );
    319             break;
    320             case PS_TYPE_S64:
    321             SORT_INDICES( S64 );
    322             break;
    323             case PS_TYPE_F32:
    324             SORT_INDICES( F32 );
    325             break;
    326             case PS_TYPE_F64:
    327             SORT_INDICES( F64 );
    328             break;
    329             default:
    330             psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
    331         }
    332        
     300    case PS_TYPE_U8:
     301        SORT_INDICES( U8 );
     302        break;
     303    case PS_TYPE_U16:
     304        SORT_INDICES( U16 );
     305        break;
     306    case PS_TYPE_U32:
     307        SORT_INDICES( U32 );
     308        break;
     309    case PS_TYPE_U64:
     310        SORT_INDICES( U64 );
     311        break;
     312    case PS_TYPE_S8:
     313        SORT_INDICES( S8 );
     314        break;
     315    case PS_TYPE_S16:
     316        SORT_INDICES( S16 );
     317        break;
     318    case PS_TYPE_S32:
     319        SORT_INDICES( S32 );
     320        break;
     321    case PS_TYPE_S64:
     322        SORT_INDICES( S64 );
     323        break;
     324    case PS_TYPE_F32:
     325        SORT_INDICES( F32 );
     326        break;
     327    case PS_TYPE_F64:
     328        SORT_INDICES( F64 );
     329        break;
     330    default:
     331        psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
     332    }
     333
    333334    // Free temp memory
    334335    psFree( tmpVector );
    335    
     336
    336337    return outVector;
    337338}
     
    340341{
    341342    if ( psVec == NULL ) {
    342             return ;
    343         }
    344        
     343        return ;
     344    }
     345
    345346    psFree( psVec->data.V );
    346347}
  • trunk/psLib/src/collections/psVector.h

    r1233 r1385  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-07-15 23:52:33 $
     13 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-04 23:37:39 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
Note: See TracChangeset for help on using the changeset viewer.