Changeset 8848 for trunk/psModules/src/concepts/pmConceptsWrite.c
- Timestamp:
- Sep 19, 2006, 4:36:36 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/concepts/pmConceptsWrite.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/concepts/pmConceptsWrite.c
r8815 r8848 5 5 #include <stdio.h> 6 6 #include <assert.h> 7 #include <string s.h>7 #include <string.h> 8 8 #include <pslib.h> 9 9 … … 132 132 static bool writeSingleHeader(pmHDU *hdu, // HDU for which to add to the header 133 133 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 135 135 ) 136 136 { 137 137 assert(hdu); 138 138 assert(keyword && strlen(keyword) > 0); 139 assert(item);140 139 141 140 if (!hdu->header) { 142 141 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); 143 147 } 144 148 switch (item->type) { … … 188 192 if (item->type == PS_DATA_LIST) { 189 193 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); 192 199 return false; 193 }194 psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords195 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);198 200 } 199 201 psListIterator *keysIter = psListIteratorAlloc(keys, PS_LIST_HEAD, false); // Iterator for keywords 200 202 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator for values 201 203 psString key = NULL; // Keyword from iteration 202 psMetadataItem *value = NULL; // Value from iteration203 while ((key = psListGetAndIncrement(keysIter)) && (value = psListGetAndIncrement(valuesIter))) {204 while ((key = psListGetAndIncrement(keysIter))) { 205 psMetadataItem *value = psListGetAndIncrement(valuesIter); // Value from iteration; may be NULL 204 206 status |= writeSingleHeader(hdu, key, value); 205 207 } … … 394 396 continue; 395 397 } 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); 418 399 psFree(formatted); 419 psFree(keywords);420 400 } 421 401 }
Note:
See TracChangeset
for help on using the changeset viewer.
