IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7770


Ignore:
Timestamp:
Jun 30, 2006, 2:00:11 PM (20 years ago)
Author:
magnier
Message:

added psPipe, psIOBuffer, added to detselect

Location:
trunk/psModules/src/detrend
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/Makefile.am

    r7589 r7770  
    1010        pmNonLinear.c \
    1111        pmSubtractBias.c \
    12         pmDetrendDB.c
     12        pmDetrendDB.c \
     13        psPipe.c \
     14        psIOBuffer.c
    1315
    1416#       pmSubtractSky.c
  • trunk/psModules/src/detrend/pmDetrendDB.c

    r7589 r7770  
    8585pmDetrendSelectResults *pmDetrendSelect (pmDetrendSelectOptions *options)
    8686{
    87 
    88     char answer[128];
    89     char line[1024];
     87    bool status;
     88    char *line = NULL;
    9089
    9190    char *time = psTimeToISO (&options->time);
    9291    char *type = pmDetrendTypeToString (options->type);
    9392
    94     sprintf (line, "detselect -camera %s -time %s -type %s",
    95             options->camera, time, type);
     93    // generate the detselect command
     94    psStringAppend (&line, "detselect -camera %s -time %s -type %s", options->camera, time, type);
    9695    psFree (time);
    9796    psFree (type);
    9897
    99     // XXX put this in a fork/exec to catch the timeout
    100     FILE *p = popen (line, "r");
    101     fgets (answer, 127, p);
    102     pclose (p);
     98    // use psPipe to exec the command, wait for response
     99    psIOBuffer *buffer = psIOBufferAlloc (512);
     100    psPipe *pipe = psPipeOpen (line);
     101    status = psIOBufferReadEmpty (buffer, 100, pipe->stdout);
     102    if (!status) {
     103        psError (PS_ERR_IO, false, "detselect is not responding");
     104        psFree (buffer);
     105        psFree (pipe);
     106        psFree (line);
     107        return NULL;
     108    }
     109    psPipeClose (pipe);
     110    psFree (pipe);
     111    psFree (line);
    103112
    104     psList *list = psStringSplit (answer, " ", false);
    105     psArray *array = psListToArray (list);
     113    // XXX need to parse the response more robustly
     114    // XXX for now, assume a single line
     115    psArray *array = psStringSplitArray (buffer->data, " ", false);
     116    psFree (buffer);
    106117
    107118    if (!array)
     
    121132
    122133    psFree (array);
    123     psFree (list);
    124 
    125134    return results;
    126135}
     
    130139char *pmDetrendFile (char *detID, char *classID)
    131140{
     141    bool status;
     142    char *line = NULL;
    132143
    133     char answer[128];
    134     char line[1024];
     144    // generate the detselect command
     145    psStringAppend (&line, "detselect -select -detID %s -classID %s", detID, classID);
    135146
    136     sprintf (line, "detselect -select -detID %s -classID %s", detID, classID);
     147    // use psPipe to exec the command, wait for response
     148    psIOBuffer *buffer = psIOBufferAlloc (512);
     149    psPipe *pipe = psPipeOpen (line);
     150    status = psIOBufferReadEmpty (buffer, 100, pipe->stdout);
     151    if (!status) {
     152        psError (PS_ERR_IO, false, "detselect is not responding");
     153        psFree (buffer);
     154        psFree (pipe);
     155        psFree (line);
     156        return NULL;
     157    }
     158    psPipeClose (pipe);
     159    psFree (pipe);
     160    psFree (line);
    137161
    138     // XXX put this in a fork/exec to catch the timeout
    139     FILE *p = popen (line, "r");
    140     fgets (answer, 127, p);
    141     pclose (p);
    142 
    143     psList *list = psStringSplit (answer, " ", false);
    144     psArray *array = psListToArray (list);
     162    // XXX need to parse the response more robustly
     163    // XXX for now, assume a single line
     164    psArray *array = psStringSplitArray (buffer->data, " ", false);
     165    psFree (buffer);
    145166
    146167    if (!array)
     
    154175
    155176    psFree (array);
    156     psFree (list);
    157 
    158177    return result;
    159178}
  • trunk/psModules/src/detrend/pmDetrendDB.h

    r7589 r7770  
    1414*  @author EAM, IfA
    1515*
    16 *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    17 *  @date $Date: 2006-06-17 01:50:43 $
     16*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     17*  @date $Date: 2006-07-01 00:00:11 $
    1818*
    1919*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    6666char *pmDetrendFile (char *detID, char *classID);
    6767
     68// move these to pslib??
     69typedef struct
     70{
     71    int stdin;
     72    int stdout;
     73    int stderr;
     74}
     75psPipe;
     76
     77typedef struct
     78{
     79    char *data;
     80    int nAlloc;    // current size of allocated buffer
     81    int nReset;    // size to set buffer after flush
     82    int nBlock;    // number of bytes to try to read at a time
     83    int n;    // current size of filled data
     84}
     85psIOBuffer;
     86
     87// psIOBuffer functions
     88psIOBuffer *psIOBufferAlloc (int nBuffer);
     89bool psIOBufferFlush (psIOBuffer *buffer);
     90int psIOBufferRead (psIOBuffer *buffer, int fd);
     91int psIOBufferReadEmpty (psIOBuffer *buffer, int maxRetries, int fd);
     92
     93// psPipe functions
     94psPipe *psPipeAlloc ();
     95psPipe *psPipeOpen (char *command);
     96bool psPipeClose (psPipe *pipe);
     97
    6898# endif
Note: See TracChangeset for help on using the changeset viewer.