Index: trunk/psLib/src/astronomy/psMetadata.c
===================================================================
--- trunk/psLib/src/astronomy/psMetadata.c	(revision 1440)
+++ trunk/psLib/src/astronomy/psMetadata.c	(revision 1447)
@@ -12,6 +12,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-09 23:34:57 $
+*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-10 01:43:05 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -501,4 +501,10 @@
     psMetadataItem* entry = NULL;
 
+
+    if (md == NULL) {
+        psError(__func__, "Null metadata collection not allowed");
+        return NULL;
+    }
+
     mdList = md->list;
     if (mdList == NULL) {
@@ -507,4 +513,38 @@
     }
 
+    psListSetIterator(mdList, which);
+    entry = psListGetCurrent(mdList);
+    while (entry != NULL) {
+        if(match != NULL) {
+            if (!strncmp(match, entry->name, strlen(match))) {
+
+                // Match found
+                return entry;
+            }
+            entry = psListGetNext(mdList);
+        } else {
+            return psListGetNext(mdList);
+        }
+    }
+
+    // Match not found
+    if (entry == NULL) {
+        psError(__func__, "Couldn't find metadata item");
+    }
+
+    return entry;
+}
+
+psMetadataItem* psMetadataGetPrevious(psMetadata* restrict md, const char *restrict match, int which)
+{
+    psList* mdList = NULL;
+    psMetadataItem* entry = NULL;
+
+
+    if (md == NULL) {
+        psError(__func__, "Null metadata collection not allowed");
+        return NULL;
+    }
+
     mdList = md->list;
     if (mdList == NULL) {
@@ -516,51 +556,19 @@
     entry = psListGetCurrent(mdList);
     while (entry != NULL) {
-        if (!strncmp(match, entry->name, strlen(match))) {
-
-            // Match found
-            return entry;
-        }
-        entry = psListGetNext(mdList);
+        if(match != NULL) {
+            if (!strncmp(match, entry->name, strlen(match))) {
+
+                // Match found
+                return entry;
+            }
+            entry = psListGetPrevious(mdList);
+        } else {
+            return psListGetPrevious(mdList);
+        }
     }
 
     // Match not found
     if (entry == NULL) {
-        psError(__func__, "Couldn't find metadata item with given match. Match: %s", match);
-    }
-
-    return entry;
-}
-
-psMetadataItem* psMetadataGetPrevious(psMetadata* restrict md, const char *restrict match, int which)
-{
-    psList* mdList = NULL;
-    psMetadataItem* entry = NULL;
-
-    mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
-
-    mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
-
-    psListSetIterator(mdList, which);
-    entry = psListGetCurrent(mdList);
-    while (entry != NULL) {
-        if (!strncmp(match, entry->name, strlen(match))) {
-
-            // Match found
-            return entry;
-        }
-        entry = psListGetPrevious(mdList);
-    }
-
-    // Match not found
-    if (entry == NULL) {
-        psError(__func__, "Couldn't find metadata item with given match. Match: %s", match);
+        psError(__func__, "Couldn't find metadata item", match);
     }
 
