IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20304


Ignore:
Timestamp:
Oct 21, 2008, 3:53:09 PM (18 years ago)
Author:
Paul Price
Message:

Support more types, and generate an error when the type isn't recognised.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStats/src/ppStatsFromMetadataPrint.c

    r20303 r20304  
    22
    33// calculate the stats for the non-constant entries (already calculated)
    4 bool ppStatsFromMetadataPrint (psArray *entries, char *filename) {
    5 
     4bool ppStatsFromMetadataPrint(psArray *entries, char *filename)
     5{
     6    bool status = true;                 // Status of printing
    67    FILE *f = NULL;
    78    if (!strcmp (filename, "-")) {
     
    2122        if (!entry->value) continue;
    2223
    23         if (entry->value->type == PS_DATA_STRING) {
    24             fprintf (f, "%s '%s' ", entry->flag, entry->value->data.str);
    25         }
     24// Print a value
     25#define VALUE_NUMERICAL_CASE(TYPE, FORMAT, NAME) \
     26      case PS_TYPE_##TYPE: \
     27        fprintf(f, "%s %" FORMAT, entry->flag, entry->value->data.NAME); \
     28        break; \
    2629
    27         if (entry->value->type == PS_DATA_BOOL && entry->value->data.B) {
    28             fprintf (f, "%s ", entry->flag);
    29         }
    3030
    31         if (entry->value->type == PS_DATA_F32) {
    32             fprintf (f, "%s %f ", entry->flag, entry->value->data.F32);
    33         }
    34         if (entry->value->type == PS_DATA_TIME) {
    35             psTime *t = (psTime *)  entry->value->data.V;
    36             psString str = psTimeToISO(t);
    37             fprintf (f, "%s %.19sZ ", entry->flag, str);
    38             psFree(str);
     31        switch (entry->value->type) {
     32            VALUE_NUMERICAL_CASE(U8,  PRIu8,  U8);
     33            VALUE_NUMERICAL_CASE(U16, PRIu16, U16);
     34            VALUE_NUMERICAL_CASE(U32, PRIu32, U32);
     35            VALUE_NUMERICAL_CASE(U64, PRIu64, U64);
     36            VALUE_NUMERICAL_CASE(S8,  PRId8,  S8);
     37            VALUE_NUMERICAL_CASE(S16, PRId16, S16);
     38            VALUE_NUMERICAL_CASE(S32, PRId32, S32);
     39            VALUE_NUMERICAL_CASE(S64, PRId64, S64);
     40            VALUE_NUMERICAL_CASE(F32, "f",    F32);
     41            VALUE_NUMERICAL_CASE(F64, "lf",   F64);
     42          case PS_DATA_STRING:
     43            fprintf(f, "%s '%s' ", entry->flag, entry->value->data.str);
     44            break;
     45          case PS_DATA_BOOL:
     46            if (entry->value->data.B) {
     47                fprintf(f, "%s ", entry->flag);
     48            }
     49            break;
     50          case PS_DATA_TIME: {
     51              psTime *t = (psTime*)entry->value->data.V;
     52              psString str = psTimeToISO(t);
     53              fprintf(f, "%s %.19sZ ", entry->flag, str);
     54              psFree(str);
     55              break;
     56          }
     57          default:
     58            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type: %x", entry->value->type);
     59            status = false;
    3960        }
    4061    }
    41     fprintf (f, "\n");
     62    fprintf(f, "\n");
    4263
    4364    if (f != stdout) fclose (f);
    44     return true;
     65    return status;
    4566}
Note: See TracChangeset for help on using the changeset viewer.