IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16499


Ignore:
Timestamp:
Feb 15, 2008, 9:33:56 AM (18 years ago)
Author:
eugene
Message:

finish basic coding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimSequence.c

    r16393 r16499  
    1 # include "ppSim.h"
     1# include "ppSimSequence.h"
    22
    3 int main(int argc, char *argv[])
    4 {
     3int main (int argc, char **argv) {
     4
     5    int argNum;
     6    bool status;
     7    unsigned int nFail;
     8
    59    psLibInit(NULL);
    610
    7     if (argc != 2) {
    8       fprintf (stderr, "USAGE: ppSimSequence (seq.config)\n");
    9       fprintf (stderr, "generates a set of simulated data defined by the sequence file\n");
    10       exit (2);
     11    char *dbname = NULL;
     12    if ((argNum = psArgumentGet (argc, argv, "-dbname"))) {
     13        psArgumentRemove(argNum, &argc, argv);
     14        dbname = psStringCopy (argv[argNum]);
     15        psArgumentRemove(argNum, &argc, argv);
     16    }
     17
     18    char *path = NULL;
     19    if (psArgumentGet (argc, argv, "-path")) {
     20        psArgumentRemove(argNum, &argc, argv);
     21        path = psStringCopy (argv[argNum]);
     22        psArgumentRemove(argNum, &argc, argv);
     23    }
     24
     25    char *workdir = NULL;
     26    if (psArgumentGet (argc, argv, "-workdir")) {
     27        psArgumentRemove(argNum, &argc, argv);
     28        workdir = psStringCopy (argv[argNum]);
     29        psArgumentRemove(argNum, &argc, argv);
     30    }
     31
     32    char *basename = NULL;
     33    if (psArgumentGet (argc, argv, "-basename")) {
     34        psArgumentRemove(argNum, &argc, argv);
     35        basename = psStringCopy (argv[argNum]);
     36        psArgumentRemove(argNum, &argc, argv);
     37    } else {
     38        basename = psStringCopy ("simtest");
     39    }
     40
     41    if (argc != 4) {
     42        fprintf (stderr, "USAGE: ppSimSequence (sequence) (simulate) (inject)\n");
     43        fprintf (stderr, "generates a set of simulated data defined by the sequence file\n");
     44        fprintf (stderr, " (sequence) : a mdc-file describing the desired image sequences\n");
     45        fprintf (stderr, " (simulate) : an output file with commands to generate the images\n");
     46        fprintf (stderr, " (inject)   : an output file with commands to inject the images into the pipeline\n");
     47        fprintf (stderr, "\n");
     48        exit (2);
    1149    }
    1250
    1351    // load the sequence description
    1452    psMetadata *config = psMetadataConfigRead (NULL, &nFail, argv[1], false);
     53    if (!config) {
     54        psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to read sequence description from %s", argv[1]);
     55        exit (1);
     56    }
    1557   
     58    FILE *simfile = fopen (argv[2], "w");
     59    if (!simfile) {
     60        psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[2]);
     61        exit (1);
     62    }
     63       
     64    FILE *inject = fopen (argv[3], "w");
     65    if (!inject) {
     66        psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[3]);
     67        exit (1);
     68    }
     69
     70    // build the base injectCommand string
     71    psString injectCommand = psStringCopy ("ipp_inject_fileset.pl --telescope SIMTEST");
     72    if (dbname)  psStringAppend (&injectCommand, " --dbname %s",  dbname);
     73    if (workdir) psStringAppend (&injectCommand, " --workdir %s", workdir);
     74
     75    unsigned long seed = psMetadataLookupS32 (&status, config, "RND_SEED");
     76    if (!status) seed = 0;
     77    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, seed);
     78
    1679    psMetadataItem *item = psMetadataLookup (config, "SEQUENCE");
    1780    if (item == NULL) {
    18       psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");
    19       exit (1);
     81        psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");
     82        exit (1);
    2083    }
    2184
     85    psArray *sequences = NULL;
    2286    if (item->type == PS_DATA_METADATA) {
    23       sequences = psArrayAlloc(1);
    24       sequences->data[0] = psMemIncrRefCounter (item->data.V);
     87        sequences = psArrayAlloc(1);
     88        sequences->data[0] = psMemIncrRefCounter (item->data.V);
    2589    } else {
    26       if (item->type != PS_DATA_METADATA_MULTI)  {
    27         psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");
    28         exit (1);
    29       }
    30       sequences = psListToArray (item->data.list);
     90        if (item->type != PS_DATA_METADATA_MULTI)  {
     91            psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");
     92            exit (1);
     93        }
     94        sequences = psListToArray (item->data.list);
    3195    }
    3296
    3397    for (int i = 0; i < sequences->n; i++) {
    3498
    35       // a OBJECT sequence is described by a center position and a set of offsets at each
    36       // offset, we perform a set of dithers for each pointing, we have a set of filters
    37       // and exposure times
     99        // XXX this is not obvious: the entry on the list is a metadata item
     100        // containing the psMetadata :: why is this not just a metadata?
     101        psMetadataItem *item = sequences->data[i];
     102        psMetadata *sequence = item->data.V;
     103        // double check item type?
     104     
     105        // determine the sequence type
     106        char *type = psMetadataLookupStr (&status, sequence, "OBSTYPE");
     107        if (!status) {
     108            psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d is missing a type", i);
     109            exit (1);
     110        }
    38111
    39       // a non-OBJECT sequence consists of a number of a given type
     112        if (!strcasecmp (type, "BIAS")) {
     113            ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, injectCommand);
     114            continue;
     115        }
     116        if (!strcasecmp (type, "DARK")) {
     117            ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, injectCommand);
     118            continue;
     119        }
     120        if (!strcasecmp (type, "FLAT")) {
     121            ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, injectCommand);
     122            continue;
     123        }
     124        if (!strcasecmp (type, "OBJECT")) {
     125            ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, injectCommand);
     126            continue;
     127        }
    40128
    41       // create files with ppSim:
    42       // ppSim -camera CAMERA -type TYPE filename
    43      
    44       // inject --camera
    45 
    46       psMetadata *sequence = sequences->data[i];
    47      
    48       // determine the sequence type
    49       char *type = psMetadataLookupStr (&status, sequence, "TYPE");
    50       if (!status) {
    51         psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d is missing a type", i);
     129        psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d has an unknown type: %s", i, type);
    52130        exit (1);
    53       }
    54 
    55       if (!strcasecmp (type, "BIAS")) {
    56         ppSimSequenceBias (sequence);
    57         continue;
    58       }
    59       if (!strcasecmp (type, "DARK")) {
    60         ppSimSequenceDark (sequence);
    61         continue;
    62       }
    63       if (!strcasecmp (type, "FLAT")) {
    64         ppSimSequenceFlat (sequence);
    65         continue;
    66       }
    67       if (!strcasecmp (type, "OBJECT")) {
    68         ppSimSequenceObject (sequence);
    69         continue;
    70       }
    71131    }
     132    exit (0);
    72133}
Note: See TracChangeset for help on using the changeset viewer.