source: SH_SHM/trunk/source/logplot.c @ 344

Revision 16, 7.1 KB checked in by marcus, 15 years ago (diff)

r1 | svn | 2007-12-13 11:10:29 +0100 (Do, 13 Dez 2007) | 2 lines

Initial import

Line 
1/* file logplot.c
2 *      =========
3 *
4 * version 4, 22-May-2006
5 *
6 * Logarithmic plot routine for SH
7 * K. Stammler, 5-Sep-92
8 */
9
10
11/*
12 *
13 *  SeismicHandler, seismic analysis software
14 *  Copyright (C) 1992,  Klaus Stammler, Federal Institute for Geosciences
15 *                                       and Natural Resources (BGR), Germany
16 *
17 *  This program is free software; you can redistribute it and/or modify
18 *  it under the terms of the GNU General Public License as published by
19 *  the Free Software Foundation; either version 2 of the License, or
20 *  (at your option) any later version.
21 *
22 *  This program is distributed in the hope that it will be useful,
23 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 *  GNU General Public License for more details.
26 *
27 *  You should have received a copy of the GNU General Public License
28 *  along with this program; if not, write to the Free Software
29 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
30 *
31 */
32
33
34
35#include <stdio.h>
36#include <string.h>
37#include <math.h>
38#include "basecnst.h"
39#include BC_SYSBASE
40#include BC_GCUSRDEF
41#include BC_SHCONST
42#include "lgusrdef.h"
43
44
45/* constants */
46#define MARGIN 0.2
47
48
49
50/* global variables */
51static CHMAP     lgv_wdw;       /* output window */
52static REAL      lgv_lg_lofrq;  /* logarithm of lower frq bound */
53static REAL      lgv_lg_hifrq;  /* logarithm of upper frq bound */
54static REAL      lgv_lg_loamp;  /* logarithm of lower amplitude bound */
55static REAL      lgv_lg_hiamp;  /* logarithm of upper amplitude bound */
56static REAL      lgv_ha_hshift; /* horiz. pos. of horiz. labelling */
57static REAL      lgv_ha_vshift; /* vert. pos. of horiz. labelling */
58static REAL      lgv_va_hshift; /* horiz. pos. of vert. labelling */
59static REAL      lgv_va_vshift; /* vert. pos. of vert. labelling */
60
61
62
63/*---------------------------------------------------------------------*/
64
65
66
67void lg_setwindow( CHMAP wdw )
68
69/* sets output window for logplot
70 *
71 * parameter of routine
72 * CHMAP     wdw;      input; output window
73 */
74{
75        /* executable code */
76
77        lgv_wdw = wdw;
78
79} /* end of lg_setwindow */
80
81
82
83/*---------------------------------------------------------------------*/
84
85
86
87void lg_labshift( REAL ha_hs, REAL ha_vs, REAL va_hs, REAL va_vs )
88
89/* sets label positions
90 *
91 * parameters of routine
92 * REAL       ha_hs;   input; horizontal pos. at horizontal axis
93 * REAL       ha_vs;   input; vertical pos. at horizontal axis
94 * REAL       va_hs;   input; horizontal pos. at vertical axis
95 * REAL       va_vs;   input; vertical pos. at vertical axis
96 */
97{
98        /* executable code */
99
100        if  (ha_hs != LGC_NOCHANGE)  lgv_ha_hshift = ha_hs;
101        if  (ha_vs != LGC_NOCHANGE)  lgv_ha_vshift = ha_vs;
102        if  (va_hs != LGC_NOCHANGE)  lgv_va_hshift = va_hs;
103        if  (va_vs != LGC_NOCHANGE)  lgv_va_vshift = va_vs;
104
105} /* end of lg_labshift */
106
107
108
109/*---------------------------------------------------------------------*/
110
111
112
113void lg_scale( int style, REAL lofrq, REAL hifrq, REAL loamp,
114        REAL hiamp, STATUS *status )
115
116/* set scale of plots
117 *
118 * parameters of routine
119 * int        style;             input; drawing style
120 * REAL       lofrq, hifrq;      input; frequency bounds
121 * REAL       loamp, hiamp;      input; amplitude bounds
122 * STATUS     *status;           output; return status
123 */
124{
125        /* local variables */
126        REAL     w_x, w_y;          /* window lower left coordinates */
127        REAL     w_width;           /* window width */
128        REAL     w_height;          /* window height */
129        REAL     tmp;               /* scratch */
130        REAL     tickl, ltickl;     /* tick lengths */
131        REAL     curr;              /* current position */
132        int      i;                 /* counter */
133        char     str[BC_LINELTH+1]; /* scratch string */
134
135        /* executable code */
136
137        if  (lofrq >= hifrq || loamp >= hiamp)  {
138                *status = LGE_ILLSCALE;
139                return;
140        } else if  (lofrq <= 0.0 || loamp <= 0.0)  {
141                *status = LGE_ILLSCALE;
142                return;
143        } /*endif*/
144
145        lgv_lg_lofrq = floor( log10(lofrq)+0.01 );
146        lgv_lg_hifrq = ceil( log10(hifrq)-0.01 );
147        lgv_lg_loamp = floor( log10(loamp)+0.01 );
148        lgv_lg_hiamp = ceil( log10(hiamp)-0.01 );
149
150        w_width = lgv_lg_hifrq - lgv_lg_lofrq;
151        w_height = lgv_lg_hiamp - lgv_lg_loamp;
152        tmp = w_width * MARGIN;
153        w_x = lgv_lg_lofrq - tmp;
154        w_width += 2.0*tmp;
155        tmp = w_height * MARGIN;
156        w_y = lgv_lg_loamp - tmp;
157        w_height += 2.0*tmp;
158
159        gc_erase( lgv_wdw );
160        gc_setcoo( lgv_wdw, w_x, w_y, w_width, w_height, status );
161        if  (Severe(status))  return;
162
163        /* draw axes */
164        gc_moveto( lgv_wdw, lgv_lg_lofrq, lgv_lg_hiamp );
165        gc_drawto( lgv_wdw, style, lgv_lg_lofrq, lgv_lg_loamp );
166        gc_drawto( lgv_wdw, style, lgv_lg_hifrq, lgv_lg_loamp );
167
168        /* draw ticks of horizontal axis */
169        tickl = w_height / 40.0;
170        ltickl = 2.0*tickl;
171        curr = lgv_lg_lofrq;
172        do  {
173                for  (i=0; i<10; i++)  {
174                        tmp = curr + log10( 1.0+(float)i );
175                        gc_moveto( lgv_wdw, tmp, lgv_lg_loamp );
176                        if  (i == 0)  {
177                                gc_drawto( lgv_wdw, style, tmp, lgv_lg_loamp-ltickl );
178                                sprintf( str, "%1.0f", curr );
179                                gc_text( lgv_wdw, style, tmp+lgv_ha_hshift*w_width,
180                                        lgv_lg_loamp-ltickl+lgv_ha_vshift*w_height, str );
181                        } else {
182                                gc_drawto( lgv_wdw, style, tmp, lgv_lg_loamp-tickl );
183                        } /*endif*/
184                } /*endfor*/
185                curr += 1.0;
186        } while (curr < lgv_lg_hifrq);
187
188        /* draw ticks of vertical axis */
189        tickl = w_width / 40.0;
190        ltickl = 2.0*tickl;
191        curr = lgv_lg_loamp;
192        do  {
193                for  (i=0; i<10; i++)  {
194                        tmp = curr + log10( 1.0+(float)i );
195                        gc_moveto( lgv_wdw, lgv_lg_lofrq, tmp );
196                        if  (i == 0)  {
197                                gc_drawto( lgv_wdw, style, lgv_lg_lofrq-ltickl, tmp );
198                                sprintf( str, "%1.0f", curr );
199                                gc_text( lgv_wdw, style, lgv_lg_lofrq-ltickl+
200                                        lgv_va_hshift*w_width, tmp+lgv_va_vshift*w_height, str );
201                        } else {
202                                gc_drawto( lgv_wdw, style, lgv_lg_lofrq-tickl, tmp );
203                        } /*endif*/
204                } /*endfor*/
205                curr += 1.0;
206        } while (curr < lgv_lg_hiamp);
207
208        gc_flushbuffers();
209
210} /* end of lg_scale */
211
212
213
214/*---------------------------------------------------------------------*/
215
216
217
218void lg_logplot( int style, SAMPLE smp[], long lth, REAL offset,
219        REAL delta )
220
221/* plot trace into logplot window
222 *
223 * parameters of routine
224 * int        style;        input; style number
225 * SAMPLE     smp[];        input; trace to plot
226 * long       lth;          input; length of trace
227 * REAL       offset;       input; frq offset of trace
228 * REAL       delta;        input; x-increment
229 */
230{
231        /* local variables */
232        REAL     x;           /* current x position */
233        REAL     logx, logy;  /* logarithm of position */
234        long     i, istart;   /* counter */
235        BOOLEAN  move;        /* move, not draw */
236
237        /* executable code */
238
239        /* find onset */
240        istart = 0;
241        x = offset;
242        while  (x <= 0.0)  {
243                x += delta;
244                istart++;
245        } /*endwhile */
246
247        /* plot it */
248        move = TRUE;
249        for  (i=istart; i<lth; i++)  {
250                logx = log10( x );
251                logy = log10( smp[i] );
252                if  (lgv_lg_lofrq <= logx && logx <= lgv_lg_hifrq &&
253                        lgv_lg_loamp <= logy && logy <= lgv_lg_hiamp)  {
254                        if  (move)  {
255                                gc_moveto( lgv_wdw, logx, logy );
256                                move = FALSE;
257                        } else {
258                                gc_drawto( lgv_wdw, style, logx, logy );
259                        } /*endif*/
260                } else {
261                        move = TRUE;
262                } /*endif*/
263                x += delta;
264        } /*endfor*/
265
266        gc_flushbuffers();
267
268} /* end of lg_logplot */
269
270
271
272/*---------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.