Changeset 41161
- Timestamp:
- Nov 27, 2019, 11:07:45 AM (7 years ago)
- Location:
- trunk/Ohana/src/opihi/lib.shell
- Files:
-
- 3 edited
-
VectorIO.c (modified) (4 diffs)
-
multicommand.c (modified) (2 diffs)
-
startup.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/VectorIO.c
r40291 r41161 110 110 } 111 111 112 // insert a new header line, return end pointer 113 char *gfits_insert_header_line (Header *header, char *endptr, char *newline) { 114 115 if (0) { 116 char temp1[32], temp2[32]; 117 memset (temp1, 0, 32); 118 memset (temp2, 0, 32); 119 120 if (endptr) { 121 memcpy (temp1, endptr, 8); 122 } 123 memcpy (temp2, newline, 8); 124 fprintf (stderr, "insert: %s : %s\n", temp1, temp2); 125 } 126 127 /* find the END of the header, if not supplied */ 128 if (!endptr) { 129 endptr = gfits_header_field (header, "END", 1); 130 if (endptr == NULL) return NULL; 131 } 132 133 /* is there enough space for 1 more line? */ 134 if (header[0].datasize - (endptr - (header[0].buffer)) < 2*FT_LINE_LENGTH) { 135 // no, so expand by a full header block (FT_RECORD_SIZE = 32*80 = 2880) 136 header[0].datasize += FT_RECORD_SIZE; 137 REALLOCATE (header[0].buffer, char, header[0].datasize); 138 // re-find the "END" marker, in case new memory block is used 139 endptr = gfits_header_field (header, "END", 1); 140 if (endptr == NULL) return NULL; 141 memset (endptr + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE); 142 } 143 144 /* push END line back 1 */ 145 memmove ((endptr + FT_LINE_LENGTH), endptr, FT_LINE_LENGTH); 146 memset (endptr, ' ', FT_LINE_LENGTH); 147 148 strncpy (endptr, newline, 80); 149 endptr += FT_LINE_LENGTH; 150 151 return endptr; 152 } 153 154 static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TZERO", "TSCAL", " ", NULL}; 155 112 156 // write a set of vectors to a FITS file (vectors names become fits column names) 113 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) {157 int WriteVectorTableFITS (char *filename, char *extname, Header *extraheader, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) { 114 158 115 159 Header rawheader; … … 139 183 rawtable.header = &rawheader; 140 184 if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format, (compress != NULL))) goto escape; 141 // NOTE : for compression, the table is constructed in native by order185 // NOTE : for compression, the table is constructed in native byte order 142 186 143 187 FTable *outtable = &rawtable; … … 163 207 164 208 if (!append) { 209 // generate a blank PHU header 165 210 Header header; 166 211 Matrix matrix; … … 176 221 } 177 222 223 if (extraheader) { 224 // copy keywords which are not the standard or table keywords 225 char *buf = extraheader->buffer; 226 char *endptr = NULL; 227 for (int i = 0; i < extraheader->datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) { 228 229 if (0) { 230 char temp1[32]; 231 memset (temp1, 0, 32); 232 memcpy (temp1, buf, 8); 233 fprintf (stderr, "buffer: %s\n", temp1); 234 } 235 236 for (int j = 0; rawkeywords[j] != NULL; j++) { 237 if (!strncmp (buf, rawkeywords[j], strlen(rawkeywords[j]))) goto skip_insert; 238 } 239 endptr = gfits_insert_header_line (outheader, endptr, buf); 240 if (!endptr) { 241 gprint (GP_ERR, "failed to update FITS header with extra keywords\n"); 242 return (FALSE); 243 } 244 skip_insert: 245 continue; 246 } 247 } 248 178 249 // write the actual table data 179 250 gfits_fwrite_Theader (f, outheader); -
trunk/Ohana/src/opihi/lib.shell/multicommand.c
r39457 r41161 63 63 64 64 p = line; 65 int Nline = strlen(line); 66 65 67 done = FALSE; 66 68 status = TRUE; … … 74 76 tmpline = strncreate (p, q - p); 75 77 stripwhite (tmpline); 76 if (*tmpline) {78 myAssert (tmpline, "oops"); 77 79 78 if (bufferPending) { 79 // flush old messages 80 ExpectMessage (server, 0.2, &message); 81 bufferPending = FALSE; 80 // empty command, free and continue 81 if (*tmpline == 0) { 82 free (tmpline); 83 if (q == line + Nline) { 84 done = TRUE; 85 } else { 86 p = q + 1; 87 myAssert (p - line <= Nline, "oops"); 82 88 } 89 continue; 90 } 83 91 84 status = command (tmpline, &outline, verbose); 92 if (bufferPending) { 93 // flush old messages 94 ExpectMessage (server, 0.2, &message); 95 bufferPending = FALSE; 96 } 85 97 86 if (status == -1) { 87 if (server) { 88 // send the command to the server instead 89 if (!SendMessage (server, "%s", outline)) { 90 switch (errno) { 91 case EPIPE: 92 gprint (GP_ERR, "server connection has died\n"); 93 exit (32); 94 default: 95 gprint (GP_ERR, "server is busy...32\n"); 96 bufferPending = TRUE; 97 goto escape; 98 } 98 // input tmpline is freed by command 99 status = command (tmpline, &outline, verbose); 100 101 if (status == -1) { 102 if (server) { 103 // send the command to the server instead 104 if (!SendMessage (server, "%s", outline)) { 105 switch (errno) { 106 case EPIPE: 107 gprint (GP_ERR, "server connection has died\n"); 108 exit (32); 109 default: 110 gprint (GP_ERR, "server is busy...32\n"); 111 bufferPending = TRUE; 112 goto escape; 99 113 } 114 } 100 115 101 // receive the command exit status 102 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 103 switch (errno) { 104 case EPIPE: 105 gprint (GP_ERR, "server connection has died\n"); 106 exit (33); 107 default: 108 gprint (GP_ERR, "server is busy...33\n"); 109 bufferPending = TRUE; 110 goto escape; 111 } 112 } else { 113 sscanf (message.buffer, "STATUS %d", &status); 114 } 115 116 // receive the resulting stderr 117 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 118 switch (errno) { 119 case EPIPE: 120 gprint (GP_ERR, "server connection has died\n"); 121 exit (34); 122 default: 123 gprint (GP_ERR, "server is busy...34\n"); 124 bufferPending = TRUE; 125 goto escape; 126 } 127 } else { 128 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 129 } 130 131 // receive the resulting stdout 132 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 133 switch (errno) { 134 case EPIPE: 135 gprint (GP_ERR, "server connection has died\n"); 136 exit (35); 137 default: 138 gprint (GP_ERR, "server is busy...35\n"); 139 bufferPending = TRUE; 140 goto escape; 141 } 142 } else { 143 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 116 // receive the command exit status 117 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 118 switch (errno) { 119 case EPIPE: 120 gprint (GP_ERR, "server connection has died\n"); 121 exit (33); 122 default: 123 gprint (GP_ERR, "server is busy...33\n"); 124 bufferPending = TRUE; 125 goto escape; 144 126 } 145 127 } else { 146 // if no server is defined, we treat an unknown command as an error 147 status = FALSE; 148 } 149 } 150 escape: 151 if (outline != NULL) free (outline); 152 if (!status && auto_break) done = TRUE; 128 sscanf (message.buffer, "STATUS %d", &status); 129 } 130 131 // receive the resulting stderr 132 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 133 switch (errno) { 134 case EPIPE: 135 gprint (GP_ERR, "server connection has died\n"); 136 exit (34); 137 default: 138 gprint (GP_ERR, "server is busy...34\n"); 139 bufferPending = TRUE; 140 goto escape; 141 } 142 } else { 143 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 144 } 145 146 // receive the resulting stdout 147 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 148 switch (errno) { 149 case EPIPE: 150 gprint (GP_ERR, "server connection has died\n"); 151 exit (35); 152 default: 153 gprint (GP_ERR, "server is busy...35\n"); 154 bufferPending = TRUE; 155 goto escape; 156 } 157 } else { 158 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 159 } 160 } else { 161 // if no server is defined, we treat an unknown command as an error 162 status = FALSE; 163 } 153 164 } 165 escape: 166 if (outline != NULL) free (outline); 167 if (!status && auto_break) done = TRUE; 168 154 169 p = q + 1; 155 170 } -
trunk/Ohana/src/opihi/lib.shell/startup.c
r39926 r41161 107 107 LOAD_RC = FALSE; 108 108 } 109 if ((N = get_argument (*argc, argv, "--no-rc"))) { 110 remove_argument (N, argc, argv); 111 LOAD_RC = FALSE; 112 } 113 if ((N = get_argument (*argc, argv, "-norc"))) { 114 remove_argument (N, argc, argv); 115 LOAD_RC = FALSE; 116 } 117 if ((N = get_argument (*argc, argv, "-no-rc"))) { 118 remove_argument (N, argc, argv); 119 LOAD_RC = FALSE; 120 } 109 121 110 122 ONLY_INPUT = FALSE;
Note:
See TracChangeset
for help on using the changeset viewer.
