9#include "tpcclibConfig.h"
23static char *info[] = {
24 "Convert model or function fit parameter data in filename1 into filename2",
25 "in specified file format.",
26 "Data can be written only in a few formats (listed below), but more",
27 "file formats can be read.",
29 "Usage: @P [options] filename1 [filename2]",
33 " Accepted format-id's:",
34 " CSV-INT - CSV format with semicolons and decimal commas.",
35 " CSV-UK - CSV format with commas and decimal points.",
36 " TSV-INT - TSV format with tabs and decimal commas.",
37 " TSV-UK - TSV format with tabs and decimal points.",
38 " RES - TPC RES format (deprecated).",
39 " FIT - TPC FIT format (deprecated).",
40 " IFT - Interfile type format.",
41 " XML - MS Excel compatible XML format.",
42 " Without this option, only the format of the given file is shown.",
44 " Extra information is (y, default) or is not stored (n) in lines",
45 " starting with '#' character; not effective with all formats.",
47 " Keep (y, default) or remove (n) parameter units.",
50 "Example: convert RES file into CSV format for exporting to Excel",
51 " @P -f=CSV-UK -hdr=no iea446ki.res iea446ki.csv",
53 "See also: parsort, paradd, parget, csvtrps, reslist, parmatch, rescoll",
55 "Keywords: parameter, tool, format, CSV, RES, FIT",
74int main(
int argc,
char **argv)
76 int ai, help=0, version=0, verbose=1;
81 char *cptr, parfile1[FILENAME_MAX], parfile2[FILENAME_MAX];
88 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
90 parfile1[0]=parfile2[0]=(char)0;
92 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
94 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
95 if(strncasecmp(cptr,
"F=", 2)==0) {
98 }
else if(strncasecmp(cptr,
"FORMAT=", 7)==0) {
101 }
else if(strncasecmp(cptr,
"HDR=", 4)==0) {
103 if(strncasecmp(cptr,
"YES", 1)==0) {save_header=1;
continue;}
104 else if(strncasecmp(cptr,
"NO", 1)==0) {save_header=0;
continue;}
105 }
else if(strncasecmp(cptr,
"HEADER=", 7)==0) {
107 if(strncasecmp(cptr,
"YES", 1)==0) {save_header=1;
continue;}
108 else if(strncasecmp(cptr,
"NO", 1)==0) {save_header=0;
continue;}
109 }
else if(strncasecmp(cptr,
"UNITS=", 6)==0) {
111 if(strncasecmp(cptr,
"YES", 1)==0) {keep_units=1;
continue;}
112 else if(strncasecmp(cptr,
"NO", 1)==0) {keep_units=0;
continue;}
114 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
119 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
124 for(; ai<argc; ai++) {
127 strlcpy(parfile1, argv[ai], FILENAME_MAX);
129 strlcpy(parfile2, argv[ai], FILENAME_MAX);
131 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
136 if(!parfile1[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
141 printf(
"save_header := %d\n", save_header);
142 printf(
"keep_units := %d\n", keep_units);
143 printf(
"parfile1 := %s\n", parfile1);
144 if(parfile2[0]) printf(
"parfile2 := %s\n", parfile2);
154 if(verbose>1) printf(
"reading %s\n", parfile1);
155 ret=
parRead(&par, parfile1, &status);
157 fprintf(stderr,
"Error: %s (%s)\n",
errorMsg(status.
error), parfile1);
176 strcpy(parfile2, parfile1);
181 printf(
"parfile2 := %s\n", parfile2);
186 printf(
"\n---- par.h ----\n");
188 printf(
"---------------\n\n");
192 if(verbose>1) printf(
"writing %s\n", parfile2);
193 FILE *fp; fp=fopen(parfile2,
"w");
195 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", parfile2);
198 ret=
parWrite(&par, fp, new_format, save_header, &status);
202 fprintf(stderr,
"Error: writing format %s is not supported.\n",
parFormattxt(new_format));
209 if(verbose>0) printf(
" %s written.\n", parfile2);
void filenameRmPath(char *s)
int filenameRmExtension(char *s)
int iftWrite(IFT *ift, FILE *fp, TPCSTATUS *status)
char * parFormattxt(parformat c)
int parFormatIdentify(const char *s)
int parWrite(PAR *par, FILE *fp, parformat format, int extra, TPCSTATUS *status)
int parRead(PAR *par, const char *fname, TPCSTATUS *status)
char * parDefaultExtension(parformat c)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
IFT h
Optional (but often useful) header information.
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
Header file for library libtpcextensions.
@ UNIT_UNKNOWN
Unknown unit.
@ TPCERROR_UNSUPPORTED
Unsupported file type.
Header file for library libtpcift.
Header file for libtpcpar.
@ PAR_FORMAT_UNKNOWN
Unknown format.
Header file for library libtpctac.