Index: trunk/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- trunk/ippTools/share/pxadmin_create_tables.sql	(revision 33705)
+++ 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 33705)
+++ 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 33705)
+++ 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
