177#define SET_PARAMETERS 1
179#define SET_FROMPAGE 3
181#define SET_FORMATDEFAULTS 5
184#define SET_PAGEADVANCE 8
187#define SET_SPREADSHEET 11
188#define SET_PAGINATE 12
189#define SET_NOWARNINGS 13
190#define SET_POSTPAGELINES 14
191#define SET_NOLABELS 15
192#define SET_BUFFERLINES 16
193#define SET_LATEXFORMAT 17
194#define SET_HTMLFORMAT 18
197char *option[N_OPTIONS] = {
198 "columns",
"parameters",
"arrays",
"frompage",
"topage",
199 "formatdefaults",
"width",
"pipe",
"pageadvance",
"notitle",
"title",
200 "spreadsheet",
"paginate",
"nowarnings",
"postpagelines",
"nolabels",
201 "bufferlines",
"latexformat",
"htmlformat"};
203char *USAGE =
"sddsprintout [<SDDSinput>] [<outputfile>] [-pipe=[input][,output]] \n\
204[-columns[=<name-list>[,format={<string>|@<columnName>}][,label=<string>][,editLabel=<command>][,useDefaultFormat][,endsline][,blankLines=<number>]][,factor=<value>][,nounits]] \n\
205[-parameters[=<name-list>[,format={<string>|@<parameterName>}][,label=<string>][,editLabel=<command>][,useDefaultFormat][,endsline][,blankLines=<number]][,factor=<value>]] \n\
206[-array[=<name-list>[,format=<string>]] \n\
207[-fromPage=<number>] [-toPage=<number>] \n\
208[-formatDefaults=<SDDStype>=<format-string>[,...]]\n\
209[-width=<integer>] [-pageAdvance] [-paginate[=lines=<number>][,notitle][,nolabels]]\n\
210[-noTitle] [-title=<string>] [-noLabels] [-postPageLines=<number>]\n\
211[-spreadsheet[=delimiter=<string>][,quotemark=<string>][,nolabels][,csv][,schfile=<filename>]]\n\
212[-latexFormat[=longtable][,booktable][,sideways][,label={<string>|@<parameterName>}][,caption={<string>|@<parameterName>}][,group=<columnName>][,translate=<filename>][,justify=<codeList>][,complete][,comment=<string>]]\n\
213[-htmlFormat[=caption=<string>][,translate=<filename>]]\n\
215-spreadsheet=csv is the simple way of -spreadsheet=nolabels,quote=\",delimiter=\\, -notitle \n\
216Translation file for LaTeX mode has columns OldName and NewName, and can be used to translate symbols and units.\n\n\
217Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
219#define PAGINATION_ON 0x0001U
220#define PAGINATION_NOTITLE 0x0002U
221#define PAGINATION_NOLABELS 0x0004U
223#define LATEX_FORMAT 0x0001UL
224#define LATEX_LONGTABLE 0x0002UL
225#define LATEX_BOOKTABLE 0x0004UL
226#define LATEX_LABEL 0x0008UL
227#define LATEX_CAPTION 0x0010UL
228#define LATEX_GROUP 0x0020UL
229#define LATEX_TRANSLATE 0x0040UL
230#define LATEX_SIDEWAYS 0x0080UL
231#define LATEX_JUSTIFY 0x0100UL
232#define LATEX_COMPLETE 0x0200UL
233#define LATEX_COMMENT 0x0400UL
234#define LATEX_LABEL_PARAM 0x0800UL
235#define LATEX_CAPTION_PARAM 0x1000UL
237#define HTML_FORMAT 0x0001U
238#define HTML_CAPTION 0x0002U
239#define HTML_TRANSLATE 0x0004U
248#define ENDSLINE 0x0001U
249#define USEDEFAULTFORMAT 0x0002U
250#define LABEL_GIVEN 0x0004U
251#define EDITLABEL_GIVEN 0x0008U
252#define FACTOR_GIVEN 0x0010U
253#define NO_UNITS 0x0020U
257 char *name, *format, **header, *label, *editLabel;
258 long fieldWidth, index, headers, type, endsLine, blankLines, useDefaultFormat, noUnits;
265 char *name, *format, *label, *editLabel;
266 long fieldWidth, index, type, endsLine, blankLines, useDefaultFormat;
273 char *name, *format, *label;
278char *makeTexSafeString(
char *source);
279char *makeTexExponentialString(
char *text);
280void copyAndPad(
char *target,
char *source,
long sourceWidth,
long targetWidth);
281long makeColumnHeaders(
char ***header,
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
282 char **format,
unsigned long spreadsheetFlags,
unsigned long latexFormat, htab *translationTable,
unsigned long htmlFormat);
283char *makeParameterLabel(
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
char *format);
284long changeDefaultFormats(
char **argv,
long argc,
long noWarnings);
285void setDefaultFormats(
void);
287 unsigned long spreadsheetFlags,
long csv,
unsigned long latexformat, htab *translationTable,
unsigned long htmlformat);
288void printColumnHeaders(FILE *fpOut,
PRINT_COLUMN *printColumn,
long printColumns,
long width,
PAGINATION *pagination,
289 long latexFormat,
char *latexTitle,
long htmlFormat,
char *htmlTitle);
291 long noWarnings,
long noLabels,
long csv);
293long getFormatFieldLength(
char *format,
long *extraChars);
294char **makeListOfNames(
char *
string,
long *names);
296 FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
297 char *spreadsheetQuoteMark,
PAGINATION *pagination,
char *title,
long noLabels);
298long characterCount(
char *
string,
char c);
299long printPageTitle(FILE *fpOut,
char *title);
301 long width, FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
char *spreadsheetQuoteMark,
302 long latexFormat,
char *latexTitle,
char *latexLabel,
char *latexGroupColumn,
303 long htmlFormat,
char *htmlTitle,
304 PAGINATION *pagination,
char *title,
long noLabels);
305long checkPagination(FILE *fpOut,
PAGINATION *pagination,
char *title);
306void replaceFormatWidth(
char *buffer,
char *format,
long width);
307void CreateSCHFile(
char *output,
char *input,
unsigned long flags,
char *delimiter,
char *quote,
309htab *readTranslationTable(
char *TranslationFile);
310char *findTranslation(htab *ht,
char *key);
311char *modifyUnitsWithFactor(
char *units0,
double factor,
unsigned long latexFormat);
313static char **defaultFormat = NULL;
314static char **csvFormat = NULL;
315static char *latexJustify = NULL;
317#define SPREADSHEET_ON 0x0001U
318#define SPREADSHEET_DELIMITER 0x0002U
319#define SPREADSHEET_QUOTEMARK 0x0004U
320#define SPREADSHEET_NOLABELS 0x0008U
321#define SPREADSHEET_CSV 0x0010UL
323int main(
int argc,
char **argv) {
325 long i, i_arg, pageNumber, width;
327 char *input, *output, **name, *format, *title, *label, *editLabel, *schFile;
331 long printColumns, printParameters, printArrays, firstPage, bufferLines;
332 long fromPage, toPage, names, pageAdvance, noTitle, noLabels, noWarnings;
334 unsigned long latexFormat, htmlFormat;
336 unsigned long flags, pipeFlags, spreadsheetFlags, dummyFlags, postPageLines, CSV = 0;
337 char *spreadsheetDelimiter, *spreadsheetQuoteMark;
339 char **formatDefaultArg;
340 long formatDefaultArgs;
341 static char formatbuffer[100], formatbuffer2[100];
342 char *latexLabel, *latexCaption = NULL, *latexGroup, *latexTranslationFile, *latexComment = NULL;
343 char *latexCaptionBuffer=NULL, *latexLabelBuffer=NULL;
344 htab *TranslationTable;
345 char *htmlCaption = NULL, *htmlTranslationFile;
349 argc =
scanargs(&s_arg, argc, argv);
353 input = output = NULL;
354 fromPage = toPage = 0;
356 printParameter = NULL;
360 printColumns = printParameters = printArrays = pipeFlags = flags = 0;
361 postPageLines = pageAdvance = noTitle = noLabels = 0;
363 spreadsheetFlags = 0;
364 pagination.flags = pagination.currentLine = 0;
366 formatDefaultArgs = 0;
368 formatDefaultArg = NULL;
371 TranslationTable = NULL;
374 for (i_arg = 1; i_arg < argc; i_arg++) {
375 if (s_arg[i_arg].arg_type == OPTION) {
376 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
378 if (s_arg[i_arg].n_items < 2) {
379 s_arg[i_arg].n_items = 2;
380 s_arg[i_arg].list =
SDDS_Realloc(s_arg[i_arg].list,
sizeof(*s_arg[i_arg].list) * 2);
383 name = makeListOfNames(s_arg[i_arg].list[1], &names);
384 printColumn =
SDDS_Realloc(printColumn,
sizeof(*printColumn) * (names + printColumns));
385 s_arg[i_arg].n_items -= 2;
389 if (!
scanItemList(&flags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
391 "endsline", -1, NULL, 0, ENDSLINE,
392 "usedefaultformat", -1, NULL, 0, USEDEFAULTFORMAT,
393 "blanklines",
SDDS_LONG, &blankLines, 1, 0,
394 "editlabel",
SDDS_STRING, &editLabel, 1, EDITLABEL_GIVEN,
396 "nounits", -1, NULL, 0, NO_UNITS,
397 "factor",
SDDS_DOUBLE, &factor, 1, FACTOR_GIVEN, NULL))
399 for (i = 0; i < names; i++) {
401 printColumn[i + printColumns].name = name[i];
404 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
407 if (flags & ENDSLINE && (i == names - 1))
408 printColumn[i + printColumns].endsLine = 1;
409 if (flags & USEDEFAULTFORMAT)
410 printColumn[i + printColumns].useDefaultFormat = 1;
411 printColumn[i + printColumns].label = printColumn[i + printColumns].editLabel = NULL;
412 if (flags & LABEL_GIVEN)
413 printColumn[i + printColumns].label = label;
414 if (flags & EDITLABEL_GIVEN)
415 printColumn[i + printColumns].editLabel = editLabel;
416 printColumn[i + printColumns].noUnits = flags & NO_UNITS ? 1 : 0;
417 printColumn[i + printColumns].factor = factor;
418 printColumn[i + printColumns].blankLines = blankLines;
421 printColumns += names;
424 if (s_arg[i_arg].n_items < 2) {
425 s_arg[i_arg].n_items = 2;
426 s_arg[i_arg].list =
SDDS_Realloc(s_arg[i_arg].list,
sizeof(*s_arg[i_arg].list) * 2);
429 name = makeListOfNames(s_arg[i_arg].list[1], &names);
430 printParameter =
SDDS_Realloc(printParameter,
sizeof(*printParameter) * (names + printParameters));
431 s_arg[i_arg].n_items -= 2;
435 if (!
scanItemList(&flags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
437 "endsline", -1, NULL, 0, ENDSLINE,
438 "usedefaultformat", -1, NULL, 0, USEDEFAULTFORMAT,
439 "blanklines",
SDDS_LONG, &blankLines, 1, 0,
440 "editlabel",
SDDS_STRING, &editLabel, 1, EDITLABEL_GIVEN,
442 "factor",
SDDS_DOUBLE, &factor, 1, FACTOR_GIVEN, NULL))
444 for (i = 0; i < names; i++) {
445 SDDS_ZeroMemory(printParameter + i + printParameters,
sizeof(*printParameter));
446 printParameter[i + printParameters].name = name[i];
449 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
450 SDDS_CopyString(&printParameter[i + printParameters].format, formatbuffer2);
452 if (flags & ENDSLINE && (i == names - 1))
453 printParameter[i + printParameters].endsLine = 1;
454 if (flags & USEDEFAULTFORMAT)
455 printParameter[i + printParameters].useDefaultFormat = 1;
456 printParameter[i + printParameters].label = printParameter[i + printParameters].editLabel = NULL;
457 if (flags & LABEL_GIVEN)
458 printParameter[i + printParameters].label = label;
459 if (flags & EDITLABEL_GIVEN)
460 printParameter[i + printParameters].editLabel = editLabel;
461 printParameter[i + printParameters].factor = factor;
462 printParameter[i + printParameters].blankLines = blankLines;
465 printParameters += names;
468 if (s_arg[i_arg].n_items < 2) {
469 s_arg[i_arg].n_items = 2;
470 s_arg[i_arg].list =
SDDS_Realloc(s_arg[i_arg].list,
sizeof(*s_arg[i_arg].list) * 2);
473 name = makeListOfNames(s_arg[i_arg].list[1], &names);
474 printArray =
SDDS_Realloc(printArray,
sizeof(*printArray) * (names + printArrays));
475 s_arg[i_arg].n_items -= 2;
477 if (!
scanItemList(&flags, s_arg[i_arg].list + 2, &s_arg[i_arg].n_items, 0,
480 for (i = 0; i < names; i++) {
481 printArray[i + printArrays].name = name[i];
484 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
489 printArrays += names;
492 if (s_arg[i_arg].n_items < 2)
495 SDDS_Bomb(
"invalid syntax: specify -fromPage once only");
496 if (sscanf(s_arg[i_arg].list[1],
"%ld", &fromPage) != 1 || fromPage <= 0)
497 SDDS_Bomb(
"invalid -fromPage syntax or value");
500 if (s_arg[i_arg].n_items < 2)
503 SDDS_Bomb(
"invalid syntax: specify -toPage once only");
504 if (sscanf(s_arg[i_arg].list[1],
"%ld", &toPage) != 1 || toPage <= 0)
505 SDDS_Bomb(
"invalid -toPage syntax or value");
507 case SET_FORMATDEFAULTS:
508 formatDefaultArg = s_arg[i_arg].list + 1;
509 formatDefaultArgs = s_arg[i_arg].n_items - 1;
512 if (s_arg[i_arg].n_items != 2 || sscanf(s_arg[i_arg].list[1],
"%ld", &width) != 1 || (width < 40 && width))
513 SDDS_Bomb(
"invalid -width syntax or value");
516 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
519 case SET_PAGEADVANCE:
526 if (s_arg[i_arg].n_items != 2)
528 title = s_arg[i_arg].list[1];
530 case SET_SPREADSHEET:
531 s_arg[i_arg].n_items--;
532 spreadsheetDelimiter = NULL;
533 spreadsheetQuoteMark =
"";
534 if (!
scanItemList(&spreadsheetFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
535 "delimiter",
SDDS_STRING, &spreadsheetDelimiter, 1, SPREADSHEET_DELIMITER,
536 "quotemark",
SDDS_STRING, &spreadsheetQuoteMark, 1, SPREADSHEET_QUOTEMARK,
537 "nolabels", -1, NULL, 0, SPREADSHEET_NOLABELS,
"csv", -1, NULL, 0, SPREADSHEET_CSV,
539 SDDS_Bomb(
"invalid -spreadsheet syntax");
540 if (!spreadsheetDelimiter || !(spreadsheetFlags & SPREADSHEET_DELIMITER))
541 spreadsheetDelimiter =
"\t";
542 if (spreadsheetFlags & SPREADSHEET_CSV) {
543 spreadsheetDelimiter =
",";
544 spreadsheetFlags |= SPREADSHEET_DELIMITER;
545 spreadsheetFlags |= SPREADSHEET_QUOTEMARK;
546 spreadsheetQuoteMark =
"\"";
550 spreadsheetFlags |= SPREADSHEET_ON;
554 s_arg[i_arg].n_items--;
555 pagination.lines = 66;
556 if (!
scanItemList(&dummyFlags, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
557 "lines",
SDDS_LONG, &pagination.lines, 1, 0,
558 "notitle", -1, NULL, 0, PAGINATION_NOTITLE,
559 "nolabels", -1, NULL, 0, PAGINATION_NOLABELS, NULL) ||
560 pagination.lines <= 3)
561 SDDS_Bomb(
"invalid -paginate syntax/values");
562 pagination.flags |= PAGINATION_ON;
567 case SET_POSTPAGELINES:
568 if (s_arg[i_arg].n_items != 2 || sscanf(s_arg[i_arg].list[1],
"%ld", &postPageLines) != 1)
569 SDDS_Bomb(
"invalid -postPageLines syntax/values");
574 case SET_BUFFERLINES:
575 if (s_arg[i_arg].n_items < 2)
576 SDDS_Bomb(
"invalid -bufferLines syntax");
577 if (sscanf(s_arg[i_arg].list[1],
"%ld", &bufferLines) != 1 || bufferLines < 0)
578 SDDS_Bomb(
"invalid -bufferLines syntax or value");
580 case SET_LATEXFORMAT:
581 s_arg[i_arg].n_items--;
585 if (!
scanItemList(&latexFormat, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
586 "longtable", -1, NULL, 0, LATEX_LONGTABLE,
587 "booktable", -1, NULL, 0, LATEX_BOOKTABLE,
588 "sideways", -1, NULL, 0, LATEX_SIDEWAYS,
590 "caption",
SDDS_STRING, &latexCaption, 1, LATEX_CAPTION,
591 "comment",
SDDS_STRING, &latexComment, 1, LATEX_COMMENT,
593 "translate",
SDDS_STRING, &latexTranslationFile, 1, LATEX_TRANSLATE,
594 "justify",
SDDS_STRING, &latexJustify, 1, LATEX_JUSTIFY,
595 "complete", -1, NULL, 0, LATEX_COMPLETE, NULL))
596 SDDS_Bomb(
"invalid -latexFormat syntax/values");
597 latexFormat |= LATEX_FORMAT;
598 if (latexFormat & LATEX_LONGTABLE && latexFormat & LATEX_SIDEWAYS)
599 SDDS_Bomb(
"invalid -latexFormat syntax/values: give only one of longtable and sideways");
602 s_arg[i_arg].n_items--;
604 if (!
scanItemList(&htmlFormat, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
605 "caption",
SDDS_STRING, &htmlCaption, 1, HTML_CAPTION,
606 "translate",
SDDS_STRING, &htmlTranslationFile, 1, HTML_TRANSLATE, NULL))
607 SDDS_Bomb(
"invalid -htmlFormat syntax/values");
608 htmlFormat |= HTML_FORMAT;
611 fprintf(stderr,
"error: unknown switch: %s\n", s_arg[i_arg].list[0]);
617 input = s_arg[i_arg].list[0];
619 output = s_arg[i_arg].list[0];
625 pipeFlags |= DEFAULT_STDOUT;
626 processFilenames(
"sddsprintout", &input, &output, pipeFlags, noWarnings, NULL);
628 if (formatDefaultArgs)
629 changeDefaultFormats(formatDefaultArg, formatDefaultArgs, noWarnings);
633 SDDS_Bomb(
"-pageAdvance and -postPageLines are incompatible");
634 if (pagination.flags & PAGINATION_ON)
635 SDDS_Bomb(
"-pageAdvance and -paginate are incompatible");
637 if (pagination.flags & PAGINATION_ON && postPageLines)
638 SDDS_Bomb(
"-postPageLines and -paginate are incompatible");
640 if (!printColumns && !printParameters && !printArrays)
641 SDDS_Bomb(
"you must specify at least one of -columns, -parameters, or -arrays");
642 if (fromPage && toPage && fromPage > toPage)
643 SDDS_Bomb(
"invalid -fromPage and -toPage");
644 if (latexFormat && htmlFormat)
645 SDDS_Bomb(
"-latexFormat and -htmlFormat are incompatible");
647 if (latexFormat & LATEX_TRANSLATE)
648 TranslationTable = readTranslationTable(latexTranslationFile);
649 if (htmlFormat & HTML_TRANSLATE)
650 TranslationTable = readTranslationTable(htmlTranslationFile);
659 if (output && !(fpOut = fopen(output,
"w")))
662 printColumns = processPrintColumns(&printColumn, printColumns, &SDDS_dataset, noWarnings,
663 spreadsheetFlags, CSV, latexFormat, TranslationTable, htmlFormat);
664 printParameters = processPrintParameters(&printParameter, printParameters, &SDDS_dataset, noWarnings, noLabels, CSV);
670 pagination.flags |= noTitle ? PAGINATION_NOTITLE : 0;
672 title =
tmalloc(
sizeof(*title) * ((input ? strlen(input) : 10) + 100));
674 sprintf(title,
"Printout for SDDS file %s", input ? input :
"stdin");
676 sprintf(title,
"Printout for SDDS file %s%s", input ? input :
"stdin", latexFormat ?
"" :
"\n");
680 if (printArrays || printParameters || !printColumns)
681 SDDS_Bomb(
"Can't create schFile except for pure column printout.");
682 CreateSCHFile(schFile, input, spreadsheetFlags, spreadsheetDelimiter, spreadsheetQuoteMark, printColumn, printColumns);
686 if (latexFormat & LATEX_LABEL && latexLabel[0]==
'@') {
687 memmove(latexLabel, latexLabel+1, strlen(latexLabel));
689 fprintf(stderr,
"sddsprintout: error: parameter %s not found in input file\n", latexLabel);
692 latexFormat |= LATEX_LABEL_PARAM;
694 if (latexFormat & LATEX_CAPTION && latexCaption[0]==
'@') {
695 memmove(latexCaption, latexCaption+1, strlen(latexCaption));
697 fprintf(stderr,
"sddsprintout: error: parameter %s not found in input file\n", latexCaption);
700 latexFormat |= LATEX_CAPTION_PARAM;
702 if (latexFormat & LATEX_COMPLETE) {
703 fprintf(fpOut,
"\\documentclass{report}\n\\pagestyle{empty}\n");
704 if (latexFormat & LATEX_BOOKTABLE)
705 fprintf(fpOut,
"\\usepackage{booktabs}\n");
706 if (latexFormat & LATEX_SIDEWAYS)
707 fprintf(fpOut,
"\\usepackage{rotating}\n");
708 fprintf(fpOut,
"\\begin{document}\n");
711 fprintf(fpOut,
"%% %s\n", latexComment);
717 while ((pageNumber =
SDDS_ReadPageSparse(&SDDS_dataset, 0, printColumns || SDDS_dataset.layout.data_mode.column_major ? 1 : 1000000, 0, 0)) > 0) {
718 if ((fromPage && pageNumber < fromPage) || (toPage && pageNumber > toPage))
720 if (pagination.flags & PAGINATION_ON) {
722 fputc(
'\014', fpOut);
723 pagination.currentLine = 1;
726 pagination.currentLine += printPageTitle(fpOut, title);
730 printPageTitle(fpOut, title);
731 }
else if (pageAdvance)
732 fputc(
'\014', fpOut);
733 else if (postPageLines > 0) {
734 long line = postPageLines;
739 if (!latexFormat && !htmlFormat)
740 doPrintParameters(&SDDS_dataset, printParameter, printParameters, width, fpOut, spreadsheetFlags,
741 spreadsheetDelimiter, spreadsheetQuoteMark, &pagination, title, noLabels);
743 latexCaptionBuffer = latexLabelBuffer = NULL;
744 if (latexFormat&LATEX_CAPTION_PARAM && !(latexCaptionBuffer =
SDDS_GetParameterAsString(&SDDS_dataset, latexCaption, NULL))) {
746 snprintf(buffer, 1024,
"Error: can't read latex caption parameter %s\n", latexCaption);
751 snprintf(buffer, 1024,
"Error: can't read latex label parameter %s\n", latexLabel);
754 doPrintColumns(&SDDS_dataset, printColumn, printColumns, width, fpOut, spreadsheetFlags, spreadsheetDelimiter,
755 spreadsheetQuoteMark, latexFormat,
756 latexFormat&LATEX_CAPTION_PARAM ? latexCaptionBuffer : latexCaption,
757 latexFormat&LATEX_LABEL_PARAM ? latexLabelBuffer : latexLabel,
758 latexGroup, htmlFormat, htmlCaption,
759 &pagination, title, noLabels);
760 if (latexFormat&LATEX_CAPTION_PARAM && latexCaptionBuffer)
761 free(latexCaptionBuffer);
762 if (latexFormat&LATEX_LABEL_PARAM && latexLabelBuffer)
763 free(latexLabelBuffer);
765 for (i = 0; i < bufferLines; i++)
773 for (i = 0; i < printColumns; i++) {
774 if (printColumn[i].headers)
775 free(printColumn[i].header);
777 if (latexFormat & LATEX_COMPLETE)
778 fprintf(fpOut,
"\\end{document}\n");
786 unsigned long spreadsheetFlags,
long csv,
unsigned long latexFormat, htab *TranslationTable,
unsigned long htmlFormat) {
788 long i, irequest, iname, printColumns, names, *columnUsed, columnLimit;
790 char **name, *units, *format;
792 if (printRequests < 1 || !(printRequest = *printRequestPtr))
796 fprintf(stderr,
"warning: no column data in input file\n");
799 columnUsed =
tmalloc(
sizeof(*columnUsed) * columnLimit);
800 for (i = 0; i < columnLimit; i++)
802 printColumn =
tmalloc(
sizeof(*printColumn) * columnLimit);
806 for (irequest = 0; irequest < printRequests; irequest++) {
807 if ((names =
SDDS_MatchColumns(inTable, &name, SDDS_MATCH_STRING, FIND_ANY_TYPE, printRequest[irequest].name, SDDS_0_PREVIOUS | SDDS_OR)) > 0) {
808 for (iname = 0; iname < names; iname++) {
811 if (!columnUsed[index]) {
815 printColumn[printColumns].index = index;
816 if (iname == names - 1)
817 printColumn[printColumns].endsLine = printRequest[irequest].endsLine;
819 printColumn[printColumns].endsLine = 0;
821 printColumn[printColumns].blankLines = printRequest[irequest].blankLines;
825 SDDS_CopyString(&printColumn[printColumns].format, csvFormat[printColumn[printColumns].type - 1]);
827 if (printRequest[irequest].format) {
828 if (printRequest[irequest].format[0]!=
'@') {
830 fprintf(stderr,
"error: given format (\"%s\") for column %s is invalid\n",
831 printRequest[irequest].format, name[iname]);
838 fprintf(stderr,
"error: given format column (\"%s\") for column %s is absent or not string type\n",
839 printRequest[irequest].format+1, name[iname]);
844 SDDS_CopyString(&printColumn[printColumns].format, printRequest[irequest].format);
846 SDDS_CopyString(&printColumn[printColumns].format, defaultFormat[printColumn[printColumns].type - 1]);
850 printColumn[printColumns].headers =
851 makeColumnHeaders(&printColumn[printColumns].header, &printColumn[printColumns].fieldWidth,
852 printRequest[irequest].label ? printRequest[irequest].label : name[iname],
853 printRequest[irequest].editLabel,
854 printRequest[irequest].noUnits?NULL:units, printRequest[irequest].factor,
855 &printColumn[printColumns].format, spreadsheetFlags, latexFormat, TranslationTable, htmlFormat);
857 fprintf(stderr,
"%s has format >%s<\n",
858 printRequest[irequest].label ? printRequest[irequest].label : name[iname], printColumn[printColumns].format);
860 printColumn[printColumns].data = NULL;
861 printColumn[printColumns].factor = printRequest[irequest].factor;
863 columnUsed[index] = 1;
870 }
else if (names < 0)
872 else if (!noWarnings)
873 fprintf(stderr,
"warning: no column matches %s\n", printRequest[irequest].name);
874 free(printRequest[irequest].name);
875 if (printRequest[irequest].format)
876 free(printRequest[irequest].format);
879 *printRequestPtr = printColumn;
884 long noWarnings,
long noLabels,
long csv) {
886 long i, irequest, iname, printParameters, names, *parameterUsed, parameterLimit, maxFieldWidth, index;
887 char **name, *units, *format;
889 if (printRequests < 1 || !(printRequest = *printRequestPtr))
893 fprintf(stderr,
"warning: no parameter data in input file\n");
896 parameterUsed =
tmalloc(
sizeof(*parameterUsed) * parameterLimit);
897 for (i = 0; i < parameterLimit; i++)
898 parameterUsed[i] = 0;
899 printParameter =
tmalloc(
sizeof(*printParameter) * parameterLimit);
903 for (irequest = 0; irequest < printRequests; irequest++) {
904 if ((names =
SDDS_MatchParameters(inTable, &name, SDDS_MATCH_STRING, FIND_ANY_TYPE, printRequest[irequest].name, SDDS_0_PREVIOUS | SDDS_OR)) > 0) {
905 for (iname = 0; iname < names; iname++) {
908 if (!parameterUsed[index]) {
912 printParameter[printParameters].index = index;
914 if (iname == names - 1)
915 printParameter[printParameters].endsLine = printRequest[irequest].endsLine;
916 printParameter[printParameters].blankLines = printRequest[irequest].blankLines;
921 SDDS_CopyString(&printParameter[printParameters].format, csvFormat[printParameter[printParameters].type - 1]);
923 if (printRequest[irequest].format) {
925 fprintf(stderr,
"error: given format (\"%s\") for parameter %s is invalid\n", printRequest[irequest].format, name[iname]);
928 SDDS_CopyString(&printParameter[printParameters].format, printRequest[irequest].format);
930 SDDS_CopyString(&printParameter[printParameters].format, defaultFormat[printParameter[printParameters].type - 1]);
936 printParameter[printParameters].label =
937 makeParameterLabel(&printParameter[printParameters].fieldWidth, printRequest[irequest].label ? printRequest[irequest].label : name[iname], printRequest[irequest].editLabel, units, printRequest[irequest].factor, printParameter[printParameters].format);
939 printParameter[printParameters].label =
"";
941 if (printParameter[printParameters].fieldWidth > maxFieldWidth)
942 maxFieldWidth = printParameter[printParameters].fieldWidth;
943 printParameter[printParameters].data = NULL;
944 printParameter[printParameters].factor = printRequest[irequest].factor;
946 parameterUsed[index] = 1;
953 }
else if (names < 0)
955 else if (!noWarnings)
956 fprintf(stderr,
"warning: no parameter matches %s\n", printRequest[irequest].name);
957 free(printRequest[irequest].name);
958 if (printRequest[irequest].format)
959 free(printRequest[irequest].format);
961 for (i = 0; i < printParameters; i++) {
963 if (printParameter[i].fieldWidth < maxFieldWidth) {
964 ptr =
tmalloc(
sizeof(*ptr) * (maxFieldWidth + 1));
965 strcpy(ptr, printParameter[i].label);
967 free(printParameter[i].label);
968 printParameter[i].label = ptr;
969 printParameter[i].fieldWidth = maxFieldWidth;
973 *printRequestPtr = printParameter;
974 return printParameters;
977#if SDDS_NUM_TYPES != 11
978# error "number of SDDS types is not 9 as expected"
981void setDefaultFormats(
void) {
1008long changeDefaultFormats(
char **argv,
long argc,
long noWarnings) {
1011 static char formatbuffer[100], formatbuffer2[100];
1013 for (i = 0; i < argc; i++) {
1014 if (!(format = strchr(argv[i],
'='))) {
1015 fprintf(stderr,
"-formatDefault syntax error with keyword \"%s\"\n", argv[i]);
1020 fprintf(stderr,
"-formatDefault error: unknown type \"%s\"\n", argv[i]);
1024 fprintf(stderr,
"-formatDefault error: invalid format string \"%s\" for type \"%s\"\n", format, argv[i]);
1027 free(defaultFormat[type - 1]);
1031 replaceString(formatbuffer2, formatbuffer,
"lu", PRIu32, -1, 0);
1036 if (!getFormatFieldLength(format, NULL) && !noWarnings)
1037 fprintf(stderr,
"warning: no field length for default format \"%s\"---this will produce poor results\n", defaultFormat[type - 1]);
1042long makeColumnHeaders(
char ***header,
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
1043 char **format,
unsigned long spreadsheetHeaders,
unsigned long latexFormat, htab *TranslationTable,
unsigned long htmlFormat) {
1044 long formatWidth, unitsWidth, nameWidth, headers, i, formatPadding, formatExtraChars;
1045 static char buffer[1024], buffer2[1026];
1046 static char nameBuffer[1024];
1050 if (latexFormat & LATEX_TRANSLATE) {
1051 name = findTranslation(TranslationTable, name);
1052 units = findTranslation(TranslationTable, units);
1054 if (htmlFormat & HTML_TRANSLATE) {
1055 name = findTranslation(TranslationTable, name);
1056 units = findTranslation(TranslationTable, units);
1059 units = modifyUnitsWithFactor(units, 1. / factor, latexFormat);
1062 strcpy(nameBuffer, name);
1063 if (!edit_string(nameBuffer, editLabel))
1064 SDDS_Bomb(
"Problem editing column label");
1069 fprintf(stderr,
"name: >%s< format: >%s<\n", name, *format ? *format :
"NULL");
1073 unitsWidth = units ? strlen(units) : 0;
1074 nameWidth = strlen(name);
1075 *fieldWidth = unitsWidth > nameWidth ? unitsWidth : nameWidth;
1077 if (!(spreadsheetHeaders & SPREADSHEET_ON)) {
1082 if (!*format || (*format && (*format)[0]!=
'@')) {
1084 formatWidth = getFormatFieldLength(*format, &formatExtraChars);
1085 if ((formatWidth + formatExtraChars) > *fieldWidth)
1086 *fieldWidth = formatWidth + formatExtraChars;
1089 if (*fieldWidth < 2)
1092 fprintf(stderr,
"fieldWidth = %ld, formatWidth = %ld, formatExtra = %ld\n", *fieldWidth, formatWidth, formatExtraChars);
1094 if (*format && (formatPadding = (*fieldWidth - 2 - formatExtraChars) - formatWidth) > 0) {
1099 formatWidth = *fieldWidth - 2 - formatExtraChars;
1100 replaceFormatWidth(buffer, *format, formatWidth);
1102 fprintf(stderr,
"Adjusted format width to %ld: >%s<\n", formatWidth, buffer);
1105 sprintf(buffer2,
" %s ", buffer);
1108 sprintf(buffer,
" %s ", *format);
1115 *header =
tmalloc(
sizeof(**header) * (headers = 2));
1116 for (i = 0; i < headers; i++)
1117 (*header)[i] =
tmalloc(
sizeof(***header) * (*fieldWidth + 1));
1120 copyAndPad((*header)[0], name, nameWidth, *fieldWidth);
1122 copyAndPad((*header)[1], units, unitsWidth, *fieldWidth);
1124 fprintf(stderr,
"header0 padded to %ld: >%s<\n", *fieldWidth, (*header)[0]);
1125 (*header)[0][0] =
'+';
1126 (*header)[0][strlen((*header)[0]) - 1] =
'-';
1127 fprintf(stderr,
"header1 padded to %ld: >%s<\n", *fieldWidth, (*header)[1]);
1128 (*header)[1][0] =
'+';
1129 (*header)[1][strlen((*header)[1]) - 1] =
'-';
1135void copyAndPad(
char *target,
char *source,
long sourceWidth,
long targetWidth) {
1136 long i, head, tail, excess;
1137 if ((excess = targetWidth - sourceWidth) < 0)
1138 SDDS_Bomb(
"negative excess in copyAndPad()---programming error");
1139 head = tail = excess / 2;
1140 if ((i = excess - head - tail))
1142 for (i = 0; i < head; i++)
1146 strcat(target, source);
1147 for (i = strlen(target); i < targetWidth; i++)
1174char *makeParameterLabel(
long *fieldWidth,
char *name,
char *editLabel,
char *units,
double factor,
char *format) {
1175 long formatWidth, labelWidth, extraFormatChars;
1177 static char buffer[1024];
1180 strcpy(buffer, name);
1181 if (!edit_string(buffer, editLabel))
1182 SDDS_Bomb(
"Problem editing parameter label");
1186 *fieldWidth = (labelWidth = strlen(name) + 4 + (units && !
SDDS_StringIsBlank(units) ? strlen(units) + 3 : 0)) + (formatWidth = getFormatFieldLength(format, &extraFormatChars));
1187 *fieldWidth += extraFormatChars;
1188 if (*fieldWidth < 2)
1190 label =
tmalloc(
sizeof(*label) * (labelWidth + 1));
1192 units = modifyUnitsWithFactor(units, 1. / factor, 0);
1194 sprintf(label,
"%s (%s) = ", name, units);
1196 sprintf(label,
"%s = ", name);
1200long getFormatFieldLength(
char *format,
long *extraChars) {
1207 while (*format && *format !=
'%')
1209 if (*format !=
'%') {
1210 fprintf(stderr,
"Bad format string: %s\n", format0);
1214 *extraChars = format - format0;
1215 while (*format && !isdigit(*format))
1220 if (!*format || !isdigit(*format))
1223 width = atoi(format);
1225 while (isdigit(*format) || *format ==
'.')
1227 if (*format ==
'l' || *format ==
'h')
1232 *extraChars += strlen(format);
1238 FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
1239 char *spreadsheetQuoteMark,
PAGINATION *pagination,
char *title,
long noLabels) {
1240 long parameter, outputRow, length;
1241 char printBuffer[2 * SDDS_MAXLINE];
1242 static char *dataBuffer = NULL;
1245 if (!printParameters)
1247 if (!dataBuffer && !(dataBuffer = malloc(
sizeof(
double) * 4)))
1248 SDDS_Bomb(
"Allocation failure in doPrintParameters");
1251 for (parameter = 0; parameter < printParameters; parameter++) {
1253 if (printParameter[parameter].format && printParameter[parameter].format[0]==
'@' &&
1255 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1257 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1259 format?format:printParameter[parameter].format, printBuffer,
1260 SDDS_PRINT_NOQUOTES, printParameter[parameter].factor))
1261 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1262 if (spreadsheetFlags & SPREADSHEET_ON) {
1263 if (!(spreadsheetFlags & SPREADSHEET_NOLABELS))
1264 fprintf(fpOut,
"%s%s", printParameter[parameter].name, spreadsheetDelimiter);
1265 fprintf(fpOut,
"%s%s%s\n", spreadsheetQuoteMark, printBuffer, spreadsheetQuoteMark);
1268 length = strlen(printParameter[parameter].label) + strlen(printBuffer) + (parameter ? 2 : 0);
1269 if ((parameter && printParameter[parameter - 1].endsLine) || (outputRow && (outputRow + length) > width)) {
1271 checkPagination(fpOut, pagination, title);
1272 outputRow = length - 2;
1273 if (parameter && printParameter[parameter - 1].blankLines && printParameter[parameter - 1].endsLine) {
1275 for (i = 1; i < printParameter[parameter - 1].blankLines; i++) {
1276 checkPagination(fpOut, pagination, title);
1283 outputRow += length;
1285 fputs(printParameter[parameter].label, fpOut);
1286 fputs(printBuffer, fpOut);
1287 if (printParameter[parameter].type ==
SDDS_STRING)
1288 free(*((
char **)dataBuffer));
1290 if (!(spreadsheetFlags & SPREADSHEET_ON)) {
1291 checkPagination(fpOut, pagination, title);
1293 checkPagination(fpOut, pagination, title);
1298char **makeListOfNames(
char *
string,
long *names) {
1302 *names = characterCount(
string,
',') + 1;
1303 name =
tmalloc(
sizeof(*name) * *names);
1304 for (iName = 0;
string && iName < *names; iName++) {
1305 if ((ptr = strchr(
string,
',')))
1310 if (iName != *names)
1311 SDDS_Bomb(
"problem occurred scanning list of names");
1315long characterCount(
char *
string,
char c) {
1318 while ((ptr = strchr(
string, c))) {
1325long printPageTitle(FILE *fpOut,
char *title) {
1329 fprintf(fpOut,
"%s\n", title);
1332 while ((ptr = strchr(ptr,
'\n'))) {
1339long checkPagination(FILE *fpOut,
PAGINATION *pagination,
char *title) {
1340 if (!(pagination->flags & PAGINATION_ON))
1342 if ((pagination->currentLine += 1) >= pagination->lines) {
1343 fputc(
'\014', fpOut);
1344 pagination->currentLine = 0;
1345 if (!(pagination->flags & PAGINATION_NOTITLE))
1346 pagination->currentLine += printPageTitle(fpOut, title);
1352void printColumnHeaders(FILE *fpOut,
PRINT_COLUMN *printColumn,
long printColumns,
long width,
1353 PAGINATION *pagination,
long latexFormat,
char *latexTitle,
long htmlFormat,
char *htmlTitle) {
1355 long row, column, header, outputRow, maxOutputRow, length, noUnitsLine;
1358 if (latexFormat & LATEX_LONGTABLE) {
1359 fprintf(fpOut,
"\\begin{longtable}{");
1360 if (latexFormat & LATEX_JUSTIFY) {
1361 fprintf(fpOut,
"%s", latexJustify);
1363 for (column = 0; column < printColumns; column++)
1364 fprintf(fpOut,
"%s", latexFormat & LATEX_BOOKTABLE ?
"c" : (column == 0 ?
"|c|" :
"c|"));
1366 fprintf(fpOut,
"}\n");
1367 if (latexTitle && strlen(latexTitle)) {
1368 fprintf(fpOut,
"\\caption{%s}\\\\\n", latexTitle ? makeTexSafeString(latexTitle) :
"No caption");
1371 fprintf(fpOut,
"\\begin{%s}[htb]", latexFormat & LATEX_SIDEWAYS ?
"sidewaystable" :
"table");
1372 if (latexTitle && strlen(latexTitle)) {
1373 fprintf(fpOut,
"\\caption{%s}\n", latexTitle ? makeTexSafeString(latexTitle) :
"No caption");
1375 fprintf(fpOut,
"\n");
1376 fprintf(fpOut,
"\\begin{center}\n");
1377 fprintf(fpOut,
"\\begin{tabular}{");
1378 if (latexFormat & LATEX_JUSTIFY) {
1379 fprintf(fpOut,
"%s", latexJustify);
1381 for (column = 0; column < printColumns; column++)
1382 fprintf(fpOut,
"%s", latexFormat & LATEX_BOOKTABLE ?
"c" : (column == 0 ?
"|c|" :
"c|"));
1384 fprintf(fpOut,
"}\n");
1387 if (latexFormat & LATEX_BOOKTABLE)
1388 fprintf(fpOut,
"\\toprule\n");
1390 fprintf(fpOut,
"\\hline\n");
1393 fprintf(fpOut,
"<table style=\"width:100%%\">\n");
1394 if (htmlTitle && strlen(htmlTitle)) {
1395 fprintf(fpOut,
" <caption>%s</caption>\n", htmlTitle);
1400 for (column = 0; column < printColumns; column++) {
1404 if (column != printColumns)
1408 for (header = 0; header < printColumn[0].headers; header++) {
1410 if (noUnitsLine && header == 1)
1413 fprintf(fpOut,
" <tr>\n");
1415 for (column = 0; column < printColumns; column++) {
1416 label = printColumn[column].header[header];
1417 length = strlen(label);
1418 if (!latexFormat && !htmlFormat && ((column && printColumn[column - 1].endsLine) || (width && outputRow && (outputRow + length) > width))) {
1419 printColumn[column - 1].endsLine = 1;
1421 pagination->currentLine++;
1425 if (latexFormat & LATEX_TRANSLATE && strchr(label,
'$'))
1426 fputs(label, fpOut);
1427 else if (strpbrk(label,
"_^{}\\"))
1428 fprintf(fpOut,
"$%s$", label);
1430 fputs(makeTexSafeString(printColumn[column].header[header]), fpOut);
1431 fputs(column == printColumns - 1 ? (latexFormat & LATEX_BOOKTABLE ?
" \\\\ \n" :
" \\\\ \\hline") :
" & ", fpOut);
1432 }
else if (htmlFormat) {
1433 fprintf(fpOut,
" <th>%s</th>\n",
trim_spaces(label));
1435 fputs(label, fpOut);
1436 outputRow += length;
1437 if (outputRow > maxOutputRow)
1438 maxOutputRow = outputRow;
1442 fprintf(fpOut,
" </tr>");
1445 pagination->currentLine++;
1447 if (!latexFormat && !htmlFormat) {
1448 for (row = 0; row < maxOutputRow; row++)
1451 }
else if (latexFormat & LATEX_BOOKTABLE) {
1452 fputs(
"\\midrule\n", fpOut);
1454 pagination->currentLine++;
1458 long width, FILE *fpOut,
unsigned long spreadsheetFlags,
char *spreadsheetDelimiter,
char *spreadsheetQuoteMark,
1459 long latexFormat,
char *latexTitle,
char *latexLabel,
char *latexGroupColumn,
1460 long htmlFormat,
char *htmlTitle,
1461 PAGINATION *pagination,
char *title,
long noLabels) {
1463 int64_t row, rows, nGroups, maxGroupLength, groupLength;
1465 char **groupData = NULL;
1466 char ***format = NULL;
1467 char printBuffer[16 * SDDS_MAXLINE];
1473 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1477 if ((latexTitle != NULL) && (latexTitle[0] ==
'@')) {
1478 latexTitle = latexTitle + 1;
1482 if ((htmlTitle != NULL) && (htmlTitle[0] ==
'@')) {
1483 htmlTitle = htmlTitle + 1;
1487 if (!(spreadsheetFlags & SPREADSHEET_ON) && !noLabels)
1488 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination,
1489 latexFormat, latexTitle ? latexTitle : title,
1490 htmlFormat, htmlTitle ? htmlTitle : title);
1491 else if (!(spreadsheetFlags & SPREADSHEET_NOLABELS) && !noLabels) {
1492 for (column = 0; column < printColumns; column++)
1493 fprintf(fpOut,
"%s%s", printColumn[column].name, column != printColumns - 1 ? spreadsheetDelimiter :
"\n");
1497 maxGroupLength = groupLength = 1;
1498 if (latexFormat & LATEX_GROUP) {
1500 fprintf(stderr,
"Error: unable to get data for column %s\n", latexGroupColumn);
1501 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1503 for (row = 1; row < rows; row++) {
1504 if (strcmp(groupData[row], groupData[row - 1])) {
1505 if (groupLength > maxGroupLength)
1506 maxGroupLength = groupLength;
1513 if (groupLength > maxGroupLength)
1514 maxGroupLength = groupLength;
1516 fprintf(fpOut,
"%% nGroups = %" PRId64
", maxGroupLength = %" PRId64
"\n", nGroups, maxGroupLength);
1519 data =
tmalloc(
sizeof(*data) * printColumns);
1520 format =
tmalloc(
sizeof(*format) * printColumns);
1521 for (column = 0; column < printColumns; column++) {
1522 if (!(data[column] =
SDDS_GetColumn(inTable, printColumn[column].name))) {
1523 fprintf(stderr,
"Error: unable to get data for column %s\n", printColumn[column].name);
1524 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1526 format[column] = NULL;
1527 if (printColumn[column].format && printColumn[column].format[0]==
'@') {
1528 if (!(format[column] =
SDDS_GetColumn(inTable, printColumn[column].format+1))) {
1529 fprintf(stderr,
"Error: unable to get format data for column %s from %s\n",
1530 printColumn[column].name, printColumn[column].format+1);
1531 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1535 for (row = 0; row < rows; row++) {
1538 fprintf(fpOut,
" <tr bgcolor=\"#ddd\">\n");
1540 fprintf(fpOut,
" <tr>\n");
1542 if (latexFormat && nGroups > 1) {
1543 if (row == 0 || strcmp(groupData[row], groupData[row - 1])) {
1544 if (row != 0 && latexFormat & LATEX_BOOKTABLE)
1545 fprintf(fpOut,
"\\midrule\n");
1546 fprintf(fpOut,
"\\multicolumn{%ld}{l}{\\bf %s} \\\\ \n", printColumns, groupData[row]);
1549 for (column = 0; column < printColumns; column++) {
1551 fprintf(fpOut,
" <td style=\"text-align:center\">");
1554 sprintf(printBuffer, format[column]?format[column][row]:printColumn[column].format,
" ");
1557 format[column]?format[column][row]:printColumn[column].format,
1558 printBuffer, SDDS_PRINT_NOQUOTES,
1559 printColumn[column].factor)) {
1560 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1563 if (spreadsheetFlags & SPREADSHEET_ON) {
1564 fprintf(fpOut,
"%s%s%s%s", spreadsheetQuoteMark, printBuffer, spreadsheetQuoteMark, column != printColumns - 1 ? spreadsheetDelimiter :
"\n");
1569 fputs(makeTexExponentialString(printBuffer), fpOut);
1571 fputs(makeTexSafeString(printBuffer), fpOut);
1572 fputs(column != printColumns - 1 ?
" & " : (latexFormat & LATEX_BOOKTABLE ?
" \\\\ " :
" \\\\ \\hline"), fpOut);
1577 fprintf(fpOut,
"</td>\n");
1580 fputs(printBuffer, fpOut);
1581 if (printColumn[column].endsLine) {
1584 if (checkPagination(fpOut, pagination, title))
1585 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination, latexFormat, latexTitle ? latexTitle : title, htmlFormat, htmlTitle ? htmlTitle : title);
1586 for (i = 0; i < printColumn[column].blankLines; i++) {
1588 if (checkPagination(fpOut, pagination, title))
1589 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination, latexFormat, latexTitle ? latexTitle : title, htmlFormat, htmlTitle ? htmlTitle : title);
1594 fprintf(fpOut,
" </tr>\n");
1596 if (!(spreadsheetFlags & SPREADSHEET_ON) && !printColumn[column - 1].endsLine) {
1598 if (!latexFormat && !htmlFormat && checkPagination(fpOut, pagination, title))
1599 printColumnHeaders(fpOut, printColumn, printColumns, width, pagination, latexFormat, latexTitle ? latexTitle : title, htmlFormat, htmlTitle ? htmlTitle : title);
1604 if (latexFormat & LATEX_BOOKTABLE)
1605 fputs(
"\\bottomrule\n", fpOut);
1606 if (latexFormat & LATEX_LONGTABLE) {
1608 fprintf(fpOut,
"\\label{%s}\n", latexLabel);
1610 fprintf(fpOut,
"%%\\label{%s}\n",
"tab:labelHere");
1611 fprintf(fpOut,
"\\end{longtable}\n");
1613 fprintf(fpOut,
"\\end{tabular}\n");
1614 fprintf(fpOut,
"\\end{center}\n");
1616 fprintf(fpOut,
"\\label{%s}\n", latexLabel);
1618 fprintf(fpOut,
"%%\\label{%s}\n",
"tab:labelHere");
1619 fprintf(fpOut,
"\\end{%s}\n", latexFormat & LATEX_SIDEWAYS ?
"sidewaystable" :
"table");
1623 fprintf(fpOut,
"</table><br>\n");
1625 for (column = 0; column < printColumns; column++) {
1628 free(format[column]);
1634void replaceFormatWidth(
char *buffer,
char *format,
long width) {
1638 if (*ptr ==
'%' && *(ptr + 1) !=
'%')
1644 if (*(ptr + 1) ==
'-') {
1645 sprintf(buffer,
"%s%%-%ld", format, width);
1648 sprintf(buffer,
"%s%%%ld", format, width);
1650 while (*ptr && isdigit(*ptr))
1652 strcat(buffer, ptr);
1654 strcpy(buffer, format);
1658void CreateSCHFile(
char *output,
char *input,
unsigned long flags,
char *delimiter,
1659 char *quote,
PRINT_COLUMN *printColumn,
long printColumns) {
1663 if (!(fp = fopen(output,
"w")))
1664 SDDS_Bomb(
"Couldn't open SCHFile for writing.");
1665 fprintf(fp,
"[%s]\nFiletype=Delimited\nDelimiter=%s\nSeparator=%s\nCharSet=ascii\n", input ? input :
"NULL", quote, delimiter);
1666 for (i = 0; i < printColumns; i++) {
1667 printColumn[i].useDefaultFormat = 1;
1668 fprintf(fp,
"Field%ld=%s,%s,00,00,00\n\n", i + 1, printColumn[i].name,
SDDS_NUMERIC_TYPE(printColumn[i].type) ?
"Float" :
"Char");
1672char *makeTexSafeString(
char *source) {
1673 static char *buffer = NULL;
1674 static long buflen = 0;
1675 long index = 0, length, inMath = 0;
1678 length = strlen(source);
1679 if (length > (buflen - 2)) {
1680 buflen = length * 2 + 2;
1681 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * buflen)))
1686 if (*source ==
'_' || *source ==
'^' || *source ==
'{' || *source ==
'}' || *source ==
'%' || *source ==
'#') {
1688 buffer[index++] =
'\\';
1689 buffer[index++] = *source++;
1690 }
else if (*source ==
'<' || *source ==
'>' || *source ==
'|') {
1692 buffer[index++] =
'$';
1693 buffer[index++] = *source++;
1695 buffer[index++] =
'$';
1699 buffer[index++] = *source++;
1701 if (index >= (buflen - 1)) {
1703 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * buflen)))
1711char *makeTexExponentialString(
char *text) {
1715 if ((ptr1 = ptr2 = strchr(text,
'e'))) {
1717 while (*ptr2 && !(isdigit(*ptr2) || *ptr2 ==
'-'))
1721 if (strlen(ptr2) >= 100)
1722 bomb(
"buffer overflow in makeTexExponentialString", NULL);
1723 sscanf(ptr2,
"%ld", &exponent);
1725 if (exponent != 0) {
1726 sprintf(buffer,
"%ld", exponent);
1727 sprintf(ptr1,
"$\\times 10^{%s}$", buffer);
1733htab *readTranslationTable(
char *TranslationFile) {
1736 char **oldName, **newName;
1739 fprintf(stderr,
"The latex and html options in sddsprintout is not available on Windows\n");
1745 (rows = SDDS_RowCount(&SDDSin)) <= 0 ||
1748 SDDS_Bomb(
"Problem with translation file");
1751 hadd(ht, oldName[rows], strlen(oldName[rows]), newName[rows]);
1757char *findTranslation(htab *ht,
char *key) {
1759 SDDS_Bomb(
"The latex and html options in sddsprintout is not available on Windows");
1761 if (key && ht &&
hfind(ht, key, strlen(key)) == TRUE)
1762 return (
char *)hstuff(ht);
1767char *modifyUnitsWithFactor(
char *units0,
double factor,
unsigned long latexFormat) {
1768 char *units, buffer[100];
1770 units =
tmalloc(
sizeof(*units) * ((units0 ? strlen(units0) : 0) + 100));
1773 sprintf(buffer,
"%.2g", factor);
1774 sprintf(units,
"%s%s", makeTexExponentialString(buffer), units0 ? units0 :
"");
1776 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.
#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.