Changeset 41341 for trunk/Ohana/src/opihi/cmd.data/write_vectors.c
- Timestamp:
- Apr 16, 2020, 2:04:27 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/write_vectors.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r41340 r41341 32 32 } 33 33 34 /* option generate a FITS output table */ 34 // option generate a FITS output table (FITS holds the filename) 35 // in FITS output context, -header is interpretted as a buffer containing 36 // header keywords to supplement the FITS table header 35 37 char *FITS = NULL; 38 Header *fitsheader = NULL; 39 Buffer *headbuffer = NULL; 36 40 if ((N = get_argument (argc, argv, "-fits"))) { 37 41 remove_argument (N, &argc, argv); 38 42 FITS = strcreate (argv[N]); 39 43 remove_argument (N, &argc, argv); 40 } 41 44 45 if ((N = get_argument (argc, argv, "-header"))) { 46 remove_argument (N, &argc, argv); 47 if ((headbuffer = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE); 48 fitsheader = &headbuffer->header; 49 remove_argument (N, &argc, argv); 50 } 51 } 52 42 53 /* option generate a FITS output table */ 43 54 int CSV = FALSE; … … 124 135 125 136 if (FITS) { 126 int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format, Ntile);137 int status = WriteVectorTableFITS (argv[1], FITS, fitsheader, vec, Nvec, append, compress, format, Ntile); 127 138 free (vec); 128 139 return status; … … 143 154 if (ADD_HEADER) { 144 155 for (j = 0; j < Nvec; j++) { 156 if (j == 0) fprintf (f, "# "); 145 157 if (CSV) { 146 158 fprintf (f, "%s,", vec[j][0].name); 147 159 } else { 148 if (j == 0) fprintf (f, "# ");149 160 fprintf (f, "%s ", vec[j][0].name); 150 161 } … … 155 166 /* default output format */ 156 167 if (format == (char *) NULL) { 168 char padChar = CSV ? ',' : ' '; 157 169 for (i = 0; i < vec[0][0].Nelements; i++) { 158 170 for (j = 0; j < Nvec; j++) { 159 if (vec[j][0].type == OPIHI_FLT) { 160 if (CSV) { 161 fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]); 162 } else { 163 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 164 } 165 } else { 166 if (CSV) { 167 fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]); 168 } else { 169 fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]); 170 } 171 switch (vec[j][0].type) { 172 case OPIHI_FLT: 173 fprintf (f, "%.12g%c", vec[j][0].elements.Flt[i], padChar); 174 break; 175 case OPIHI_INT: 176 fprintf (f, OPIHI_INT_FMT"%c", vec[j][0].elements.Int[i], padChar); 177 break; 178 case OPIHI_STR: 179 fprintf (f, "%s%c", vec[j][0].elements.Str[i], padChar); 180 break; 171 181 } 172 182 } … … 215 225 fmttype[j] = 'd'; 216 226 break; 227 case 's': 228 fmttype[j] = 's'; 229 break; 217 230 default: 218 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x allowed)\n");231 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x,s allowed)\n"); 219 232 return (FALSE); 220 233 } … … 223 236 strcat (fmtlist[Nvec-1], p0); 224 237 238 // check format types against vector types: 239 for (j = 0; j < Nvec; j++) { 240 switch (vec[j][0].type) { 241 case OPIHI_FLT: 242 case OPIHI_INT: 243 if (fmttype[j] == 's') { 244 gprint (GP_ERR, "mismatch between string format and numerical vector for %s\n", vec[j][0].name); 245 return FALSE; 246 } 247 break; 248 case OPIHI_STR: 249 if (fmttype[j] != 's') { 250 gprint (GP_ERR, "mismatch between numerical format and string vector for %s\n", vec[j][0].name); 251 return FALSE; 252 } 253 break; 254 } 255 } 256 225 257 for (i = 0; i < vec[0][0].Nelements; i++) { 226 258 for (j = 0; j < Nvec; j++) { … … 239 271 } 240 272 } 273 if (fmttype[j] == 's') { 274 fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]); 275 } 241 276 } 242 277 fprintf (f, "\n"); … … 260 295 gprint (GP_ERR, " -append : write to the end of the existing file\n"); 261 296 gprint (GP_ERR, " -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n"); 297 gprint (GP_ERR, " in FITS output context, -header takes an additional argument which is interpretted\n"); 298 gprint (GP_ERR, " as a buffer containing header keywords to supplement the FITS table header\n"); 262 299 gprint (GP_ERR, " -csv : write a comma-separated values file (eg, to read in excel)\n"); 263 300 gprint (GP_ERR, " -f \"format\" : provide formatting codes for output:\n");
Note:
See TracChangeset
for help on using the changeset viewer.
