~ubuntu-branches/ubuntu/trusty/argyll/trusty-proposed

« back to all changes in this revision

Viewing changes to rspl/rspl1.c

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-02-12 00:35:39 UTC
  • mfrom: (13.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20140212003539-24tautzlitsiz61w
Tags: 1.5.1-5ubuntu1
* Merge from Debian unstable. (LP: #1275572) Remaining changes:
  - debian/control:
    + Build-depend on libtiff-dev rather than libtiff4-dev.
  - debian/control, debian/patches/06_fix_udev_rule.patch:
    + Fix udev rules to actually work; ENV{ACL_MANAGE} has
      stopped working ages ago, and with logind it's now the
      "uaccess" tag. Dropping also consolekit from Recommends.
  - debian/patches/drop-usb-db.patch:
    + Use hwdb builtin, instead of the obsolete usb-db
      in the udev rules.
* debian/patches/05_ftbfs-underlinkage.diff:
  - Dropped change, no needed anymore.
* Refresh the patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#undef DEBUG
27
27
 
28
28
#ifdef DEBUG
29
 
#ifdef DBG
30
 
#undef DBG
31
 
#undef dbgo
32
 
#endif
33
 
#define dbgo stderr
34
 
#define DBG(aaa) fprintf aaa
 
29
# define DBGA g_log, 0          /* First argument to DBGF() */
 
30
# define DBGF(xx)       a1logd xx
35
31
#else
36
 
#define DBG(aaa) 
 
32
# define DBGF(xx)
37
33
#endif
38
34
 
 
35
 
39
36
/* Do an interpolation based on the grid */
40
37
/* Use a linear interp between grid points. */
41
38
/* If the input is outside the grid range, it will */
101
98
        int n;
102
99
        double cw;
103
100
 
104
 
        DBG((dbgo, "rspl1:fit_rspl_imp() with %d points called, dtp = %d\n",ndp,dtp));
 
101
        DBGF((DBGA, "rspl1:fit_rspl_imp() with %d points called, dtp = %d\n",ndp,dtp));
105
102
 
106
103
        /* Allocate space for interpolation grid */
107
104
        t->nig = *gres;
108
105
 
109
106
        if ((t->x   = dvector(0, t->nig)) == NULL) {
110
 
                DBG((dbgo, "rspl1:Malloc of vector x failed\n"));
 
107
                DBGF((DBGA, "rspl1:Malloc of vector x failed\n"));
111
108
                return 1;
112
109
        }
113
110
 
114
111
        /* Normalize curve weight to grid resolution. */
115
112
        cw = 0.0000005 * smooth * pow((t->nig-1),4.0) / (t->nig - 2);
116
 
        DBG((dbgo, "rspl1:cw = %e\n",cw));
 
113
        DBGF((DBGA, "rspl1:cw = %e\n",cw));
117
114
 
118
115
        /* cw is multiplied by the sum of grid curvature errors squared to keep */
119
116
        /* the same ratio with the sum of data position errors squared */
136
133
                        if (dd[n].v[0] > t->dh)
137
134
                                t->dh = dd[n].v[0];
138
135
 
139
 
                        DBG((dbgo, "rspl1:Point %d = %f, %f\n",n,dd[n].p[0],dd[n].v[0]));
 
136
                        DBGF((DBGA, "rspl1:Point %d = %f, %f\n",n,dd[n].p[0],dd[n].v[0]));
140
137
                }
141
138
        } else if (dtp == 1) {
142
139
                cow *dd = (cow *)d;
150
147
                                t->dl = dd[n].v[0];
151
148
                        if (dd[n].v[0] > t->dh)
152
149
                                t->dh = dd[n].v[0];
153
 
                        DBG((dbgo, "rspl1:Point %d = %f, %f (%f)\n",n,dd[n].p[0],dd[n].v[0],dd[n].w));
 
150
                        DBGF((DBGA, "rspl1:Point %d = %f, %f (%f)\n",n,dd[n].p[0],dd[n].v[0],dd[n].w));
154
151
                }
155
152
        } else {
156
 
                DBG((dbgo, "rspl1:Internal error, unknown dtp value %d\n",dtp));
 
153
                DBGF((DBGA, "rspl1:Internal error, unknown dtp value %d\n",dtp));
157
154
                return 1;
158
155
        }
159
156
 
172
169
        t->vl  = vlow != NULL ? *vlow : 0.0;
173
170
        t->vw  = ((vhigh != NULL ? *vhigh : 1.0) - t->vl);
174
171
 
175
 
        DBG((dbgo, "rspl1:gl %f, gh %f, gw %f, vl %f, vw %f\n",t->gl,t->gh,t->gw,t->vl,t->vw));
 
172
        DBGF((DBGA, "rspl1:gl %f, gh %f, gw %f, vl %f, vw %f\n",t->gl,t->gh,t->gw,t->vl,t->vw));
176
173
 
177
174
        /* create smoothed grid data */
178
175
        {
182
179
 
183
180
                /* We just store the diagonal of the A matrix */
184
181
                if ((A = dmatrix(0, t->nig, 0, 2)) == NULL) {
185
 
                        DBG((dbgo, "rspl1:Malloc of matrix A failed\n"));
 
182
                        DBGF((DBGA, "rspl1:Malloc of matrix A failed\n"));
186
183
                        return 1;
187
184
                }
188
185
 
189
186
                if ((b = dvector(0,t->nig)) == NULL) {
190
187
                        free_dvector(b,0,t->nig);
191
 
                        DBG((dbgo, "rspl1:Malloc of vector b failed\n"));
 
188
                        DBGF((DBGA, "rspl1:Malloc of vector b failed\n"));
192
189
                        return 1;
193
190
                }
194
191
 
217
214
                                yv = dd[n].v[0];
218
215
                                wv = dd[n].w;
219
216
                        } else {
220
 
                                DBG((dbgo, "rspl1:Internal error, unknown dtp value %d\n",dtp));
 
217
                                DBGF((DBGA, "rspl1:Internal error, unknown dtp value %d\n",dtp));
221
218
                                return 1;
222
219
                        }
223
220
                        yv = (yv - t->vl)/t->vw;        /* Normalize the value */
257
254
                }
258
255
 
259
256
#ifdef DEBUG
260
 
                fprintf(dbgo, "A matrix:\n");
261
 
                for (i = 0; i < t->nig; i++) {
262
 
                        for (k = 0; k < 3; k++) {
263
 
                                fprintf(dbgo, "A[%d][%d] = %f\n",i,k,A[i][k]);
264
 
                        }
265
 
                }
266
 
                fprintf(dbgo, "b vector:\n");
267
 
                for (i = 0; i < t->nig; i++) {
268
 
                        fprintf(dbgo, "b[%d] = %f\n",i,b[i]);
269
 
                }
 
257
                DBGF((DBGA, "A matrix:\n"));
 
258
                for (i = 0; i < t->nig; i++) {
 
259
                        for (k = 0; k < 3; k++)
 
260
                                DBGF((DBGA, "A[%d][%d] = %f\n",i,k,A[i][k]));
 
261
                }
 
262
                DBGF((DBGA, "b vector:\n"));
 
263
                for (i = 0; i < t->nig; i++)
 
264
                        DBGF((DBGA, "b[%d] = %f\n",i,b[i]));
270
265
#endif /* DEBUG */
271
266
 
272
267
                /* Apply Cholesky decomposition to A[][] to create L[][] */
281
276
                                        if (sm <= 0.0) {
282
277
                                                free_dvector(b,0,t->nig);
283
278
                                                free_dmatrix(A,0,t->nig,0,2);
284
 
                                                DBG((dbgo, "rspl1:Sum is -ve - loss of accuracy ?\n"));
 
279
                                                DBGF((DBGA, "rspl1:Sum is -ve - loss of accuracy ?\n"));
285
280
                                                return 1;
286
281
                                        }
287
282
                                        A[i][0] = sqrt(sm);
311
306
                        t->x[i] = sm/A[i][0];
312
307
                }
313
308
#ifdef DEBUG
314
 
                fprintf(dbgo, "Solution vector:\n");
 
309
                DBGF((DBGA, "Solution vector:\n"));
315
310
                for (i = 0; i < t->nig; i++) {
316
 
                        fprintf(dbgo, "x[%d] = %f\n",i,t->x[i]);
 
311
                        DBGF((DBGA, "x[%d] = %f\n",i,t->x[i]));
317
312
                }
318
313
#endif /* DEBUG */
319
314
 
372
367
        rspl *t;        /* this */
373
368
 
374
369
        if (flags != RSPL_NOFLAGS || di != 1 || fdi != 1) {
375
 
                DBG((dbgo, "rspl1:Can't handle general rspl: flags %d, di %d, do %d\n",flags,di,fdi));
 
370
                DBGF((DBGA, "rspl1:Can't handle general rspl: flags %d, di %d, do %d\n",flags,di,fdi));
376
371
                return NULL;
377
372
        }
378
373
 
379
374
        if ((t = (rspl *)calloc(1, sizeof(rspl))) == NULL) {
380
 
                DBG((dbgo, "rspl1:Malloc of structure failed\n"));
 
375
                DBGF((DBGA, "rspl1:Malloc of structure failed\n"));
381
376
                return NULL;
382
377
        }
383
378