110char *option[N_OPTIONS] = {
133 "sddsprintout [<SDDSinput>] [<outputfile>]\n"
134 " [-pipe=[input][,output]] \n"
135 " [-columns[=<name-list>[,format={<string>|@<columnName>}][,label=<string>][,editLabel=<command>][,useDefaultFormat][,endsline][,blankLines=<number>]][,factor=<value>][,nounits]] \n"
136 " [-parameters[=<name-list>[,format={<string>|@<parameterName>}][,label=<string>][,editLabel=<command>][,useDefaultFormat][,endsline][,blankLines=<number]][,factor=<value>]] \n"
137 " [-array[=<name-list>[,format=<string>]] \n"
138 " [-fromPage=<number>] \n"
139 " [-toPage=<number>] \n"
140 " [-formatDefaults=<SDDStype>=<format-string>[,...]]\n"
141 " [-width=<integer>] \n"
143 " [-paginate[=lines=<number>][,notitle][,nolabels]]\n"
145 " [-title=<string>] \n"
147 " [-postPageLines=<number>]\n"
148 " [-spreadsheet[=delimiter=<string>][,quotemark=<string>][,nolabels][,csv][,schfile=<filename>]]\n"
149 " [-latexFormat[=longtable][,booktable][,sideways][,label={<string>|@<parameterName>}][,caption={<string>|@<parameterName>}][,group=<columnName>][,translate=<filename>][,justify=<codeList>][,complete][,comment=<string>]]\n"
150 " [-htmlFormat[=caption=<string>][,translate=<filename>]]\n"
153 "-spreadsheet=csv is the simple way of -spreadsheet=nolabels,quote=\",delimiter=\\, -notitle \n"
154 "Translation file for LaTeX mode has columns OldName and NewName, and can be used to translate symbols and units.\n\n"
157 "Program by Michael Borland. (\"" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
159#define PAGINATION_ON 0x0001U
160#define PAGINATION_NOTITLE 0x0002U
161#define PAGINATION_NOLABELS 0x0004U
163#define LATEX_FORMAT 0x0001UL
164#define LATEX_LONGTABLE 0x0002UL
165#define LATEX_BOOKTABLE 0x0004UL
166#define LATEX_LABEL 0x0008UL
167#define LATEX_CAPTION 0x0010UL
168#define LATEX_GROUP 0x0020UL
169#define LATEX_TRANSLATE 0x0040UL
170#define LATEX_SIDEWAYS 0x0080UL
171#define LATEX_JUSTIFY 0x0100UL
172#define LATEX_COMPLETE 0x0200UL
173#define LATEX_COMMENT 0x0400UL
174#define LATEX_LABEL_PARAM 0x0800UL
175#define LATEX_CAPTION_PARAM 0x1000UL
177#define HTML_FORMAT 0x0001U
178#define HTML_CAPTION 0x0002U
179#define HTML_TRANSLATE 0x0004U
188#define ENDSLINE 0x0001U
189#define USEDEFAULTFORMAT 0x0002U
190#define LABEL_GIVEN 0x0004U
191#define EDITLABEL_GIVEN 0x0008U
192#define FACTOR_GIVEN 0x0010U
193#define NO_UNITS 0x0020U
197 char *name, *format, **header, *label, *editLabel;
198 long fieldWidth, index, headers, type, endsLine, blankLines, useDefaultFormat, noUnits;
205 char *name, *format, *label, *editLabel;
206 long fieldWidth, index, type, endsLine, blankLines, useDefaultFormat;
213 char *name, *format, *label;
218char *makeTexSafeString(
char *source);
219char *makeTexExponentialString(
char *text);
220void copyAndPad(
char *target,
char *source,
long sourceWidth,
long targetWidth);
221long makeColumnHeaders(
char ***header,
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
222 char **format,
unsigned long spreadsheetFlags,
unsigned long latexFormat, htab *translationTable,
unsigned long htmlFormat);
223char *makeParameterLabel(
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
char *format);
224long changeDefaultFormats(
char **argv,
long argc,
long noWarnings);
225void setDefaultFormats(
void);
227 unsigned long spreadsheetFlags,
long csv,
unsigned long latexformat, htab *translationTable,
unsigned long htmlformat);
228void printColumnHeaders(FILE *fpOut,
PRINT_COLUMN *printColumn,
long printColumns,
long width,
PAGINATION *pagination,
229 long latexFormat,
char *latexTitle,
long htmlFormat,
char *htmlTitle);
231 long noWarnings,
long noLabels,
long csv);
233long getFormatFieldLength(
char *format,
long *extraChars);
234char **makeListOfNames(
char *
string,
long *names);
236 FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
237 char *spreadsheetQuoteMark,
PAGINATION *pagination,
char *title,
long noLabels);
238long characterCount(
char *
string,
char c);
239long printPageTitle(FILE *fpOut,
char *title);
241 long width, FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
char *spreadsheetQuoteMark,
242 long latexFormat,
char *latexTitle,
char *latexLabel,
char *latexGroupColumn,
243 long htmlFormat,
char *htmlTitle,
244 PAGINATION *pagination,
char *title,
long noLabels);
245long checkPagination(FILE *fpOut,
PAGINATION *pagination,
char *title);
246void replaceFormatWidth(
char *buffer,
char *format,
long width);
247void CreateSCHFile(
char *output,
char *input,
unsigned long flags,
char *delimiter,
char *quote,
249htab *readTranslationTable(
char *TranslationFile);
250char *findTranslation(htab *ht,
char *key);
251char *modifyUnitsWithFactor(
char *units0,
double factor,
unsigned long latexFormat);
253static char **defaultFormat = NULL;
254static char **csvFormat = NULL;
255static char *latexJustify = NULL;
257#define SPREADSHEET_ON 0x0001U
258#define SPREADSHEET_DELIMITER 0x0002U
259#define SPREADSHEET_QUOTEMARK 0x0004U
260#define SPREADSHEET_NOLABELS 0x0008U
261#define SPREADSHEET_CSV 0x0010UL
263int main(
int argc,
char **argv) {
265 long i, i_arg, pageNumber, width;
267 char *input, *output, **name, *format, *title, *label, *editLabel, *schFile;
271 long printColumns, printParameters, printArrays, firstPage, bufferLines;
272 long fromPage, toPage, names, pageAdvance, noTitle, noLabels, noWarnings;
274 unsigned long latexFormat, htmlFormat;
276 unsigned long flags, pipeFlags, spreadsheetFlags, dummyFlags, postPageLines, CSV = 0;
277 char *spreadsheetDelimiter, *spreadsheetQuoteMark;
279 char **formatDefaultArg;
280 long formatDefaultArgs;
281 static char formatbuffer[100], formatbuffer2[100];
282 char *latexLabel, *latexCaption = NULL, *latexGroup, *latexTranslationFile, *latexComment = NULL;
283 char *latexCaptionBuffer = NULL, *latexLabelBuffer = NULL;
284 htab *TranslationTable;
285 char *htmlCaption = NULL, *htmlTranslationFile;
289 argc =
scanargs(&s_arg, argc, argv);
293 input = output = NULL;
294 fromPage = toPage = 0;
296 printParameter = NULL;
300 printColumns = printParameters = printArrays = pipeFlags = flags = 0;
301 postPageLines = pageAdvance = noTitle = noLabels = 0;
303 spreadsheetFlags = 0;
304 pagination.flags = pagination.currentLine = 0;
306 formatDefaultArgs = 0;
308 formatDefaultArg = NULL;
311 TranslationTable = NULL;
314 for (i_arg = 1; i_arg < argc; i_arg++) {
315 if (s_arg[i_arg].arg_type == OPTION) {
316 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
318 if (s_arg[i_arg].n_items < 2) {
319 s_arg[i_arg].n_items = 2;
320 s_arg[i_arg].list =
SDDS_Realloc(s_arg[i_arg].list,
sizeof(*s_arg[i_arg].list) * 2);
323 name = makeListOfNames(s_arg[i_arg].list[1], &names);
324 printColumn =
SDDS_Realloc(printColumn,
sizeof(*printColumn) * (names + printColumns));
325 s_arg[i_arg].n_items -= 2;
329 if (!
scanItemList(&flags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
331 "endsline", -1, NULL, 0, ENDSLINE,
332 "usedefaultformat", -1, NULL, 0, USEDEFAULTFORMAT,
333 "blanklines",
SDDS_LONG, &blankLines, 1, 0,
334 "editlabel",
SDDS_STRING, &editLabel, 1, EDITLABEL_GIVEN,
336 "nounits", -1, NULL, 0, NO_UNITS,
337 "factor",
SDDS_DOUBLE, &factor, 1, FACTOR_GIVEN, NULL))
339 for (i = 0; i < names; i++) {
341 printColumn[i + printColumns].name = name[i];
344 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
347 if (flags & ENDSLINE && (i == names - 1))
348 printColumn[i + printColumns].endsLine = 1;
349 if (flags & USEDEFAULTFORMAT)
350 printColumn[i + printColumns].useDefaultFormat = 1;
351 printColumn[i + printColumns].label = printColumn[i + printColumns].editLabel = NULL;
352 if (flags & LABEL_GIVEN)
353 printColumn[i + printColumns].label = label;
354 if (flags & EDITLABEL_GIVEN)
355 printColumn[i + printColumns].editLabel = editLabel;
356 printColumn[i + printColumns].noUnits = flags & NO_UNITS ? 1 : 0;
357 printColumn[i + printColumns].factor = factor;
358 printColumn[i + printColumns].blankLines = blankLines;
361 printColumns += names;
364 if (s_arg[i_arg].n_items < 2) {
365 s_arg[i_arg].n_items = 2;
366 s_arg[i_arg].list =
SDDS_Realloc(s_arg[i_arg].list,
sizeof(*s_arg[i_arg].list) * 2);
369 name = makeListOfNames(s_arg[i_arg].list[1], &names);
370 printParameter =
SDDS_Realloc(printParameter,
sizeof(*printParameter) * (names + printParameters));
371 s_arg[i_arg].n_items -= 2;
375 if (!
scanItemList(&flags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
377 "endsline", -1, NULL, 0, ENDSLINE,
378 "usedefaultformat", -1, NULL, 0, USEDEFAULTFORMAT,
379 "blanklines",
SDDS_LONG, &blankLines, 1, 0,
380 "editlabel",
SDDS_STRING, &editLabel, 1, EDITLABEL_GIVEN,
382 "factor",
SDDS_DOUBLE, &factor, 1, FACTOR_GIVEN, NULL))
384 for (i = 0; i < names; i++) {
385 SDDS_ZeroMemory(printParameter + i + printParameters,
sizeof(*printParameter));
386 printParameter[i + printParameters].name = name[i];
389 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
390 SDDS_CopyString(&printParameter[i + printParameters].format, formatbuffer2);
392 if (flags & ENDSLINE && (i == names - 1))
393 printParameter[i + printParameters].endsLine = 1;
394 if (flags & USEDEFAULTFORMAT)
395 printParameter[i + printParameters].useDefaultFormat = 1;
396 printParameter[i + printParameters].label = printParameter[i + printParameters].editLabel = NULL;
397 if (flags & LABEL_GIVEN)
398 printParameter[i + printParameters].label = label;
399 if (flags & EDITLABEL_GIVEN)
400 printParameter[i + printParameters].editLabel = editLabel;
401 printParameter[i + printParameters].factor = factor;
402 printParameter[i + printParameters].blankLines = blankLines;
405 printParameters += names;
408 if (s_arg[i_arg].n_items < 2) {
409 s_arg[i_arg].n_items = 2;
410 s_arg[i_arg].list =
SDDS_Realloc(s_arg[i_arg].list,
sizeof(*s_arg[i_arg].list) * 2);
413 name = makeListOfNames(s_arg[i_arg].list[1], &names);
414 printArray =
SDDS_Realloc(printArray,
sizeof(*printArray) * (names + printArrays));
415 s_arg[i_arg].n_items -= 2;
417 if (!
scanItemList(&flags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
420 for (i = 0; i < names; i++) {
421 printArray[i + printArrays].name = name[i];
424 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
429 printArrays += names;
432 if (s_arg[i_arg].n_items < 2)
435 SDDS_Bomb(
"invalid syntax: specify -fromPage once only");
436 if (sscanf(s_arg[i_arg].list[1],
"%ld", &fromPage) != 1 || fromPage <= 0)
437 SDDS_Bomb(
"invalid -fromPage syntax or value");
440 if (s_arg[i_arg].n_items < 2)
443 SDDS_Bomb(
"invalid syntax: specify -toPage once only");
444 if (sscanf(s_arg[i_arg].list[1],
"%ld", &toPage) != 1 || toPage <= 0)
445 SDDS_Bomb(
"invalid -toPage syntax or value");
447 case SET_FORMATDEFAULTS:
448 formatDefaultArg = s_arg[i_arg].list + 1;
449 formatDefaultArgs = s_arg[i_arg].n_items - 1;
452 if (s_arg[i_arg].n_items != 2 || sscanf(s_arg[i_arg].list[1],
"%ld", &width) != 1 || (width < 40 && width))
453 SDDS_Bomb(
"invalid -width syntax or value");
456 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
459 case SET_PAGEADVANCE:
466 if (s_arg[i_arg].n_items != 2)
468 title = s_arg[i_arg].list[1];
470 case SET_SPREADSHEET:
471 s_arg[i_arg].n_items--;
472 spreadsheetDelimiter = NULL;
473 spreadsheetQuoteMark =
"";
474 if (!
scanItemList(&spreadsheetFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
475 "delimiter",
SDDS_STRING, &spreadsheetDelimiter, 1, SPREADSHEET_DELIMITER,
476 "quotemark",
SDDS_STRING, &spreadsheetQuoteMark, 1, SPREADSHEET_QUOTEMARK,
477 "nolabels", -1, NULL, 0, SPREADSHEET_NOLABELS,
"csv", -1, NULL, 0, SPREADSHEET_CSV,
479 SDDS_Bomb(
"invalid -spreadsheet syntax");
480 if (!spreadsheetDelimiter || !(spreadsheetFlags & SPREADSHEET_DELIMITER))
481 spreadsheetDelimiter =
"\t";
482 if (spreadsheetFlags & SPREADSHEET_CSV) {
483 spreadsheetDelimiter =
",";
484 spreadsheetFlags |= SPREADSHEET_DELIMITER;
485 spreadsheetFlags |= SPREADSHEET_QUOTEMARK;
486 spreadsheetQuoteMark =
"\"";
490 spreadsheetFlags |= SPREADSHEET_ON;
494 s_arg[i_arg].n_items--;
495 pagination.lines = 66;
496 if (!
scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
497 "lines",
SDDS_LONG, &pagination.lines, 1, 0,
498 "notitle", -1, NULL, 0, PAGINATION_NOTITLE,
499 "nolabels", -1, NULL, 0, PAGINATION_NOLABELS, NULL) ||
500 pagination.lines <= 3)
501 SDDS_Bomb(
"invalid -paginate syntax/values");
502 pagination.flags |= PAGINATION_ON;
507 case SET_POSTPAGELINES:
508 if (s_arg[i_arg].n_items != 2 || sscanf(s_arg[i_arg].list[1],
"%ld", &postPageLines) != 1)
509 SDDS_Bomb(
"invalid -postPageLines syntax/values");
514 case SET_BUFFERLINES:
515 if (s_arg[i_arg].n_items < 2)
516 SDDS_Bomb(
"invalid -bufferLines syntax");
517 if (sscanf(s_arg[i_arg].list[1],
"%ld", &bufferLines) != 1 || bufferLines < 0)
518 SDDS_Bomb(
"invalid -bufferLines syntax or value");
520 case SET_LATEXFORMAT:
521 s_arg[i_arg].n_items--;
525 if (!
scanItemList(&latexFormat, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
526 "longtable", -1, NULL, 0, LATEX_LONGTABLE,
527 "booktable", -1, NULL, 0, LATEX_BOOKTABLE,
528 "sideways", -1, NULL, 0, LATEX_SIDEWAYS,
530 "caption",
SDDS_STRING, &latexCaption, 1, LATEX_CAPTION,
531 "comment",
SDDS_STRING, &latexComment, 1, LATEX_COMMENT,
533 "translate",
SDDS_STRING, &latexTranslationFile, 1, LATEX_TRANSLATE,
534 "justify",
SDDS_STRING, &latexJustify, 1, LATEX_JUSTIFY,
535 "complete", -1, NULL, 0, LATEX_COMPLETE, NULL))
536 SDDS_Bomb(
"invalid -latexFormat syntax/values");
537 latexFormat |= LATEX_FORMAT;
538 if (latexFormat & LATEX_LONGTABLE && latexFormat & LATEX_SIDEWAYS)
539 SDDS_Bomb(
"invalid -latexFormat syntax/values: give only one of longtable and sideways");
542 s_arg[i_arg].n_items--;
544 if (!
scanItemList(&htmlFormat, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
545 "caption",
SDDS_STRING, &htmlCaption, 1, HTML_CAPTION,
546 "translate",
SDDS_STRING, &htmlTranslationFile, 1, HTML_TRANSLATE, NULL))
547 SDDS_Bomb(
"invalid -htmlFormat syntax/values");
548 htmlFormat |= HTML_FORMAT;
551 fprintf(stderr,
"error: unknown switch: %s\n", s_arg[i_arg].list[0]);
557 input = s_arg[i_arg].list[0];
559 output = s_arg[i_arg].list[0];
565 pipeFlags |= DEFAULT_STDOUT;
566 processFilenames(
"sddsprintout", &input, &output, pipeFlags, noWarnings, NULL);
568 if (formatDefaultArgs)
569 changeDefaultFormats(formatDefaultArg, formatDefaultArgs, noWarnings);
573 SDDS_Bomb(
"-pageAdvance and -postPageLines are incompatible");
574 if (pagination.flags & PAGINATION_ON)
575 SDDS_Bomb(
"-pageAdvance and -paginate are incompatible");
577 if (pagination.flags & PAGINATION_ON && postPageLines)
578 SDDS_Bomb(
"-postPageLines and -paginate are incompatible");
580 if (!printColumns && !printParameters && !printArrays)
581 SDDS_Bomb(
"you must specify at least one of -columns, -parameters, or -arrays");
582 if (fromPage && toPage && fromPage > toPage)
583 SDDS_Bomb(
"invalid -fromPage and -toPage");
584 if (latexFormat && htmlFormat)
585 SDDS_Bomb(
"-latexFormat and -htmlFormat are incompatible");
587 if (latexFormat & LATEX_TRANSLATE)
588 TranslationTable = readTranslationTable(latexTranslationFile);
589 if (htmlFormat & HTML_TRANSLATE)
590 TranslationTable = readTranslationTable(htmlTranslationFile);
598 if (output && !(fpOut = fopen(output,
"w")))
601 printColumns = processPrintColumns(&printColumn, printColumns, &SDDS_dataset, noWarnings,
602 spreadsheetFlags, CSV, latexFormat, TranslationTable, htmlFormat);
603 printParameters = processPrintParameters(&printParameter, printParameters, &SDDS_dataset, noWarnings, noLabels, CSV);
609 pagination.flags |= noTitle ? PAGINATION_NOTITLE : 0;
611 title =
tmalloc(
sizeof(*title) * ((input ? strlen(input) : 10) + 100));
613 sprintf(title,
"Printout for SDDS file %s", input ? input :
"stdin");
615 sprintf(title,
"Printout for SDDS file %s%s", input ? input :
"stdin", latexFormat ?
"" :
"\n");
619 if (printArrays || printParameters || !printColumns)
620 SDDS_Bomb(
"Can't create schFile except for pure column printout.");
621 CreateSCHFile(schFile, input, spreadsheetFlags, spreadsheetDelimiter, spreadsheetQuoteMark, printColumn, printColumns);
625 if (latexFormat & LATEX_LABEL && latexLabel[0] ==
'@') {
626 memmove(latexLabel, latexLabel + 1, strlen(latexLabel));
628 fprintf(stderr,
"sddsprintout: error: parameter %s not found in input file\n", latexLabel);
631 latexFormat |= LATEX_LABEL_PARAM;
633 if (latexFormat & LATEX_CAPTION && latexCaption[0] ==
'@') {
634 memmove(latexCaption, latexCaption + 1, strlen(latexCaption));
636 fprintf(stderr,
"sddsprintout: error: parameter %s not found in input file\n", latexCaption);
639 latexFormat |= LATEX_CAPTION_PARAM;
641 if (latexFormat & LATEX_COMPLETE) {
642 fprintf(fpOut,
"\\documentclass{report}\n\\pagestyle{empty}\n");
643 if (latexFormat & LATEX_BOOKTABLE)
644 fprintf(fpOut,
"\\usepackage{booktabs}\n");
645 if (latexFormat & LATEX_SIDEWAYS)
646 fprintf(fpOut,
"\\usepackage{rotating}\n");
647 fprintf(fpOut,
"\\begin{document}\n");
650 fprintf(fpOut,
"%% %s\n", latexComment);
656 while ((pageNumber =
SDDS_ReadPageSparse(&SDDS_dataset, 0, (printColumns || SDDS_dataset.layout.data_mode.column_major) ? 1 : 1000000, 0, 0)) > 0) {
657 if ((fromPage && pageNumber < fromPage) || (toPage && pageNumber > toPage))
659 if (pagination.flags & PAGINATION_ON) {
661 fputc(
'\014', fpOut);
662 pagination.currentLine = 1;
665 pagination.currentLine += printPageTitle(fpOut, title);
669 printPageTitle(fpOut, title);
670 }
else if (pageAdvance)
671 fputc(
'\014', fpOut);
672 else if (postPageLines > 0) {
673 long line = postPageLines;
678 if (!latexFormat && !htmlFormat)
679 doPrintParameters(&SDDS_dataset, printParameter, printParameters, width, fpOut, spreadsheetFlags,
680 spreadsheetDelimiter, spreadsheetQuoteMark, &pagination, title, noLabels);
682 latexCaptionBuffer = latexLabelBuffer = NULL;
683 if (latexFormat & LATEX_CAPTION_PARAM && !(latexCaptionBuffer =
SDDS_GetParameterAsString(&SDDS_dataset, latexCaption, NULL))) {
685 snprintf(buffer, 1024,
"Error: can't read latex caption parameter %s\n", latexCaption);
688 if (latexFormat & LATEX_LABEL_PARAM && !(latexLabelBuffer =
SDDS_GetParameterAsString(&SDDS_dataset, latexLabel, NULL))) {
690 snprintf(buffer, 1024,
"Error: can't read latex label parameter %s\n", latexLabel);
693 doPrintColumns(&SDDS_dataset, printColumn, printColumns, width, fpOut, spreadsheetFlags, spreadsheetDelimiter,
694 spreadsheetQuoteMark, latexFormat,
695 latexFormat & LATEX_CAPTION_PARAM ? latexCaptionBuffer : latexCaption,
696 latexFormat & LATEX_LABEL_PARAM ? latexLabelBuffer : latexLabel,
697 latexGroup, htmlFormat, htmlCaption,
698 &pagination, title, noLabels);
699 if (latexFormat & LATEX_CAPTION_PARAM && latexCaptionBuffer)
700 free(latexCaptionBuffer);
701 if (latexFormat & LATEX_LABEL_PARAM && latexLabelBuffer)
702 free(latexLabelBuffer);
704 for (i = 0; i < bufferLines; i++)
712 for (i = 0; i < printColumns; i++) {
713 if (printColumn[i].headers) {
714 for (
long j = 0; j < printColumn[i].headers; j++) {
715 free(printColumn[i].header[j]);
717 free(printColumn[i].header);
720 if (latexFormat & LATEX_COMPLETE)
721 fprintf(fpOut,
"\\end{document}\n");
729 unsigned long spreadsheetFlags,
long csv,
unsigned long latexFormat, htab *TranslationTable,
unsigned long htmlFormat) {
731 long i, irequest, iname, printColumns, names, *columnUsed, columnLimit;
733 char **name, *units, *format;
735 if (printRequests < 1 || !(printRequest = *printRequestPtr))
739 fprintf(stderr,
"warning: no column data in input file\n");
742 columnUsed =
tmalloc(
sizeof(*columnUsed) * columnLimit);
743 for (i = 0; i < columnLimit; i++)
745 printColumn =
tmalloc(
sizeof(*printColumn) * columnLimit);
749 for (irequest = 0; irequest < printRequests; irequest++) {
750 if ((names =
SDDS_MatchColumns(inTable, &name, SDDS_MATCH_STRING, FIND_ANY_TYPE, printRequest[irequest].name, SDDS_0_PREVIOUS | SDDS_OR)) > 0) {
751 for (iname = 0; iname < names; iname++) {
754 if (!columnUsed[index]) {
758 printColumn[printColumns].index = index;
759 if (iname == names - 1)
760 printColumn[printColumns].endsLine = printRequest[irequest].endsLine;
762 printColumn[printColumns].endsLine = 0;
764 printColumn[printColumns].blankLines = printRequest[irequest].blankLines;
769 SDDS_CopyString(&printColumn[printColumns].format, csvFormat[printColumn[printColumns].type - 1]);
771 if (printRequest[irequest].format) {
772 if (printRequest[irequest].format[0] !=
'@') {
774 fprintf(stderr,
"error: given format (\"%s\") for column %s is invalid\n",
775 printRequest[irequest].format, name[iname]);
782 fprintf(stderr,
"error: given format column (\"%s\") for column %s is absent or not string type\n",
783 printRequest[irequest].format + 1, name[iname]);
788 SDDS_CopyString(&printColumn[printColumns].format, printRequest[irequest].format);
790 SDDS_CopyString(&printColumn[printColumns].format, defaultFormat[printColumn[printColumns].type - 1]);
794 printColumn[printColumns].headers =
795 makeColumnHeaders(&printColumn[printColumns].header, &printColumn[printColumns].fieldWidth,
796 printRequest[irequest].label ? printRequest[irequest].label : name[iname],
797 printRequest[irequest].editLabel,
798 printRequest[irequest].noUnits ? NULL : units, printRequest[irequest].factor,
799 &printColumn[printColumns].format, spreadsheetFlags, latexFormat, TranslationTable, htmlFormat);
801 fprintf(stderr,
"%s has format >%s<\n",
802 printRequest[irequest].label ? printRequest[irequest].label : name[iname], printColumn[printColumns].format);
804 printColumn[printColumns].data = NULL;
805 printColumn[printColumns].factor = printRequest[irequest].factor;
807 columnUsed[index] = 1;
814 }
else if (names < 0)
816 else if (!noWarnings)
817 fprintf(stderr,
"warning: no column matches %s\n", printRequest[irequest].name);
818 free(printRequest[irequest].name);
819 if (printRequest[irequest].format)
820 free(printRequest[irequest].format);
823 *printRequestPtr = printColumn;
828 long noWarnings,
long noLabels,
long csv) {
830 long i, irequest, iname, printParameters, names, *parameterUsed, parameterLimit, maxFieldWidth, index;
831 char **name, *units, *format;
833 if (printRequests < 1 || !(printRequest = *printRequestPtr))
837 fprintf(stderr,
"warning: no parameter data in input file\n");
840 parameterUsed =
tmalloc(
sizeof(*parameterUsed) * parameterLimit);
841 for (i = 0; i < parameterLimit; i++)
842 parameterUsed[i] = 0;
843 printParameter =
tmalloc(
sizeof(*printParameter) * parameterLimit);
847 for (irequest = 0; irequest < printRequests; irequest++) {
848 if ((names =
SDDS_MatchParameters(inTable, &name, SDDS_MATCH_STRING, FIND_ANY_TYPE, printRequest[irequest].name, SDDS_0_PREVIOUS | SDDS_OR)) > 0) {
849 for (iname = 0; iname < names; iname++) {
852 if (!parameterUsed[index]) {
856 printParameter[printParameters].index = index;
858 if (iname == names - 1)
859 printParameter[printParameters].endsLine = printRequest[irequest].endsLine;
860 printParameter[printParameters].blankLines = printRequest[irequest].blankLines;
865 SDDS_CopyString(&printParameter[printParameters].format, csvFormat[printParameter[printParameters].type - 1]);
867 if (printRequest[irequest].format) {
869 fprintf(stderr,
"error: given format (\"%s\") for parameter %s is invalid\n", printRequest[irequest].format, name[iname]);
872 SDDS_CopyString(&printParameter[printParameters].format, printRequest[irequest].format);
874 SDDS_CopyString(&printParameter[printParameters].format, defaultFormat[printParameter[printParameters].type - 1]);
880 printParameter[printParameters].label =
881 makeParameterLabel(&printParameter[printParameters].fieldWidth, printRequest[irequest].label ? printRequest[irequest].label : name[iname], printRequest[irequest].editLabel, units, printRequest[irequest].factor, printParameter[printParameters].format);
883 printParameter[printParameters].label =
"";
885 if (printParameter[printParameters].fieldWidth > maxFieldWidth)
886 maxFieldWidth = printParameter[printParameters].fieldWidth;
887 printParameter[printParameters].data = NULL;
888 printParameter[printParameters].factor = printRequest[irequest].factor;
890 parameterUsed[index] = 1;
897 }
else if (names < 0)
899 else if (!noWarnings)
900 fprintf(stderr,
"warning: no parameter matches %s\n", printRequest[irequest].name);
901 free(printRequest[irequest].name);
902 if (printRequest[irequest].format)
903 free(printRequest[irequest].format);
905 for (i = 0; i < printParameters; i++) {
907 if (printParameter[i].fieldWidth < maxFieldWidth) {
908 ptr =
tmalloc(
sizeof(*ptr) * (maxFieldWidth + 1));
909 strcpy(ptr, printParameter[i].label);
911 free(printParameter[i].label);
912 printParameter[i].label = ptr;
913 printParameter[i].fieldWidth = maxFieldWidth;
917 *printRequestPtr = printParameter;
918 return printParameters;
921#if SDDS_NUM_TYPES != 11
922# error "number of SDDS types is not 11 as expected"
925void setDefaultFormats(
void) {
952long changeDefaultFormats(
char **argv,
long argc,
long noWarnings) {
955 static char formatbuffer[100], formatbuffer2[100];
957 for (i = 0; i < argc; i++) {
958 if (!(format = strchr(argv[i],
'='))) {
959 fprintf(stderr,
"-formatDefault syntax error with keyword \"%s\"\n", argv[i]);
964 fprintf(stderr,
"-formatDefault error: unknown type \"%s\"\n", argv[i]);
968 fprintf(stderr,
"-formatDefault error: invalid format string \"%s\" for type \"%s\"\n", format, argv[i]);
971 free(defaultFormat[type - 1]);
975 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
980 if (!getFormatFieldLength(format, NULL) && !noWarnings)
981 fprintf(stderr,
"warning: no field length for default format \"%s\"---this will produce poor results\n", defaultFormat[type - 1]);
986long makeColumnHeaders(
char ***header,
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
987 char **format,
unsigned long spreadsheetHeaders,
unsigned long latexFormat, htab *TranslationTable,
unsigned long htmlFormat) {
988 long formatWidth, unitsWidth, nameWidth, headers, i, formatPadding, formatExtraChars;
989 static char buffer[1024], buffer2[1026];
990 static char nameBuffer[1024];
994 if (latexFormat & LATEX_TRANSLATE) {
995 name = findTranslation(TranslationTable, name);
996 units = findTranslation(TranslationTable, units);
998 if (htmlFormat & HTML_TRANSLATE) {
999 name = findTranslation(TranslationTable, name);
1000 units = findTranslation(TranslationTable, units);
1003 units = modifyUnitsWithFactor(units, 1. / factor, latexFormat);
1006 strcpy(nameBuffer, name);
1008 SDDS_Bomb(
"Problem editing column label");
1013 fprintf(stderr,
"name: >%s< format: >%s<\n", name, *format ? *format :
"NULL");
1017 unitsWidth = units ? strlen(units) : 0;
1018 nameWidth = strlen(name);
1019 *fieldWidth = unitsWidth > nameWidth ? unitsWidth : nameWidth;
1021 if (!(spreadsheetHeaders & SPREADSHEET_ON)) {
1026 if (!*format || (*format && (*format)[0] !=
'@')) {
1028 formatWidth = getFormatFieldLength(*format, &formatExtraChars);
1029 if ((formatWidth + formatExtraChars) > *fieldWidth)
1030 *fieldWidth = formatWidth + formatExtraChars;
1033 if (*fieldWidth < 2)
1036 fprintf(stderr,
"fieldWidth = %ld, formatWidth = %ld, formatExtra = %ld\n", *fieldWidth, formatWidth, formatExtraChars);
1038 if (*format && (formatPadding = (*fieldWidth - 2 - formatExtraChars) - formatWidth) > 0) {
1043 formatWidth = *fieldWidth - 2 - formatExtraChars;
1044 replaceFormatWidth(buffer, *format, formatWidth);
1046 fprintf(stderr,
"Adjusted format width to %ld: >%s<\n", formatWidth, buffer);
1049 sprintf(buffer2,
" %s ", buffer);
1052 sprintf(buffer,
" %s ", *format);
1059 *header =
tmalloc(
sizeof(**header) * (headers = 2));
1060 for (i = 0; i < headers; i++)
1061 (*header)[i] =
tmalloc(
sizeof(***header) * (*fieldWidth + 1));
1064 copyAndPad((*header)[0], name, nameWidth, *fieldWidth);
1066 copyAndPad((*header)[1], units, unitsWidth, *fieldWidth);
1068 fprintf(stderr,
"header0 padded to %ld: >%s<\n", *fieldWidth, (*header)[0]);
1069 (*header)[0][0] =
'+';
1070 (*header)[0][strlen((*header)[0]) - 1] =
'-';
1071 fprintf(stderr,
"header1 padded to %ld: >%s<\n", *fieldWidth, (*header)[1]);
1072 (*header)[1][0] =
'+';
1073 (*header)[1][strlen((*header)[1]) - 1] =
'-';
1079void copyAndPad(
char *target,
char *source,
long sourceWidth,
long targetWidth) {
1080 long i, head, tail, excess;
1081 if ((excess = targetWidth - sourceWidth) < 0)
1082 SDDS_Bomb(
"negative excess in copyAndPad()---programming error");
1083 head = tail = excess / 2;
1084 if ((i = excess - head - tail))
1086 for (i = 0; i < head; i++)
1090 strcat(target, source);
1091 for (i = strlen(target); i < targetWidth; i++)
1118char *makeParameterLabel(
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
char *format) {
1119 long formatWidth, labelWidth, extraFormatChars;
1121 static char buffer[1024];
1124 strcpy(buffer, name);
1126 SDDS_Bomb(
"Problem editing parameter label");
1130 *fieldWidth = (labelWidth = strlen(name) + 4 + (units && !
SDDS_StringIsBlank(units) ? strlen(units) + 3 : 0)) + (formatWidth = getFormatFieldLength(format, &extraFormatChars));
1131 *fieldWidth += extraFormatChars;
1132 if (*fieldWidth < 2)
1134 label =
tmalloc(
sizeof(*label) * (labelWidth + 1));
1136 units = modifyUnitsWithFactor(units, 1. / factor, 0);
1138 sprintf(label,
"%s (%s) = ", name, units);
1140 sprintf(label,
"%s = ", name);
1144long getFormatFieldLength(
char *format,
long *extraChars) {
1151 while (*format && *format !=
'%')
1153 if (*format !=
'%') {
1154 fprintf(stderr,
"Bad format string: %s\n", format0);
1158 *extraChars = format - format0;
1159 while (*format && !isdigit(*format))
1164 if (!*format || !isdigit(*format))
1167 width = atoi(format);
1169 while (isdigit(*format) || *format ==
'.')
1171 if (*format ==
'l' || *format ==
'h')
1176 *extraChars += strlen(format);
1182 FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
1183 char *spreadsheetQuoteMark,
PAGINATION *pagination,
char *title,
long noLabels) {
1184 long parameter, outputRow, length;
1185 char printBuffer[2 * SDDS_MAXLINE];
1186 static void **dataBuffer = NULL;
1189 if (!printParameters)
1191 if (!dataBuffer && !(dataBuffer = malloc(
sizeof(
void *) * 4)))
1192 SDDS_Bomb(
"Allocation failure in doPrintParameters");
1195 for (parameter = 0; parameter < printParameters; parameter++) {
1197 if (printParameter[parameter].format && printParameter[parameter].format[0] ==
'@' &&
1199 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1200 if (!
SDDS_GetParameter(inTable, printParameter[parameter].name, &dataBuffer[0]))
1201 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1203 format ? format : printParameter[parameter].format, printBuffer,
1204 SDDS_PRINT_NOQUOTES, printParameter[parameter].factor))
1205 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1206 if (spreadsheetFlags & SPREADSHEET_ON) {
1207 if (!(spreadsheetFlags & SPREADSHEET_NOLABELS))
1208 fprintf(fpOut,
"%s%s", printParameter[parameter].name, spreadsheetDelimiter);
1209 fprintf(fpOut,
"%s%s%s\n", spreadsheetQuoteMark, printBuffer, spreadsheetQuoteMark);
1212 length = strlen(printParameter[parameter].label) + strlen(printBuffer) + (parameter ? 2 : 0);
1213 if ((parameter && printParameter[parameter - 1].endsLine) || (outputRow && (outputRow + length) > width)) {
1215 checkPagination(fpOut, pagination, title);
1216 outputRow = length - 2;
1217 if (parameter && printParameter[parameter - 1].blankLines && printParameter[parameter - 1].endsLine) {
1219 for (i = 1; i < printParameter[parameter - 1].blankLines; i++) {
1220 checkPagination(fpOut, pagination, title);
1227 outputRow += length;
1229 fputs(printParameter[parameter].label, fpOut);
1230 fputs(printBuffer, fpOut);
1231 if (printParameter[parameter].type ==
SDDS_STRING && dataBuffer[0])
1232 free((
char *)dataBuffer[0]);
1234 if (!(spreadsheetFlags & SPREADSHEET_ON)) {
1235 checkPagination(fpOut, pagination, title);
1237 checkPagination(fpOut, pagination, title);
1242char **makeListOfNames(
char *
string,
long *names) {
1246 *names = characterCount(
string,
',') + 1;
1247 name =
tmalloc(
sizeof(*name) * *names);
1248 for (iName = 0;
string && iName < *names; iName++) {
1249 if ((ptr = strchr(
string,
',')))
1254 if (iName != *names)
1255 SDDS_Bomb(
"problem occurred scanning list of names");
1259long characterCount(
char *
string,
char c) {
1262 while ((ptr = strchr(
string, c))) {
1269long printPageTitle(FILE *fpOut,
char *title) {
1273 fprintf(fpOut,
"%s\n", title);
1276 while ((ptr = strchr(ptr,
'\n'))) {
1283long checkPagination(FILE *fpOut,
PAGINATION *pagination,
char *title) {
1284 if (!(pagination->flags & PAGINATION_ON))
1286 if ((pagination->currentLine += 1) >= pagination->lines) {
1287 fputc(
'\014', fpOut);
1288 pagination->currentLine = 0;
1289 if (!(pagination->flags & PAGINATION_NOTITLE))
1290 pagination->currentLine += printPageTitle(fpOut, title);
1296void printColumnHeaders(FILE *fpOut,
PRINT_COLUMN *printColumn,
long printColumns,
long width,
1297 PAGINATION *pagination,
long latexFormat,
char *latexTitle,
long htmlFormat,
char *htmlTitle) {
1299 long row, column, header, outputRow, maxOutputRow, length, noUnitsLine;
1302 if (latexFormat & LATEX_LONGTABLE) {
1303 fprintf(fpOut,
"\\begin{longtable}{");
1304 if (latexFormat & LATEX_JUSTIFY) {
1305 fprintf(fpOut,
"%s", latexJustify);
1307 for (column = 0; column < printColumns; column++)
1308 fprintf(fpOut,
"%s", latexFormat & LATEX_BOOKTABLE ?
"c" : (column == 0 ?
"|c|" :
"c|"));
1310 fprintf(fpOut,
"}\n");
1311 if (latexTitle && strlen(latexTitle)) {
1312 fprintf(fpOut,
"\\caption{%s}\\\\\n", latexTitle ? makeTexSafeString(latexTitle) :
"No caption");
1315 fprintf(fpOut,
"\\begin{%s}[htb]", latexFormat & LATEX_SIDEWAYS ?
"sidewaystable" :
"table");
1316 if (latexTitle && strlen(latexTitle)) {
1317 fprintf(fpOut,
"\\caption{%s}\n", latexTitle ? makeTexSafeString(latexTitle) :
"No caption");
1319 fprintf(fpOut,
"\n");
1320 fprintf(fpOut,
"\\begin{center}\n");
1321 fprintf(fpOut,
"\\begin{tabular}{");
1322 if (latexFormat & LATEX_JUSTIFY) {
1323 fprintf(fpOut,
"%s", latexJustify);
1325 for (column = 0; column < printColumns; column++)
1326 fprintf(fpOut,
"%s", latexFormat & LATEX_BOOKTABLE ?
"c" : (column == 0 ?
"|c|" :
"c|"));
1328 fprintf(fpOut,
"}\n");
1331 if (latexFormat & LATEX_BOOKTABLE)
1332 fprintf(fpOut,
"\\toprule\n");
1334 fprintf(fpOut,
"\\hline\n");
1337 fprintf(fpOut,
"<table style=\"width:100%%\">\n");
1338 if (htmlTitle && strlen(htmlTitle)) {
1339 fprintf(fpOut,
" <caption>%s</caption>\n", htmlTitle);
1344 for (column = 0; column < printColumns; column++) {
1348 if (column != printColumns)
1352 for (header = 0; header < printColumn[0].headers; header++) {
1354 if (noUnitsLine && header == 1)
1357 fprintf(fpOut,
" <tr>\n");
1359 for (column = 0; column < printColumns; column++) {
1360 label = printColumn[column].header[header];
1361 length = strlen(label);
1362 if (!latexFormat && !htmlFormat && ((column && printColumn[column - 1].endsLine) || (width && outputRow && (outputRow + length) > width))) {
1363 printColumn[column - 1].endsLine = 1;
1365 pagination->currentLine++;
1369 if (latexFormat & LATEX_TRANSLATE && strchr(label,
'$'))
1370 fputs(label, fpOut);
1371 else if (strpbrk(label,
"_^{}\\"))
1372 fprintf(fpOut,
"$%s$", label);
1374 fputs(makeTexSafeString(printColumn[column].header[header]), fpOut);
1375 fputs(column == printColumns - 1 ? (latexFormat & LATEX_BOOKTABLE ?
" \\\\ \n" :
" \\\\ \\hline") :
" & ", fpOut);
1376 }
else if (htmlFormat) {
1377 fprintf(fpOut,
" <th>%s</th>\n",
trim_spaces(label));
1379 fputs(label, fpOut);
1380 outputRow += length;
1381 if (outputRow > maxOutputRow)
1382 maxOutputRow = outputRow;
1386 fprintf(fpOut,
" </tr>\n");
1389 pagination->currentLine++;
1391 if (!latexFormat && !htmlFormat) {
1392 for (row = 0; row < maxOutputRow; row++)
1395 }
else if (latexFormat & LATEX_BOOKTABLE) {
1396 fputs(
"\\midrule\n", fpOut);
1398 pagination->currentLine++;
1402 long width, FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
char *spreadsheetQuoteMark,
1403 long latexFormat,
char *latexTitle,
char *latexLabel,
char *latexGroupColumn,
1404 long htmlFormat,
char *htmlTitle,
1405 PAGINATION *pagination,
char *title,
long noLabels) {
1407 int64_t row, rows, nGroups, maxGroupLength, groupLength;
1409 char **groupData = NULL;
1410 char ***format = NULL;
1411 char printBuffer[16 * SDDS_MAXLINE];
1417 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1421 if ((latexTitle != NULL) && (latexTitle[0] ==
'@')) {
1422 latexTitle = latexTitle + 1;
1426 if ((htmlTitle != NULL) && (htmlTitle[0] ==
'@')) {
1427 htmlTitle = htmlTitle + 1;
1431 if (!(spreadsheetFlags & SPREADSHEET_ON) && !noLabels)
1432 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination,
1433 latexFormat, latexTitle ? latexTitle : title,
1434 htmlFormat, htmlTitle ? htmlTitle : title);
1435 else if (!(spreadsheetFlags & SPREADSHEET_NOLABELS) && !noLabels) {
1436 for (column = 0; column < printColumns; column++)
1437 fprintf(fpOut,
"%s%s", printColumn[column].name, column != printColumns - 1 ? spreadsheetDelimiter :
"\n");
1441 maxGroupLength = groupLength = 1;
1442 if (latexFormat & LATEX_GROUP) {
1444 fprintf(stderr,
"Error: unable to get data for column %s\n", latexGroupColumn);
1445 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1447 for (row = 1; row < rows; row++) {
1448 if (strcmp(groupData[row], groupData[row - 1])) {
1449 if (groupLength > maxGroupLength)
1450 maxGroupLength = groupLength;
1457 if (groupLength > maxGroupLength)
1458 maxGroupLength = groupLength;
1460 fprintf(fpOut,
"%% nGroups = %" PRId64
", maxGroupLength = %" PRId64
"\n", nGroups, maxGroupLength);
1463 data =
tmalloc(
sizeof(*data) * printColumns);
1464 format =
tmalloc(
sizeof(*format) * printColumns);
1465 for (column = 0; column < printColumns; column++) {
1466 if (!(data[column] =
SDDS_GetColumn(inTable, printColumn[column].name))) {
1467 fprintf(stderr,
"Error: unable to get data for column %s\n", printColumn[column].name);
1468 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1470 format[column] = NULL;
1471 if (printColumn[column].format && printColumn[column].format[0] ==
'@') {
1472 if (!(format[column] =
SDDS_GetColumn(inTable, printColumn[column].format + 1))) {
1473 fprintf(stderr,
"Error: unable to get format data for column %s from %s\n",
1474 printColumn[column].name, printColumn[column].format + 1);
1475 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1479 for (row = 0; row < rows; row++) {
1482 fprintf(fpOut,
" <tr bgcolor=\"#ddd\">\n");
1484 fprintf(fpOut,
" <tr>\n");
1486 if (latexFormat && nGroups > 1) {
1487 if (row == 0 || strcmp(groupData[row], groupData[row - 1])) {
1488 if (row != 0 && latexFormat & LATEX_BOOKTABLE)
1489 fprintf(fpOut,
"\\midrule\n");
1490 fprintf(fpOut,
"\\multicolumn{%ld}{l}{\\bf %s} \\\\ \n", printColumns, groupData[row]);
1493 for (column = 0; column < printColumns; column++) {
1495 fprintf(fpOut,
" <td style=\"text-align:center\">");
1498 sprintf(printBuffer, format[column] ? format[column][row] : printColumn[column].format,
" ");
1501 format[column] ? format[column][row] : printColumn[column].format,
1502 printBuffer, SDDS_PRINT_NOQUOTES,
1503 printColumn[column].factor)) {
1504 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1507 if (spreadsheetFlags & SPREADSHEET_ON) {
1508 fprintf(fpOut,
"%s%s%s%s", spreadsheetQuoteMark, printBuffer, spreadsheetQuoteMark, column != printColumns - 1 ? spreadsheetDelimiter :
"\n");
1513 fputs(makeTexExponentialString(printBuffer), fpOut);
1515 fputs(makeTexSafeString(printBuffer), fpOut);
1516 fputs(column != printColumns - 1 ?
" & " : (latexFormat & LATEX_BOOKTABLE ?
" \\\\ " :
" \\\\ \\hline"), fpOut);
1521 fprintf(fpOut,
"</td>\n");
1524 fputs(printBuffer, fpOut);
1525 if (printColumn[column].endsLine) {
1528 if (checkPagination(fpOut, pagination, title))
1529 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination, latexFormat, latexTitle ? latexTitle : title, htmlFormat, htmlTitle ? htmlTitle : title);
1530 for (i = 0; i < printColumn[column].blankLines; i++) {
1532 if (checkPagination(fpOut, pagination, title))
1533 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination, latexFormat, latexTitle ? latexTitle : title, htmlFormat, htmlTitle ? htmlTitle : title);
1538 fprintf(fpOut,
" </tr>\n");
1540 if (!(spreadsheetFlags & SPREADSHEET_ON) && !printColumn[column - 1].endsLine) {
1542 if (!latexFormat && !htmlFormat && checkPagination(fpOut, pagination, title))
1543 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination, latexFormat, latexTitle ? latexTitle : title, htmlFormat, htmlTitle ? htmlTitle : title);
1548 if (latexFormat & LATEX_BOOKTABLE)
1549 fputs(
"\\bottomrule\n", fpOut);
1550 if (latexFormat & LATEX_LONGTABLE) {
1552 fprintf(fpOut,
"\\label{%s}\n", latexLabel);
1554 fprintf(fpOut,
"%%\\label{%s}\n",
"tab:labelHere");
1555 fprintf(fpOut,
"\\end{longtable}\n");
1557 fprintf(fpOut,
"\\end{tabular}\n");
1558 fprintf(fpOut,
"\\end{center}\n");
1560 fprintf(fpOut,
"\\label{%s}\n", latexLabel);
1562 fprintf(fpOut,
"%%\\label{%s}\n",
"tab:labelHere");
1563 fprintf(fpOut,
"\\end{%s}\n", latexFormat & LATEX_SIDEWAYS ?
"sidewaystable" :
"table");
1567 fprintf(fpOut,
"</table><br>\n");
1569 for (column = 0; column < printColumns; column++) {
1572 free(format[column]);
1578void replaceFormatWidth(
char *buffer,
char *format,
long width) {
1582 if (*ptr ==
'%' && *(ptr + 1) !=
'%')
1588 if (*(ptr + 1) ==
'-') {
1589 sprintf(buffer,
"%s%%-%ld", format, width);
1592 sprintf(buffer,
"%s%%%ld", format, width);
1594 while (*ptr && isdigit(*ptr))
1596 strcat(buffer, ptr);
1598 strcpy(buffer, format);
1602void CreateSCHFile(
char *output,
char *input,
unsigned long flags,
char *delimiter,
1603 char *quote,
PRINT_COLUMN *printColumn,
long printColumns) {
1607 if (!(fp = fopen(output,
"w")))
1608 SDDS_Bomb(
"Couldn't open SCHFile for writing.");
1609 fprintf(fp,
"[%s]\nFiletype=Delimited\nDelimiter=%s\nSeparator=%s\nCharSet=ascii\n", input ? input :
"NULL", quote, delimiter);
1610 for (i = 0; i < printColumns; i++) {
1611 printColumn[i].useDefaultFormat = 1;
1612 fprintf(fp,
"Field%ld=%s,%s,00,00,00\n\n", i + 1, printColumn[i].name,
SDDS_NUMERIC_TYPE(printColumn[i].type) ?
"Float" :
"Char");
1616char *makeTexSafeString(
char *source) {
1617 static char *buffer = NULL;
1618 static long buflen = 0;
1619 long index = 0, length, inMath = 0;
1622 length = strlen(source);
1623 if (length > (buflen - 2)) {
1624 buflen = length * 2 + 2;
1625 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * buflen)))
1630 if (*source ==
'_' || *source ==
'^' || *source ==
'{' || *source ==
'}' || *source ==
'%' || *source ==
'#') {
1632 buffer[index++] =
'\\';
1633 buffer[index++] = *source++;
1634 }
else if (*source ==
'<' || *source ==
'>' || *source ==
'|') {
1636 buffer[index++] =
'$';
1637 buffer[index++] = *source++;
1639 buffer[index++] =
'$';
1643 buffer[index++] = *source++;
1645 if (index >= (buflen - 1)) {
1647 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * buflen)))
1655char *makeTexExponentialString(
char *text) {
1659 if ((ptr1 = ptr2 = strchr(text,
'e')) || (ptr1 = ptr2 = strchr(text,
'E'))) {
1661 while (*ptr2 && !(isdigit(*ptr2) || *ptr2 ==
'-'))
1665 if (strlen(ptr2) >= 100)
1666 SDDS_Bomb(
"buffer overflow in makeTexExponentialString");
1667 sscanf(ptr2,
"%ld", &exponent);
1669 if (exponent != 0) {
1670 sprintf(buffer,
"%ld", exponent);
1671 sprintf(ptr1,
"$\\times 10^{%s}$", buffer);
1677htab *readTranslationTable(
char *TranslationFile) {
1679 fprintf(stderr,
"The latex and html options in sddsprintout are not available on Windows\n");
1684 char **oldName, **newName;
1689 (rows = SDDS_RowCount(&SDDSin)) <= 0 ||
1692 SDDS_Bomb(
"Problem with translation file");
1695 hadd(ht, oldName[rows], strlen(oldName[rows]), newName[rows]);
1701char *findTranslation(htab *ht,
char *key) {
1703 SDDS_Bomb(
"The latex and html options in sddsprintout are not available on Windows");
1705 if (key && ht &&
hfind(ht, key, strlen(key)) == TRUE)
1706 return (
char *)hstuff(ht);
1711char *modifyUnitsWithFactor(
char *units0,
double factor,
unsigned long latexFormat) {
1712 char *units, buffer[100];
1714 units =
tmalloc(
sizeof(*units) * ((units0 ? strlen(units0) : 0) + 100));
1717 sprintf(buffer,
"%.2g", factor);
1718 sprintf(units,
"%s%s", makeTexExponentialString(buffer), units0 ? units0 :
"");
1720 sprintf(units,
"%.2g%s", factor, units0 ? units0 :
"");
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_GetParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified parameter in the SDDS dataset.
int32_t SDDS_GetColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Retrieves information about a specified column in the SDDS dataset.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
int32_t SDDS_VerifyPrintfFormat(const char *string, int32_t type)
Verifies that a printf format string is compatible with a specified data type.
int32_t SDDS_ParameterCount(SDDS_DATASET *page)
Retrieves the number of parameters in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_MatchParameters(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves parameter names from an SDDS dataset based on specified criteria.
int32_t SDDS_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
int32_t SDDS_SprintTypedValueFactor(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode, double factor)
Reallocates memory to a new size and zero-initializes the additional space.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_IdentifyType(char *typeName)
Identifies the SDDS data type based on its string name.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_MatchColumns(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves column names from an SDDS dataset based on specified criteria.
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CheckParameter(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a parameter exists in the SDDS dataset with the specified name, units, and type.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
long edit_string(char *text, char *edit)
Edits the provided text based on the specified edit commands.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
htab * hcreate(word logsize)
Create a hash table.
word hadd(htab *t, ub1 *key, ub4 keyl, void *stuff)
Add an item to the hash table.
word hfind(htab *t, ub1 *key, ub4 keyl)
Find an item with a given key in the hash table.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
char * pad_with_spaces(char *s, int n)
Adds a specified number of spaces to the end of a string.
int replaceString(char *t, char *s, char *orig, char *repl, long count_limit, long here)
Replace occurrences of one string with another string with additional options.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
void free_scanargs(SCANNED_ARG **scanned, int argc)
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.
char * trim_spaces(char *s)
Trims leading and trailing spaces from a string.