Index: /trunk/psLib/src/astronomy/psMetadata.c
===================================================================
--- /trunk/psLib/src/astronomy/psMetadata.c	(revision 1375)
+++ /trunk/psLib/src/astronomy/psMetadata.c	(revision 1376)
@@ -11,6 +11,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-07-31 00:48:20 $
+*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-04 20:47:52 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,4 +32,5 @@
 #include "psHash.h"
 #include "psMetadata.h"
+#include "psString.h"
 
 
@@ -38,12 +39,9 @@
 /******************************************************************************/
 
-// Maximum metadata length string
-#define MAX_VAL_SIZE 1024
-
 // Maximum metadata error length
 #define MAX_ERR_MESSAGE_LENGTH 1024
 
 // Maximum line size
-#define MAX_LINE_SIZE 80
+#define FITS_LINE_SIZE 80
 
 /******************************************************************************/
@@ -80,11 +78,14 @@
     psFree( metadataItem->name );
     psFree( metadataItem->comment );
-    
-    if ( type == PS_META_STR || type == PS_META_IMG || type == PS_META_JPEG || type == PS_META_PNG ||
-            type == PS_META_ASTROM || type == PS_META_UNKNOWN ) {
+    psFree( metadataItem->items );
+    
+    if ( type == PS_META_STR ||
+            type == PS_META_IMG ||
+            type == PS_META_JPEG ||
+            type == PS_META_PNG ||
+            type == PS_META_ASTROM ||
+            type == PS_META_UNKNOWN ) {
             psFree( metadataItem->data.V );
         }
-        
-    psFree( metadataItem->items );
 }
 
@@ -94,5 +95,4 @@
             return ;
         }
-        
     psFree( metadata->list );
     psFree( metadata->table );
@@ -155,4 +155,7 @@
     // Set metadata item value
     switch ( type ) {
+            case PS_META_BOOL:
+            metadataItem->data.B = ( bool ) va_arg( argPtr, int );
+            break;
             case PS_META_S32:
             metadataItem->data.S32 = va_arg( argPtr, psS32 );
@@ -165,4 +168,6 @@
             break;
             case PS_META_STR:
+            metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
+            break;
             case PS_META_IMG:
             case PS_META_JPEG:
@@ -170,8 +175,6 @@
             case PS_META_ASTROM:
             case PS_META_UNKNOWN:
-            metadataItem->data.V = psMemIncrRefCounter( va_arg( argPtr, psPTR ) );
-            break;
             default:
-            psError( __func__, " Invalid psMetadataType: %d", type );
+            psError( __func__, "Invalid psMetadataType: %d", type );
         }
         
@@ -201,15 +204,18 @@
     p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree );
     
-    // Allocate internal containers
-    list = ( psList * ) psAlloc( sizeof( psList ) );
+    // Allocate metadata's internal containers
+    list = ( psList * ) psListAlloc( NULL );
     if ( list == NULL ) {
             psAbort( __func__, "Failed to allocate list" );
         }
         
-    table = ( psHash * ) psAlloc( sizeof( psHash ) );
+    table = ( psHash * ) psHashAlloc( 10 );
     if ( table == NULL ) {
             psAbort( __func__, "Failed to allocate table" );
         }
         
+    metadata->list = list;
+    metadata->table = table;
+    
     return metadata;
 }
@@ -308,4 +314,7 @@
         }
         
+    // Decrement reference count, since the metadata item is now in metadata collection and no longer needed here
+    psMemDecrRefCounter( metadataItem );
+    
     return true;
 }
@@ -543,4 +552,7 @@
     
     switch ( type ) {
+            case PS_META_BOOL:
+            fprintf( fd, format, metadataItem->data.B );
+            break;
             case PS_META_S32:
             fprintf( fd, format, metadataItem->data.S32 );
@@ -566,99 +578,13 @@
 }
 
-psMetadata *psMetadataReadHeader( psMetadata *output, const char *extname, int extnum, const char *filename )
-{
-    /*    char line[ MAX_VAL_SIZE ];
-        char keyName[ MAX_VAL_SIZE ];
-        char keyValue[ MAX_VAL_SIZE ];
-        char keyComment[ MAX_VAL_SIZE ];
-        int status = 0;
-        extnumCtr = 1;
-        FILE *fd = NULL;
-        
-        if ( filename == NULL ) {
-                psError( __func__, "Null file name not allowed" );
-                return NULL;
-            }
-            
-        if ( extname == NULL && extnum == 0 ) {
-                psError( __func__, "Null extname AND extnum = 0 not allowed" );
-                return NULL;
-            } else if ( extname && extnum ) {
-                psError( __func__, "Both extname AND extnum arguments should not have valid values." );
-                return NULL;
-            }
-            
-        fd = fopen( filename, "r" );
-        if ( fd == NULL ) {
-                psError( __func__, "Null FITS file descriptor not allowed" );
-                return NULL;
-            }
-            
-        // Allocate metadata if user didn't
-        if ( output == NULL ) {
-                output = psMetadataAlloc();
-                psError( __func__, "Failed to allocate metadata" );
-                return NULL;
-            }
-            
-        // Move to user designated HDU number or HDU name in text file. HDU numbers starts at one.
-         TODO    if(extname == NULL) {
-                    return output;
-                }
-            } else if(extnum > 0) {
-                    return output;
-                }
-            }
-         
-         
-             line = fgets(line, MAX_LINE_SIZE+1, fp);
-             while(line != NULL) {
-         
-                 if(!strncmp("END", line, 3)){
-                     extnumCtr++;
-                 }
-         
-                 if(extnumCtr == extnum) {
-         
-                     // Put text into metadata
-                     if(!strncmp("COMMENT", line, 7)){
-                         // COMMENT keywords have no "=" sign
-                         //TODO
-                     } else if (strchr(line, '\'') != NULL){
-         
-                         // Output and logging keywords have tic (') characters
-                         keyName = strtok(line, "=");
-                         keyValue = strtok(NULL, "'");
-                         keyValue = strtok(NULL, "'");
-                         keyComment = strtok(NULL, "XXX");
-         
-         
-                     } else
-         
-                         // Everything else is considered to be the standard name and value
-                         keyName = strtok(line, "=");
-                         keyValue = strtok(NULL, "/");
-                         keyComment = strtok(NULL, "XXX");
-                     }
-         
-         
-                 }
-         
-                 // Read next line
-                 line = fgets(line, MAX_LINE_SIZE+1, fp);
-             }
-         
-        */ 
-    return output;
-}
-
 psMetadata *psMetadataFReadHeader( psMetadata *output, const char *extname, int extnum, fitsfile *fd )
 {
+    bool tempBool;
     bool success;
     char keyType;
-    char keyName[ MAX_VAL_SIZE ];
-    char keyValue[ MAX_VAL_SIZE ];
-    char keyComment[ MAX_VAL_SIZE ];
-    char fitsErr[ MAX_ERR_MESSAGE_LENGTH ];
+    char keyName[ FITS_LINE_SIZE ];
+    char keyValue[ FITS_LINE_SIZE ];
+    char keyComment[ FITS_LINE_SIZE ];
+    char fitsErr[ MAX_STRING_LENGTH ];
     char* tempExtname = NULL;
     int i;
@@ -666,4 +592,5 @@
     int status = 0;
     int numKeys = 0;
+    int keyNum = 0;
     psMetadataType metadataItemType;
     
@@ -677,5 +604,5 @@
             return NULL;
         } else if ( extname && extnum ) {
-            psError( __func__, "Both extname AND extnum arguments should not have valid values." );
+            psError( __func__, "Both extname AND extnum arguments should not have values." );
             return NULL;
         }
@@ -684,6 +611,4 @@
     if ( output == NULL ) {
             output = psMetadataAlloc();
-            psError( __func__, "Failed to allocate metadata" );
-            return NULL;
         }
         
@@ -694,27 +619,21 @@
                     psError( __func__, "FITS error while locating header: %s", fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
                     return output;
                 }
         } else if ( extnum > 0 ) {
-            tempExtname = ( char* ) psAlloc( strlen( extname ) + 1 ); // fits_movnam_hdu doesn't like const part of extname
-            strncpy( tempExtname, extname, MAX_VAL_SIZE );
+            tempExtname = ( char* ) extname;
             if ( fits_movnam_hdu( fd, ANY_HDU, tempExtname, 0, &status ) != 0 ) {
                     fits_get_errstatus( status, fitsErr );
                     psError( __func__, "FITS error while locating header: %s", fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
-                    psFree( tempExtname );
                     return output;
                 }
-            psFree( tempExtname );
         }
         
     // Get number of key names
-    if ( fits_get_hdrpos( fd, &numKeys, NULL, &status ) != 0 ) {
+    if ( fits_get_hdrpos( fd, &numKeys, &keyNum, &status ) != 0 ) {
             fits_get_errstatus( status, fitsErr );
             psError( __func__, "FITS error while reading keys: %s", fitsErr );
             status = 0;
-            fits_close_file( fd, &status );
             return output;
         }
@@ -726,14 +645,17 @@
                     psError( __func__, "FITS error while reading key number %d: %s", i, fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
                     return output;
                 }
-                
             if ( fits_get_keytype( keyValue, &keyType, &status ) != 0 ) {
                     fits_get_errstatus( status, fitsErr );
-                    psError( __func__, "FITS error while determining key type: %s", fitsErr );
-                    status = 0;
-                    fits_close_file( fd, &status );
-                    return output;
+                    if ( status != VALUE_UNDEFINED ) {
+                            psError( __func__, "FITS error while determining key type: %s", fitsErr );
+                            status = 0;
+                            return output;
+                        } else {
+                            // Some keywords are still valid even though they don't have a type or value, like COMMENTS
+                            keyType = 'C';
+                            status = 0;
+                        }
                 }
                 
@@ -752,4 +674,9 @@
                     break;
                     case 'L':
+                    metadataItemType = PS_META_BOOL;
+                    tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
+                    success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, tempBool );
+                    break;
+                    case 'U':
                     case 'X':
                     default:
Index: /trunk/psLib/src/collections/psMetadata.c
===================================================================
--- /trunk/psLib/src/collections/psMetadata.c	(revision 1375)
+++ /trunk/psLib/src/collections/psMetadata.c	(revision 1376)
@@ -11,6 +11,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-07-31 00:48:20 $
+*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-04 20:47:52 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,4 +32,5 @@
 #include "psHash.h"
 #include "psMetadata.h"
+#include "psString.h"
 
 
@@ -38,12 +39,9 @@
 /******************************************************************************/
 
-// Maximum metadata length string
-#define MAX_VAL_SIZE 1024
-
 // Maximum metadata error length
 #define MAX_ERR_MESSAGE_LENGTH 1024
 
 // Maximum line size
-#define MAX_LINE_SIZE 80
+#define FITS_LINE_SIZE 80
 
 /******************************************************************************/
@@ -80,11 +78,14 @@
     psFree( metadataItem->name );
     psFree( metadataItem->comment );
-    
-    if ( type == PS_META_STR || type == PS_META_IMG || type == PS_META_JPEG || type == PS_META_PNG ||
-            type == PS_META_ASTROM || type == PS_META_UNKNOWN ) {
+    psFree( metadataItem->items );
+    
+    if ( type == PS_META_STR ||
+            type == PS_META_IMG ||
+            type == PS_META_JPEG ||
+            type == PS_META_PNG ||
+            type == PS_META_ASTROM ||
+            type == PS_META_UNKNOWN ) {
             psFree( metadataItem->data.V );
         }
-        
-    psFree( metadataItem->items );
 }
 
@@ -94,5 +95,4 @@
             return ;
         }
-        
     psFree( metadata->list );
     psFree( metadata->table );
@@ -155,4 +155,7 @@
     // Set metadata item value
     switch ( type ) {
+            case PS_META_BOOL:
+            metadataItem->data.B = ( bool ) va_arg( argPtr, int );
+            break;
             case PS_META_S32:
             metadataItem->data.S32 = va_arg( argPtr, psS32 );
@@ -165,4 +168,6 @@
             break;
             case PS_META_STR:
+            metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
+            break;
             case PS_META_IMG:
             case PS_META_JPEG:
@@ -170,8 +175,6 @@
             case PS_META_ASTROM:
             case PS_META_UNKNOWN:
-            metadataItem->data.V = psMemIncrRefCounter( va_arg( argPtr, psPTR ) );
-            break;
             default:
-            psError( __func__, " Invalid psMetadataType: %d", type );
+            psError( __func__, "Invalid psMetadataType: %d", type );
         }
         
@@ -201,15 +204,18 @@
     p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree );
     
-    // Allocate internal containers
-    list = ( psList * ) psAlloc( sizeof( psList ) );
+    // Allocate metadata's internal containers
+    list = ( psList * ) psListAlloc( NULL );
     if ( list == NULL ) {
             psAbort( __func__, "Failed to allocate list" );
         }
         
-    table = ( psHash * ) psAlloc( sizeof( psHash ) );
+    table = ( psHash * ) psHashAlloc( 10 );
     if ( table == NULL ) {
             psAbort( __func__, "Failed to allocate table" );
         }
         
+    metadata->list = list;
+    metadata->table = table;
+    
     return metadata;
 }
@@ -308,4 +314,7 @@
         }
         
+    // Decrement reference count, since the metadata item is now in metadata collection and no longer needed here
+    psMemDecrRefCounter( metadataItem );
+    
     return true;
 }
@@ -543,4 +552,7 @@
     
     switch ( type ) {
+            case PS_META_BOOL:
+            fprintf( fd, format, metadataItem->data.B );
+            break;
             case PS_META_S32:
             fprintf( fd, format, metadataItem->data.S32 );
@@ -566,99 +578,13 @@
 }
 
-psMetadata *psMetadataReadHeader( psMetadata *output, const char *extname, int extnum, const char *filename )
-{
-    /*    char line[ MAX_VAL_SIZE ];
-        char keyName[ MAX_VAL_SIZE ];
-        char keyValue[ MAX_VAL_SIZE ];
-        char keyComment[ MAX_VAL_SIZE ];
-        int status = 0;
-        extnumCtr = 1;
-        FILE *fd = NULL;
-        
-        if ( filename == NULL ) {
-                psError( __func__, "Null file name not allowed" );
-                return NULL;
-            }
-            
-        if ( extname == NULL && extnum == 0 ) {
-                psError( __func__, "Null extname AND extnum = 0 not allowed" );
-                return NULL;
-            } else if ( extname && extnum ) {
-                psError( __func__, "Both extname AND extnum arguments should not have valid values." );
-                return NULL;
-            }
-            
-        fd = fopen( filename, "r" );
-        if ( fd == NULL ) {
-                psError( __func__, "Null FITS file descriptor not allowed" );
-                return NULL;
-            }
-            
-        // Allocate metadata if user didn't
-        if ( output == NULL ) {
-                output = psMetadataAlloc();
-                psError( __func__, "Failed to allocate metadata" );
-                return NULL;
-            }
-            
-        // Move to user designated HDU number or HDU name in text file. HDU numbers starts at one.
-         TODO    if(extname == NULL) {
-                    return output;
-                }
-            } else if(extnum > 0) {
-                    return output;
-                }
-            }
-         
-         
-             line = fgets(line, MAX_LINE_SIZE+1, fp);
-             while(line != NULL) {
-         
-                 if(!strncmp("END", line, 3)){
-                     extnumCtr++;
-                 }
-         
-                 if(extnumCtr == extnum) {
-         
-                     // Put text into metadata
-                     if(!strncmp("COMMENT", line, 7)){
-                         // COMMENT keywords have no "=" sign
-                         //TODO
-                     } else if (strchr(line, '\'') != NULL){
-         
-                         // Output and logging keywords have tic (') characters
-                         keyName = strtok(line, "=");
-                         keyValue = strtok(NULL, "'");
-                         keyValue = strtok(NULL, "'");
-                         keyComment = strtok(NULL, "XXX");
-         
-         
-                     } else
-         
-                         // Everything else is considered to be the standard name and value
-                         keyName = strtok(line, "=");
-                         keyValue = strtok(NULL, "/");
-                         keyComment = strtok(NULL, "XXX");
-                     }
-         
-         
-                 }
-         
-                 // Read next line
-                 line = fgets(line, MAX_LINE_SIZE+1, fp);
-             }
-         
-        */ 
-    return output;
-}
-
 psMetadata *psMetadataFReadHeader( psMetadata *output, const char *extname, int extnum, fitsfile *fd )
 {
+    bool tempBool;
     bool success;
     char keyType;
-    char keyName[ MAX_VAL_SIZE ];
-    char keyValue[ MAX_VAL_SIZE ];
-    char keyComment[ MAX_VAL_SIZE ];
-    char fitsErr[ MAX_ERR_MESSAGE_LENGTH ];
+    char keyName[ FITS_LINE_SIZE ];
+    char keyValue[ FITS_LINE_SIZE ];
+    char keyComment[ FITS_LINE_SIZE ];
+    char fitsErr[ MAX_STRING_LENGTH ];
     char* tempExtname = NULL;
     int i;
@@ -666,4 +592,5 @@
     int status = 0;
     int numKeys = 0;
+    int keyNum = 0;
     psMetadataType metadataItemType;
     
@@ -677,5 +604,5 @@
             return NULL;
         } else if ( extname && extnum ) {
-            psError( __func__, "Both extname AND extnum arguments should not have valid values." );
+            psError( __func__, "Both extname AND extnum arguments should not have values." );
             return NULL;
         }
@@ -684,6 +611,4 @@
     if ( output == NULL ) {
             output = psMetadataAlloc();
-            psError( __func__, "Failed to allocate metadata" );
-            return NULL;
         }
         
@@ -694,27 +619,21 @@
                     psError( __func__, "FITS error while locating header: %s", fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
                     return output;
                 }
         } else if ( extnum > 0 ) {
-            tempExtname = ( char* ) psAlloc( strlen( extname ) + 1 ); // fits_movnam_hdu doesn't like const part of extname
-            strncpy( tempExtname, extname, MAX_VAL_SIZE );
+            tempExtname = ( char* ) extname;
             if ( fits_movnam_hdu( fd, ANY_HDU, tempExtname, 0, &status ) != 0 ) {
                     fits_get_errstatus( status, fitsErr );
                     psError( __func__, "FITS error while locating header: %s", fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
-                    psFree( tempExtname );
                     return output;
                 }
-            psFree( tempExtname );
         }
         
     // Get number of key names
-    if ( fits_get_hdrpos( fd, &numKeys, NULL, &status ) != 0 ) {
+    if ( fits_get_hdrpos( fd, &numKeys, &keyNum, &status ) != 0 ) {
             fits_get_errstatus( status, fitsErr );
             psError( __func__, "FITS error while reading keys: %s", fitsErr );
             status = 0;
-            fits_close_file( fd, &status );
             return output;
         }
@@ -726,14 +645,17 @@
                     psError( __func__, "FITS error while reading key number %d: %s", i, fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
                     return output;
                 }
-                
             if ( fits_get_keytype( keyValue, &keyType, &status ) != 0 ) {
                     fits_get_errstatus( status, fitsErr );
-                    psError( __func__, "FITS error while determining key type: %s", fitsErr );
-                    status = 0;
-                    fits_close_file( fd, &status );
-                    return output;
+                    if ( status != VALUE_UNDEFINED ) {
+                            psError( __func__, "FITS error while determining key type: %s", fitsErr );
+                            status = 0;
+                            return output;
+                        } else {
+                            // Some keywords are still valid even though they don't have a type or value, like COMMENTS
+                            keyType = 'C';
+                            status = 0;
+                        }
                 }
                 
@@ -752,4 +674,9 @@
                     break;
                     case 'L':
+                    metadataItemType = PS_META_BOOL;
+                    tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
+                    success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, tempBool );
+                    break;
+                    case 'U':
                     case 'X':
                     default:
Index: /trunk/psLib/src/types/psMetadata.c
===================================================================
--- /trunk/psLib/src/types/psMetadata.c	(revision 1375)
+++ /trunk/psLib/src/types/psMetadata.c	(revision 1376)
@@ -11,6 +11,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-07-31 00:48:20 $
+*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-04 20:47:52 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,4 +32,5 @@
 #include "psHash.h"
 #include "psMetadata.h"
+#include "psString.h"
 
 
@@ -38,12 +39,9 @@
 /******************************************************************************/
 
-// Maximum metadata length string
-#define MAX_VAL_SIZE 1024
-
 // Maximum metadata error length
 #define MAX_ERR_MESSAGE_LENGTH 1024
 
 // Maximum line size
-#define MAX_LINE_SIZE 80
+#define FITS_LINE_SIZE 80
 
 /******************************************************************************/
@@ -80,11 +78,14 @@
     psFree( metadataItem->name );
     psFree( metadataItem->comment );
-    
-    if ( type == PS_META_STR || type == PS_META_IMG || type == PS_META_JPEG || type == PS_META_PNG ||
-            type == PS_META_ASTROM || type == PS_META_UNKNOWN ) {
+    psFree( metadataItem->items );
+    
+    if ( type == PS_META_STR ||
+            type == PS_META_IMG ||
+            type == PS_META_JPEG ||
+            type == PS_META_PNG ||
+            type == PS_META_ASTROM ||
+            type == PS_META_UNKNOWN ) {
             psFree( metadataItem->data.V );
         }
-        
-    psFree( metadataItem->items );
 }
 
@@ -94,5 +95,4 @@
             return ;
         }
-        
     psFree( metadata->list );
     psFree( metadata->table );
@@ -155,4 +155,7 @@
     // Set metadata item value
     switch ( type ) {
+            case PS_META_BOOL:
+            metadataItem->data.B = ( bool ) va_arg( argPtr, int );
+            break;
             case PS_META_S32:
             metadataItem->data.S32 = va_arg( argPtr, psS32 );
@@ -165,4 +168,6 @@
             break;
             case PS_META_STR:
+            metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH );
+            break;
             case PS_META_IMG:
             case PS_META_JPEG:
@@ -170,8 +175,6 @@
             case PS_META_ASTROM:
             case PS_META_UNKNOWN:
-            metadataItem->data.V = psMemIncrRefCounter( va_arg( argPtr, psPTR ) );
-            break;
             default:
-            psError( __func__, " Invalid psMetadataType: %d", type );
+            psError( __func__, "Invalid psMetadataType: %d", type );
         }
         
@@ -201,15 +204,18 @@
     p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree );
     
-    // Allocate internal containers
-    list = ( psList * ) psAlloc( sizeof( psList ) );
+    // Allocate metadata's internal containers
+    list = ( psList * ) psListAlloc( NULL );
     if ( list == NULL ) {
             psAbort( __func__, "Failed to allocate list" );
         }
         
-    table = ( psHash * ) psAlloc( sizeof( psHash ) );
+    table = ( psHash * ) psHashAlloc( 10 );
     if ( table == NULL ) {
             psAbort( __func__, "Failed to allocate table" );
         }
         
+    metadata->list = list;
+    metadata->table = table;
+    
     return metadata;
 }
@@ -308,4 +314,7 @@
         }
         
+    // Decrement reference count, since the metadata item is now in metadata collection and no longer needed here
+    psMemDecrRefCounter( metadataItem );
+    
     return true;
 }
@@ -543,4 +552,7 @@
     
     switch ( type ) {
+            case PS_META_BOOL:
+            fprintf( fd, format, metadataItem->data.B );
+            break;
             case PS_META_S32:
             fprintf( fd, format, metadataItem->data.S32 );
@@ -566,99 +578,13 @@
 }
 
-psMetadata *psMetadataReadHeader( psMetadata *output, const char *extname, int extnum, const char *filename )
-{
-    /*    char line[ MAX_VAL_SIZE ];
-        char keyName[ MAX_VAL_SIZE ];
-        char keyValue[ MAX_VAL_SIZE ];
-        char keyComment[ MAX_VAL_SIZE ];
-        int status = 0;
-        extnumCtr = 1;
-        FILE *fd = NULL;
-        
-        if ( filename == NULL ) {
-                psError( __func__, "Null file name not allowed" );
-                return NULL;
-            }
-            
-        if ( extname == NULL && extnum == 0 ) {
-                psError( __func__, "Null extname AND extnum = 0 not allowed" );
-                return NULL;
-            } else if ( extname && extnum ) {
-                psError( __func__, "Both extname AND extnum arguments should not have valid values." );
-                return NULL;
-            }
-            
-        fd = fopen( filename, "r" );
-        if ( fd == NULL ) {
-                psError( __func__, "Null FITS file descriptor not allowed" );
-                return NULL;
-            }
-            
-        // Allocate metadata if user didn't
-        if ( output == NULL ) {
-                output = psMetadataAlloc();
-                psError( __func__, "Failed to allocate metadata" );
-                return NULL;
-            }
-            
-        // Move to user designated HDU number or HDU name in text file. HDU numbers starts at one.
-         TODO    if(extname == NULL) {
-                    return output;
-                }
-            } else if(extnum > 0) {
-                    return output;
-                }
-            }
-         
-         
-             line = fgets(line, MAX_LINE_SIZE+1, fp);
-             while(line != NULL) {
-         
-                 if(!strncmp("END", line, 3)){
-                     extnumCtr++;
-                 }
-         
-                 if(extnumCtr == extnum) {
-         
-                     // Put text into metadata
-                     if(!strncmp("COMMENT", line, 7)){
-                         // COMMENT keywords have no "=" sign
-                         //TODO
-                     } else if (strchr(line, '\'') != NULL){
-         
-                         // Output and logging keywords have tic (') characters
-                         keyName = strtok(line, "=");
-                         keyValue = strtok(NULL, "'");
-                         keyValue = strtok(NULL, "'");
-                         keyComment = strtok(NULL, "XXX");
-         
-         
-                     } else
-         
-                         // Everything else is considered to be the standard name and value
-                         keyName = strtok(line, "=");
-                         keyValue = strtok(NULL, "/");
-                         keyComment = strtok(NULL, "XXX");
-                     }
-         
-         
-                 }
-         
-                 // Read next line
-                 line = fgets(line, MAX_LINE_SIZE+1, fp);
-             }
-         
-        */ 
-    return output;
-}
-
 psMetadata *psMetadataFReadHeader( psMetadata *output, const char *extname, int extnum, fitsfile *fd )
 {
+    bool tempBool;
     bool success;
     char keyType;
-    char keyName[ MAX_VAL_SIZE ];
-    char keyValue[ MAX_VAL_SIZE ];
-    char keyComment[ MAX_VAL_SIZE ];
-    char fitsErr[ MAX_ERR_MESSAGE_LENGTH ];
+    char keyName[ FITS_LINE_SIZE ];
+    char keyValue[ FITS_LINE_SIZE ];
+    char keyComment[ FITS_LINE_SIZE ];
+    char fitsErr[ MAX_STRING_LENGTH ];
     char* tempExtname = NULL;
     int i;
@@ -666,4 +592,5 @@
     int status = 0;
     int numKeys = 0;
+    int keyNum = 0;
     psMetadataType metadataItemType;
     
@@ -677,5 +604,5 @@
             return NULL;
         } else if ( extname && extnum ) {
-            psError( __func__, "Both extname AND extnum arguments should not have valid values." );
+            psError( __func__, "Both extname AND extnum arguments should not have values." );
             return NULL;
         }
@@ -684,6 +611,4 @@
     if ( output == NULL ) {
             output = psMetadataAlloc();
-            psError( __func__, "Failed to allocate metadata" );
-            return NULL;
         }
         
@@ -694,27 +619,21 @@
                     psError( __func__, "FITS error while locating header: %s", fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
                     return output;
                 }
         } else if ( extnum > 0 ) {
-            tempExtname = ( char* ) psAlloc( strlen( extname ) + 1 ); // fits_movnam_hdu doesn't like const part of extname
-            strncpy( tempExtname, extname, MAX_VAL_SIZE );
+            tempExtname = ( char* ) extname;
             if ( fits_movnam_hdu( fd, ANY_HDU, tempExtname, 0, &status ) != 0 ) {
                     fits_get_errstatus( status, fitsErr );
                     psError( __func__, "FITS error while locating header: %s", fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
-                    psFree( tempExtname );
                     return output;
                 }
-            psFree( tempExtname );
         }
         
     // Get number of key names
-    if ( fits_get_hdrpos( fd, &numKeys, NULL, &status ) != 0 ) {
+    if ( fits_get_hdrpos( fd, &numKeys, &keyNum, &status ) != 0 ) {
             fits_get_errstatus( status, fitsErr );
             psError( __func__, "FITS error while reading keys: %s", fitsErr );
             status = 0;
-            fits_close_file( fd, &status );
             return output;
         }
@@ -726,14 +645,17 @@
                     psError( __func__, "FITS error while reading key number %d: %s", i, fitsErr );
                     status = 0;
-                    fits_close_file( fd, &status );
                     return output;
                 }
-                
             if ( fits_get_keytype( keyValue, &keyType, &status ) != 0 ) {
                     fits_get_errstatus( status, fitsErr );
-                    psError( __func__, "FITS error while determining key type: %s", fitsErr );
-                    status = 0;
-                    fits_close_file( fd, &status );
-                    return output;
+                    if ( status != VALUE_UNDEFINED ) {
+                            psError( __func__, "FITS error while determining key type: %s", fitsErr );
+                            status = 0;
+                            return output;
+                        } else {
+                            // Some keywords are still valid even though they don't have a type or value, like COMMENTS
+                            keyType = 'C';
+                            status = 0;
+                        }
                 }
                 
@@ -752,4 +674,9 @@
                     break;
                     case 'L':
+                    metadataItemType = PS_META_BOOL;
+                    tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0;
+                    success = psMetadataAdd( output, PS_LIST_HEAD, keyName, metadataItemType, keyComment, tempBool );
+                    break;
+                    case 'U':
                     case 'X':
                     default:
