| 1 |
|
| 2 |
CGATS file I/O library, V2.01 README file |
| 3 |
----------------------------------------- |
| 4 |
|
| 5 |
Package contents: |
| 6 |
----------------- |
| 7 |
cgatslib.zip ZIP archive of the following files |
| 8 |
Readme.txt This file. |
| 9 |
License4.txt Important! - Permissions for use of this package. |
| 10 |
cgats.c CGATS Library source code. |
| 11 |
cgatsstd.c I/O and malloc source code. |
| 12 |
cgats.h CGATS Library include file. Note machine dependent defines. |
| 13 |
pars.c Parser source code. |
| 14 |
parsstd.c I/O and malloc source code. |
| 15 |
pars.h Parser include file. Note machine dependent defines. |
| 16 |
Jampfile JAM style "makefile" see <http://www.perforce.com/jam/jam.html> |
| 17 |
Makefile Makefile. Modify this to include one of the following rule sets. |
| 18 |
Makefile.WNT Makefile defines for Microsoft C++ on Windows NT |
| 19 |
Makefile.IBMNT Makefile defines for IBM C++ on Windows NT |
| 20 |
Makefile.UNIX Makefile defines for generic UNIX system |
| 21 |
Makefile.OSX Makefile defines for Apple MAC OSX |
| 22 |
|
| 23 |
Changes: |
| 24 |
-------- |
| 25 |
|
| 26 |
Changes since V2.00 |
| 27 |
|
| 28 |
Removed all exit()s from code - now return error values |
| 29 |
from all functions. |
| 30 |
|
| 31 |
Added abstract objects for File I/O and memory allocation |
| 32 |
to improve system compatibility. |
| 33 |
|
| 34 |
Separated the implimentations of the abstract I/O and |
| 35 |
memory objects that ise stdio and malloc into separate |
| 36 |
files so that a library can be compiled without reference |
| 37 |
to these system calls. |
| 38 |
|
| 39 |
|
| 40 |
--------------------------------------------------------------- |
| 41 |
DOCUMENTATION |
| 42 |
|
| 43 |
This library has been implemented from the CGATS.5 Data Exchange Format |
| 44 |
specification, in Annex J, of the ANSI CGATS.5-1993 standard. |
| 45 |
See <http://www.npes.org/standards/description.htm> |
| 46 |
|
| 47 |
This module attempts to make reading CGATS.5 and IT8.7 files |
| 48 |
easy and convenient. Since the standard is a less than clear |
| 49 |
on some points it is hard to know how much compatibility is |
| 50 |
to be expected. |
| 51 |
|
| 52 |
The module supports non-standard keywords and fields automatically. |
| 53 |
It does not support reading of comments. |
| 54 |
It supports reading and writing multiple tables within one file. |
| 55 |
Abreviated tables may be written. |
| 56 |
Non-standard fields written by this module will be recognized |
| 57 |
correcty when read by this module (data types are written |
| 58 |
unambiguously - reals all have a decimal point, no non-quoted strings |
| 59 |
are written that could be interpreted as a real or integer), but |
| 60 |
there is no certainty that non-standard fields written by other |
| 61 |
software will be recognized corectly (e.g. - how to you tell |
| 62 |
whether 1234 is an integer, real, or non-quoted string ?) |
| 63 |
|
| 64 |
To creat a file each element needs to be built up in turn: |
| 65 |
|
| 66 |
Create an empty cgats structure: |
| 67 |
new_cgats(). |
| 68 |
|
| 69 |
A non-standard memory allocator can be specified for use |
| 70 |
by the cgats object by passing an object that inherits |
| 71 |
from the cgatsAlloc class defined in parse.h, to the |
| 72 |
new_cgats_al(cgatsAlloc *al) constructor. |
| 73 |
|
| 74 |
|
| 75 |
Use the module methods to: |
| 76 |
|
| 77 |
|
| 78 |
Add a user defined file identifier to augment the standard identifiers: |
| 79 |
add_other(cgats *p, char *osym) |
| 80 |
This can be used to read or write table that are compatible with CGATS.5 |
| 81 |
syntax but have different file identifiers. |
| 82 |
Use a zero length string (ie. just "") for wildcard. |
| 83 |
Normaly returns 0, returns -ve if there was a system error, |
| 84 |
& sets p->errc & p->err appropriately. |
| 85 |
|
| 86 |
|
| 87 |
create an empty table entry: |
| 88 |
add_table(cgats *p, table_type tt, int oi) |
| 89 |
tt is the table type: it8_7_1, it8_7_2, it8_7_3, it8_7_4, cgats_5, cgats_X, |
| 90 |
tt_other or tt_none. |
| 91 |
cgat_X represents any "CGATS.XXX" table type. |
| 92 |
If tt_other is used for creating a file, then oi must be set to the index of the |
| 93 |
user defined table identifiers set by calls to p->add_other(); |
| 94 |
The table type read can be identified by looking at the index |
| 95 |
p->t[table_number].tt, which will be set to the table type. |
| 96 |
If the type is cgats_X type, the type actually found will be in p->cgats_type. |
| 97 |
If tt == tt_other, then the "other index" value is p->t[table_numberx].oi. |
| 98 |
For a wildcard tt_other, the actual type found will be at p->others[oi]. |
| 99 |
|
| 100 |
Tables are added in turn, and are indexed from 0 in other functions. |
| 101 |
Returns 0 normally. |
| 102 |
It returns -2 if there was a system error, & sets p->errc & p->err appropriately. |
| 103 |
|
| 104 |
|
| 105 |
Suppress the writing of the file identifier string, standard keyword definitions |
| 106 |
and/or field definitions for a second or subsequent table: |
| 107 |
set_table_flags(cgats *p, int table, int sup_id, int sup_kwords, int sup_fields); |
| 108 |
This only makes sense if the subsequent table has the same identifier type, keywords |
| 109 |
and field definitions as the preceding table. Returns 0 normally. |
| 110 |
It returns -1 if there was an error, & sets p->errc & p->err appropriately. |
| 111 |
|
| 112 |
|
| 113 |
Add keywords and their values: |
| 114 |
int add_kword(cgats *p, int table, char *ksym, char *kdata, char *kcom); |
| 115 |
The return value is the index of the new keyword, or -1, errc & err on error. |
| 116 |
Any non-standard keywords will automatically be declared in the file. |
| 117 |
The comment is optional and NULL should be passed if no comment is to be used |
| 118 |
after the keyword/value pair. |
| 119 |
|
| 120 |
Standard keywords are: |
| 121 |
ORIGINATOR System, organization or individual that created data |
| 122 |
DESCRIPTOR Purpose or contents of the data file |
| 123 |
CREATED Date of creation of the file |
| 124 |
MANUFACTURER Manufacturer of physical target |
| 125 |
PROD_DATE Year and month of physical target production yyyy:mm |
| 126 |
SERIAL Unique physical target serial number |
| 127 |
MATERIAL Material physical target was produced on |
| 128 |
INSTRUMENTATION Manufacturer and model number of measuring instrument |
| 129 |
MEASUREMENT_SOURCE Illumination used for spectral measurements |
| 130 |
PRINT_CONDITIONS Characteristics of printed sheet being reported |
| 131 |
|
| 132 |
Standard keywords will be created automatically if necessary for a legal file format. |
| 133 |
|
| 134 |
The following kewords are supplied automatically by the module, |
| 135 |
and cannot be used for other things: |
| 136 |
NUMBER_OF_FIELDS |
| 137 |
BEGIN_DATA_FORMAT |
| 138 |
END_DATA_FORMAT |
| 139 |
NUMBER_OF_SETS |
| 140 |
BEGIN_DATA |
| 141 |
END_DATA |
| 142 |
KEYWORD |
| 143 |
|
| 144 |
|
| 145 |
Add fields: |
| 146 |
int add_field(cgats *p, int table, char *fsym, data_type ftype); |
| 147 |
|
| 148 |
The return value is the index of the new field, or return |
| 149 |
-1, errc & err on error, -2, errc & err on system error. |
| 150 |
|
| 151 |
ftype defines the data type from: r_t, i_t, cs_t, nqcs_t. |
| 152 |
r_t is the real (double) type, |
| 153 |
i_t is the integer (int) type, |
| 154 |
cs_t is the character string (char*) type, |
| 155 |
nqcs_t is the same as cs_t except that it will be non-quoted if possible. |
| 156 |
Note that the type must agree with the standard type if the field is |
| 157 |
from the set default data format identifiers: |
| 158 |
|
| 159 |
SAMPLE_ID nqcs_t Identifies sample which data represents |
| 160 |
STRING cs_t Identifies label, or other non-machine readable value. |
| 161 |
CMYK_C r_t Cyan percentage of CMYK |
| 162 |
CMYK_M r_t Magenta percentage of CMYK |
| 163 |
CMYK_Y r_t Yellow percentage of CMYK |
| 164 |
CMYK_K r_t Black percentage of CMYK |
| 165 |
D_RED r_t Red filter reflection density |
| 166 |
D_GREEN r_t Green filter reflection density |
| 167 |
D_BLUE r_t Blue filter reflection density |
| 168 |
D_VIS r_t Visual filter reflection density |
| 169 |
RGB_R r_t Red component of RGB data |
| 170 |
RGB_G r_t Green component of RGB data |
| 171 |
RGB_B r_t Blue component of RGB data |
| 172 |
SPECTRAL_NM r_t Wavelength of measurement in nanometers |
| 173 |
SPECTRAL_PCT r_t Precentage reflectance/transmittance |
| 174 |
XYZ_X r_t X component of tristimulus data |
| 175 |
XYZ_Y r_t Y component of tristimulus data |
| 176 |
XYZ_Z r_t Z component of tristimulus data |
| 177 |
XYY_X r_t x component of chromaticity data |
| 178 |
XYY_Y r_t y component of chromaticity data |
| 179 |
XYY_CAPY r_t Y component of chromaticity data |
| 180 |
LAB_L r_t L* component of Lab data |
| 181 |
LAB_A r_t a* component of Lab data |
| 182 |
LAB_B r_t b* component of Lab data |
| 183 |
LAB_C r_t C*ab component of Lab data |
| 184 |
LAB_H r_t hab component of Lab data |
| 185 |
LAB_DE r_t CIA delta E |
| 186 |
STDEV_X r_t Standard deviation of X (tristimulous data) |
| 187 |
STDEV_Y r_t Standard deviation of Y (tristimulous data) |
| 188 |
STDEV_Z r_t Standard deviation of Z (tristimulous data) |
| 189 |
STDEV_L r_t Standard deviation of L* |
| 190 |
STDEV_A r_t Standard deviation of a* |
| 191 |
STDEV_B r_t Standard deviation of b* |
| 192 |
STDEV_DE r_t Standard deviation of CIE delta E |
| 193 |
|
| 194 |
Add a set of data: |
| 195 |
add_set(cgats *p, int table, ...) |
| 196 |
The data should be supplied as a varargs list in the appropropriate |
| 197 |
data format [char*, double or int]. |
| 198 |
Returns 0 normally, -1 errc & err if parameter error, |
| 199 |
-2 errc & err if system error. |
| 200 |
|
| 201 |
Add a set of data from union array: |
| 202 |
add_setarr(cgats *p, int table, cgats_set_elem *args); |
| 203 |
The data should be supplied as an array of cgats_set_elem unions. |
| 204 |
Returns 0 normally, -1 errc & err if parameter error, |
| 205 |
-2 errc & err if system error. |
| 206 |
|
| 207 |
Write the data out to a file. |
| 208 |
write_name(cgats *p, char *fname); |
| 209 |
The method will return non-zero on an error, with an error |
| 210 |
description in the err location of the structure. |
| 211 |
|
| 212 |
|
| 213 |
A non-standard destination of data can be read by passing an |
| 214 |
object that inherits from the cgatsFile class defined in |
| 215 |
parse.h to the write(cgats *p, cgatsFile *fp) method. |
| 216 |
|
| 217 |
To read in a data file, the cgats structure should be created |
| 218 |
as usual. The read method can then be called to read in the file: |
| 219 |
read_name(cgats *p, char *fname) |
| 220 |
Returns 0 normally, and -ve on an error, with an error |
| 221 |
description in the err location of the structure, |
| 222 |
and errc set with the return code. |
| 223 |
|
| 224 |
A non-standard source of data can be read by passing an |
| 225 |
object that inherits from the cgatsFile class defined in |
| 226 |
parse.h to the read(cgats *p, cgatsFile *fp) method. |
| 227 |
|
| 228 |
The reader will deal automaticaly with carry over of keywords |
| 229 |
and/or field definitions from one table to another, making each |
| 230 |
table appear independent once read. |
| 231 |
|
| 232 |
The data is accessed by refering to the following read-only |
| 233 |
structure entries: |
| 234 |
|
| 235 |
The number of tables will be in p->ntables |
| 236 |
|
| 237 |
The number of keywords will be in p->t[table_number].nkwords |
| 238 |
The number of fields will be in p->t[table_number].nfields |
| 239 |
The number of sets will be in p->t[table_number].nsets |
| 240 |
|
| 241 |
Tables, keywords, fields and sets index from 0. |
| 242 |
|
| 243 |
The keywords will be in |
| 244 |
p->t[table_number].ksym[keyword_index] |
| 245 |
|
| 246 |
The keywords character string value be in |
| 247 |
p->t[table_number].kdata[keyword_index] |
| 248 |
|
| 249 |
The field format identifiers of each field will be in |
| 250 |
p->t[table_number].fsym[field_index] |
| 251 |
|
| 252 |
The data type of each field will be in |
| 253 |
p->t[table_number].ftype[field_index] |
| 254 |
|
| 255 |
A void pointer to the data of each field of each set will be in |
| 256 |
p->t[table_number].fdata[set_index][field_index] |
| 257 |
Cast the void pointet according to its type to retrieve the data. |
| 258 |
Alternatively the |
| 259 |
p->get_setarr(struct _cgats *p, int table, int set_index, cgats_set_elem *ary) |
| 260 |
method can be used to fill in a suitable sized cgats_set_elem array with |
| 261 |
the value of all the fields at a particular index. Any character string |
| 262 |
type will be a pointer to the data in p->t[table_number].fdata[set_index][field_index]. |
| 263 |
|
| 264 |
To find the index to a particular keyword, use: |
| 265 |
find_kword(cgats *p, int table, char *ksym) |
| 266 |
-1 will be returned if no match is found. |
| 267 |
-2 will be returned, p->errc & p->err will be set if table is out of range. |
| 268 |
|
| 269 |
To find the index to a particular field, use: |
| 270 |
find_field(cgats *p, int table, char *fsym); |
| 271 |
-1 will be returned if no match is found. |
| 272 |
-2 will be returned, p->errc & p->err will be set if table is out of range. |
| 273 |
|
| 274 |
Rather than checking the error return codes from every method, |
| 275 |
the first error is "sticky", and recorded in the object. |
| 276 |
This can be checked after a series of operations by calling |
| 277 |
the error(cgats *p, char **mes) method, which will return the |
| 278 |
error code, and (optionaly) the error message. |
| 279 |
|
| 280 |
Once operations are finished, the object can be deleted by calling |
| 281 |
the delete method: |
| 282 |
del(cgats *p) |
| 283 |
|
| 284 |
Graeme Gill. |
| 285 |
|
| 286 |
--------------------------------------------------------------- |