IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2006, 4:36:36 PM (20 years ago)
Author:
Paul Price
Message:

When writing concepts to headers, if given a list, write out all the keywords (use blank value, if required). Removed excess code in this regard (pmConceptsWriteToHeader had code already in writeHeader). Include string.h where required.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/concepts/pmConceptsWrite.c

    r8815 r8848  
    55#include <stdio.h>
    66#include <assert.h>
    7 #include <strings.h>
     7#include <string.h>
    88#include <pslib.h>
    99
     
    132132static bool writeSingleHeader(pmHDU *hdu, // HDU for which to add to the header
    133133                              const char *keyword, // Keyword to add
    134                               psMetadataItem *item // Item to add to the header
     134                              psMetadataItem *item // Item to add to the header; may be NULL
    135135                             )
    136136{
    137137    assert(hdu);
    138138    assert(keyword && strlen(keyword) > 0);
    139     assert(item);
    140139
    141140    if (!hdu->header) {
    142141        hdu->header = psMetadataAlloc();
     142    }
     143    if (!item) {
     144        psTrace("psModules.concepts", 9, "Writing header %s: <<<BLANK>>>\n", keyword);
     145        // Assume it's a NULL string: it's most easily parsed.
     146        return psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, NULL, NULL);
    143147    }
    144148    switch (item->type) {
     
    188192    if (item->type == PS_DATA_LIST) {
    189193        psList *values = item->data.V;  // List of outputs
    190         if (values->n == 0) {
    191             // Nothing to write
     194        psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords
     195        if (keys->n != values->n && values->n != 0) {
     196            psError(PS_ERR_UNKNOWN, true, "Number of keywords (%ld) does not match number of "
     197                    "values (%ld).\n", keys->n, values->n);
     198            psFree(keys);
    192199            return false;
    193         }
    194         psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords
    195         if (keys->n != values->n) {
    196             psLogMsg(__func__, PS_LOG_WARN, "Number of keywords (%ld) does not match number of values (%ld).\n",
    197                      keys->n, values->n);
    198200        }
    199201        psListIterator *keysIter = psListIteratorAlloc(keys, PS_LIST_HEAD, false); // Iterator for keywords
    200202        psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator for values
    201203        psString key = NULL;            // Keyword from iteration
    202         psMetadataItem *value = NULL;   // Value from iteration
    203         while ((key = psListGetAndIncrement(keysIter)) && (value = psListGetAndIncrement(valuesIter))) {
     204        while ((key = psListGetAndIncrement(keysIter))) {
     205            psMetadataItem *value = psListGetAndIncrement(valuesIter); // Value from iteration; may be NULL
    204206            status |= writeSingleHeader(hdu, key, value);
    205207        }
     
    394396                continue;
    395397            }
    396             psList *keywords = psStringSplit(headerItem->data.V, " ,;", true); // List of header keywords
    397             if (formatted->type == PS_DATA_LIST) {
    398                 psList *values = formatted->data.V; // The values for the headers
    399                 if (values->n != keywords->n) {
    400                     psLogMsg(__func__, PS_LOG_WARN, "Number of headers specified does not match number "
    401                              "of values for concept %s.\n", name);
    402                 }
    403                 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator
    404                 psListIterator *keywordsIter = psListIteratorAlloc(keywords, PS_LIST_HEAD, false);
    405                 psMetadataItem *valuesItem = NULL; // Item from list
    406                 while ((valuesItem = psListGetAndIncrement(valuesIter))) {
    407                     psString keyword = psListGetAndIncrement(keywordsIter); // Keyword from the list
    408                     if (strlen(keyword) > 0) {
    409                         writeHeader(hdu, keyword, formatted);
    410                     }
    411                 }
    412                 psFree(valuesIter);
    413                 psFree(keywordsIter);
    414             } else {
    415                 psString keyword = psListGet(keywords, PS_LIST_HEAD); // The keyword
    416                 writeHeader(hdu, keyword, formatted);
    417             }
     398            writeHeader(hdu, headerItem->data.V, formatted);
    418399            psFree(formatted);
    419             psFree(keywords);
    420400        }
    421401    }
Note: See TracChangeset for help on using the changeset viewer.