IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 28, 2009, 3:31:25 PM (17 years ago)
Author:
Paul Price
Message:

It builds. Hasn't been tested yet, though.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSkycell/src/ppSkycellCamera.c

    r23982 r23992  
    99#include "ppSkycell.h"
    1010
     11/// Read list of images
     12static psArray *fileList(const char *filename // Filename
     13    )
     14{
     15    psString input = psSlurpFilename(filename);
     16    if (!input) {
     17        psError(PS_ERR_IO, false, "Unable to read %s", filename);
     18        return false;
     19    }
     20    psArray *inputs = psStringSplitArray(input, "\n", false); // Input filenames
     21    psFree(input);
     22    if (!inputs || inputs->n == 0) {
     23        psError(PS_ERR_IO, false, "Unable to read filenames from %s", filename);
     24        psFree(inputs);
     25        return NULL;
     26    }
     27    return inputs;
     28}
     29
    1130/// Add a single filename to the arguments as an array, so that it can be used with pmFPAfileBindFromArgs, etc
    12 static void fileList(const char *file, // The symbolic name for the file
    13                      const char *name, // The name of the file
    14                      const char *comment, // Description of the file
    15                      pmConfig *config // Configuration
     31static void fileArguments(const char *file, // The symbolic name for the file
     32                          const char *name, // The name of the file
     33                          const char *comment, // Description of the file
     34                          pmConfig *config // Configuration
    1635    )
    1736{
    1837    psArray *files = psArrayAlloc(1); // Array with file names
    1938    files->data[0] = psStringCopy(name);
     39    if (psMetadataLookup(config->arguments, file)) {
     40        psMetadataRemoveKey(config->arguments, file);
     41    }
    2042    psMetadataAddArray(config->arguments, PS_LIST_TAIL, file, 0, comment, files);
    2143    psFree(files);
     
    2749    )
    2850{
    29     psString input = psSlurpFilename(data->inName);
    30     if (!input) {
    31         psError(PS_ERR_IO, false, "Unable to read %s", data->inName);
     51    psArray *images = fileList(data->imagesName); // Image names
     52    if (!images) {
     53        psError(psErrorCodeLast(), false, "No images provided.");
    3254        return false;
    3355    }
     56    data->numInputs = images->n;
    3457
    35     psArray *inputs = psStringSplitArray(input, "\n", false); // Input filenames
    36     psFree(input);
    37     if (!inputs || inputs->n == 0) {
    38         psError(PS_ERR_IO, false, "Unable to read filenames from %s", data->inName);
    39         psFree(inputs);
    40         return false;
    41     }
    42 
    43     data->numInputs = inputs->n;
    44     psMetadataAddArray(config->arguments, PS_LIST_TAIL, "INPUTS", 0, "Input files", inputs);
    45     psFree(inputs);
    46     psMetadataAddString(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Output root", data->outRoot);
    47 
    48     pmFPAfile *inFile = NULL;           // Representative input file
    49     for (int i = 0; i < data->numInputs; i++) {
    50         bool found = false;             // Found file definition?
    51         pmFPAfile *file = pmFPAfileDefineSingleFromArgs(&found, data->config, "PPSKYCELL.INPUT",
    52                                                         "INPUTS", i); // Input file
    53         if (!file || !found) {
    54             psError(psErrorCodeLast(), false, "Unable to define input %d\n", i);
     58    psArray *masks = NULL;              // Mask names
     59    if (data->masksName) {
     60        masks = fileList(data->masksName);
     61        if (!masks) {
     62            psError(psErrorCodeLast(), false, "No masks provided.");
     63            psFree(images);
    5564            return false;
    5665        }
    57         if (!inFile) {
    58             inFile = file;
     66        if (masks->n != data->numInputs) {
     67            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Number of images (%ld) and masks (%ld) do not match",
     68                    images->n, masks->n);
     69            psFree(images);
     70            psFree(masks);
     71            return false;
    5972        }
    6073    }
    6174
    62     pmFPAfile *outFile = pmFPAfileDefineFromFile(data->config, inFile, data->bin1, data->bin1,
    63                                                  "PPSKYCELL.JPEG1"); // Output file
    64     if (!outFile) {
     75    psMetadataAddStr(data->config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Output root", data->outRoot);
     76
     77    for (int i = 0; i < data->numInputs; i++) {
     78        bool status = false;             // Status of file definition
     79        fileArguments("IMAGE", images->data[i], "Name of the image", data->config);
     80        pmFPAfile *image = pmFPAfileDefineFromArgs(&status, data->config, "PPSKYCELL.IMAGE", "IMAGE"); // File
     81        if (!status || !image) {
     82            psError(PS_ERR_IO, false, "Failed to build file from PPSKYCELL.IMAGE");
     83            // XXX Cleanup
     84            return false;
     85        }
     86
     87        if (data->masksName) {
     88            fileArguments("MASK", masks->data[i], "Name of the mask", data->config);
     89            if (!pmFPAfileBindFromArgs(&status, image, data->config, "PPSKYCELL.MASK", "MASK") || !status) {
     90                psError(PS_ERR_IO, false, "Failed to build file from PPSKYCELL.MASK");
     91                // XXX Cleanup
     92                return false;
     93            }
     94        }
     95    }
     96
     97    if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.JPEG1")) {
    6598        psError(psErrorCodeLast(), false, "Unable to define output.");
    6699        return false;
    67100    }
    68     if (!pmFPAfileDefineFromFile(data->config, outFile, data->bin2, data->bin2, "PPSKYCELL.JPEG2")) {
     101    if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.JPEG2")) {
    69102        psError(psErrorCodeLast(), false, "Unable to define output.");
    70103        return false;
Note: See TracChangeset for help on using the changeset viewer.