diff options
Diffstat (limited to 'cgats')
-rwxr-xr-x[-rw-r--r--] | cgats/Jamfile | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/License.txt | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/Makefile | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/Makefile.IBMNT | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/Makefile.OSX | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/Makefile.UNIX | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/Makefile.WNT | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/Readme.txt | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/afiles | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/cgats.c | 66 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/cgats.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/cgatsstd.c | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/makezip.ksh | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/pars.c | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/pars.h | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | cgats/parsstd.c | 0 | ||||
-rwxr-xr-x | cgats/test.txt | 73 |
17 files changed, 117 insertions, 28 deletions
diff --git a/cgats/Jamfile b/cgats/Jamfile index 813269a..813269a 100644..100755 --- a/cgats/Jamfile +++ b/cgats/Jamfile diff --git a/cgats/License.txt b/cgats/License.txt index 7655233..7655233 100644..100755 --- a/cgats/License.txt +++ b/cgats/License.txt diff --git a/cgats/Makefile b/cgats/Makefile index 5312104..5312104 100644..100755 --- a/cgats/Makefile +++ b/cgats/Makefile diff --git a/cgats/Makefile.IBMNT b/cgats/Makefile.IBMNT index 26a2bd2..26a2bd2 100644..100755 --- a/cgats/Makefile.IBMNT +++ b/cgats/Makefile.IBMNT diff --git a/cgats/Makefile.OSX b/cgats/Makefile.OSX index fb1c88f..fb1c88f 100644..100755 --- a/cgats/Makefile.OSX +++ b/cgats/Makefile.OSX diff --git a/cgats/Makefile.UNIX b/cgats/Makefile.UNIX index 91d6005..91d6005 100644..100755 --- a/cgats/Makefile.UNIX +++ b/cgats/Makefile.UNIX diff --git a/cgats/Makefile.WNT b/cgats/Makefile.WNT index 4ca291d..4ca291d 100644..100755 --- a/cgats/Makefile.WNT +++ b/cgats/Makefile.WNT diff --git a/cgats/Readme.txt b/cgats/Readme.txt index 94f3e3d..94f3e3d 100644..100755 --- a/cgats/Readme.txt +++ b/cgats/Readme.txt diff --git a/cgats/afiles b/cgats/afiles index dc20cb4..e185eb7 100644..100755 --- 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 index a39ec04..3e6e642 100644..100755 --- 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 index 7537a48..bc0cdd7 100644..100755 --- 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 index d8fbb34..d8fbb34 100644..100755 --- a/cgats/cgatsstd.c +++ b/cgats/cgatsstd.c diff --git a/cgats/makezip.ksh b/cgats/makezip.ksh index 8cc5f6c..8cc5f6c 100644..100755 --- a/cgats/makezip.ksh +++ b/cgats/makezip.ksh diff --git a/cgats/pars.c b/cgats/pars.c index a0e694c..8a4e4b9 100644..100755 --- 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 index 83bbdad..83bbdad 100644..100755 --- a/cgats/pars.h +++ b/cgats/pars.h diff --git a/cgats/parsstd.c b/cgats/parsstd.c index 4443e0a..4443e0a 100644..100755 --- a/cgats/parsstd.c +++ b/cgats/parsstd.c 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 |