IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 17, 2009, 12:08:50 PM (17 years ago)
Author:
beaumont
Message:

merged with head

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/ppSub

  • branches/cnb_branches/cnb_branch_20090301/ppSub/src/ppSubCamera.c

    r21524 r23352  
    2222#include "ppSub.h"
    2323
     24// Define an input file
     25static pmFPAfile *defineInputFile(pmConfig *config,// Configuration
     26                                  pmFPAfile *bind,    // File to which to bind, or NULL
     27                                  char *filerule,     // Name of file rule
     28                                  char *argname,      // Argument name
     29                                  pmFPAfileType fileType // Type of file
     30    )
     31{
     32    bool status;
     33
     34    // look for the file on the RUN metadata
     35    pmFPAfile *file = pmFPAfileDefineFromRun(&status, config, filerule); // File to return
     36    if (!status) {
     37        psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     38        return NULL;
     39    }
     40    if (!file) {
     41        // look for the file on the argument list
     42        if (bind) {
     43            file = pmFPAfileBindFromArgs(&status, bind, config, filerule, argname);
     44        } else {
     45            file = pmFPAfileDefineFromArgs(&status, config, filerule, argname);
     46        }
     47        if (!status) {
     48            psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     49            return false;
     50        }
     51    }
     52
     53    if (!file) {
     54        return NULL;
     55    }
     56
     57    if (file->type != fileType) {
     58        psError(PS_ERR_UNKNOWN, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     59        return NULL;
     60    }
     61
     62    return file;
     63}
     64
     65// Define an output file
     66static pmFPAfile *defineOutputFile(pmConfig *config, // Configuration
     67                                   pmFPAfile *template,    // File to use as basis for definition
     68                                   char *filerule,     // Name of file rule
     69                                   pmFPAfileType fileType // Type of file
     70    )
     71{
     72
     73    pmFPAfile *file = pmFPAfileDefineFromFile(config, template, 1, 1, filerule);
     74    if (!file) {
     75        psError(PS_ERR_IO, false, _("Unable to generate output file from %s"), filerule);
     76        return NULL;
     77    }
     78    if (file->type != fileType) {
     79        psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     80        return NULL;
     81    }
     82
     83    return file;
     84}
     85
     86
     87// Define an output file that will be used in a calculation
     88// This means it might already be available in the RUN metadata
     89static pmFPAfile *defineCalcFile(pmConfig *config, // Configuration
     90                                 pmFPAfile *bind,    // File to which to bind, or NULL
     91                                 char *filerule,     // Name of file rule
     92                                 pmFPAfileType fileType // Type of file
     93    )
     94{
     95    bool status;
     96
     97    // look for the file on the RUN metadata
     98    pmFPAfile *file = pmFPAfileDefineFromRun(&status, config, filerule); // File to return
     99    if (!status) {
     100        psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     101        return NULL;
     102    }
     103    if (file) {
     104        // It's an input
     105        file->save = false;
     106    }
     107
     108    // define new version of file
     109    if (!file) {
     110        pmFPAfileDefineOutput(config, bind ? bind->fpa : NULL, filerule);
     111        if (!status) {
     112            psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     113            return false;
     114        }
     115        if (file) {
     116            // It's an output
     117            file->save = true;
     118        }
     119    }
     120
     121    if (!file) {
     122        return NULL;
     123    }
     124
     125    if (file->type != fileType) {
     126        psError(PS_ERR_UNKNOWN, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     127        return NULL;
     128    }
     129
     130    return file;
     131}
     132
     133
    24134bool ppSubCamera(pmConfig *config)
    25135{
    26     bool status = false;                // result from pmFPAfileDefine operations
     136    psAssert(config, "Require configuration");
    27137
    28138    // Input image
    29     pmFPAfile *input = pmFPAfileDefineFromArgs(&status, config, "PPSUB.INPUT", "INPUT");
    30     if (!status || !input) {
     139    pmFPAfile *input = defineInputFile(config, NULL, "PPSUB.INPUT", "INPUT", PM_FPA_FILE_IMAGE);
     140    if (!input) {
    31141        psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.INPUT");
    32142        return false;
    33143    }
    34     if (input->type != PM_FPA_FILE_IMAGE) {
    35         psError(PS_ERR_IO, true, "PPSUB.INPUT is not of type IMAGE");
    36         return false;
    37     }
    38 
    39     // Input mask
    40     pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPSUB.INPUT.MASK", "INPUT.MASK");
    41     if (!status) {
    42         psError (PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.INPUT.MASK");
    43         return NULL;
    44     }
    45     if (inputMask && inputMask->type != PM_FPA_FILE_MASK) {
    46         psError(PS_ERR_IO, true, "PPSUB.INPUT.MASK is not of type MASK");
    47         return false;
    48     }
    49 
    50     // Input variance map
    51     pmFPAfile *inputVariance = pmFPAfileBindFromArgs(&status, input, config, "PPSUB.INPUT.VARIANCE", "INPUT.VARIANCE");
    52     if (!status) {
    53         psError (PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.INPUT.VARIANCE");
    54         return NULL;
    55     }
    56     if (inputVariance && inputVariance->type != PM_FPA_FILE_VARIANCE) {
    57         psError(PS_ERR_IO, true, "PPSUB.INPUT.VARIANCE is not of type VARIANCE");
    58         return false;
    59     }
     144    defineInputFile(config, input, "PPSUB.INPUT.MASK", "INPUT.MASK", PM_FPA_FILE_MASK);
     145    pmFPAfile *inVar = defineInputFile(config, input, "PPSUB.INPUT.VARIANCE", "INPUT.VARIANCE",
     146                                       PM_FPA_FILE_VARIANCE);
     147    defineInputFile(config, input, "PPSUB.INPUT.SOURCES", "INPUT.SOURCES", PM_FPA_FILE_CMF);
    60148
    61149    // Reference image
    62     status = false;
    63     pmFPAfile *ref = pmFPAfileDefineFromArgs(&status, config, "PPSUB.REF", "REF");
     150    pmFPAfile *ref = defineInputFile(config, NULL, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE);
    64151    if (!ref) {
    65152        psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.REF");
    66153        return false;
    67154    }
    68     if (ref->type != PM_FPA_FILE_IMAGE) {
    69         psError(PS_ERR_IO, true, "PPSUB.REF is not of type IMAGE");
    70         return false;
    71     }
    72 
    73     // Reference mask
    74     pmFPAfile *refMask = pmFPAfileBindFromArgs(&status, ref, config, "PPSUB.REF.MASK", "REF.MASK");
    75     if (!status) {
    76         psError (PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.REF.MASK");
    77         return NULL;
    78     }
    79     if (refMask && refMask->type != PM_FPA_FILE_MASK) {
    80         psError(PS_ERR_IO, true, "PPSUB.REF.MASK is not of type MASK");
    81         return false;
    82     }
    83 
    84     // Reference variance map
    85     pmFPAfile *refVariance = pmFPAfileBindFromArgs(&status, ref, config, "PPSUB.REF.VARIANCE", "REF.VARIANCE");
    86     if (!status) {
    87         psError (PS_ERR_UNKNOWN, false, "Failed to load file definition PPSUB.REF.VARIANCE");
    88         return NULL;
    89     }
    90     if (refVariance && refVariance->type != PM_FPA_FILE_VARIANCE) {
    91         psError(PS_ERR_IO, true, "PPSUB.REF.VARIANCE is not of type VARIANCE");
    92         return false;
    93     }
     155    defineInputFile(config, ref, "PPSUB.REF.MASK", "REF.MASK", PM_FPA_FILE_MASK);
     156    pmFPAfile *refVar = defineInputFile(config, ref, "PPSUB.REF.VARIANCE", "REF.VARIANCE",
     157                                        PM_FPA_FILE_VARIANCE);
     158    defineInputFile(config, ref, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
     159
    94160
    95161    // Output image
    96     pmFPAfile *output = pmFPAfileDefineFromFile(config, input, 1, 1, "PPSUB.OUTPUT");
    97     if (!output) {
    98         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT"));
    99         return false;
    100     }
    101     if (output->type != PM_FPA_FILE_IMAGE) {
    102         psError(PS_ERR_IO, true, "PPSUB.OUTPUT is not of type IMAGE");
     162    pmFPAfile *output = defineOutputFile(config, input, "PPSUB.OUTPUT", PM_FPA_FILE_IMAGE);
     163    pmFPAfile *outMask = defineOutputFile(config, output, "PPSUB.OUTPUT.MASK", PM_FPA_FILE_MASK);
     164    if (!output || !outMask) {
     165        psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    103166        return false;
    104167    }
    105168    output->save = true;
    106 
    107     // Output mask
    108     pmFPAfile *outMask = pmFPAfileDefineOutput(config, output->fpa, "PPSUB.OUTPUT.MASK");
    109     if (!outMask) {
    110         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.MASK"));
    111         return false;
    112     }
    113     if (outMask->type != PM_FPA_FILE_MASK) {
    114         psError(PS_ERR_IO, true, "PPSUB.OUTPUT.MASK is not of type MASK");
    115         return false;
    116     }
    117169    outMask->save = true;
    118 
    119     // Output variance
    120     if (inputVariance && refVariance) {
    121         pmFPAfile *outVariance = pmFPAfileDefineOutput(config, output->fpa, "PPSUB.OUTPUT.VARIANCE");
    122         if (!outVariance) {
    123             psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.VARIANCE"));
    124             return false;
    125         }
    126         if (outVariance->type != PM_FPA_FILE_VARIANCE) {
    127             psError(PS_ERR_IO, true, "PPSUB.OUTPUT.VARIANCE is not of type VARIANCE");
    128             return false;
    129         }
    130         outVariance->save = true;
    131     }
     170    pmFPAfile *outVar = NULL;
     171    if (inVar && refVar) {
     172        outVar = defineOutputFile(config, output, "PPSUB.OUTPUT.VARIANCE", PM_FPA_FILE_VARIANCE);
     173        if (!outVar) {
     174            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     175            return false;
     176        }
     177        outVar->save = true;
     178    }
     179
    132180
    133181    // Convolved input image
    134     pmFPAfile *inConv = pmFPAfileDefineFromFile(config, input, 1, 1, "PPSUB.INPUT.CONV");
    135     if (!inConv) {
    136         psError(PS_ERR_IO, false, _("Unable to generate output file for PPSUB.INPUT.CONV"));
    137         return false;
    138     }
    139     if (output->type != PM_FPA_FILE_IMAGE) {
    140         psError(PS_ERR_IO, true, "PPSUB.INPUT.CONV is not of type IMAGE");
    141         return false;
    142     }
    143     // XXX should be based on recipe : inConv->save = true;
    144 
    145     // Convolved input mask
    146     pmFPAfile *inConvMask = pmFPAfileDefineOutput(config, inConv->fpa, "PPSUB.INPUT.CONV.MASK");
    147     if (!inConvMask) {
    148         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.INPUT.CONV.MASK"));
    149         return false;
    150     }
    151     if (inConvMask->type != PM_FPA_FILE_MASK) {
    152         psError(PS_ERR_IO, true, "PPSUB.INPUT.CONV.MASK is not of type MASK");
    153         return false;
    154     }
    155     // XXX should be based on recipe : inConvMask->save = true;
    156 
    157     // Convolved input variance
    158     if (inputVariance) {
    159         pmFPAfile *inConvVariance = pmFPAfileDefineOutput(config, inConv->fpa, "PPSUB.INPUT.CONV.VARIANCE");
    160         if (!inConvVariance) {
    161             psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.VARIANCE"));
    162             return false;
    163         }
    164         if (inConvVariance->type != PM_FPA_FILE_VARIANCE) {
    165             psError(PS_ERR_IO, true, "PPSUB.INPUT.CONV.VARIANCE is not of type VARIANCE");
    166             return false;
    167         }
    168         // XXX should be based on recipe : inConvVariance->save = true;
     182    pmFPAfile *inConvImage = defineOutputFile(config, input, "PPSUB.INPUT.CONV", PM_FPA_FILE_IMAGE);
     183    pmFPAfile *inConvMask = defineOutputFile(config, input, "PPSUB.INPUT.CONV.MASK", PM_FPA_FILE_MASK);
     184    if (!inConvImage || !inConvMask) {
     185        psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     186        return false;
     187    }
     188    if (inVar) {
     189        pmFPAfile *inConvVar = defineOutputFile(config, input, "PPSUB.INPUT.CONV.VARIANCE",
     190                                                PM_FPA_FILE_VARIANCE);
     191        if (!inConvVar) {
     192            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     193            return false;
     194        }
    169195    }
    170196
    171197    // Convolved ref image
    172     pmFPAfile *refConv = pmFPAfileDefineFromFile(config, ref, 1, 1, "PPSUB.REF.CONV");
    173     if (!refConv) {
    174         psError(PS_ERR_IO, false, _("Unable to generate output file for PPSUB.REF.CONV"));
    175         return false;
    176     }
    177     if (output->type != PM_FPA_FILE_IMAGE) {
    178         psError(PS_ERR_IO, true, "PPSUB.REF.CONV is not of type IMAGE");
    179         return false;
    180     }
    181     // XXX should be based on recipe : refConv->save = true;
    182 
    183     // Convolved ref mask
    184     pmFPAfile *refConvMask = pmFPAfileDefineOutput(config, refConv->fpa, "PPSUB.REF.CONV.MASK");
    185     if (!refConvMask) {
    186         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.REF.CONV.MASK"));
    187         return false;
    188     }
    189     if (refConvMask->type != PM_FPA_FILE_MASK) {
    190         psError(PS_ERR_IO, true, "PPSUB.REF.CONV.MASK is not of type MASK");
    191         return false;
    192     }
    193     // XXX should be based on recipe : refConvMask->save = true;
    194 
    195     // Convolved ref variance
    196     if (refVariance) {
    197         pmFPAfile *refConvVariance = pmFPAfileDefineOutput(config, refConv->fpa, "PPSUB.REF.CONV.VARIANCE");
    198         if (!refConvVariance) {
    199             psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.VARIANCE"));
    200             return false;
    201         }
    202         if (refConvVariance->type != PM_FPA_FILE_VARIANCE) {
    203             psError(PS_ERR_IO, true, "PPSUB.REF.CONV.VARIANCE is not of type VARIANCE");
    204             return false;
    205         }
    206         // XXX should be based on recipe : refConvVariance->save = true;
    207     }
     198    pmFPAfile *refConvImage = defineOutputFile(config, input, "PPSUB.REF.CONV", PM_FPA_FILE_IMAGE);
     199    pmFPAfile *refConvMask = defineOutputFile(config, input, "PPSUB.REF.CONV.MASK", PM_FPA_FILE_MASK);
     200    if (!refConvImage || !refConvMask) {
     201        psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     202        return false;
     203    }
     204    if (refVar) {
     205        pmFPAfile *refConvVar = defineOutputFile(config, input, "PPSUB.REF.CONV.VARIANCE",
     206                                                 PM_FPA_FILE_VARIANCE);
     207        if (!refConvVar) {
     208            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     209            return false;
     210        }
     211    }
     212
    208213
    209214    // Output JPEGs
     
    230235
    231236    // Output subtraction kernel
    232     pmFPAfile *outKernels = pmFPAfileDefineOutput(config, output->fpa, "PPSUB.OUTPUT.KERNELS");
    233     if (!outKernels) {
    234         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.KERNELS"));
    235         return false;
    236     }
    237     if (outKernels->type != PM_FPA_FILE_SUBKERNEL) {
    238         psError(PS_ERR_IO, true, "PPSUB.OUTPUT.KERNELS is not of type SUBKERNEL");
    239         return false;
    240     }
    241     outKernels->save = true;
    242 
    243 #if 0
    244     if (!pmFPAAddSourceFromFormat(output->fpa, "Subtraction", output->format)) {
    245         psError(PS_ERR_UNKNOWN, false, "Unable to generate output FPA.");
    246         return false;
    247     }
    248 #endif
    249 
    250     pmFPAfile *sources = pmFPAfileDefineFromArgs(&status, config, "PPSUB.SOURCES", "PPSUB.SOURCES");
    251     if (!status) {
    252         psError(PS_ERR_IO, false, "Failed to load file definition PPSUB.SOURCES");
    253         return false;
    254     }
    255     if (sources && sources->type != PM_FPA_FILE_CMF) {
    256         psError(PS_ERR_IO, true, "PPSUB.SOURCES is not of type CMF");
     237    pmFPAfile *kernel = defineCalcFile(config, output, "PPSUB.OUTPUT.KERNELS", PM_FPA_FILE_SUBKERNEL);
     238    if (!kernel) {
     239        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to define file PPSUB.OUTPUT.KERNELS");
    257240        return false;
    258241    }
Note: See TracChangeset for help on using the changeset viewer.