Changeset 41269 for trunk/Ohana/src/opihi/cmd.data/write_vectors.c
- Timestamp:
- Feb 24, 2020, 3:19:09 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/write_vectors.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r41164 r41269 154 154 if (ADD_HEADER) { 155 155 for (j = 0; j < Nvec; j++) { 156 if (j == 0) fprintf (f, "# "); 156 157 if (CSV) { 157 158 fprintf (f, "%s,", vec[j][0].name); 158 159 } else { 159 if (j == 0) fprintf (f, "# ");160 160 fprintf (f, "%s ", vec[j][0].name); 161 161 } … … 166 166 /* default output format */ 167 167 if (format == (char *) NULL) { 168 char padChar = CSV ? ',' : ' '; 168 169 for (i = 0; i < vec[0][0].Nelements; i++) { 169 170 for (j = 0; j < Nvec; j++) { 170 if (vec[j][0].type == OPIHI_FLT) { 171 if (CSV) { 172 fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]); 173 } else { 174 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 175 } 176 } else { 177 if (CSV) { 178 fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]); 179 } else { 180 fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]); 181 } 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; 182 181 } 183 182 } … … 226 225 fmttype[j] = 'd'; 227 226 break; 227 case 's': 228 fmttype[j] = 's'; 229 break; 228 230 default: 229 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"); 230 232 return (FALSE); 231 233 } … … 234 236 strcat (fmtlist[Nvec-1], p0); 235 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 236 257 for (i = 0; i < vec[0][0].Nelements; i++) { 237 258 for (j = 0; j < Nvec; j++) { … … 249 270 fprintf (f, fmtlist[j], (opihi_flt)(vec[j][0].elements.Int[i])); 250 271 } 272 } 273 if (fmttype[j] == 's') { 274 fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]); 251 275 } 252 276 }
Note:
See TracChangeset
for help on using the changeset viewer.
