89
92
ocg->add_kword(ocg, 0, "TECHNOLOGY", p->tech,NULL);
90
93
if (p->disp == NULL && p->tech == NULL) {
91
sprintf(p->err, "write_ccss: ccss for file '%s' doesn't contain display or techology strings",outname);
94
sprintf(p->err, "write_ccss: ccss doesn't contain display or techology strings");
99
ocg->add_kword(ocg, 0, "DISPLAY_TYPE_REFRESH", p->refrmode ? "YES" : "NO", NULL);
101
ocg->add_kword(ocg, 0, "UI_SELECTORS", p->sel, NULL);
95
102
if (p->ref != NULL)
96
103
ocg->add_kword(ocg, 0, "REFERENCE",p->ref, NULL);
101
108
ocg->add_kword(ocg, 0, "SPECTRAL_START_NM",buf, NULL);
102
109
sprintf(buf,"%f", p->samples[0].spec_wl_long);
103
110
ocg->add_kword(ocg, 0, "SPECTRAL_END_NM",buf, NULL);
111
sprintf(buf,"%f", p->samples[0].norm);
112
ocg->add_kword(ocg, 0, "SPECTRAL_NORM",buf, NULL);
105
114
/* Fields we want */
106
115
ocg->add_field(ocg, 0, "SAMPLE_ID", nqcs_t);
157
/* Write out the ccss to a CGATS format .ccss file */
158
/* Return nz on error */
159
static int write_ccss(
161
char *outname /* Filename to write to */
164
cgats *ocg; /* CGATS structure */
166
if (p->no_samp < 3) {
167
strcpy(p->err, "Need at least three spectral samples");
171
/* Create CGATS elements */
172
if ((rv = create_ccss_cgats(p, &ocg)) != 0) {
176
/* Write it to file */
143
177
if (ocg->write_name(ocg, outname)) {
144
178
strcpy(p->err, ocg->err);
145
179
ocg->del(ocg); /* Clean up */
149
ocg->del(ocg); /* Clean up */
154
/* Read in the ccss CGATS .ccss file */
182
ocg->del(ocg); /* Clean up */
187
/* write to a CGATS .ccss file to a memory buffer. */
188
/* return nz on error, with message in err[] */
189
static int buf_write_ccss(
191
unsigned char **buf, /* Return allocated buffer */
192
int *len /* Return length */
195
cgats *ocg; /* CGATS structure */
198
if (p->no_samp < 3) {
199
strcpy(p->err, "Need at least three spectral samples");
203
/* Create CGATS elements */
204
if ((rv = create_ccss_cgats(p, &ocg)) != 0) {
208
if ((fp = new_cgatsFileMem(NULL, 0)) == NULL) {
209
strcpy(p->err, "new_cgatsFileMem failed");
213
/* Write it to file */
214
if (ocg->write(ocg, fp)) {
215
strcpy(p->err, ocg->err);
216
ocg->del(ocg); /* Clean up */
221
/* Get the buffer the ccss has been written to */
222
if (fp->get_buf(fp, buf, (size_t *)len)) {
223
strcpy(p->err, "cgatsFileMem get_buf failed");
227
ocg->del(ocg); /* Clean up */
233
/* Read in the ccss CGATS .ccss file from cgats */
155
234
/* Return nz on error */
156
static int read_ccss(
158
char *inname /* Filename to read from */
235
static int read_ccss_cgats(
237
cgats *icg /* input cgats structure */
161
cgats *icg; /* input cgats structure */
162
240
int ti, ii; /* Temporary CGATs index */
163
241
int spi[XSPECT_MAX_BANDS]; /* CGATS indexes for each wavelength */
166
/* Open and look at the .ccss file */
167
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
168
sprintf(p->err, "read_ccss: new_cgats() failed");
171
icg->add_other(icg, "CCSS"); /* our special type is Model Printer Profile */
173
if (icg->read_name(icg, inname)) {
174
strcpy(p->err, icg->err);
179
244
if (icg->ntables == 0 || icg->t[0].tt != tt_other || icg->t[0].oi != 0) {
180
sprintf(p->err, "read_ccss: Input file '%s' isn't a CCSS format file",inname);
245
sprintf(p->err, "read_ccss: Input file isn't a CCSS format file");
184
249
if (icg->ntables != 1) {
185
sprintf(p->err, "Input file '%s' doesn't contain exactly one table",inname);
250
sprintf(p->err, "Input file doesn't contain exactly one table");
228
293
if (p->disp == NULL && p->tech == NULL) {
229
sprintf(p->err, "read_ccss: Input file '%s' doesn't contain keyword DISPLAY or TECHNOLOGY",inname);
294
sprintf(p->err, "read_ccss: Input file doesn't contain keyword DISPLAY or TECHNOLOGY");
298
if ((ti = icg->find_kword(icg, 0, "DISPLAY_TYPE_REFRESH")) >= 0) {
299
if (stricmp(icg->t[0].kdata[ti], "YES") == 0)
301
else if (stricmp(icg->t[0].kdata[ti], "NO") == 0)
305
if ((ti = icg->find_kword(icg, 0, "UI_SELECTORS")) >= 0) {
306
if ((p->sel = strdup(icg->t[0].kdata[ti])) == NULL) {
307
sprintf(p->err, "read_ccss: malloc failed");
234
313
if ((ti = icg->find_kword(icg, 0, "REFERENCE")) >= 0) {
235
314
if ((p->ref = strdup(icg->t[0].kdata[ti])) == NULL) {
242
321
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_BANDS")) < 0) {
243
sprintf(p->err,"Input file '%s' doesn't contain keyword SPECTRAL_BANDS",inname);
322
sprintf(p->err,"Input file doesn't contain keyword SPECTRAL_BANDS");
247
326
sp.spec_n = atoi(icg->t[0].kdata[ii]);
248
327
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_START_NM")) < 0) {
249
sprintf(p->err,"Input file '%s' doesn't contain keyword SPECTRAL_START_NM",inname);
328
sprintf(p->err,"Input file doesn't contain keyword SPECTRAL_START_NM");
253
332
sp.spec_wl_short = atof(icg->t[0].kdata[ii]);
254
333
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_END_NM")) < 0) {
255
sprintf(p->err,"Input file '%s' doesn't contain keyword SPECTRAL_END_NM",inname);
334
sprintf(p->err,"Input file doesn't contain keyword SPECTRAL_END_NM");
259
338
sp.spec_wl_long = atof(icg->t[0].kdata[ii]);
340
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_NORM")) < 0) {
341
sp.norm = 1.0; /* Older versions don't have SPECTRAL_NORM */
343
sp.norm = atof(icg->t[0].kdata[ii]);
262
346
/* Find the fields for spectral values */
263
347
for (j = 0; j < sp.spec_n; j++) {
271
355
sprintf(buf,"SPEC_%03d",nm);
273
357
if ((spi[j] = icg->find_field(icg, 0, buf)) < 0) {
274
sprintf(p->err,"Input file '%s' doesn't contain field %s",inname,buf);
358
sprintf(p->err,"Input file doesn't contain field %s",buf);
280
364
if ((p->no_samp = icg->t[0].nsets) < 3) {
281
sprintf(p->err, "Input file '%s' doesn't contain at least three spectral samples",inname);
365
sprintf(p->err, "Input file doesn't contain at least three spectral samples");
283
367
icg->del(icg); /* Clean up */
393
/* Read in the ccss CGATS .ccss file */
394
/* Return nz on error */
395
static int read_ccss(
397
char *inname /* Filename to read from */
400
cgats *icg; /* input cgats structure */
402
/* Open and look at the .ccss file */
403
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
404
sprintf(p->err, "read_ccss: new_cgats() failed");
407
icg->add_other(icg, "CCSS"); /* our special type is Model Printer Profile */
409
if (icg->read_name(icg, inname)) {
410
strcpy(p->err, icg->err);
415
if ((rv = read_ccss_cgats(p, icg)) != 0) {
416
icg->del(icg); /* Clean up */
420
icg->del(icg); /* Clean up */
425
/* Read in the ccss CGATS .ccss file from a memory buffer */
426
/* Return nz on error */
427
static int buf_read_ccss(
434
cgats *icg; /* input cgats structure */
436
if ((fp = new_cgatsFileMem(buf, len)) == NULL) {
437
strcpy(p->err, "new_cgatsFileMem failed");
441
/* Open and look at the .ccss file */
442
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
443
sprintf(p->err, "read_ccss: new_cgats() failed");
447
icg->add_other(icg, "CCSS"); /* our special type is Model Printer Profile */
449
if (icg->read(icg, fp)) {
450
strcpy(p->err, icg->err);
457
if ((rv = read_ccss_cgats(p, icg)) != 0) {
458
icg->del(icg); /* Clean up */
306
462
icg->del(icg); /* Clean up */
316
472
char *desc, /* General description (optional) */
317
473
char *disp, /* Display make and model (optional if tech) */
318
474
char *tech, /* Display technology description (optional if disp) */
319
char *ref, /* Reference spectrometer description (optional) */
475
int refrmode, /* Display refresh mode, -1 = unknown, 0 = n, 1 = yes */
476
char *sel, /* UI selector characters - NULL for none */
477
char *refd, /* Reference spectrometer description (optional) */
320
478
xspect *samples, /* Arry of spectral samples. All assumed to be same dim as first */
321
479
int no_samp /* Number of spectral samples */