From c0b89ac5bfb90835ef01573267020e42d4fe070c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 23 Aug 2015 12:17:05 +0200 Subject: Imported Upstream version 1.8.0 --- cgats/Jamfile | 0 cgats/License.txt | 0 cgats/Makefile | 0 cgats/Makefile.IBMNT | 0 cgats/Makefile.OSX | 0 cgats/Makefile.UNIX | 0 cgats/Makefile.WNT | 0 cgats/Readme.txt | 0 cgats/afiles | 1 + cgats/cgats.c | 66 ++++++++++++++++++++++++++++------------------- cgats/cgats.h | 3 +++ cgats/cgatsstd.c | 0 cgats/makezip.ksh | 0 cgats/pars.c | 2 +- cgats/pars.h | 0 cgats/parsstd.c | 0 cgats/test.txt | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 117 insertions(+), 28 deletions(-) mode change 100644 => 100755 cgats/Jamfile mode change 100644 => 100755 cgats/License.txt mode change 100644 => 100755 cgats/Makefile mode change 100644 => 100755 cgats/Makefile.IBMNT mode change 100644 => 100755 cgats/Makefile.OSX mode change 100644 => 100755 cgats/Makefile.UNIX mode change 100644 => 100755 cgats/Makefile.WNT mode change 100644 => 100755 cgats/Readme.txt mode change 100644 => 100755 cgats/afiles mode change 100644 => 100755 cgats/cgats.c mode change 100644 => 100755 cgats/cgats.h mode change 100644 => 100755 cgats/cgatsstd.c mode change 100644 => 100755 cgats/makezip.ksh mode change 100644 => 100755 cgats/pars.c mode change 100644 => 100755 cgats/pars.h mode change 100644 => 100755 cgats/parsstd.c create mode 100755 cgats/test.txt (limited to 'cgats') diff --git a/cgats/Jamfile b/cgats/Jamfile old mode 100644 new mode 100755 diff --git a/cgats/License.txt b/cgats/License.txt old mode 100644 new mode 100755 diff --git a/cgats/Makefile b/cgats/Makefile old mode 100644 new mode 100755 diff --git a/cgats/Makefile.IBMNT b/cgats/Makefile.IBMNT old mode 100644 new mode 100755 diff --git a/cgats/Makefile.OSX b/cgats/Makefile.OSX old mode 100644 new mode 100755 diff --git a/cgats/Makefile.UNIX b/cgats/Makefile.UNIX old mode 100644 new mode 100755 diff --git a/cgats/Makefile.WNT b/cgats/Makefile.WNT old mode 100644 new mode 100755 diff --git a/cgats/Readme.txt b/cgats/Readme.txt old mode 100644 new mode 100755 diff --git a/cgats/afiles b/cgats/afiles old mode 100644 new mode 100755 index dc20cb4..e185eb7 --- a/cgats/afiles +++ b/cgats/afiles @@ -7,6 +7,7 @@ pars.c pars.h parsstd.c cgatsstd.c +test.txt Jamfile Makefile Makefile.WNT diff --git a/cgats/cgats.c b/cgats/cgats.c old mode 100644 new mode 100755 index a39ec04..3e6e642 --- a/cgats/cgats.c +++ b/cgats/cgats.c @@ -68,7 +68,8 @@ extern void error(const char *fmt, ...), warning(const char *fmt, ...); #include "pars.h" #include "cgats.h" -#define REAL_SIGDIG 6 /* Number of significant digits in real representation */ +#undef EMIT_KEYWORDS /* [und] Emit unknown keywords by default */ +#define REAL_SIGDIG 6 /* [6] Number of significant digits in real representation */ static int cgats_read(cgats *p, cgatsFile *fp); static int find_kword(cgats *p, int table, const char *ksym); @@ -147,6 +148,10 @@ cgatsAlloc *al /* memory allocator */ p->write_name = NULL; #endif +#ifdef EMIT_KEYWORDS + p->emit_keywords = 1; +#endif + return p; } @@ -668,6 +673,7 @@ cgats_read(cgats *p, cgatsFile *fp) { for (j = 0; j < ct->nsets; j++) { data_type ty; ty = guess_type(((char *)ct->rfdata[j][i])); + if (ty == cs_t) { bt = cs_t; break; /* Early out */ @@ -678,7 +684,7 @@ cgats_read(cgats *p, cgatsFile *fp) { if (bt == i_t) bt = ty; } else { /* ty == i_t */ - bt = ty; + /* This is the default */ } } /* Got guessed type bt. Sanity check against known field types */ @@ -1446,7 +1452,7 @@ cgats_write(cgats *p, cgatsFile *fp) { /* Keyword and data if it is present */ if (t->ksym[i] != NULL && t->kdata[i] != NULL) { - if (!standard_kword(t->ksym[i])) { /* Do the right thing */ + if (p->emit_keywords && !standard_kword(t->ksym[i])) { /* Do the right thing */ if ((qs = quote_cs(al, t->ksym[i])) == NULL) { al->free(al, sfield); return err(p,-2,"quote_cs() malloc failed!"); @@ -1485,7 +1491,7 @@ cgats_write(cgats *p, cgatsFile *fp) { /* Declare any non-standard fields */ for (field = 0; field < t->nfields; field++) { - if (!sfield[field]) /* Non-standard */ { + if (p->emit_keywords && !sfield[field]) /* Non-standard */ { char *qs; if ((qs = quote_cs(al, t->fsym[field])) == NULL) { al->free(al, sfield); @@ -1931,21 +1937,22 @@ real_format(double value, int nsd, char *fmt) { xtot++; } if (value < 1.0) { + int thr = -5; ndigs = (int)(log10(value)); - if (ndigs <= -2) { + if (ndigs <= thr) { sprintf(fmt,"%%%d.%de",xtot,tot-2); return; } sprintf(fmt,"%%%d.%df",xtot-ndigs,nsd-ndigs); return; } else { + int thr = -0; ndigs = (int)(log10(value)); - if (ndigs >= (nsd -1)) - { + if (ndigs >= (nsd + thr)) { sprintf(fmt,"%%%d.%de",xtot,tot-2); return; - } - sprintf(fmt,"%%%d.%df",xtot,(nsd-1)-ndigs); + } + sprintf(fmt,"%%%d.%df",xtot,(nsd + thr)-ndigs); return; } } @@ -2090,24 +2097,29 @@ main(int argc, char *argv[]) { || pp->add_field(pp, 0, "XYZ_X", r_t) < 0) error("Initial error: '%s'",pp->err); - if (pp->add_set(pp, 0, "1", "A1", 0.000012345678) < 0 - || pp->add_set(pp, 0, "2", "A2", 0.00012345678) < 0 - || pp->add_set(pp, 0, "3 ", "A#5",0.0012345678) < 0 - || pp->add_set(pp, 0, "4", "A5", 0.012345678) < 0 - || pp->add_set(pp, 0, "5", "A5", 0.12345678) < 0 - || pp->add_set(pp, 0, "5", "A5", 0.00000000) < 0 - || pp->add_set(pp, 0, "6", "A5", 1.2345678) < 0 - || pp->add_set(pp, 0, "7", "A5", 12.345678) < 0 - || pp->add_set(pp, 0, "8", "A5", 123.45678) < 0 - || pp->add_set(pp, 0, "9", "A5", 1234.5678) < 0 - || pp->add_set(pp, 0, "10", "A5", 12345.678) < 0 - || pp->add_set(pp, 0, "12", "A5", 123456.78) < 0 - || pp->add_set(pp, 0, "13", "A5", 1234567.8) < 0 - || pp->add_set(pp, 0, "14", "A5", 12345678.0) < 0 - || pp->add_set(pp, 0, "15", "A5", 123456780.0) < 0 - || pp->add_set(pp, 0, "16", "A5", 1234567800.0) < 0 - || pp->add_set(pp, 0, "17", "A5", 12345678000.0) < 0 - || pp->add_set(pp, 0, "18", "A5", 123456780000.0) < 0) + if (pp->add_set(pp, 0, "1", "A1", 0.000000012345678) < 0 + || pp->add_set(pp, 0, "2", "A1", 0.00000012345678) < 0 + || pp->add_set(pp, 0, "3", "A1", 0.0000012345678) < 0 + || pp->add_set(pp, 0, "4", "A1", 0.000012345678) < 0 + || pp->add_set(pp, 0, "5", "A1", 0.000012345678) < 0 + || pp->add_set(pp, 0, "6", "A2", 0.00012345678) < 0 + || pp->add_set(pp, 0, "7", "A5",0.0012345678) < 0 + || pp->add_set(pp, 0, "8", "A5", 0.012345678) < 0 + || pp->add_set(pp, 0, "9", "A5", 0.12345678) < 0 + || pp->add_set(pp, 0, "10", "A5", 0.00000000) < 0 + || pp->add_set(pp, 0, "11", "A5", 1.2345678) < 0 + || pp->add_set(pp, 0, "12", "A5", 12.345678) < 0 + || pp->add_set(pp, 0, "13", "A5", 123.45678) < 0 + || pp->add_set(pp, 0, "14", "A5", 1234.5678) < 0 + || pp->add_set(pp, 0, "15", "A5", 12345.678) < 0 + || pp->add_set(pp, 0, "16", "A5", 123456.78) < 0 + || pp->add_set(pp, 0, "17", "A5", 1234567.8) < 0 + || pp->add_set(pp, 0, "18", "A5", 12345678.0) < 0 + || pp->add_set(pp, 0, "19", "A5", 123456780.0) < 0 + || pp->add_set(pp, 0, "20", "A5", 1234567800.0) < 0 + || pp->add_set(pp, 0, "21", "A5", 12345678000.0) < 0 + || pp->add_set(pp, 0, "22", "A5", 123456780000.0) < 0 + || pp->add_set(pp, 0, "23", "A5", 1234567800000.0) < 0) error("Adding set error '%s'",pp->err); if (pp->add_table(pp, cgats_5, 0) < 0 /* Start the second table */ diff --git a/cgats/cgats.h b/cgats/cgats.h old mode 100644 new mode 100755 index 7537a48..bc0cdd7 --- a/cgats/cgats.h +++ b/cgats/cgats.h @@ -87,6 +87,9 @@ struct _cgats { int nothers; /* Number of other identifiers */ char **others; /* Other file type identifiers */ + /* Options */ + int emit_keywords; /* NZ to emit "KEYWORD" for non-standard keywords (default no) */ + /* Public Methods */ int (*set_cgats_type)(struct _cgats *p, const char *osym); /* Define the (one) variable CGATS type */ diff --git a/cgats/cgatsstd.c b/cgats/cgatsstd.c old mode 100644 new mode 100755 diff --git a/cgats/makezip.ksh b/cgats/makezip.ksh old mode 100644 new mode 100755 diff --git a/cgats/pars.c b/cgats/pars.c old mode 100644 new mode 100755 index a0e694c..8a4e4b9 --- a/cgats/pars.c +++ b/cgats/pars.c @@ -606,7 +606,7 @@ main() { error("Failed to create parse object with file 'test.txt'"); /* Setup our token parsing charaters */ - pp->add_del(pp, " ,\to"," ,\t", "#", "\""); + pp->add_del(pp, " ,\t"," ,\t", "#", "\""); for (;;) { char *tp; diff --git a/cgats/pars.h b/cgats/pars.h old mode 100644 new mode 100755 diff --git a/cgats/parsstd.c b/cgats/parsstd.c old mode 100644 new mode 100755 diff --git a/cgats/test.txt b/cgats/test.txt new file mode 100755 index 0000000..5036d32 --- /dev/null +++ b/cgats/test.txt @@ -0,0 +1,73 @@ +CGATS.5 + +# Comment only test comment +KEYWORD "TEST_KEY_WORD" +TEST_KEY_WORD "try this out" # Keyword comment +KEYWORD "TEST_KEY_WORD2" +TEST_KEY_WORD2 "try this"" out """" huh !" +ORIGINATOR "Not specified" +DESCRIPTOR "Not specified" +CREATED "November 16, 2000" +INSTRUMENTATION "Not specified" +MEASUREMENT_SOURCE "Not specified" +PRINT_CONDITIONS "Not specified" + +KEYWORD "SAMPLE_LOC" +NUMBER_OF_FIELDS 3 +BEGIN_DATA_FORMAT +SAMPLE_ID SAMPLE_LOC XYZ_X +END_DATA_FORMAT + +NUMBER_OF_SETS 22 +BEGIN_DATA +1 A1 1.2346e-09 +2 A1 1.2346e-08 +3 A1 1.2346e-07 +4 A1 1.2346e-06 +5 A1 1.2346e-05 +6 A2 1.2346e-04 +"7 " "A#5" 1.2346e-03 +8 A5 0.012346 +9 A5 0.12346 +10 A5 0.0000 +11 A5 1.2346 +12 A5 12.346 +13 A5 123.46 +14 A5 1234.6 +16 A5 1.2346e+04 +17 A5 1.2346e+05 +18 A5 1.2346e+06 +19 A5 1.2346e+07 +20 A5 1.2346e+08 +21 A5 1.2346e+09 +22 A5 1.2346e+10 +23 A5 1.2346e+11 +END_DATA + + +# Second Comment only test comment + +NUMBER_OF_SETS 22 +BEGIN_DATA +1 A4 -1.2346e-09 +2 A4 -1.2346e-08 +3 A4 -1.2346e-07 +4 A4 -1.2346e-06 +5 A4 -1.2346e-05 +6 A5 -1.2346e-04 +7 A5 -1.2346e-03 +8 A5 -0.012346 +9 A5 -0.12346 +10 A5 -1.2346 +11 A5 -12.346 +12 A5 -123.46 +13 A5 -1234.6 +14 A5 -1.2346e+04 +15 A5 -1.2346e+05 +16 A5 -1.2346e+06 +17 A5 -1.2346e+07 +18 A5 -1.2346e+08 +19 A5 -1.2346e+09 +20 A5 -1.2346e+10 +21 A5 -1.2346e+11 +E7D_DATA -- cgit v1.2.3