tomwalters@0
|
1 /*
|
tomwalters@0
|
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
|
tomwalters@0
|
3 ===========================================================================
|
tomwalters@0
|
4
|
tomwalters@0
|
5 Permission to use, copy, modify, and distribute this software without fee
|
tomwalters@0
|
6 is hereby granted for research purposes, provided that this copyright
|
tomwalters@0
|
7 notice appears in all copies and in all supporting documentation, and that
|
tomwalters@0
|
8 the software is not redistributed for any fee (except for a nominal shipping
|
tomwalters@0
|
9 charge). Anyone wanting to incorporate all or part of this software in a
|
tomwalters@0
|
10 commercial product must obtain a license from the Medical Research Council.
|
tomwalters@0
|
11
|
tomwalters@0
|
12 The MRC makes no representations about the suitability of this
|
tomwalters@0
|
13 software for any purpose. It is provided "as is" without express or implied
|
tomwalters@0
|
14 warranty.
|
tomwalters@0
|
15
|
tomwalters@0
|
16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
tomwalters@0
|
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
|
tomwalters@0
|
18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
|
tomwalters@0
|
19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
tomwalters@0
|
20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
tomwalters@0
|
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
tomwalters@0
|
22 */
|
tomwalters@0
|
23
|
tomwalters@0
|
24 /*
|
tomwalters@0
|
25 scales.c
|
tomwalters@0
|
26 ========
|
tomwalters@0
|
27
|
tomwalters@0
|
28 generates double arrays of numbers spaced on arbitrary frequency scales
|
tomwalters@0
|
29
|
tomwalters@0
|
30 */
|
tomwalters@0
|
31
|
tomwalters@0
|
32 #include <math.h>
|
tomwalters@0
|
33
|
tomwalters@0
|
34 #ifndef _STITCH_H_
|
tomwalters@0
|
35 #include "stitch.h"
|
tomwalters@0
|
36 #endif
|
tomwalters@0
|
37 #ifndef _SCALES_H_
|
tomwalters@0
|
38 #include "scales.h"
|
tomwalters@0
|
39 #endif
|
tomwalters@0
|
40
|
tomwalters@0
|
41 double *GenerateScale( min, max, density, base, inverse )
|
tomwalters@0
|
42 double min, max, density, base, (*inverse)() ;
|
tomwalters@0
|
43 {
|
tomwalters@0
|
44 unsigned n_scale = NumberOnScale( min, max, density, base ) ;
|
tomwalters@0
|
45 double *scale = NewArray( double, n_scale+1, "for scale in scales.c" ) ;
|
tomwalters@0
|
46 double scale_start ;
|
tomwalters@0
|
47 int i ;
|
tomwalters@0
|
48
|
tomwalters@0
|
49 if( min != max ) {
|
tomwalters@0
|
50
|
tomwalters@0
|
51 scale_start = base - floor( ( base - min ) * density ) / density ;
|
tomwalters@0
|
52
|
tomwalters@0
|
53 /* fill array scale points 1./density apart */
|
tomwalters@0
|
54
|
tomwalters@0
|
55 for( i=0 ; i < n_scale ; i++ )
|
tomwalters@0
|
56 scale[ i ] = scale_start + i / density ;
|
tomwalters@0
|
57
|
tomwalters@0
|
58 scale[ i++ ] = 0. ;
|
tomwalters@0
|
59 }
|
tomwalters@0
|
60 else {
|
tomwalters@0
|
61 scale[0] = min ;
|
tomwalters@0
|
62 scale[1] = 0. ;
|
tomwalters@0
|
63 }
|
tomwalters@0
|
64
|
tomwalters@0
|
65 /* convert scale space back to units required */
|
tomwalters@0
|
66
|
tomwalters@0
|
67 if( inverse != (double ( * )()) 0 )
|
tomwalters@0
|
68 for( i=0 ; i < n_scale ; i++ )
|
tomwalters@0
|
69 scale[ i ] = inverse( scale[ i ] ) ;
|
tomwalters@0
|
70
|
tomwalters@0
|
71 return ( scale ) ;
|
tomwalters@0
|
72 }
|
tomwalters@0
|
73
|
tomwalters@0
|
74 int NumberOnScale( min, max, density, base )
|
tomwalters@0
|
75 double min, max, density, base ;
|
tomwalters@0
|
76 {
|
tomwalters@0
|
77 if( min != max )
|
tomwalters@0
|
78 return ( ( int ) ( ( floor( ( base - min ) * density ) + 1. + ( floor( ( max - base ) * density ) ) ) ) ) ;
|
tomwalters@0
|
79 else
|
tomwalters@0
|
80 return ( 1 ) ;
|
tomwalters@0
|
81 }
|
tomwalters@0
|
82
|
tomwalters@0
|
83 double *NumberedScale( min, max, channels, inverse )
|
tomwalters@0
|
84 double min, max ;
|
tomwalters@0
|
85 int channels ;
|
tomwalters@0
|
86 double (*inverse)() ;
|
tomwalters@0
|
87 {
|
tomwalters@0
|
88 DeclareNewArray( double, scale, channels+1, "for scale in scales.c" ) ;
|
tomwalters@0
|
89 int chan ;
|
tomwalters@0
|
90
|
tomwalters@0
|
91 scale[ 0 ] = min ;
|
tomwalters@0
|
92 for( chan=1 ; chan < channels ; chan++ )
|
tomwalters@0
|
93 scale[ chan ] = min + chan * (max-min) / ( channels - 1 ) ;
|
tomwalters@0
|
94
|
tomwalters@0
|
95 if( inverse != (double ( * )()) 0 )
|
tomwalters@0
|
96 for( chan=0 ; chan < channels ; chan++ )
|
tomwalters@0
|
97 scale[ chan ] = inverse( scale[ chan ] ) ;
|
tomwalters@0
|
98
|
tomwalters@0
|
99 scale[ channels ] = 0. ;
|
tomwalters@0
|
100
|
tomwalters@0
|
101 return ( scale ) ;
|
tomwalters@0
|
102 }
|