Index: trunk/Ohana/src/addstar/src/skycells_to_mdc.c
===================================================================
--- trunk/Ohana/src/addstar/src/skycells_to_mdc.c	(revision 33719)
+++ trunk/Ohana/src/addstar/src/skycells_to_mdc.c	(revision 33720)
@@ -48,6 +48,6 @@
             fprintf(mdcfile, "    radeg\tF32\t%f\n", raCenter);
             fprintf(mdcfile, "    decdeg\tF32\t%f\n", decCenter);
-            fprintf(mdcfile, "    glonCenter\tF32\t%f\n", glonCenter);
-            fprintf(mdcfile, "    glatCenter\tF32\t%f\n", glatCenter);
+            fprintf(mdcfile, "    glong\tF32\t%f\n", glonCenter);
+            fprintf(mdcfile, "    glat\tF32\t%f\n", glatCenter);
             fprintf(mdcfile, "    width\tF32\t%f\n", width);
             fprintf(mdcfile, "    height\tF32\t%f\n", height);
Index: trunk/dbconfig/ipp.m4
===================================================================
--- trunk/dbconfig/ipp.m4	(revision 33719)
+++ trunk/dbconfig/ipp.m4	(revision 33720)
@@ -38,2 +38,3 @@
 include(lap.md)
 include(vp.md)
+include(skycell.md)
Index: trunk/dbconfig/skycell.md
===================================================================
--- trunk/dbconfig/skycell.md	(revision 33719)
+++ trunk/dbconfig/skycell.md	(revision 33720)
@@ -1,25 +1,10 @@
-# $Id: skycell.md,v 1.4 2007-07-06 01:16:08 jhoblitt Exp $
-
-skyCell METADATA
-    skycell_id  STR         64      # Primary Key
-    tess_id     STR         64      # Primary Key
-    ra1         F64         0.0
-    decl1       F64         0.0
-    ra2         F64         0.0
-    decl2       F64         0.0
-    ra3         F64         0.0
-    decl3       F64         0.0
-    ra4         F64         0.0
-    decl4       F64         0.0
+skycell METADATA
+    tess_id	STR	64 
+    skycell_id	STR	64
+    radeg	F32	0
+    decdeg	F32	0
+    glong       F32	0
+    glat        F32	0
+    width	F32	0
+    height	F32	0
 END
-
-skyCellMap METADATA
-    skycell_id  STR         64      # Primary Key
-    tess_id     STR         64      # Primary Key
-    exp_id     S64         64      # Primary Key
-    p3_version  S32         0       # Primary Key
-# class is not yet consistently carried through pXtools
-#    class       STR         64      # Primary Key
-    class_id    STR         64      # Primary Key
-END
-
Index: trunk/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- trunk/ippTools/share/pxadmin_create_tables.sql	(revision 33719)
+++ trunk/ippTools/share/pxadmin_create_tables.sql	(revision 33720)
@@ -2127,4 +2127,20 @@
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
+CREATE TABLE skycell (
+    tess_id     VARCHAR(64),
+    skycell_id  VARCHAR(64),
+    radeg       float,
+    decdeg      float,
+    glong       float,
+    glat        float,
+    width       float,
+    height      float,
+    PRIMARY KEY (tess_id, skycell_id),
+    KEY(radeg),
+    KEY(decdeg),
+    KEY(glong),
+    KEY(glat)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
 
 -- This comment line is here to avoid empty query error.
Index: trunk/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- trunk/ippTools/share/pxadmin_drop_tables.sql	(revision 33719)
+++ trunk/ippTools/share/pxadmin_drop_tables.sql	(revision 33720)
@@ -108,4 +108,5 @@
 DROP TABLE IF EXISTS skycalRun;
 DROP TABLE IF EXISTS skycalResult;
+DROP TABLE IF EXISTS skycell;
 
 SET FOREIGN_KEY_CHECKS=1
Index: trunk/ippTools/src/Makefile.am
===================================================================
--- trunk/ippTools/src/Makefile.am	(revision 33719)
+++ trunk/ippTools/src/Makefile.am	(revision 33720)
@@ -31,5 +31,6 @@
 	mergetool \
 	laptool \
-	vptool
+	vptool \
+	sctool
 
 pkginclude_HEADERS = \
@@ -83,5 +84,6 @@
 	mergetool.h \
 	laptool.h \
-	vptool.h
+	vptool.h \
+	sctool.h
 
 lib_LTLIBRARIES = libpxtools.la
@@ -316,4 +318,10 @@
     vptoolConfig.c
 
+sctool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
+sctool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
+sctool_SOURCES = \
+    sctool.c \
+    sctoolConfig.c
+
 clean-local:
 	-rm -f TAGS
Index: trunk/ippTools/src/sctool.c
===================================================================
--- trunk/ippTools/src/sctool.c	(revision 33720)
+++ trunk/ippTools/src/sctool.c	(revision 33720)
@@ -0,0 +1,132 @@
+/*
+ * sctool.c
+ *
+ * Copyright (C) 2012 IfA University of Hawaii
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "pxtools.h"
+#include "pxdata.h"
+#include "pxchip.h"
+
+#include "sctool.h"
+
+static bool defineskycellsMode(pxConfig *config);
+
+# define MODECASE(caseName, func) \
+    case caseName: \
+    if (!func(config)) { \
+        goto FAIL; \
+    } \
+    break;
+
+int main(int argc, char **argv) {
+    psLibInit(NULL);
+
+    pxConfig *config = sctoolConfig(NULL, argc, argv);
+    if (!config) {
+        psError(PXTOOLS_ERR_CONFIG, false, "failed to configure");
+        goto FAIL;
+    }
+
+    switch (config->mode) {
+        MODECASE(SCTOOL_MODE_DEFINESKYCELLS,         defineskycellsMode);
+        default:
+            psAbort("invalid option (this should not happen)");
+    }
+
+    psFree(config);
+    pmConfigDone();
+    psLibFinalize();
+
+    exit(EXIT_SUCCESS);
+
+FAIL:
+    psErrorStackPrint(stderr, "\n");
+    int exit_status = pxerrorGetExitStatus();
+
+    psFree(config);
+    pmConfigDone();
+    psLibFinalize();
+
+    exit(exit_status);
+}
+
+
+static bool defineskycellsMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    PXOPT_LOOKUP_STR(inputFile, config->args, "-input", true, false);
+
+    unsigned int numBad = 0;
+    psMetadata *skycells = psMetadataConfigRead(NULL, &numBad, inputFile, false);
+    if (!skycells || numBad > 0) {
+        psError(PXTOOLS_ERR_UNKNOWN, false, "failed to read %s", inputFile);
+        return false;
+    }
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psMetadataIterator *iter = psMetadataIteratorAlloc(skycells, PS_LIST_HEAD, NULL);
+
+    psMetadataItem *item;
+    int numSkycells = 0;
+    while ((item = psMetadataGetAndIncrement(iter))) {
+        if (item->type != PS_DATA_METADATA) {
+            psError(PS_ERR_UNKNOWN, true, "unexpected item in metadata type: %d", item->type);
+            return false;
+        }
+        psMetadata *md = item->data.md;
+        psString tess_id = psMetadataLookupStr(NULL, md, "tess_id");
+        psString skycell_id = psMetadataLookupStr(NULL, md, "skycell_id");
+
+        skycellRow *skycell = skycellObjectFromMetadata(md);
+        if (!skycell) {
+            psError(PS_ERR_UNKNOWN, false, "failed to create skycellRow from Metadata");
+            return false;
+        }
+
+        numSkycells++;
+        if (!skycellInsertObject(config->dbh, skycell)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to insert skycell %s %s", tess_id, skycell_id);
+            return false;
+        }
+    } 
+    psFree(iter);
+    psFree(skycells);
+
+   if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psLogMsg("sctool", PS_LOG_INFO, "%d skycells added", numSkycells);
+
+    return true;
+}
Index: trunk/ippTools/src/sctool.h
===================================================================
--- trunk/ippTools/src/sctool.h	(revision 33720)
+++ trunk/ippTools/src/sctool.h	(revision 33720)
@@ -0,0 +1,32 @@
+/*
+ * sctool.h
+ *
+ * Copyright (C) 2012 University of Hawaii IFA 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef SCTOOL_H
+#define SCTOOL_H 1
+
+#include "pxtools.h"
+
+typedef enum {
+    SCTOOL_MODE_NONE      = 0x0,
+    SCTOOL_MODE_DEFINESKYCELLS,
+} sctoolMode;
+
+pxConfig *sctoolConfig(pxConfig *config, int argc, char **argv);
+
+#endif // SCTOOL_H
