IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 10, 2012, 10:13:17 AM (14 years ago)
Author:
bills
Message:

add sctool -list to list out skycells matching selection criteria

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/sctool.c

    r33720 r33744  
    3535
    3636static bool defineskycellsMode(pxConfig *config);
     37static bool listMode(pxConfig *config);
    3738
    3839# define MODECASE(caseName, func) \
     
    5354
    5455    switch (config->mode) {
    55         MODECASE(SCTOOL_MODE_DEFINESKYCELLS,         defineskycellsMode);
     56        MODECASE(SCTOOL_MODE_DEFINESKYCELLS,    defineskycellsMode);
     57        MODECASE(SCTOOL_MODE_LIST,              listMode);
    5658        default:
    5759            psAbort("invalid option (this should not happen)");
     
    131133    return true;
    132134}
     135static bool listMode(pxConfig *config)
     136{
     137    PS_ASSERT_PTR_NON_NULL(config, NULL);
     138
     139    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     140    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     141    psMetadata *where = psMetadataAlloc();
     142
     143    PXOPT_COPY_STR(config->args, where, "-skycell_id", "skycell.skycell_id", "LIKE");
     144    PXOPT_COPY_STR(config->args, where, "-tess_id", "skycell.tess_id", "LIKE");
     145    PXOPT_COPY_F32(config->args, where, "-ra_min", "skycell.radeg", ">=");
     146    PXOPT_COPY_F32(config->args, where, "-dec_min", "skycell.decdeg", ">=");
     147    PXOPT_COPY_F32(config->args, where, "-ra_max", "skycell.radeg", "<");
     148    PXOPT_COPY_F32(config->args, where, "-dec_max", "skycell.decdeg", "<");
     149    PXOPT_COPY_F32(config->args, where, "-glong_min", "skycell.glong", ">=");
     150    PXOPT_COPY_F32(config->args, where, "-glat_min", "skycell.glat", ">=");
     151    PXOPT_COPY_F32(config->args, where, "-glong_max", "skycell.glong", "<");
     152    PXOPT_COPY_F32(config->args, where, "-glat_max", "skycell.glat", "<");
     153
     154    psString query = pxDataGet("sctool_list.sql");
     155    if (!query) {
     156        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     157        return false;
     158    }
     159
     160    if (!psListLength(where->list)) {
     161        psError(PXTOOLS_ERR_CONFIG, false, "search paramters are required\n");
     162        psFree(where);
     163        return false;
     164    }
     165    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     166    psStringAppend(&query, " WHERE %s", whereClause);
     167    psFree(whereClause);
     168
     169    if (limit) {
     170        psString limitString = psDBGenerateLimitSQL(limit);
     171        psStringAppend(&query, " %s", limitString);
     172        psFree(limitString);
     173    }
     174
     175    if (!p_psDBRunQuery(config->dbh, query)) {
     176        psError(PS_ERR_UNKNOWN, false, "database error");
     177        psFree(query);
     178        return false;
     179    }
     180    psFree(query);
     181
     182    psArray *output = p_psDBFetchResult(config->dbh);
     183    if (!output) {
     184        psError(PS_ERR_UNKNOWN, false, "database error");
     185        return false;
     186    }
     187
     188    if (!psArrayLength(output)) {
     189        psTrace("sctool", PS_LOG_INFO, "no rows found");
     190        psFree(output);
     191        return true;
     192    }
     193
     194    if (!ippdbPrintMetadatas(stdout, output, "skycell", !simple)) {
     195        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     196        psFree(output);
     197        return false;
     198    }
     199
     200    psFree(output);
     201
     202
     203    return true;
     204}
Note: See TracChangeset for help on using the changeset viewer.