IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2004, 10:47:52 AM (22 years ago)
Author:
harman
Message:

Simple updates

File:
1 edited

Legend:

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

    r1355 r1376  
    1111*  @author Ross Harman, MHPCC
    1212*
    13 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-07-31 00:48:20 $
     13*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-08-04 20:47:52 $
    1515*
    1616*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "psHash.h"
    3333#include "psMetadata.h"
     34#include "psString.h"
    3435
    3536
     
    3839/******************************************************************************/
    3940
    40 // Maximum metadata length string
    41 #define MAX_VAL_SIZE 1024
    42 
    4341// Maximum metadata error length
    4442#define MAX_ERR_MESSAGE_LENGTH 1024
    4543
    4644// Maximum line size
    47 #define MAX_LINE_SIZE 80
     45#define FITS_LINE_SIZE 80
    4846
    4947/******************************************************************************/
     
    8078    psFree( metadataItem->name );
    8179    psFree( metadataItem->comment );
    82    
    83     if ( type == PS_META_STR || type == PS_META_IMG || type == PS_META_JPEG || type == PS_META_PNG ||
    84             type == PS_META_ASTROM || type == PS_META_UNKNOWN ) {
     80    psFree( metadataItem->items );
     81   
     82    if ( type == PS_META_STR ||
     83            type == PS_META_IMG ||
     84            type == PS_META_JPEG ||
     85            type == PS_META_PNG ||
     86            type == PS_META_ASTROM ||
     87            type == PS_META_UNKNOWN ) {
    8588            psFree( metadataItem->data.V );
    8689        }
    87        
    88     psFree( metadataItem->items );
    8990}
    9091
     
    9495            return ;
    9596        }
    96        
    9797    psFree( metadata->list );
    9898    psFree( metadata->table );
     
    155155    // Set metadata item value
    156156    switch ( type ) {
     157            case PS_META_BOOL:
     158            metadataItem->data.B = ( bool ) va_arg( argPtr, int );
     159            break;
    157160            case PS_META_S32:
    158161            metadataItem->data.S32 = va_arg( argPtr, psS32 );
     
    165168            break;
    166169            case PS_META_STR:
     170            metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
     171            break;
    167172            case PS_META_IMG:
    168173            case PS_META_JPEG:
     
    170175            case PS_META_ASTROM:
    171176            case PS_META_UNKNOWN:
    172             metadataItem->data.V = psMemIncrRefCounter( va_arg( argPtr, psPTR ) );
    173             break;
    174177            default:
    175             psError( __func__, " Invalid psMetadataType: %d", type );
     178            psError( __func__, "Invalid psMetadataType: %d", type );
    176179        }
    177180       
     
    201204    p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree );
    202205   
    203     // Allocate internal containers
    204     list = ( psList * ) psAlloc( sizeof( psList ) );
     206    // Allocate metadata's internal containers
     207    list = ( psList * ) psListAlloc( NULL );
    205208    if ( list == NULL ) {
    206209            psAbort( __func__, "Failed to allocate list" );
    207210        }
    208211       
    209     table = ( psHash * ) psAlloc( sizeof( psHash ) );
     212    table = ( psHash * ) psHashAlloc( 10 );
    210213    if ( table == NULL ) {
    211214            psAbort( __func__, "Failed to allocate table" );
    212215        }
    213216       
     217    metadata->list = list;
     218    metadata->table = table;
     219   
    214220    return metadata;
    215221}
     
    308314        }
    309315       
     316    // Decrement reference count, since the metadata item is now in metadata collection and no longer needed here
     317    psMemDecrRefCounter( metadataItem );
     318   
    310319    return true;
    311320}
     
    543552   
    544553    switch ( type ) {
     554            case PS_META_BOOL:
     555            fprintf( fd, format, metadataItem->data.B );
     556            break;
    545557            case PS_META_S32:
    546558            fprintf( fd, format, metadataItem->data.S32 );
     
    566578}
    567579
    568 psMetadata *psMetadataReadHeader( psMetadata *output, const char *extname, int extnum, const char *filename )
    569 {
    570     /*    char line[ MAX_VAL_SIZE ];
    571         char keyName[ MAX_VAL_SIZE ];
    572         char keyValue[ MAX_VAL_SIZE ];
    573         char keyComment[ MAX_VAL_SIZE ];
    574         int status = 0;
    575         extnumCtr = 1;
    576         FILE *fd = NULL;
    577        
    578         if ( filename == NULL ) {
    579                 psError( __func__, "Null file name not allowed" );
    580                 return NULL;
    581             }
    582            
    583         if ( extname == NULL && extnum == 0 ) {
    584                 psError( __func__, "Null extname AND extnum = 0 not allowed" );
    585                 return NULL;
    586             } else if ( extname && extnum ) {
    587                 psError( __func__, "Both extname AND extnum arguments should not have valid values." );
    588                 return NULL;
    589             }
    590            
    591         fd = fopen( filename, "r" );
    592         if ( fd == NULL ) {
    593                 psError( __func__, "Null FITS file descriptor not allowed" );
    594                 return NULL;
    595             }
    596            
    597         // Allocate metadata if user didn't
    598         if ( output == NULL ) {
    599                 output = psMetadataAlloc();
    600                 psError( __func__, "Failed to allocate metadata" );
    601                 return NULL;
    602             }
    603            
    604         // Move to user designated HDU number or HDU name in text file. HDU numbers starts at one.
    605          TODO    if(extname == NULL) {
    606                     return output;
    607                 }
    608             } else if(extnum > 0) {
    609                     return output;
    610                 }
    611             }
    612          
    613          
    614              line = fgets(line, MAX_LINE_SIZE+1, fp);
    615              while(line != NULL) {
    616          
    617                  if(!strncmp("END", line, 3)){
    618                      extnumCtr++;
    619                  }
    620          
    621                  if(extnumCtr == extnum) {
    622          
    623                      // Put text into metadata
    624                      if(!strncmp("COMMENT", line, 7)){
    625                          // COMMENT keywords have no "=" sign
    626                          //TODO
    627                      } else if (strchr(line, '\'') != NULL){
    628          
    629                          // Output and logging keywords have tic (') characters
    630                          keyName = strtok(line, "=");
    631                          keyValue = strtok(NULL, "'");
    632                          keyValue = strtok(NULL, "'");
    633                          keyComment = strtok(NULL, "XXX");
    634          
    635          
    636                      } else
    637          
    638                          // Everything else is considered to be the standard name and value
    639                          keyName = strtok(line, "=");
    640                          keyValue = strtok(NULL, "/");
    641                          keyComment = strtok(NULL, "XXX");
    642                      }
    643          
    644          
    645                  }
    646          
    647                  // Read next line
    648                  line = fgets(line, MAX_LINE_SIZE+1, fp);
    649              }
    650          
    651         */
    652     return output;
    653 }
    654 
    655580psMetadata *psMetadataFReadHeader( psMetadata *output, const char *extname, int extnum, fitsfile *fd )
    656581{
     582    bool tempBool;
    657583    bool success;
    658584    char keyType;
    659     char keyName[ MAX_VAL_SIZE ];
    660     char keyValue[ MAX_VAL_SIZE ];
    661     char keyComment[ MAX_VAL_SIZE ];
    662     char fitsErr[ MAX_ERR_MESSAGE_LENGTH ];
     585    char keyName[ FITS_LINE_SIZE ];
     586    char keyValue[ FITS_LINE_SIZE ];
     587    char keyComment[ FITS_LINE_SIZE ];
     588    char fitsErr[ MAX_STRING_LENGTH ];
    663589    char* tempExtname = NULL;
    664590    int i;
     
    666592    int status = 0;
    667593    int numKeys = 0;
     594    int keyNum = 0;
    668595    psMetadataType metadataItemType;
    669596   
     
    677604            return NULL;
    678605        } else if ( extname && extnum ) {
    679             psError( __func__, "Both extname AND extnum arguments should not have valid values." );
     606            psError( __func__, "Both extname AND extnum arguments should not have values." );
    680607            return NULL;
    681608        }
     
    684611    if ( output == NULL ) {
    685612            output = psMetadataAlloc();
    686             psError( __func__, "Failed to allocate metadata" );
    687             return NULL;
    688613        }
    689614       
     
    694619                    psError( __func__, "FITS error while locating header: %s", fitsErr );
    695620                    status = 0;
    696                     fits_close_file( fd, &status );
    697621                    return output;
    698622                }
    699623        } else if ( extnum > 0 ) {
    700             tempExtname = ( char* ) psAlloc( strlen( extname ) + 1 ); // fits_movnam_hdu doesn't like const part of extname
    701             strncpy( tempExtname, extname, MAX_VAL_SIZE );
     624            tempExtname = ( char* ) extname;
    702625            if ( fits_movnam_hdu( fd, ANY_HDU, tempExtname, 0, &status ) != 0 ) {
    703626                    fits_get_errstatus( status, fitsErr );
    704627                    psError( __func__, "FITS error while locating header: %s", fitsErr );
    705628                    status = 0;
    706                     fits_close_file( fd, &status );
    707                     psFree( tempExtname );
    708629                    return output;
    709630                }
    710             psFree( tempExtname );
    711631        }
    712632       
    713633    // Get number of key names
    714     if ( fits_get_hdrpos( fd, &numKeys, NULL, &status ) != 0 ) {
     634    if ( fits_get_hdrpos( fd, &numKeys, &keyNum, &status ) != 0 ) {
    715635            fits_get_errstatus( status, fitsErr );
    716636            psError( __func__, "FITS error while reading keys: %s", fitsErr );
    717637            status = 0;
    718             fits_close_file( fd, &status );
    719638            return output;
    720639        }
     
    726645                    psError( __func__, "FITS error while reading key number %d: %s", i, fitsErr );
    727646                    status = 0;
    728                     fits_close_file( fd, &status );
    729647                    return output;
    730648                }
    731                
    732649            if ( fits_get_keytype( keyValue, &keyType, &status ) != 0 ) {
    733650                    fits_get_errstatus( status, fitsErr );
    734                     psError( __func__, "FITS error while determining key type: %s", fitsErr );
    735                     status = 0;
    736                     fits_close_file( fd, &status );
    737                     return output;
     651                    if ( status != VALUE_UNDEFINED ) {
     652                            psError( __func__, "FITS error while determining key type: %s", fitsErr );
     653                            status = 0;
     654                            return output;
     655                        } else {
     656                            // Some keywords are still valid even though they don't have a type or value, like COMMENTS
     657                            keyType = 'C';
     658                            status = 0;
     659                        }
    738660                }
    739661               
     
    752674                    break;
    753675                    case 'L':
     676                    metadataItemType = PS_META_BOOL;
     677                    tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
     678                    success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, tempBool );
     679                    break;
     680                    case 'U':
    754681                    case 'X':
    755682                    default:
Note: See TracChangeset for help on using the changeset viewer.