Changeset 41340 for trunk/Ohana/src/opihi/cmd.data/write_vectors.c
- Timestamp:
- Apr 16, 2020, 1:54:47 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
r41269 r41340 32 32 } 33 33 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 34 /* option generate a FITS output table */ 37 35 char *FITS = NULL; 38 Header *fitsheader = NULL;39 Buffer *headbuffer = NULL;40 36 if ((N = get_argument (argc, argv, "-fits"))) { 41 37 remove_argument (N, &argc, argv); 42 38 FITS = strcreate (argv[N]); 43 39 remove_argument (N, &argc, argv); 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 40 } 41 53 42 /* option generate a FITS output table */ 54 43 int CSV = FALSE; … … 135 124 136 125 if (FITS) { 137 int status = WriteVectorTableFITS (argv[1], FITS, fitsheader,vec, Nvec, append, compress, format, Ntile);126 int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format, Ntile); 138 127 free (vec); 139 128 return status; … … 154 143 if (ADD_HEADER) { 155 144 for (j = 0; j < Nvec; j++) { 156 if (j == 0) fprintf (f, "# ");157 145 if (CSV) { 158 146 fprintf (f, "%s,", vec[j][0].name); 159 147 } else { 148 if (j == 0) fprintf (f, "# "); 160 149 fprintf (f, "%s ", vec[j][0].name); 161 150 } … … 166 155 /* default output format */ 167 156 if (format == (char *) NULL) { 168 char padChar = CSV ? ',' : ' ';169 157 for (i = 0; i < vec[0][0].Nelements; i++) { 170 158 for (j = 0; j < Nvec; j++) { 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; 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 } 181 171 } 182 172 } … … 225 215 fmttype[j] = 'd'; 226 216 break; 227 case 's':228 fmttype[j] = 's';229 break;230 217 default: 231 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x ,sallowed)\n");218 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x allowed)\n"); 232 219 return (FALSE); 233 220 } … … 236 223 strcat (fmtlist[Nvec-1], p0); 237 224 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 257 225 for (i = 0; i < vec[0][0].Nelements; i++) { 258 226 for (j = 0; j < Nvec; j++) { … … 271 239 } 272 240 } 273 if (fmttype[j] == 's') {274 fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]);275 }276 241 } 277 242 fprintf (f, "\n"); … … 295 260 gprint (GP_ERR, " -append : write to the end of the existing file\n"); 296 261 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");299 262 gprint (GP_ERR, " -csv : write a comma-separated values file (eg, to read in excel)\n"); 300 263 gprint (GP_ERR, " -f \"format\" : provide formatting codes for output:\n");
Note:
See TracChangeset
for help on using the changeset viewer.
