~ubuntu-branches/ubuntu/saucy/argyll/saucy

« back to all changes in this revision

Viewing changes to spectro/spotread.c

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2012-04-25 07:46:07 UTC
  • mfrom: (1.2.2) (13.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120425074607-yjqadetw8kum9skc
Tags: 1.4.0-4
Should Build-Depends on libusb-dev (Closes: #670329).

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
#include "xspect.h"
56
56
#include "conv.h"
57
57
#endif /* SALONEINSTLIB */
 
58
#include "ccss.h"
58
59
#include "inst.h"
59
60
#include "icoms.h"
60
61
#include "spyd2setup.h"
227
228
#endif  /* APPLE */
228
229
 
229
230
void
230
 
usage(int debug) {
 
231
usage(int debug, iccss *cl) {
 
232
        int i;
231
233
        icoms *icom;
 
234
        inst_capability cap = 0;
232
235
        fprintf(stderr,"Read Print Spot values, Version %s\n",ARGYLL_VERSION_STR);
233
236
        fprintf(stderr,"Author: Graeme W. Gill, licensed under the GPL Version 2 or later\n");
234
237
        if (setup_spyd2() == 2)
258
261
                        }
259
262
                } else
260
263
                        fprintf(stderr,"    ** No ports found **\n");
261
 
                icom->del(icom);
262
264
        }
263
265
//      fprintf(stderr," -i 22|41|51|92|SO|SS Select serial port target instrument\n");
264
266
        fprintf(stderr," -t                   Use transmission measurement mode\n");
272
274
//      Hmm. Need to add tele mode as well ~~~
273
275
        fprintf(stderr," -a                   Use ambient measurement mode (absolute results)\n");
274
276
        fprintf(stderr," -f                   Use ambient flash measurement mode (absolute results)\n");
275
 
        fprintf(stderr," -y c|l               Display type (if emissive), c = CRT, l = LCD\n");
 
277
        cap = inst_show_disptype_options(stderr, " -y                   ", icom);
276
278
        fprintf(stderr," -i illum             Choose illuminant for print/transparency spectral data:\n");
277
279
#ifndef SALONEINSTLIB
278
280
        fprintf(stderr,"                      A, C, D50 (def.), D65, F5, F8, F10 or file.sp\n");
279
281
#else
280
282
        fprintf(stderr,"                      A, C, D50 (def.), D65\n");
281
283
#endif
282
 
        fprintf(stderr," -o observ            Choose CIE Observer for spectral data:\n");
 
284
        fprintf(stderr," -Q observ            Choose CIE Observer for spectral data or CCSS instrument:\n");
283
285
#ifndef SALONEINSTLIB
284
286
        fprintf(stderr,"                      1931_2 (def), 1964_10, S&B 1955_2, shaw, J&V 1978_2\n");
285
287
#else
296
298
        fprintf(stderr," -E extrafilterfile   Apply extra filter compensation file\n");
297
299
        fprintf(stderr," -x                   Display Yxy instead of Lab\n");
298
300
        fprintf(stderr," -h                   Display LCh instead of Lab\n");
 
301
        fprintf(stderr," -V                   Show running average and std. devation from ref.\n");
299
302
#ifndef SALONEINSTLIB
300
303
        fprintf(stderr," -T                   Display correlated color temperatures and CRI\n");
301
304
#endif /* !SALONEINSTLIB */
303
306
        fprintf(stderr," -N                   Disable auto calibration of instrument\n");
304
307
        fprintf(stderr," -H                   Start in high resolution spectrum mode (if available)\n");
305
308
#ifndef SALONEINSTLIB
306
 
        fprintf(stderr," -X file.ccmx         Apply Colorimeter Correction Matrix\n");
 
309
        if (cap & inst_ccmx)
 
310
                fprintf(stderr," -X file.ccmx         Apply Colorimeter Correction Matrix\n");
307
311
#endif
 
312
        if (cap & inst_ccss) {
 
313
                fprintf(stderr," -X file.ccss         Use Colorimeter Calibration Spectral Samples for calibration\n");
 
314
                for (i = 0; cl != NULL && cl[i].desc != NULL; i++) {
 
315
                        if (i == 0)
 
316
                                fprintf(stderr," -X N                  0: %s\n",cl[i].desc); 
 
317
                        else
 
318
                                fprintf(stderr,"                       %d: %s\n",i,cl[i].desc); 
 
319
                }
 
320
                free_iccss(cl);
 
321
        }
308
322
        fprintf(stderr," -W n|h|x             Override serial port flow control: n = none, h = HW, x = Xon/Xoff\n");
309
323
        fprintf(stderr," -D [level]           Print debug diagnostics to stderr\n");
310
324
        fprintf(stderr," logfile              Optional file to save reading results as text\n");
 
325
 
 
326
        if (icom != NULL)
 
327
                icom->del(icom);
311
328
        exit(1);
312
329
        }
313
330
 
314
331
int main(int argc, char *argv[])
315
332
{
316
 
        int i,j;
 
333
        int i, j;
317
334
        int fa, nfa, mfa;                               /* current argument we're looking at */
318
335
        int verb = 0;
319
336
        int debug = 0;
337
354
        inst_opt_filter fe = inst_opt_filter_unknown;
338
355
                                                                        /* Filter configuration */
339
356
        char outname[MAXNAMEL+1] = "\000";  /* Output logfile name */
340
 
#ifndef SALONEINSTLIB
341
 
        char ccmxname[MAXNAMEL+1] = "\000";  /* Colorimeter Correction Matrix name */
342
 
#endif
 
357
        char ccxxname[MAXNAMEL+1] = "\000";  /* Colorimeter Correction/Colorimeter Calibration name */
 
358
        iccss *cl = NULL;                               /* List of installed CCSS files */
 
359
        int ncl = 0;                                    /* Number of them */
343
360
        char filtername[MAXNAMEL+1] = "\000";  /* Filter compensation */
344
361
        FILE *fp = NULL;                                /* Logfile */
345
362
        int comport = COMPORT;                  /* COM port used */
346
 
        instType itype = instUnknown;   /* No default target instrument */
347
 
        int dtype = 0;                                  /* Display type, 0 = default, 1 = CRT, 2 = LCD */
 
363
        int dtype = 0;                                  /* Display type selection charater */
348
364
        inst_capability  cap = inst_unknown;    /* Instrument capabilities */
349
365
        inst2_capability cap2 = inst2_unknown;  /* Instrument capabilities 2 */
350
366
        double lx, ly;                                  /* Read location on xy table */
356
372
        int spec = 0;                                   /* Need spectral data for observer/illuminant flag */
357
373
        icxIllumeType illum = icxIT_D50;        /* Spectral defaults */
358
374
        xspect cust_illum;                              /* Custom illumination spectrum */
359
 
        icxObserverType observ = icxOT_CIE_1931_2;
 
375
        icxObserverType obType = icxOT_default;
360
376
        xspect sp;                                              /* Last spectrum read */
361
377
        xspect rsp;                                             /* Reference spectrum */
362
378
        xsp2cie *sp2cie = NULL;                 /* default conversion */
366
382
        double rLab[3] = { -10.0, 0, 0};        /* Reference Lab */
367
383
        double Yxy[3] = { 0.0, 0, 0};   /* Yxy value */
368
384
        double LCh[3] = { 0.0, 0, 0};   /* LCh value */
 
385
        double refstats = 0;                    /* Print running avg & stddev against ref */
 
386
        double rstat_n;                                 /* Stats N */
 
387
        double rstat_Lab[3];                    /* Stats sum of Lab's */
 
388
        double rstat_Labsq[3];                  /* Stats sum of Lab's squared */
369
389
        int savdrd = 0;                                 /* At least one saved reading is available */
370
390
        int ix;                                                 /* Reading index number */
371
391
        int loghead = 0;                                /* NZ if log file heading has been printed */
380
400
        sp.spec_n = 0;
381
401
        rsp.spec_n = 0;
382
402
 
 
403
        /* Get a list of installed CCSS files */
 
404
        cl = list_iccss(&ncl);
 
405
 
383
406
        /* Process the arguments */
384
407
        mfa = 0;        /* Minimum final arguments */
385
408
        for(fa = 1;fa < argc;fa++) {
399
422
                        }
400
423
 
401
424
                        if (argv[fa][1] == '?') {
402
 
                                usage(debug);
 
425
                                usage(debug, cl);
403
426
 
404
 
                        } else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
 
427
                        } else if (argv[fa][1] == 'v') {
405
428
                                verb = 1;
406
429
 
407
430
                        } else if (argv[fa][1] == 's') {
415
438
                        /* COM port  */
416
439
                        } else if (argv[fa][1] == 'c' || argv[fa][1] == 'C') {
417
440
                                fa = nfa;
418
 
                                if (na == NULL) usage(debug);
 
441
                                if (na == NULL) usage(debug, cl);
419
442
                                comport = atoi(na);
420
 
                                if (comport < 1 || comport > 40) usage(debug);
 
443
                                if (comport < 1 || comport > 40) usage(debug, cl);
421
444
 
422
445
                        /* Display type */
423
446
                        } else if (argv[fa][1] == 'y' || argv[fa][1] == 'Y') {
424
447
                                fa = nfa;
425
 
                                if (na == NULL) usage(debug);
426
 
                                if (na[0] == 'c' || na[0] == 'C')
427
 
                                        dtype = 1;
428
 
                                else if (na[0] == 'l' || na[0] == 'L')
429
 
                                        dtype = 2;
430
 
                                else
431
 
                                        usage(debug);
 
448
                                if (na == NULL) usage(debug, cl);
 
449
                                dtype = na[0];
432
450
 
433
451
                        /* Spectral Illuminant type */
434
452
                        } else if (argv[fa][1] == 'i' || argv[fa][1] == 'I') {
435
453
                                fa = nfa;
436
 
                                if (na == NULL) usage(debug);
 
454
                                if (na == NULL) usage(debug, cl);
437
455
                                if (strcmp(na, "A") == 0) {
438
456
                                        spec = 1;
439
457
                                        illum = icxIT_A;
460
478
                                        spec = 1;
461
479
                                        illum = icxIT_custom;
462
480
                                        if (read_xspect(&cust_illum, na) != 0)
463
 
                                                usage(debug);
 
481
                                                usage(debug, cl);
464
482
                                }
465
483
#else /* SALONEINSTLIB */
466
484
                                } else
467
 
                                        usage(debug);
 
485
                                        usage(debug, cl);
468
486
#endif /* SALONEINSTLIB */
469
487
 
470
488
                        /* Spectral Observer type */
471
 
                        } else if (argv[fa][1] == 'o' || argv[fa][1] == 'O') {
 
489
                        } else if (argv[fa][1] == 'Q') {
472
490
                                fa = nfa;
473
 
                                if (na == NULL) usage(debug);
 
491
                                if (na == NULL) usage(debug, cl);
474
492
                                if (strcmp(na, "1931_2") == 0) {                        /* Classic 2 degree */
475
 
                                        spec = 1;
476
 
                                        observ = icxOT_CIE_1931_2;
 
493
                                        obType = icxOT_CIE_1931_2;
477
494
                                } else if (strcmp(na, "1964_10") == 0) {        /* Classic 10 degree */
478
 
                                        spec = 1;
479
 
                                        observ = icxOT_CIE_1964_10;
 
495
                                        obType = icxOT_CIE_1964_10;
480
496
#ifndef SALONEINSTLIB
481
497
                                } else if (strcmp(na, "1955_2") == 0) {         /* Stiles and Burch 1955 2 degree */
482
 
                                        spec = 1;
483
 
                                        observ = icxOT_Stiles_Burch_2;
 
498
                                        obType = icxOT_Stiles_Burch_2;
484
499
                                } else if (strcmp(na, "1978_2") == 0) {         /* Judd and Voss 1978 2 degree */
485
 
                                        spec = 1;
486
 
                                        observ = icxOT_Judd_Voss_2;
 
500
                                        obType = icxOT_Judd_Voss_2;
487
501
                                } else if (strcmp(na, "shaw") == 0) {           /* Shaw and Fairchilds 1997 2 degree */
488
 
                                        spec = 1;
489
 
                                        observ = icxOT_Shaw_Fairchild_2;
 
502
                                        obType = icxOT_Shaw_Fairchild_2;
490
503
#endif /* !SALONEINSTLIB */
491
504
                                } else
492
 
                                        usage(debug);
 
505
                                        usage(debug, cl);
493
506
 
494
507
                        /* Request transmission measurement */
495
508
                        } else if (argv[fa][1] == 't') {
514
527
                                        else if (argv[fa][2] == 'w' || argv[fa][2] == 'W')
515
528
                                                displ = 3;
516
529
                                        else
517
 
                                                usage(debug);
 
530
                                                usage(debug, cl);
518
531
                                }
519
532
 
520
533
                        /* Request projector (emissive) measurement */
533
546
                                        else if (argv[fa][2] == 'w' || argv[fa][2] == 'W')
534
547
                                                proj = 3;
535
548
                                        else
536
 
                                                usage(debug);
 
549
                                                usage(debug, cl);
537
550
                                }
538
551
 
539
552
                        /* Request emissive measurement */
563
576
                        /* Filter configuration */
564
577
                        } else if (argv[fa][1] == 'F') {
565
578
                                fa = nfa;
566
 
                                if (na == NULL) usage(debug);
 
579
                                if (na == NULL) usage(debug, cl);
567
580
                                if (na[0] == 'n' || na[0] == 'N')
568
581
                                        fe = inst_opt_filter_none;
569
582
                                else if (na[0] == 'p' || na[0] == 'P')
573
586
                                else if (na[0] == 'u' || na[0] == 'U')
574
587
                                        fe = inst_opt_filter_UVCut;
575
588
                                else
576
 
                                        usage(debug);
 
589
                                        usage(debug, cl);
577
590
 
578
591
                        /* Extra filter compensation file */
579
592
                        } else if (argv[fa][1] == 'E') {
580
593
                                fa = nfa;
581
 
                                if (na == NULL) usage(debug);
 
594
                                if (na == NULL) usage(debug, cl);
582
595
                                strncpy(filtername,na,MAXNAMEL-1); filtername[MAXNAMEL-1] = '\000';
583
596
 
584
597
                        /* Show Yxy */
590
603
                        } else if (argv[fa][1] == 'h') {
591
604
                                doYxy = 0;
592
605
                                doLCh = 1;
 
606
 
 
607
                        /* Compute running average and standard deviation from ref. */
 
608
                        } else if (argv[fa][1] == 'V') {
 
609
                                refstats = 1;
593
610
#ifndef SALONEINSTLIB
594
611
 
595
612
                        /* Show CCT etc. */
604
621
                                        docalib = atoi(na);
605
622
                                        fa = nfa;
606
623
                                } else
607
 
                                        usage(debug);
 
624
                                        usage(debug, cl);
608
625
 
609
626
                        /* No auto calibration */
610
627
                        } else if (argv[fa][1] == 'N') {
615
632
                                highres = 1;
616
633
 
617
634
#ifndef SALONEINSTLIB
618
 
                        /* Colorimeter Correction Matrix */
 
635
                        /* Colorimeter Correction Matrix or */
 
636
#endif
 
637
                        /* or Colorimeter Calibration Spectral Samples */
619
638
                        } else if (argv[fa][1] == 'X') {
 
639
                                int ix;
620
640
                                fa = nfa;
621
 
                                if (na == NULL) usage(debug);
622
 
                                strncpy(ccmxname,na,MAXNAMEL-1); ccmxname[MAXNAMEL-1] = '\000';
623
 
#endif
624
 
 
 
641
                                if (na == NULL) usage(debug, cl);
 
642
                                if (ncl > 0 && sscanf(na, " %d ", &ix) == 1) {
 
643
                                        if (ix < 0 || ix >= ncl)
 
644
                                                usage(debug, cl);
 
645
                                        strncpy(ccxxname,cl[ix].path,MAXNAMEL-1); ccxxname[MAXNAMEL-1] = '\000';
 
646
                                } else {
 
647
                                        strncpy(ccxxname,na,MAXNAMEL-1); ccxxname[MAXNAMEL-1] = '\000';
 
648
                                }
625
649
                        /* Serial port flow control */
626
650
                        } else if (argv[fa][1] == 'W') {
627
651
                                fa = nfa;
628
 
                                if (na == NULL) usage(debug);
 
652
                                if (na == NULL) usage(debug, cl);
629
653
                                if (na[0] == 'n' || na[0] == 'N')
630
654
                                        fc = fc_none;
631
655
                                else if (na[0] == 'h' || na[0] == 'H')
633
657
                                else if (na[0] == 'x' || na[0] == 'X')
634
658
                                        fc = fc_XonXOff;
635
659
                                else
636
 
                                        usage(debug);
 
660
                                        usage(debug, cl);
637
661
 
638
662
                        } else if (argv[fa][1] == 'D') {
639
663
                                debug = 1;
642
666
                                        fa = nfa;
643
667
                                }
644
668
                        } else 
645
 
                                usage(debug);
 
669
                                usage(debug, cl);
646
670
                }
647
671
                else
648
672
                        break;
656
680
        }
657
681
 
658
682
 
 
683
        /* See if there is an environment variable ccxx */
 
684
        if (ccxxname[0] == '\000') {
 
685
                char *na;
 
686
                if ((na = getenv("ARGYLL_COLMTER_CAL_SPEC_SET")) != NULL) {
 
687
                        strncpy(ccxxname,na,MAXNAMEL-1); ccxxname[MAXNAMEL-1] = '\000';
 
688
 
659
689
#ifndef SALONEINSTLIB
660
 
        /* See if there is an environment variable ccmx */
661
 
        {
662
 
                char *na = getenv("ARGYLL_COLMTER_COR_MATRIX");
663
 
                if (na != NULL) {
664
 
                        strncpy(ccmxname,na,MAXNAMEL-1); ccmxname[MAXNAMEL-1] = '\000';
 
690
                } else if ((na = getenv("ARGYLL_COLMTER_COR_MATRIX")) != NULL) {
 
691
                        strncpy(ccxxname,na,MAXNAMEL-1); ccxxname[MAXNAMEL-1] = '\000';
 
692
#endif
665
693
                }
666
694
        }
667
 
#endif
668
695
 
669
696
        /* - - - - - - - - - - - - - - - - - - -  */
670
697
        /* Setup the instrument ready to do reads */
671
 
        if ((it = new_inst(comport, itype, debug, verb)) == NULL) {
 
698
        if ((it = new_inst(comport, 0, debug, verb)) == NULL) {
672
699
                warning("Unknown, inappropriate or no instrument detected");
673
 
                usage(debug);
 
700
                usage(debug, cl);
674
701
        }
675
702
 
676
703
        if (verb)
714
741
                return -1;
715
742
        }
716
743
        
717
 
        itype = it->get_itype(it);              /* get actual type of instrument */
718
 
 
719
744
        /* Configure the instrument mode */
720
745
        {
 
746
                int ccssset = 0;
721
747
                cap = it->capabilities(it);
722
748
                cap2 = it->capabilities2(it);
723
749
 
804
830
                                }
805
831
                        }
806
832
 
807
 
                        /* Set CRT or LCD mode */
808
 
                        if (dtype == 1 || dtype == 2) {
809
 
                                inst_opt_mode om;
810
 
        
811
 
                                if (proj) {
812
 
                                        if (dtype == 1)
813
 
                                                om = inst_opt_proj_crt;
814
 
                                        else
815
 
                                                om = inst_opt_proj_lcd;
816
 
                                } else {
817
 
                                        if (dtype == 1)
818
 
                                                om = inst_opt_disp_crt;
819
 
                                        else
820
 
                                                om = inst_opt_disp_lcd;
821
 
                                }
822
 
        
823
 
                                if ((rv = it->set_opt_mode(it,om)) != inst_ok) {
824
 
                                        printf("Setting %s mode %s not supported by instrument\n",
825
 
                                               proj ? "projector" : "display", dtype == 1 ? "CRT" : "LCD");
826
 
                                        it->del(it);
827
 
                                        return -1;
828
 
                                }
829
 
                        } else if (proj && it->capabilities(it) & (inst_emis_proj_crt | inst_emis_proj_lcd)) {
830
 
                                printf("Either CRT or LCD must be selected\n");
831
 
                                it->del(it);
832
 
                                return -1;
833
 
 
834
 
                        } else if (it->capabilities(it) & (inst_emis_disp_crt | inst_emis_disp_lcd)) {
835
 
                                printf("Either CRT or LCD must be selected\n");
 
833
                        /* Set display type */
 
834
                        if (dtype != 0) {
 
835
 
 
836
                                if (cap & inst_emis_disptype) {
 
837
                                        int ix;
 
838
                                        if ((ix = inst_get_disptype_index(it, dtype)) == 0) {
 
839
                                                it->del(it);
 
840
                                                usage(debug, cl);
 
841
                                        }
 
842
                
 
843
                                        if ((rv = it->set_opt_mode(it, inst_opt_disp_type, ix)) != inst_ok) {
 
844
                                                printf("Setting display type ix %d not supported by instrument\n",ix);
 
845
                                                it->del(it);
 
846
                                                return -1;
 
847
                                        }
 
848
                                } else
 
849
                                        printf("Display type ignored - instrument doesn't support display type\n");
 
850
 
 
851
                        } else if (cap & (inst_emis_disptypem)) {
 
852
                                printf("A display type must be selected\n");
836
853
                                it->del(it);
837
854
                                return -1;
838
855
                        }
846
863
                        }
847
864
                }
848
865
 
 
866
                /* If we have non-standard observer we need spectral or CCSS */
 
867
                if (obType != icxOT_default && (cap & inst_spectral) == 0 && (cap & inst_ccss) == 0) {
 
868
                        printf("Non standard observer needs spectral information or CCSS capability\n");
 
869
                        printf("and instrument doesn't support either.\n");
 
870
                        it->del(it);
 
871
                        return -1;
 
872
                }
 
873
 
 
874
                /* If we don't have CCSS then we need spectral for non-standard observer */
 
875
                if (obType != icxOT_default && (cap & inst_ccss) == 0) {
 
876
                        spec = 1;
 
877
                }
 
878
 
849
879
                if ((spec || pspec) && (cap & inst_spectral) == 0) {
850
880
                        printf("Need spectral information for custom illuminant or observer\n");
851
881
                        printf("and instrument doesn't support it\n");
909
939
                        it->del(it);
910
940
                        return -1;
911
941
                }
 
942
                cap = it->capabilities(it);
 
943
                cap2 = it->capabilities2(it);
912
944
 
913
945
                /* Apply Extra filter compensation */
914
946
                if (filtername[0] != '\000') {
920
952
                        }
921
953
                }
922
954
 
923
 
#ifndef SALONEINSTLIB
924
955
                /* Colorimeter Correction Matrix */
925
 
                if (ccmxname[0] != '\000') {
926
 
                        ccmx *cmx;
 
956
                if (ccxxname[0] != '\000') {
 
957
                        ccss *cs = NULL;
 
958
#ifndef SALONEINSTLIB
 
959
                        ccmx *cx = NULL;
927
960
 
928
 
                        if ((cap & inst_ccmx) == 0) {
929
 
                                printf("\nInstrument doesn't have Colorimeter Correction Matix capability\n");
930
 
                                it->del(it);
931
 
                                return -1;
932
 
                        }
933
 
                        if ((cmx = new_ccmx()) == NULL) {
 
961
                        if ((cx = new_ccmx()) == NULL) {
934
962
                                printf("\nnew_ccmx failed\n");
935
963
                                it->del(it);
936
964
                                return -1;
937
965
                        }
938
 
                        if (cmx->read_ccmx(cmx,ccmxname)) {
939
 
                                printf("\nReading Colorimeter Correction Matrix file '%s' failed with error %d:'%s'\n",
940
 
                                       ccmxname, cmx->errc, cmx->err);
941
 
                                cmx->del(cmx);
942
 
                                it->del(it);
943
 
                                return -1;
 
966
                        if (cx->read_ccmx(cx,ccxxname) == 0) {
 
967
                                if ((cap & inst_ccmx) == 0) {
 
968
                                        printf("\nInstrument doesn't have Colorimeter Correction Matrix capability\n");
 
969
                                        it->del(it);
 
970
                                        return -1;
 
971
                                }
 
972
                                if ((rv = it->col_cor_mat(it, cx->matrix)) != inst_ok) {
 
973
                                        printf("\nSetting Colorimeter Correction Matrix failed with error :'%s' (%s)\n",
 
974
                                               it->inst_interp_error(it, rv), it->interp_error(it, rv));
 
975
                                        cx->del(cx);
 
976
                                        it->del(it);
 
977
                                        return -1;
 
978
                                }
 
979
                                cx->del(cx);
 
980
                        } else
 
981
#endif
 
982
                        {
 
983
#ifndef SALONEINSTLIB
 
984
                                cx->del(cx);
 
985
                                cx = NULL;
 
986
#endif
 
987
                                
 
988
                                /* CCMX failed, try CCSS */
 
989
                                if ((cs = new_ccss()) == NULL) {
 
990
                                        printf("\nnew_ccss failed\n");
 
991
                                        it->del(it);
 
992
                                        return -1;
 
993
                                }
 
994
                                if (cs->read_ccss(cs,ccxxname)) {
 
995
                                        printf("\nReading CCMX/CCSS File '%s' failed with error %d:'%s'\n",
 
996
                                               ccxxname, cs->errc, cs->err);
 
997
                                        cs->del(cs);
 
998
                                        it->del(it);
 
999
                                        return -1;
 
1000
                                }
 
1001
                                if ((cap & inst_ccss) == 0) {
 
1002
                                        printf("\nInstrument doesn't have Colorimeter Calibration Spectral Sample capability\n");
 
1003
                                        cs->del(cs);
 
1004
                                        it->del(it);
 
1005
                                        return -1;
 
1006
                                }
 
1007
                                if ((rv = it->col_cal_spec_set(it, obType, NULL, cs->samples, cs->no_samp)) != inst_ok) {
 
1008
                                        printf("\nSetting Colorimeter Calibration Spectral Samples failed with error :'%s' (%s)\n",
 
1009
                                               it->inst_interp_error(it, rv), it->interp_error(it, rv));
 
1010
                                        cs->del(cs);
 
1011
                                        it->del(it);
 
1012
                                        return -1;
 
1013
                                }
 
1014
                                ccssset = 1;
 
1015
                                cs->del(cs);
944
1016
                        }
945
 
                        if ((rv = it->col_cor_mat(it, cmx->matrix)) != inst_ok) {
946
 
                                printf("\nSetting Colorimeter Correction Matrix failed with error :'%s' (%s)\n",
 
1017
                }
 
1018
 
 
1019
                /* If non-standard observer wasn't set by a CCSS file above */
 
1020
                if (obType != icxOT_default && (cap & inst_ccss) && ccssset == 0) {
 
1021
                        if ((rv = it->col_cal_spec_set(it, obType, NULL, NULL, 0)) != inst_ok) {
 
1022
                                printf("\nSetting Colorimeter Calibration Spectral Samples failed with error :'%s' (%s)\n",
947
1023
                                       it->inst_interp_error(it, rv), it->interp_error(it, rv));
948
 
                                cmx->del(cmx);
949
1024
                                it->del(it);
950
1025
                                return -1;
951
1026
                        }
952
 
                        cmx->del(cmx);
953
1027
                }
954
 
#endif
955
1028
 
956
1029
                /* If it batter powered, show the status of the battery */
957
1030
                if ((cap2 & inst2_has_battery)) {
1015
1088
                it->icom->set_uih(it->icom, 0x03, 0x03, ICOM_USER);             /* ^c */
1016
1089
                it->icom->set_uih(it->icom, 0x1b, 0x1b, ICOM_USER);             /* Esc */
1017
1090
        }
 
1091
        free_iccss(cl);
 
1092
        cl = NULL;
1018
1093
 
1019
1094
#ifdef DEBUG
1020
1095
        printf("About to enter read loop\n");
1029
1104
                        illum = icxIT_none;
1030
1105
 
1031
1106
                /* Create a spectral conversion object */
1032
 
                if ((sp2cie = new_xsp2cie(illum, &cust_illum, observ, NULL
1033
 
#ifndef SALONEINSTLIB
1034
 
                     , icSigXYZData
1035
 
#endif /* !SALONEINSTLIB */
1036
 
                                      )) == NULL)
 
1107
                if ((sp2cie = new_xsp2cie(illum, &cust_illum, obType, NULL, icSigXYZData)) == NULL)
1037
1108
                        error("Creation of spectral conversion object failed");
1038
1109
        }
1039
1110
 
1090
1161
                                it->del(it);
1091
1162
                                return -1;
1092
1163
                        }
 
1164
                        cap = it->capabilities(it);
 
1165
                        cap2 = it->capabilities2(it);
1093
1166
 
1094
1167
                        /* Set N and n to be a command */
1095
1168
                        it->icom->set_uih(it->icom, 'N', 'N', ICOM_CMND);
1139
1212
                                it->del(it);
1140
1213
                                return -1;
1141
1214
                        }
 
1215
                        cap = it->capabilities(it);
 
1216
                        cap2 = it->capabilities2(it);
1142
1217
 
1143
1218
                        /* If user said no to reading stored values */
1144
1219
                        if ((rv & inst_mask) == inst_user_cmnd
1437
1512
                                if (pspec) {
1438
1513
                                        rsp = sp;               /* Save spectral reference too */
1439
1514
                                }
 
1515
                                if (refstats) {
 
1516
                                        rstat_n = 1;
 
1517
                                        for (j = 0; j < 3; j++) {
 
1518
                                                rstat_Lab[j] = Lab[j];
 
1519
                                                rstat_Labsq[j] = Lab[j] * Lab[j];
 
1520
                                        }
 
1521
                                }
1440
1522
                                printf("\n Reference is now Lab: %f %f %f\n", rLab[0], rLab[1], rLab[2]);
1441
1523
                        } else {
1442
1524
                                printf("\n No previous reading to use as reference\n");
1519
1601
                        } else {
1520
1602
                                dofwa = 1;
1521
1603
                        }
 
1604
 
1522
1605
                }
1523
1606
 
1524
1607
                /* Setup FWA compensation */
1530
1613
                                error("Instrument didn't return spectral data");
1531
1614
                        }
1532
1615
 
1533
 
                        if (inst_illuminant(&insp, itype) != 0)
 
1616
                        if (inst_illuminant(&insp, it->get_itype(it)) != 0)
1534
1617
                                error ("Instrument doesn't have an FWA illuminent");
1535
1618
 
1536
1619
                        /* Creat the base conversion object */
1537
1620
                        if (sp2cief[fidx] == NULL) {
1538
 
                                if ((sp2cief[fidx] = new_xsp2cie(illum, &cust_illum, observ,
 
1621
                                if ((sp2cief[fidx] = new_xsp2cie(illum, &cust_illum, obType,
1539
1622
                                                                 NULL, icSigXYZData)) == NULL)
1540
1623
                                        error("Creation of spectral conversion object failed");
1541
1624
                        }
1681
1764
                                nxyz[1] = XYZ[1] / XYZ[1];
1682
1765
 
1683
1766
                                /* Compute CCT */
1684
 
                                if ((cct = icx_XYZ2ill_ct(axyz, icxIT_Ptemp, observ, NULL, XYZ, NULL, 0)) < 0)
 
1767
                                if ((cct = icx_XYZ2ill_ct(axyz, icxIT_Ptemp, obType, NULL, XYZ, NULL, 0)) < 0)
1685
1768
                                        error ("Got bad cct\n");
1686
1769
                                axyz[0] /= axyz[1];
1687
1770
                                axyz[2] /= axyz[1];
1692
1775
                                cct_de = icmLabDE(lab, alab);
1693
1776
                        
1694
1777
                                /* Compute VCT */
1695
 
                                if ((vct = icx_XYZ2ill_ct(axyz, icxIT_Ptemp, observ, NULL, XYZ, NULL, 1)) < 0)
 
1778
                                if ((vct = icx_XYZ2ill_ct(axyz, icxIT_Ptemp, obType, NULL, XYZ, NULL, 1)) < 0)
1696
1779
                                        error ("Got bad vct\n");
1697
1780
                                axyz[0] /= axyz[1];
1698
1781
                                axyz[2] /= axyz[1];
1703
1786
                                vct_de = icmLabDE(lab, alab);
1704
1787
 
1705
1788
                                /* Compute VDT */
1706
 
                                if ((vdt = icx_XYZ2ill_ct(axyz, icxIT_Dtemp, observ, NULL, XYZ, NULL, 1)) < 0)
 
1789
                                if ((vdt = icx_XYZ2ill_ct(axyz, icxIT_Dtemp, obType, NULL, XYZ, NULL, 1)) < 0)
1707
1790
                                        error ("Got bad vct\n");
1708
1791
                                axyz[0] /= axyz[1];
1709
1792
                                axyz[2] /= axyz[1];
1807
1890
                        }
1808
1891
 
1809
1892
                        if (rLab[0] >= -1.0) {
 
1893
                                if (refstats) {
 
1894
                                        double avg[3], sdev[3];
 
1895
                                        rstat_n++;
 
1896
                                        for (j = 0; j < 3; j++) {
 
1897
                                                rstat_Lab[j] += Lab[j];
 
1898
                                                rstat_Labsq[j] += Lab[j] * Lab[j];
 
1899
 
 
1900
                                                avg[j] = rstat_Lab[j]/rstat_n;
 
1901
                                                sdev[j] = sqrt(rstat_n * rstat_Labsq[j] - rstat_Lab[j] * rstat_Lab[j])/rstat_n;
 
1902
                                        }
 
1903
                                        printf(" Lab stats %.0f: Avg %f %f %f, S.Dev %f %f %f\n",
 
1904
                                        rstat_n, avg[0], avg[1], avg[2], sdev[0], sdev[1], sdev[2]);
 
1905
                                }
1810
1906
#ifndef SALONEINSTLIB
1811
1907
                                printf(" Delta E to reference is %f %f %f (%f, CIE94 %f)\n",
1812
1908
                                Lab[0] - rLab[0], Lab[1] - rLab[1], Lab[2] - rLab[2],