TPCCLIB
Loading...
Searching...
No Matches
res2html.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <math.h>
14#include <time.h>
15/*****************************************************************************/
16#include "libtpcmisc.h"
17#include "libtpccurveio.h"
18/*****************************************************************************/
19//#define MAX_LINE_LEN 2048
20/*****************************************************************************/
21
22/*****************************************************************************/
23static char *info[] = {
24 "Converts result file to (X)HTML table format for viewing in web browsers",
25 "or importing into Excel or other spreadsheet software.",
26 " ",
27 "Usage: @P [Options] <Result file> [HTML filename]",
28 " ",
29 "If HTML filename is omitted, then it is named automatically by replacing",
30 "original extension with .htm.",
31 " ",
32 "Options:",
33 " -n[osd]",
34 " SDs and CVs are not saved into HTML file.",
35 " -stdoptions", // List standard options like --help, -v, etc
36 " ",
37 "Example:",
38 " @P ug77654ki.res ug77654ki.htm",
39 " ",
40 "See also: reslist, rescoll, pardiff, parformat",
41 " ",
42 "Keywords: results, HTML, tool",
43 0};
44/*****************************************************************************/
45
46/*****************************************************************************/
47/* Turn on the globbing of the command line, since it is disabled by default in
48 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
49 In Unix&Linux wildcard command line processing is enabled by default. */
50/*
51#undef _CRT_glob
52#define _CRT_glob -1
53*/
54int _dowildcard = -1;
55/*****************************************************************************/
56
57/*****************************************************************************/
61int main(int argc, char **argv)
62{
63 int ai, help=0, version=0, verbose=1;
64 int saveSD=1;
65 RES res;
66 char *cptr, resfile[FILENAME_MAX], htmfile[FILENAME_MAX];
67
68
69 /*
70 * Get arguments
71 */
72 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
73 resfile[0]=htmfile[0]=(char)0;
74 resInit(&res);
75 /* Options */
76 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
77 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
78 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!cptr[0]) continue;
79 if(strncasecmp(cptr, "NOSD", 1)==0) {
80 saveSD=0; continue;
81 }
82 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
83 return(1);
84 } else break;
85
86 /* Print help or version? */
87 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
88 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
89 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
90
91 /* Process other arguments, starting from the first non-option */
92 for(; ai<argc; ai++) {
93 if(!resfile[0]) {strlcpy(resfile, argv[ai], FILENAME_MAX); continue;}
94 else if(!htmfile[0]) {strlcpy(htmfile, argv[ai], FILENAME_MAX); continue;}
95 }
96
97 /* Is something missing? */
98 if(!resfile[0]) {
99 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
100 return(1);
101 }
102 if(!htmfile[0]) {
103 strcpy(htmfile, resfile);
104 cptr=strrchr(htmfile, '.'); if(cptr!=NULL) *cptr=(char)0;
105 strcat(htmfile, ".htm");
106 }
107
108 /* In verbose mode print arguments and options */
109 if(verbose>1) {
110 printf("resfile := %s\n", resfile);
111 printf("htmfile := %s\n", htmfile);
112 printf("saveSD := %d\n", saveSD);
113 }
114 if(verbose>4) RESULT_TEST=verbose-4; else RESULT_TEST=0;
115
116
117 /*
118 * Read result file
119 */
120 if(verbose>1) printf("reading %s\n", resfile);
121 if(resRead(resfile, &res, verbose-2)) {
122 fprintf(stderr, "Error in reading '%s': %s\n", resfile, reserrmsg);
123 resEmpty(&res);
124 return(2);
125 }
126
127
128 /*
129 * Remove SDs and CVs if required
130 */
131 if(saveSD==0) {
132 for(int ri=0; ri<res.voiNr; ri++) for(int pi=0; pi<res.parNr; pi++)
133 res.voi[ri].sd[pi]=res.voi[ri].cl1[pi]=res.voi[ri].cl2[pi]=nan("");
134 }
135
136
137 /*
138 * Write results in HTML format
139 */
140 if(verbose>1) printf("writing %s\n", htmfile);
141 if(resWriteHTML(&res, htmfile, verbose-1)) {
142 fprintf(stderr, "Error in writing '%s': %s\n", resfile, reserrmsg);
143 resEmpty(&res);
144 return(11);
145 }
146 resEmpty(&res);
147 if(verbose==1) printf("%s written.\n", htmfile);
148
149 return(0);
150}
151/*****************************************************************************/
152
153/*****************************************************************************/
Header file for libtpccurveio.
char reserrmsg[64]
Definition result.c:6
void resInit(RES *res)
Definition result.c:52
int resRead(char *filename, RES *res, int verbose)
Definition result.c:199
int resWriteHTML(RES *res, char *fname, int verbose)
Definition result.c:865
void resEmpty(RES *res)
Definition result.c:22
int RESULT_TEST
Definition result.c:5
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:213
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:383
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:158
int parNr
int voiNr
ResVOI * voi
double cl2[MAX_RESPARAMS]
double cl1[MAX_RESPARAMS]
double sd[MAX_RESPARAMS]