Changeset 7770
- Timestamp:
- Jun 30, 2006, 2:00:11 PM (20 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 added
- 3 edited
-
Makefile.am (modified) (1 diff)
-
pmDetrendDB.c (modified) (4 diffs)
-
pmDetrendDB.h (modified) (2 diffs)
-
psIOBuffer.c (added)
-
psPipe.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/Makefile.am
r7589 r7770 10 10 pmNonLinear.c \ 11 11 pmSubtractBias.c \ 12 pmDetrendDB.c 12 pmDetrendDB.c \ 13 psPipe.c \ 14 psIOBuffer.c 13 15 14 16 # pmSubtractSky.c -
trunk/psModules/src/detrend/pmDetrendDB.c
r7589 r7770 85 85 pmDetrendSelectResults *pmDetrendSelect (pmDetrendSelectOptions *options) 86 86 { 87 88 char answer[128]; 89 char line[1024]; 87 bool status; 88 char *line = NULL; 90 89 91 90 char *time = psTimeToISO (&options->time); 92 91 char *type = pmDetrendTypeToString (options->type); 93 92 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); 96 95 psFree (time); 97 96 psFree (type); 98 97 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); 103 112 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); 106 117 107 118 if (!array) … … 121 132 122 133 psFree (array); 123 psFree (list);124 125 134 return results; 126 135 } … … 130 139 char *pmDetrendFile (char *detID, char *classID) 131 140 { 141 bool status; 142 char *line = NULL; 132 143 133 char answer[128];134 char line[1024];144 // generate the detselect command 145 psStringAppend (&line, "detselect -select -detID %s -classID %s", detID, classID); 135 146 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); 137 161 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); 145 166 146 167 if (!array) … … 154 175 155 176 psFree (array); 156 psFree (list);157 158 177 return result; 159 178 } -
trunk/psModules/src/detrend/pmDetrendDB.h
r7589 r7770 14 14 * @author EAM, IfA 15 15 * 16 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $17 * @date $Date: 2006-0 6-17 01:50:43$16 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-07-01 00:00:11 $ 18 18 * 19 19 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii … … 66 66 char *pmDetrendFile (char *detID, char *classID); 67 67 68 // move these to pslib?? 69 typedef struct 70 { 71 int stdin; 72 int stdout; 73 int stderr; 74 } 75 psPipe; 76 77 typedef 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 } 85 psIOBuffer; 86 87 // psIOBuffer functions 88 psIOBuffer *psIOBufferAlloc (int nBuffer); 89 bool psIOBufferFlush (psIOBuffer *buffer); 90 int psIOBufferRead (psIOBuffer *buffer, int fd); 91 int psIOBufferReadEmpty (psIOBuffer *buffer, int maxRetries, int fd); 92 93 // psPipe functions 94 psPipe *psPipeAlloc (); 95 psPipe *psPipeOpen (char *command); 96 bool psPipeClose (psPipe *pipe); 97 68 98 # endif
Note:
See TracChangeset
for help on using the changeset viewer.
