ruby-pgplot 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/kwarg.c ADDED
@@ -0,0 +1,78 @@
1
+ /*
2
+ kwarg.c : Process keyword arguments for Ruby
3
+
4
+ Copyright (c) 2001 Masahiro TANAKA <masa@ir.isas.ac.jp>
5
+
6
+ This program is free software.
7
+ You can distribute/modify this program
8
+ under the same terms as Ruby itself.
9
+ NO WARRANTY.
10
+ */
11
+ #include <ruby.h>
12
+
13
+ /* void rb_scan_kw_args __((VALUE, ...)); */
14
+
15
+ static VALUE
16
+ kw_hash_i(i, tmp)
17
+ VALUE i, tmp;
18
+ {
19
+ VALUE key;
20
+
21
+ key = RARRAY_PTR(i)[0];
22
+ if (TYPE(key)==T_SYMBOL) {
23
+ key = rb_funcall(key, rb_intern("id2name"), 0);
24
+ } else
25
+ if (TYPE(key)!=T_STRING) {
26
+ rb_raise(rb_eArgError, "keywords must be String or Symbol");
27
+ }
28
+
29
+ rb_hash_aset(tmp, key, RARRAY_PTR(i)[1]);
30
+ return Qnil;
31
+ }
32
+
33
+ #ifdef HAVE_STDARG_PROTOTYPES
34
+ #include <stdarg.h>
35
+ #define va_init_list(a,b) va_start(a,b)
36
+ #else
37
+ #include <varargs.h>
38
+ #define va_init_list(a,b) va_start(a)
39
+ #endif
40
+
41
+ void
42
+ #ifdef HAVE_STDARG_PROTOTYPES
43
+ rb_scan_kw_args(VALUE hash, ...)
44
+ #else
45
+ rb_scan_kw_args(hash, va_alist)
46
+ VALUE hash;
47
+ va_dcl
48
+ #endif
49
+ {
50
+ char *key;
51
+ VALUE *var, val, str, tmp;
52
+ va_list vargs;
53
+
54
+ va_init_list(vargs, hash);
55
+
56
+ tmp = rb_hash_new();
57
+ if (TYPE(hash) == T_HASH)
58
+ rb_iterate(rb_each, hash, kw_hash_i, tmp);
59
+ else if (hash != Qnil)
60
+ rb_fatal("rb_san_kw_args: non-hash arg passed");
61
+
62
+ for (;;) {
63
+ key = va_arg(vargs, char*);
64
+ if (!key) break;
65
+ var = va_arg(vargs, VALUE*);
66
+ str = rb_str_new2(key);
67
+ val = rb_funcall(tmp, rb_intern("delete"), 1, str);
68
+ if (var) *var = val;
69
+ }
70
+
71
+ if (rb_funcall(tmp, rb_intern("empty?"), 0)==Qfalse) {
72
+ val = rb_funcall(tmp, rb_intern("keys"), 0);
73
+ val = rb_funcall(val, rb_intern("join"), 1, rb_str_new2(","));
74
+ rb_raise(rb_eArgError, "unknown keywords: %s",StringValuePtr(val));
75
+ }
76
+
77
+ va_end(vargs);
78
+ }
data/rb_pgplot.c.in ADDED
@@ -0,0 +1,1266 @@
1
+ /*
2
+ rb_pgplot.c : Ruby/PGPLOT extension library
3
+
4
+ Copyright (c) 2000,2001 Masahiro TANAKA <masa@ir.isas.ac.jp>
5
+
6
+ This program is free software.
7
+ You can distribute/modify this program
8
+ under the same terms as Ruby itself.
9
+ NO WARRANTY.
10
+ */
11
+ #include <stdio.h>
12
+ #include <cpgplot.h>
13
+ #include <ruby.h>
14
+ #include "narray.h"
15
+
16
+ #define min(a,b) (((a)<(b))?(a):(b))
17
+ #define rb_pgplot_fltary(obj) na_cast_object(obj,NA_SFLOAT)
18
+ #define rb_pgplot_intary(obj) na_cast_object(obj,NA_LINT)
19
+ #define rb_pgplot_newary(rank,shape) na_make_object(NA_SFLOAT,rank,shape,cNArray)
20
+
21
+ #define NA_PTR_FLT(dta) (float*)(((struct NARRAY*)DATA_PTR(dta))->ptr)
22
+ #define NA_PTR_INT(dta) (int*)(((struct NARRAY*)DATA_PTR(dta))->ptr)
23
+ #ifndef NA_RANK
24
+ #define NA_RANK(dta) (((struct NARRAY*)DATA_PTR(dta))->rank)
25
+ #endif
26
+ #ifndef NA_TYPE
27
+ #define NA_TYPE(dta) (((struct NARRAY*)DATA_PTR(dta))->type)
28
+ #endif
29
+ #ifndef NA_TOTAL
30
+ #define NA_TOTAL(dta) (((struct NARRAY*)DATA_PTR(dta))->total)
31
+ #endif
32
+ #ifndef NA_SHAPE0
33
+ #define NA_SHAPE0(dta) (((struct NARRAY*)DATA_PTR(dta))->shape[0])
34
+ #endif
35
+ #ifndef NA_SHAPE1
36
+ #define NA_SHAPE1(dta) (((struct NARRAY*)DATA_PTR(dta))->shape[1])
37
+ #endif
38
+
39
+ static VALUE mPgplot;
40
+ static VALUE cPgCursor;
41
+ static VALUE ePgCursorError;
42
+ static ID id_beg, id_end, id_x, id_y, id_char;
43
+
44
+ #ifdef GNU_FORTRAN
45
+ void MAIN__() {} /* Ruby has no 'MAIN__'! ; How should I handle this??? */
46
+ #endif
47
+
48
+ /* Search Minimum and Maximum values of array */
49
+ static void
50
+ rb_pgplot_minmax(VALUE na, float range[])
51
+ {
52
+ int i;
53
+ float *ptr = NA_PTR_FLT(na);
54
+
55
+ range[0] = range[1] = *ptr;
56
+ ptr++;
57
+ for (i=NA_TOTAL(na)-1; i>0; i--,ptr++) {
58
+ if (*ptr<range[0]) range[0] = *ptr; /* min */
59
+ if (*ptr>range[1]) range[1] = *ptr; /* max */
60
+ }
61
+ }
62
+
63
+
64
+ /* PGASK -- control new page prompting
65
+ pgask [true|false]
66
+ */
67
+ static VALUE
68
+ rb_pgplot_pgask( int argc, VALUE *argv, VALUE self)
69
+ {
70
+ VALUE vflag;
71
+
72
+ rb_scan_args(argc, argv, "01", &vflag);
73
+
74
+ if (RTEST(vflag))
75
+ cpgask(1);
76
+ else
77
+ cpgask(0);
78
+ return Qnil;
79
+ }
80
+
81
+
82
+ /* PGOPEN -- open a graphics device
83
+ stat = pgopen [device]
84
+ */
85
+ static VALUE
86
+ rb_pgplot_pgopen( int argc, VALUE *argv, VALUE self )
87
+ {
88
+ VALUE vdev;
89
+ const char *dev="?";
90
+
91
+ rb_scan_args(argc,argv, "01", &vdev);
92
+ if (vdev!=Qnil) dev = StringValuePtr(vdev);
93
+
94
+ return INT2NUM(cpgopen(dev));
95
+ }
96
+
97
+
98
+ /* PGBEG -- open a graphics device */
99
+ static VALUE
100
+ rb_pgplot_pgbeg( int argc, VALUE *argv, VALUE self )
101
+ {
102
+ VALUE vdev, vnxs, vnys;
103
+ int nxsub=1, nysub=1;
104
+ const char *dev="?";
105
+
106
+ rb_scan_args(argc, argv, "03", &vdev,&vnxs,&vnys);
107
+ if (vdev!=Qnil) dev = StringValuePtr(vdev);
108
+ if (vnxs!=Qnil) nxsub = NUM2INT(vnxs);
109
+ if (vnys!=Qnil) nysub = NUM2INT(vnys);
110
+
111
+ if (cpgbeg(0, dev, nxsub, nysub) != 1)
112
+ return Qnil;
113
+ else
114
+ return Qtrue;
115
+ }
116
+
117
+
118
+ /* PGENV -- set window and viewport and draw labeled frame
119
+ pgenv xmin,xmax,ymin,ymax [, just [, axis]]
120
+ xmin: the left of the viewport.
121
+ xmax: the right of the viewport.
122
+ ymin: the bottom of the viewport.
123
+ ymax: the top of the viewport
124
+ just: if just=1, the x and y axes is scaled equally,
125
+ otherwise scaled independently.
126
+ axis: controls of axes.
127
+ */
128
+ static VALUE
129
+ rb_pgplot_pgenv( int argc, VALUE *argv, VALUE self )
130
+ {
131
+ VALUE x0, x1, y0, y1, vjust, vaxis;
132
+ int just=0, axis=0;
133
+
134
+ rb_scan_args(argc, argv, "42", &x0,&x1,&y0,&y1,&vjust,&vaxis);
135
+ if (vjust!=Qnil) just = NUM2INT(vjust);
136
+ if (vaxis!=Qnil) axis = NUM2INT(vaxis);
137
+
138
+ cpgenv( NUM2DBL(x0), NUM2DBL(x1), NUM2DBL(y0), NUM2DBL(y1), just, axis );
139
+ return Qtrue;
140
+ }
141
+
142
+
143
+ /* PGLINE -- draw a polyline (curve defined by line-segments)
144
+ pgline xarray, yarray
145
+ */
146
+ static VALUE
147
+ rb_pgplot_pgline(VALUE obj, VALUE v1, VALUE v2)
148
+ {
149
+ VALUE x, y;
150
+
151
+ x = rb_pgplot_fltary( v1 );
152
+ y = rb_pgplot_fltary( v2 );
153
+
154
+ cpgline( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y) );
155
+
156
+ return Qtrue;
157
+ }
158
+
159
+ /* PGPOLY -- draw a polygon, using fill-area attributes
160
+ pgpoly xarray, yarray
161
+ */
162
+ static VALUE
163
+ rb_pgplot_pgpoly(VALUE obj, VALUE v1, VALUE v2)
164
+ {
165
+ VALUE x, y;
166
+
167
+ x = rb_pgplot_fltary( v1 );
168
+ y = rb_pgplot_fltary( v2 );
169
+
170
+ cpgpoly( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y) );
171
+
172
+ return Qtrue;
173
+ }
174
+
175
+
176
+ /* PGPT -- draw several graph markers
177
+ pgpt xarray, yarray [,symbol]
178
+ */
179
+ static VALUE
180
+ rb_pgplot_pgpt( int argc, VALUE *argv, VALUE self )
181
+ {
182
+ VALUE vx, vy, vsym;
183
+ VALUE x, y;
184
+ int sym=0;
185
+
186
+ rb_scan_args(argc,argv, "21", &vx,&vy,&vsym);
187
+ if (vsym!=Qnil) sym = NUM2INT(vsym);
188
+
189
+ x = rb_pgplot_fltary( vx );
190
+ y = rb_pgplot_fltary( vy );
191
+
192
+ cpgpt( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y), sym );
193
+
194
+ return Qtrue;
195
+ }
196
+
197
+ /* PGPNTS -- draw several graph markers, not all the same
198
+ pgpnts xarray, yarray, symarray
199
+ */
200
+ static VALUE
201
+ rb_pgplot_pgpnts( VALUE obj, VALUE vx, VALUE vy, VALUE vs )
202
+ {
203
+ VALUE x, y, s;
204
+
205
+ x = rb_pgplot_fltary( vx );
206
+ y = rb_pgplot_fltary( vy );
207
+ s = rb_pgplot_intary( vs );
208
+
209
+ cpgpnts( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y),
210
+ NA_PTR_INT(s), NA_TOTAL(s) );
211
+
212
+ return Qtrue;
213
+ }
214
+
215
+ /* PGBIN -- histogram of binned data
216
+ pgbin xarray, yarray [,center]
217
+ x : abscissae of bins.
218
+ y : data values of bins.
219
+ center : if true, the X values denote the center of the bin;
220
+ if false, the X values denote the lower edge (in X) of the bin.
221
+ */
222
+ static VALUE
223
+ rb_pgplot_pgbin( int argc, VALUE *argv, VALUE self )
224
+ {
225
+ VALUE vx, vy, vcent;
226
+ VALUE x, y;
227
+ int cent;
228
+
229
+ rb_scan_args(argc,argv, "21", &vx,&vy,&vcent);
230
+ if (RTEST(vcent)) cent=1; else cent=0;
231
+
232
+ x = rb_pgplot_fltary( vx );
233
+ y = rb_pgplot_fltary( vy );
234
+
235
+ cpgbin( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y), cent );
236
+
237
+ return Qtrue;
238
+ }
239
+
240
+ /* PGHIST -- histogram of unbinned data
241
+ pghist, data, nbin [,range, flag]
242
+ data : the data values. NBIN may not exceed 200.
243
+ nbin : the number of bins to use
244
+ range : the range for the histogram.
245
+ flag : = 0 PGENV is called automatically
246
+ = 1 the histogram is plotted in the current window.
247
+ = 2,3 with a filled area style.
248
+ = 4,5 simple line.
249
+ */
250
+ static VALUE
251
+ rb_pgplot_pghist( int argc, VALUE *argv, VALUE self )
252
+ {
253
+ VALUE vdat,vnbin,vrange,vflag;
254
+ VALUE na_dat;
255
+ int flag=0;
256
+ float range[2];
257
+
258
+ rb_scan_args(argc,argv, "22", &vdat,&vnbin,&vrange,&vflag);
259
+ na_dat = rb_pgplot_fltary( vdat );
260
+
261
+ /* Data Range */
262
+ if (vrange!=Qnil) {
263
+ range[0] = NUM2DBL(rb_funcall(vrange, id_beg, 0));
264
+ range[1] = NUM2DBL(rb_funcall(vrange, id_end, 0));
265
+ } else {
266
+ rb_pgplot_minmax(na_dat,range);
267
+ }
268
+ /* PGFLAG */
269
+ if (vflag!=Qnil) flag = NUM2INT(vflag);
270
+
271
+ cpghist( NA_TOTAL(na_dat), NA_PTR_FLT(na_dat),
272
+ range[0], range[1], NUM2INT(vnbin), flag );
273
+ return Qtrue;
274
+ }
275
+
276
+
277
+ /* Collection of Error bars
278
+ */
279
+ static void
280
+ rb_pgplot_errorbar( int argc, VALUE *argv, int callid, int dir )
281
+ {
282
+ VALUE v1,v2,v3,vt;
283
+ VALUE a1,a2,a3;
284
+ int size;
285
+ float tlen=1;
286
+
287
+ rb_scan_args(argc,argv, "31", &v1,&v2,&v3,&vt);
288
+ a1 = rb_pgplot_fltary( v1 );
289
+ a2 = rb_pgplot_fltary( v2 );
290
+ a3 = rb_pgplot_fltary( v3 );
291
+ size = min(NA_TOTAL(a1),NA_TOTAL(a2));
292
+ size = min(size,NA_TOTAL(a3));
293
+ if (vt!=Qnil) tlen = NUM2DBL(vt);
294
+
295
+ if (callid==1)
296
+ cpgerrx( size,
297
+ NA_PTR_FLT(a1), NA_PTR_FLT(a2), NA_PTR_FLT(a3),
298
+ tlen );
299
+ else if (callid==2)
300
+ cpgerry( size,
301
+ NA_PTR_FLT(a1), NA_PTR_FLT(a2), NA_PTR_FLT(a3),
302
+ tlen );
303
+ else
304
+ cpgerrb( dir, size,
305
+ NA_PTR_FLT(a1), NA_PTR_FLT(a2), NA_PTR_FLT(a3),
306
+ tlen );
307
+ }
308
+
309
+ /* PGERRB -- horizontal or vertical error bar
310
+ pgerrb, dir, x, y, err [,tlen]
311
+
312
+ dir : direction to plot the error bar relative to the data point.
313
+ One-sided error bar:
314
+ DIR is 1 for +X (X to X+E);
315
+ 2 for +Y (Y to Y+E);
316
+ 3 for -X (X to X-E);
317
+ 4 for -Y (Y to Y-E).
318
+ Two-sided error bar:
319
+ DIR is 5 for +/-X (X-E to X+E);
320
+ 6 for +/-Y (Y-E to Y+E).
321
+ x : world x-coordinates of the data.
322
+ y : world y-coordinates of the data.
323
+ err : value of error bar distance to be added to the
324
+ data position in world coordinates.
325
+ tlen: length of terminals to be drawn at the ends of the error bar,
326
+ as a multiple of the default length.
327
+ */
328
+ static VALUE
329
+ rb_pgplot_pgerrb( int argc, VALUE *argv, VALUE self )
330
+ {
331
+ rb_pgplot_errorbar( argc-1, argv+1, 0, NUM2INT(argv[0]) );
332
+ return Qtrue;
333
+ }
334
+
335
+ /* PGERRX -- horizontal error bar
336
+ pgerrx, x1, x2, y [,tlen]
337
+
338
+ x1 : world x-coordinates of lower end of the error bars.
339
+ x2 : world x-coordinates of upper end of the error bars.
340
+ */
341
+ static VALUE
342
+ rb_pgplot_pgerrx( int argc, VALUE *argv, VALUE self )
343
+ {
344
+ rb_pgplot_errorbar( argc, argv, 1, 0 );
345
+ return Qtrue;
346
+ }
347
+
348
+ /* PGERRY -- vertical error bar
349
+ pgerry, x, y1, y2 [,tlen]
350
+
351
+ y1 : world y-coordinates of top end of the error bars.
352
+ y2 : world y-coordinates of bottom end of the error bars.
353
+ */
354
+ static VALUE
355
+ rb_pgplot_pgerry( int argc, VALUE *argv, VALUE self )
356
+ {
357
+ rb_pgplot_errorbar( argc, argv, 2, 0 );
358
+ return Qtrue;
359
+ }
360
+
361
+
362
+ static float *
363
+ rb_pgplot_transform( VALUE val_tr )
364
+ {
365
+ static float tr_default[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
366
+ static float tr[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
367
+ VALUE na_tr;
368
+
369
+ /* Transform */
370
+ if (val_tr!=Qnil) {
371
+ na_tr = rb_pgplot_fltary( val_tr );
372
+ if (NA_TOTAL(na_tr) != 6)
373
+ rb_raise(rb_eArgError, "TR argument must be 6-elm (N)Array");
374
+ MEMCPY(tr, NA_PTR_FLT(na_tr), float, 6);
375
+ return tr;
376
+ } else {
377
+ return tr_default;
378
+ }
379
+ }
380
+
381
+ static void
382
+ rb_pgplot_find_range(VALUE na, VALUE vrange, float range[])
383
+ {
384
+ /* if Range class is set, extrant begin&end */
385
+ if (vrange!=Qnil) {
386
+ range[0] = NUM2DBL(rb_funcall(vrange, id_beg, 0));
387
+ range[1] = NUM2DBL(rb_funcall(vrange, id_end, 0));
388
+ } else {
389
+ /* if Range is not set, search min&max of array */
390
+ rb_pgplot_minmax(na,range);
391
+ }
392
+ }
393
+
394
+ /* contour routine collection */
395
+ static void
396
+ rb_pgplot_contour( int argc, VALUE *argv, int callid )
397
+ {
398
+ VALUE vmap, vtr, vcont, vblank, vtmp;
399
+ VALUE na_map, na_cont;
400
+ float blank=0, *tr;
401
+
402
+ rb_scan_args(argc, argv, "22", &vmap, &vcont, &vtr, &vblank );
403
+
404
+ if (callid==2) { /* for PGCONB */
405
+ /* Exchange */
406
+ vtmp=vblank; vblank=vtr; vtr=vtmp;
407
+ /* Blanking */
408
+ if (vblank!=Qnil) blank=NUM2DBL(vblank);
409
+ }
410
+
411
+ /* Map Data */
412
+ na_map = rb_pgplot_fltary( vmap );
413
+ if (NA_RANK(na_map) != 2)
414
+ rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
415
+ /* Contour levels */
416
+ na_cont = rb_pgplot_fltary( vcont );
417
+
418
+ /* Transform */
419
+ tr = rb_pgplot_transform( vtr );
420
+ /* Show Contour */
421
+ if (callid==1)
422
+ cpgcons( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
423
+ 1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
424
+ NA_PTR_FLT(na_cont), NA_TOTAL(na_cont), tr );
425
+ else if (callid==2)
426
+ cpgconb( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
427
+ 1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
428
+ NA_PTR_FLT(na_cont), NA_TOTAL(na_cont), tr, blank );
429
+ else
430
+ cpgcont( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
431
+ 1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
432
+ NA_PTR_FLT(na_cont), NA_TOTAL(na_cont), tr );
433
+ }
434
+
435
+ /* PGCONT -- contour map of a 2D data array (contour-following)
436
+ pgcont, map, cont [,tr]
437
+ map : 2-D array of map data
438
+ cont : array of contour levels
439
+ tr : transformation matrix between array grid and world coordinates.
440
+ */
441
+ static VALUE
442
+ rb_pgplot_pgcont( int argc, VALUE *argv, VALUE self )
443
+ {
444
+ rb_pgplot_contour( argc, argv, 0 );
445
+ return Qtrue;
446
+ }
447
+ /* PGCONS -- contour map of a 2D data array (fast algorithm)
448
+ pgcons, map, cont [,tr]
449
+ map : 2-D array of map data
450
+ cont : array of contour levels
451
+ tr : transformation matrix
452
+ */
453
+ static VALUE
454
+ rb_pgplot_pgcons( int argc, VALUE *argv, VALUE self )
455
+ {
456
+ rb_pgplot_contour( argc, argv, 1 );
457
+ return Qtrue;
458
+ }
459
+ /* PGCONB -- contour map of a 2D data array, with blanking
460
+ pgconb, map, cont [, blank, tr]
461
+ map : 2-D array of map data
462
+ cont : array of contour levels
463
+ tr : transformation matrix
464
+ blank : elements of array A that are equal to this value are blanked.
465
+ */
466
+ static VALUE
467
+ rb_pgplot_pgconb( int argc, VALUE *argv, VALUE self )
468
+ {
469
+ rb_pgplot_contour( argc, argv, 2 );
470
+ return Qtrue;
471
+ }
472
+
473
+ /* PGCONF -- fill between two contours
474
+ pgconf, map, cont_range [,tr]
475
+ map : 2-D array of map data
476
+ cont_range : range of two contour levels
477
+ tr : transformation matrix
478
+ */
479
+ static VALUE
480
+ rb_pgplot_pgconf( int argc, VALUE *argv, VALUE self )
481
+ {
482
+ VALUE vmap, vtr, vcont;
483
+ VALUE na_map;
484
+ float crange[2], *tr;
485
+
486
+ rb_scan_args(argc, argv, "21", &vmap, &vcont, &vtr );
487
+
488
+ /* Map Data */
489
+ na_map = rb_pgplot_fltary( vmap );
490
+ if (NA_RANK(na_map) != 2)
491
+ rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
492
+ /* Contour range */
493
+ rb_pgplot_find_range( na_map, vcont, crange );
494
+ /* Transform */
495
+ tr = rb_pgplot_transform( vtr );
496
+ /* Show Contour */
497
+ cpgconf( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
498
+ 1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
499
+ crange[0], crange[1], tr );
500
+ return Qtrue;
501
+ }
502
+
503
+ /* PGCONL -- label contour map of a 2D data array
504
+ pgconl, map, cont, label [,intval, minint, tr]
505
+ map : 2-D array of map data
506
+ cont : contour level tobe labeld
507
+ label : label string
508
+ intval : spacing along the contour between labels, in grid cells.
509
+ minint : contours that cross less than MININT cells will not be labelled.
510
+ tr : transformation matrix
511
+ */
512
+ static VALUE
513
+ rb_pgplot_pgconl( int argc, VALUE *argv, VALUE self )
514
+ {
515
+ VALUE vmap, vcnt, vlab, vint, vmin, vtr;
516
+ VALUE na_map;
517
+ float *tr;
518
+ int intval=20, minint=10; /* recomended default */
519
+
520
+ rb_scan_args(argc, argv, "33", &vmap,&vcnt,&vlab,&vint,&vmin,&vtr );
521
+
522
+ /* Map Data */
523
+ na_map = rb_pgplot_fltary( vmap );
524
+ if (NA_RANK(na_map) != 2)
525
+ rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
526
+ /* spacing of labels */
527
+ if (vint!=Qnil) intval = NUM2INT(vint);
528
+ if (vmin!=Qnil) minint = NUM2INT(vmin);
529
+ /* Transform */
530
+ tr = rb_pgplot_transform( vtr );
531
+ /* Show Contour */
532
+ cpgconl( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
533
+ 1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
534
+ NUM2DBL(vcnt), tr, StringValuePtr(vlab), intval, minint);
535
+ return Qtrue;
536
+ }
537
+
538
+
539
+ /* PGVECT -- vector map of a 2D data array, with blanking
540
+ pgvect, x, y [, scale, pos, tr, blank ]
541
+
542
+ x : horizontal component data array.
543
+ y : vertical component data array.
544
+ scale : scale factor for vector lengths, if 0.0, C will be
545
+ set so that the longest vector is equal to the
546
+ smaller of TR(2)+TR(3) and TR(5)+TR(6).
547
+ pos : vector positioning code.
548
+ <0 vector head positioned on coordinates
549
+ >0 vector base positioned on coordinates
550
+ =0 vector centered on the coordinates
551
+ tr : transformation matrix
552
+ blank : elements of arrays A or B that are exactly equal to
553
+ this value are ignored (blanked).
554
+ */
555
+ static VALUE
556
+ rb_pgplot_pgvect( int argc, VALUE *argv, VALUE self )
557
+ {
558
+ VALUE vx,vy,vscl,vpos,vtr,vblank;
559
+ VALUE na_x, na_y;
560
+ int pos=0;
561
+ float scale=0, blank=0, *tr;
562
+
563
+ rb_scan_args(argc, argv, "24", &vx,&vy,&vscl,&vpos,&vtr,&vblank);
564
+
565
+ /* Vector Data */
566
+ na_x = rb_pgplot_fltary( vx );
567
+ na_y = rb_pgplot_fltary( vy );
568
+ if (NA_RANK(na_x) != 2 || NA_RANK(na_y) != 2 )
569
+ rb_raise(rb_eArgError, "Vector arrays must be 2-D (N)Array");
570
+ if (NA_SHAPE0(na_x) != NA_SHAPE0(na_y) || NA_SHAPE1(na_x) != NA_SHAPE1(na_y) )
571
+ rb_raise(rb_eArgError, "Vector array sizes must be same");
572
+ /* Options */
573
+ if (vscl!=Qnil) scale = NUM2DBL(vscl);
574
+ if (vpos!=Qnil) pos = NUM2INT(vpos);
575
+ if (vblank!=Qnil) blank = NUM2DBL(vblank);
576
+ /* Transform */
577
+ tr = rb_pgplot_transform( vtr );
578
+ /* Show Contour */
579
+ cpgvect( NA_PTR_FLT(na_x), NA_PTR_FLT(na_y),
580
+ NA_SHAPE0(na_x), NA_SHAPE1(na_x),
581
+ 1, NA_SHAPE0(na_x), 1, NA_SHAPE1(na_x),
582
+ scale, pos, tr, blank );
583
+ return Qtrue;
584
+ }
585
+
586
+ /*
587
+ static void
588
+ rb_pgplot_palett()
589
+ {
590
+ float gl[2]={0.,1.};
591
+ float gr[2]={0.,1.};
592
+ float gg[2]={0.,1.};
593
+ float gb[2]={0.,1.};
594
+ float contra=1.0, bright=0.5;
595
+ cpgctab(gl, gr, gg, gb, 2, contra, bright);
596
+ }
597
+ */
598
+
599
+ /* collection of PGIMAG and PGGRAY
600
+ */
601
+ static VALUE
602
+ rb_pgplot_mapimage( int argc, VALUE *argv, VALUE self, int callid )
603
+ {
604
+ VALUE vimage, vtr, vrange;
605
+ VALUE na;
606
+ float range[2], *tr;
607
+
608
+ rb_scan_args(argc,argv, "12", &vimage, &vrange, &vtr );
609
+
610
+ /* Image */
611
+ na = rb_pgplot_fltary( vimage );
612
+ if (NA_RANK(na) != 2)
613
+ rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
614
+ /* Transform */
615
+ tr = rb_pgplot_transform( vtr );
616
+ /* Range */
617
+ rb_pgplot_find_range(na, vrange, range);
618
+ /* Show Image */
619
+ /*rb_pgplot_palett();*/
620
+ if (callid==0)
621
+ cpgimag( NA_PTR_FLT(na), NA_SHAPE0(na), NA_SHAPE1(na),
622
+ 1, NA_SHAPE0(na), 1, NA_SHAPE1(na),
623
+ range[0], range[1], tr );
624
+ else
625
+ cpggray( NA_PTR_FLT(na), NA_SHAPE0(na), NA_SHAPE1(na),
626
+ 1, NA_SHAPE0(na), 1, NA_SHAPE1(na),
627
+ range[0], range[1], tr );
628
+ return Qtrue;
629
+ }
630
+
631
+
632
+ /* PGIMAG -- color image from a 2D data array
633
+ pgimag, array [,range ,tr]
634
+ range : range of array value to be drawn
635
+ TR : transformation matrix.
636
+ */
637
+ static VALUE
638
+ rb_pgplot_pgimag( int argc, VALUE *argv, VALUE self )
639
+ {
640
+ rb_pgplot_mapimage( argc, argv, self, 0 );
641
+ return Qtrue;
642
+ }
643
+ /* PGGRAY -- gray-scale map of a 2D data array
644
+ pggray, array [, range, tr]
645
+ range : range of array value to be drawn
646
+ TR : transformation matrix.
647
+ */
648
+ static VALUE
649
+ rb_pgplot_pggray( int argc, VALUE *argv, VALUE self )
650
+ {
651
+ rb_pgplot_mapimage( argc, argv, self, 1 );
652
+ return Qtrue;
653
+ }
654
+
655
+ /* PGCTAB -- install the color table to be used by PGIMAG
656
+ pgctab, l,r,g,b [,contra,bright]
657
+ l : An array of NC normalized ramp-intensity levels
658
+ corresponding to the RGB primary color intensities
659
+ in R(),G(),B(). Colors on the ramp are linearly
660
+ interpolated from neighbouring levels.
661
+ Levels must be sorted in increasing order.
662
+ 0.0 places a color at the beginning of the ramp.
663
+ 1.0 places a color at the end of the ramp.
664
+ Colors outside these limits are legal, but will
665
+ not be visible if CONTRA=1.0 and BRIGHT=0.5.
666
+ r,g,b : array of normalized red,green,blue intensities.
667
+ contra : The contrast of the color ramp (normally 1.0).
668
+ Negative values reverse the direction of the ramp.
669
+ bright : The brightness of the color ramp. This is normally 0.5
670
+ but can sensibly hold any value between 0.0 and 1.0.
671
+ */
672
+
673
+ static VALUE
674
+ rb_pgplot_pgctab( int argc, VALUE *argv, VALUE self )
675
+ {
676
+ VALUE vl, vr, vg, vb, vcnt, vbrt;
677
+ VALUE l, r, g, b;
678
+ float contra=1.0, bright=0.5;
679
+ int n;
680
+
681
+ rb_scan_args(argc,argv, "42", &vl,&vr,&vg,&vb,&vcnt,&vbrt);
682
+
683
+ l = rb_pgplot_fltary( vl );
684
+ r = rb_pgplot_fltary( vr );
685
+ g = rb_pgplot_fltary( vg );
686
+ b = rb_pgplot_fltary( vb );
687
+
688
+ /* Optional Args */
689
+ if (vcnt!=Qnil) contra = NUM2INT(vcnt);
690
+ if (vbrt!=Qnil) bright = NUM2INT(vbrt);
691
+
692
+ n = min(NA_TOTAL(l),NA_TOTAL(r));
693
+ n = min(NA_TOTAL(g),n);
694
+ n = min(NA_TOTAL(b),n);
695
+ cpgctab( NA_PTR_FLT(l), NA_PTR_FLT(r), NA_PTR_FLT(g), NA_PTR_FLT(b),
696
+ n, contra, bright);
697
+ return Qtrue;
698
+ }
699
+
700
+
701
+ /* PGWEDG -- annotate an image plot with a wedge
702
+ pgwedg side, disp, width, fg, bg, label
703
+ side : The first character must be one of the characters
704
+ 'B', 'L', 'T', or 'R' signifying the Bottom, Left,
705
+ Top, or Right edge of the viewport.
706
+ The second character should be 'I' to use PGIMAG
707
+ to draw the wedge, or 'G' to use PGGRAY.
708
+ disp : the displacement of the wedge from the specified
709
+ edge of the viewport, measured outwards from the
710
+ viewport in units of the character height. Use a
711
+ negative value to write inside the viewport, a
712
+ positive value to write outside.
713
+ width : The total width of the wedge including annotation,
714
+ in units of the character height.
715
+ fg : The value which is to appear with shade
716
+ 1 ("foreground"). Use the values of FG and BG
717
+ that were supplied to PGGRAY or PGIMAG.
718
+ bg : the value which is to appear with shade
719
+ 0 ("background").
720
+ label : Optional units label.
721
+ */
722
+
723
+
724
+ /*
725
+ PGPIXL -- draw pixels
726
+ pgpixl, array [,x1,x2,y1,y2]
727
+
728
+ x1, y1 : world coordinates of one corner of the output region
729
+ x2, y2 : world coordinates of the opposite corner of the output region
730
+ */
731
+
732
+ static VALUE
733
+ rb_pgplot_pgpixl( int argc, VALUE *argv, VALUE self )
734
+ {
735
+ VALUE na;
736
+ float x1, x2, y1, y2;
737
+
738
+ if (argc<1)
739
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 1 or 5)", argc);
740
+ na = rb_pgplot_intary(argv[0]);
741
+
742
+ if (NA_RANK(na) != 2)
743
+ rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
744
+
745
+ if (argc==5) {
746
+ x1 = NUM2DBL(argv[1]);
747
+ x2 = NUM2DBL(argv[2]);
748
+ y1 = NUM2DBL(argv[3]);
749
+ y2 = NUM2DBL(argv[4]);
750
+ } else if (argc==1) {
751
+ x1 = 0;
752
+ x2 = NA_SHAPE0(na);
753
+ y1 = 0;
754
+ y2 = NA_SHAPE1(na);
755
+ } else
756
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 1 or 5)", argc);
757
+
758
+ cpgpixl( NA_PTR_INT(na), NA_SHAPE0(na), NA_SHAPE1(na),
759
+ 1, NA_SHAPE0(na), 1, NA_SHAPE1(na),
760
+ x1, x2, y1, y2 );
761
+ return Qtrue;
762
+ }
763
+
764
+
765
+
766
+ /* PGQINF -- inquire PGPLOT general information
767
+ value = pgqinf item
768
+ item : character string defining the information
769
+ value : character string containing the requested information.
770
+ */
771
+ static VALUE
772
+ rb_pgplot_pgqinf( VALUE obj, VALUE vitem )
773
+ {
774
+ int value_len=20;
775
+ char *item, *value;
776
+
777
+ item = StringValuePtr(vitem);
778
+ value = ALLOCA_N(char,value_len);
779
+ cpgqinf( item, value, &value_len );
780
+
781
+ return rb_str_new(value,value_len);
782
+ }
783
+
784
+ /* PGQDT -- inquire name of nth available device type
785
+ type, descr, inter = pgqdt [,ndev]
786
+ ndev : the number of the device type (1..maximum).
787
+ type : receives the character device-type code of the
788
+ Nth device type.
789
+ descr : receives a description of the device type.
790
+ inter : receives 1 if the device type is an interactive
791
+ one, 0 otherwise.
792
+ */
793
+ static VALUE
794
+ rb_pgplot_pgqdt( int argc, VALUE *argv, VALUE self )
795
+ {
796
+ VALUE vdev;
797
+ int ndev=1, type_len=9, descr_len=65, inter;
798
+ char *type, *descr;
799
+
800
+ type = ALLOCA_N(char,type_len);
801
+ descr = ALLOCA_N(char,descr_len);
802
+ rb_scan_args(argc, argv, "01", &vdev);
803
+ if (vdev!=Qnil) ndev = NUM2INT(vdev);
804
+ cpgqdt( ndev, type, &type_len, descr, &descr_len, &inter );
805
+
806
+ return rb_ary_new3( 3, rb_str_new(type,type_len),
807
+ rb_str_new(descr,descr_len),
808
+ INT2NUM(inter) );
809
+ }
810
+
811
+
812
+ /* PGQTXT -- find bounding box of text string
813
+ xbox, ybox = pgqtxt(x,y,angle,fjust,text)
814
+ */
815
+ static VALUE
816
+ rb_pgplot_pgqtxt(VALUE obj, VALUE x, VALUE y,
817
+ VALUE ang, VALUE fjust, VALUE text)
818
+ {
819
+ VALUE vx,vy;
820
+ int i;
821
+ float xbox[4], ybox[4];
822
+ char *txt = StringValuePtr(text);
823
+
824
+ cpgqtxt( NUM2DBL(x),NUM2DBL(y),NUM2DBL(ang),NUM2DBL(fjust),txt,
825
+ xbox, ybox );
826
+ vx = rb_ary_new2(4);
827
+ vy = rb_ary_new2(4);
828
+ for (i=0;i<4;i++) {
829
+ rb_ary_push(vx, rb_float_new(xbox[i]));
830
+ rb_ary_push(vy, rb_float_new(ybox[i]));
831
+ }
832
+ return rb_ary_new3(2,vx,vy);
833
+ }
834
+
835
+
836
+ /* Construct PgCursor-class instance */
837
+ static void pgcursor_init(VALUE obj, VALUE x, VALUE y, VALUE ch)
838
+ {
839
+ rb_ivar_set(obj, id_x, x);
840
+ rb_ivar_set(obj, id_y, y);
841
+ rb_ivar_set(obj, id_char, ch);
842
+ }
843
+
844
+ static VALUE pgcursor_initialize(int argc, VALUE *argv, VALUE obj)
845
+ {
846
+ VALUE x, y, ch;
847
+
848
+ rb_scan_args(argc,argv, "21", &x,&y,&ch);
849
+ pgcursor_init(obj,x,y,ch);
850
+ return Qnil;
851
+ }
852
+
853
+ static VALUE pgcursor_new(VALUE x, VALUE y, VALUE ch)
854
+ {
855
+ VALUE obj;
856
+
857
+ obj = rb_obj_alloc(cPgCursor);
858
+ pgcursor_init(obj,x,y,ch);
859
+ return obj;
860
+ }
861
+
862
+ static VALUE pgcursor_to_ary(VALUE obj)
863
+ {
864
+ return rb_ary_new3( 3, rb_ivar_get(obj, id_x),
865
+ rb_ivar_get(obj, id_y),
866
+ rb_ivar_get(obj, id_char) );
867
+ }
868
+
869
+
870
+ /*
871
+ PGCURS -- read cursor position
872
+ result = pgcurs([x,y])
873
+
874
+ PgCursorError is raised if some error occurs.
875
+
876
+ result : instance of PgCursor-class. Attrs are;
877
+ x : the world x-coordinate of the cursor.
878
+ y : the world y-coordinate of the cursor.
879
+ char : the character typed by the user;
880
+ nil if the device has no cursor or if some other error occurs.
881
+ */
882
+ static VALUE
883
+ rb_pgplot_pgcurs( int argc, VALUE *argv, VALUE self )
884
+ {
885
+ float x, y, x2, y2;
886
+ char ch[2] = " ";
887
+
888
+ switch (argc) {
889
+ case 0:
890
+ cpgqwin(&x,&x2,&y,&y2);
891
+ x = (x+x2)/2;
892
+ y = (y+y2)/2;
893
+ break;
894
+ case 2:
895
+ x = NUM2DBL(argv[0]);
896
+ y = NUM2DBL(argv[1]);
897
+ break;
898
+ default:
899
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 0 or 2)", argc);
900
+ }
901
+
902
+ if (!cpgcurs(&x, &y, ch))
903
+ rb_raise(ePgCursorError, "failure in getting cursor position");
904
+
905
+ return pgcursor_new( rb_float_new(x), rb_float_new(y),
906
+ (ch==0) ? Qnil : rb_str_new(ch,1) );
907
+ }
908
+
909
+ /*
910
+ PGBAND -- read cursor position, with anchor
911
+ result = pgband( mode, [xref, yref, [x, y, [posn]]] )
912
+
913
+ PgCursorError is raised if some error occurs.
914
+
915
+ result : instance of PgCursor-class. see pgcurs.
916
+ */
917
+ static VALUE
918
+ rb_pgplot_pgband( int argc, VALUE *argv, VALUE self )
919
+ {
920
+ int mode=0, posn=0;
921
+ float x, y, xr, yr;
922
+ char ch[2] = " ";
923
+
924
+ if (argc<5) {
925
+ cpgqwin(&x,&xr,&y,&yr);
926
+ xr = x = (x+xr)/2;
927
+ yr = y = (y+yr)/2;
928
+ }
929
+ switch (argc) {
930
+ case 6:
931
+ if (RTEST(argv[5])) {
932
+ if (argv[5]==Qtrue)
933
+ posn = 1;
934
+ else
935
+ posn = NUM2INT(argv[5]);
936
+ }
937
+ case 5:
938
+ x = NUM2DBL(argv[3]);
939
+ y = NUM2DBL(argv[4]);
940
+ case 3:
941
+ xr = NUM2DBL(argv[1]);
942
+ yr = NUM2DBL(argv[2]);
943
+ case 1:
944
+ mode = NUM2INT(argv[0]);
945
+ break;
946
+ default:
947
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 1/3/5)", argc);
948
+ }
949
+
950
+ if (!cpgband(mode, posn, xr, yr, &x, &y, ch))
951
+ rb_raise(ePgCursorError, "failure in getting cursor position");
952
+
953
+ return pgcursor_new( rb_float_new(x), rb_float_new(y),
954
+ (ch==0) ? Qnil : rb_str_new(ch,1) );
955
+ }
956
+
957
+
958
+ /*
959
+ PGOLIN -- mark a set of points using the cursor
960
+ result = pgolin( x, y, [sym, [npt]] )
961
+
962
+ x : NArray.sfloat of x-coordinates.
963
+ y : NArray.sfloat of y-coordinates.
964
+ sym : code number of symbol to use for marking entered points (see PGPT).
965
+ npt : number of points entered; should be zero on first call.
966
+
967
+ result: number of points entered.
968
+ */
969
+ static VALUE
970
+ rb_pgplot_pgolin( int argc, VALUE *argv, VALUE self )
971
+ {
972
+ VALUE x, y, vsym, vnpt;
973
+ int sym=0, npt=0;
974
+
975
+ rb_scan_args(argc,argv, "22", &x,&y,&vsym,&vnpt);
976
+ if (vsym!=Qnil) sym = NUM2INT(vsym);
977
+ if (vnpt!=Qnil) npt = NUM2INT(vnpt);
978
+
979
+ if (NA_TYPE(x)!=NA_SFLOAT || NA_TYPE(y)!=NA_SFLOAT)
980
+ rb_raise(rb_eArgError, "Array must NArray.sfloat");
981
+
982
+ cpgolin( min(NA_TOTAL(x),NA_TOTAL(y)), &npt,
983
+ NA_PTR_FLT(x), NA_PTR_FLT(y), sym );
984
+
985
+ return INT2NUM(npt);
986
+ }
987
+
988
+ /*
989
+ PGNCUR -- mark a set of points using the cursor
990
+ result = pgncur( x, y, [sym, [npt]] )
991
+
992
+ x : NArray.sfloat of x-coordinates.
993
+ y : NArray.sfloat of y-coordinates.
994
+ sym : code number of symbol to use for marking entered points (see PGPT).
995
+ npt : number of points entered; should be zero on first call.
996
+
997
+ result: number of points entered.
998
+ */
999
+ static VALUE
1000
+ rb_pgplot_pgncur( int argc, VALUE *argv, VALUE self )
1001
+ {
1002
+ VALUE x, y, vsym, vnpt;
1003
+ int sym=0, npt=0;
1004
+
1005
+ rb_scan_args(argc,argv, "22", &x,&y,&vsym,&vnpt);
1006
+ if (vsym!=Qnil) sym = NUM2INT(vsym);
1007
+ if (vnpt!=Qnil) npt = NUM2INT(vnpt);
1008
+
1009
+ if (NA_TYPE(x)!=NA_SFLOAT || NA_TYPE(y)!=NA_SFLOAT)
1010
+ rb_raise(rb_eArgError, "Array must NArray.sfloat");
1011
+
1012
+ cpgncur( min(NA_TOTAL(x),NA_TOTAL(y)), &npt,
1013
+ NA_PTR_FLT(x), NA_PTR_FLT(y), sym );
1014
+
1015
+ return INT2NUM(npt);
1016
+ }
1017
+
1018
+ /*
1019
+ PGLCUR -- PGLCUR -- draw a line using the cursor
1020
+ result = pglcur( x, y, [npt] )
1021
+
1022
+ x : NArray.sfloat of x-coordinates.
1023
+ y : NArray.sfloat of y-coordinates.
1024
+ npt : number of points entered; should be zero on first call.
1025
+
1026
+ result: number of points entered.
1027
+ */
1028
+ static VALUE
1029
+ rb_pgplot_pglcur( int argc, VALUE *argv, VALUE self )
1030
+ {
1031
+ VALUE x, y, vnpt;
1032
+ int npt=0;
1033
+
1034
+ rb_scan_args(argc,argv, "21", &x,&y,&vnpt);
1035
+ if (vnpt!=Qnil) npt = NUM2INT(vnpt);
1036
+
1037
+ if (NA_TYPE(x)!=NA_SFLOAT || NA_TYPE(y)!=NA_SFLOAT)
1038
+ rb_raise(rb_eArgError, "Array must NArray.sfloat");
1039
+
1040
+ cpglcur( min(NA_TOTAL(x),NA_TOTAL(y)), &npt,
1041
+ NA_PTR_FLT(x), NA_PTR_FLT(y) );
1042
+
1043
+ return INT2NUM(npt);
1044
+ }
1045
+
1046
+
1047
+ void rb_scan_kw_args __((VALUE, ...));
1048
+
1049
+ /* PGTICK -- draw a single tick mark on an axis
1050
+ pgtick( x1, y1, x2, y2, v, [str], {"tickl", "tickr", "disp", "orient"})
1051
+
1052
+ Example:
1053
+ pgtick( 0,0,0,1, 0.5, "half", "tickr"=>1, "disp"=>2, "orient"=>90 )
1054
+
1055
+ Draw and label single tick mark on a graph axis. The tick mark is
1056
+ a short line perpendicular to the direction of the axis (which is not
1057
+ drawn by this routine). The optional text label is drawn with its
1058
+ baseline parallel to the axis and reading in the same direction as
1059
+ the axis (from point 1 to point 2). Current line and text attributes
1060
+ are used.
1061
+
1062
+ Arguments:
1063
+ X1, Y1 : world coordinates of one endpoint of the axis.
1064
+ X2, Y2 : world coordinates of the other endpoint of the axis.
1065
+ V : draw the tick mark at fraction V (0<=V<=1) along
1066
+ the line from (X1,Y1) to (X2,Y2).
1067
+ STR : text of label (may be blank).
1068
+ Keyword Arguments:
1069
+ TICKL : length of tick mark drawn to left of axis
1070
+ (as seen looking from first endpoint to second), in
1071
+ units of the character height.
1072
+ TICKR : length of major tick marks drawn to right of axis,
1073
+ in units of the character height.
1074
+ DISP : displacement of label text to
1075
+ right of axis, in units of the character height.
1076
+ ORIENT : orientation of label text, in degrees; angle between
1077
+ baseline of text and direction of axis (0-360 deg)
1078
+ */
1079
+
1080
+ static VALUE
1081
+ rb_pgplot_pgtick( int argc, VALUE *argv, VALUE self )
1082
+ {
1083
+ const char *str="";
1084
+ VALUE val=Qnil;
1085
+ VALUE x1, y1, x2, y2, v, vstr;
1086
+ VALUE tickl, tickr, disp, orient;
1087
+
1088
+ if (argc>0 && TYPE(argv[argc-1]) == T_HASH)
1089
+ val = argv[--argc];
1090
+ rb_scan_kw_args( val, "tickl", &tickl, "tickr", &tickr,
1091
+ "disp", &disp, "orient", &orient, 0);
1092
+ rb_scan_args(argc,argv, "51", &x1,&y1, &x2,&y2, &v, &vstr);
1093
+
1094
+ if (tickl ==Qnil) tickl = INT2FIX(0);
1095
+ if (tickr ==Qnil) tickr = INT2FIX(0);
1096
+ if (disp ==Qnil) disp = INT2FIX(1);
1097
+ if (orient==Qnil) orient= INT2FIX(0);
1098
+ if (vstr !=Qnil) str = StringValuePtr(vstr);
1099
+
1100
+ cpgtick( NUM2DBL(x1),NUM2DBL(y1),NUM2DBL(x2),NUM2DBL(y2),
1101
+ NUM2DBL(v), NUM2DBL(tickl),NUM2DBL(tickr),
1102
+ NUM2DBL(disp), NUM2DBL(orient), str );
1103
+ return Qnil;
1104
+ }
1105
+
1106
+
1107
+ /*
1108
+ PGAXIS -- draw an axis
1109
+
1110
+ pgaxis( x1, y1, x2, y2, v1, v2,
1111
+ {opt, step, nsub, tickl, tickr, frac, disp, orient} )
1112
+ Example:
1113
+ pgaxis( 1, 1, 9, 5, 0, 3, "tickl"=>1, "opt"=>"NL2" )
1114
+
1115
+ Draw a labelled graph axis from world-coordinate position (X1,Y1) to
1116
+ (X2,Y2).
1117
+
1118
+ Normally, this routine draws a standard LINEAR axis with equal
1119
+ subdivisions. The quantity described by the axis runs from V1 to V2;
1120
+ this may be, but need not be, the same as X or Y.
1121
+
1122
+ If the 'L' option is specified, the routine draws a LOGARITHMIC axis.
1123
+ In this case, the quantity described by the axis runs from 10**V1 to
1124
+ 10**V2. A logarithmic axis always has major, labeled, tick marks
1125
+ spaced by one or more decades. If the major tick marks are spaced
1126
+ by one decade (as specified by the STEP argument), then minor
1127
+ tick marks are placed at 2, 3, .., 9 times each power of 10;
1128
+ otherwise minor tick marks are spaced by one decade. If the axis
1129
+ spans less than two decades, numeric labels are placed at 1, 2, and
1130
+ 5 times each power of ten.
1131
+
1132
+ If the axis spans less than one decade, or if it spans many decades,
1133
+ it is preferable to use a linear axis labeled with the logarithm of
1134
+ the quantity of interest.
1135
+
1136
+ Arguments:
1137
+ x1, y1 : world coordinates of one endpoint of the axis.
1138
+ x2, y2 : world coordinates of the other endpoint of the axis.
1139
+ v1 : axis value at first endpoint.
1140
+ v2 : axis value at second endpoint.
1141
+
1142
+ Keyword Argnuments:
1143
+ opt : a string containing single-letter codes for
1144
+ various options. The options currently
1145
+ recognized are:
1146
+ L : draw a logarithmic axis
1147
+ N : write numeric labels
1148
+ 1 : force decimal labelling, instead of automatic
1149
+ choice (see PGNUMB).
1150
+ 2 : force exponential labelling, instead of
1151
+ automatic.
1152
+ step : major tick marks are drawn at axis value 0.0 plus
1153
+ or minus integer multiples of STEP. If STEP=0.0,
1154
+ a value is chosen automatically.
1155
+ nsub : minor tick marks are drawn to divide the major
1156
+ divisions into NSUB equal subdivisions (ignored if
1157
+ STEP=0.0). If NSUB <= 1, no minor tick marks are
1158
+ drawn. NSUB is ignored for a logarithmic axis.
1159
+ tickl : length of major tick marks drawn to left of axis
1160
+ (as seen looking from first endpoint to second), in
1161
+ units of the character height.
1162
+ tickr : length of major tick marks drawn to right of axis,
1163
+ in units of the character height.
1164
+ frac : length of minor tick marks, as fraction of major.
1165
+ disp : displacement of baseline of tick labels to
1166
+ right of axis, in units of the character height.
1167
+ orient : orientation of label text, in degrees; angle between
1168
+ baseline of text and direction of axis (0-360
1169
+ */
1170
+
1171
+ static VALUE
1172
+ rb_pgplot_pgaxis( int argc, VALUE *argv, VALUE self )
1173
+ {
1174
+ const char *opt="";
1175
+ float frac=0.5;
1176
+ VALUE val=Qnil;
1177
+ VALUE x1, y1, x2, y2, v1, v2;
1178
+ VALUE vopt, step, nsub, tickl, tickr, vfrac, disp, orient;
1179
+
1180
+ if (argc>0 && TYPE(argv[argc-1]) == T_HASH)
1181
+ val = argv[--argc];
1182
+
1183
+ rb_scan_kw_args( val,
1184
+ "opt",&vopt, "step",&step, "nsub",&nsub,
1185
+ "tickl",&tickl, "tickr",&tickr,
1186
+ "frac",&vfrac, "disp",&disp, "orient",&orient, 0);
1187
+ rb_scan_args(argc,argv, "60", &x1,&y1, &x2,&y2, &v1,&v2);
1188
+
1189
+ if (step ==Qnil) step = INT2FIX(0);
1190
+ if (nsub ==Qnil) nsub = INT2FIX(0);
1191
+ if (tickl ==Qnil) tickl = INT2FIX(0);
1192
+ if (tickr ==Qnil) tickr = INT2FIX(0);
1193
+ if (disp ==Qnil) disp = INT2FIX(1);
1194
+ if (orient==Qnil) orient= INT2FIX(0);
1195
+ if (vopt !=Qnil) opt = StringValuePtr(vopt);
1196
+ if (vfrac !=Qnil) frac = NUM2DBL(vfrac);
1197
+
1198
+ cpgaxis( opt, NUM2DBL(x1),NUM2DBL(y1),NUM2DBL(x2),NUM2DBL(y2),
1199
+ NUM2DBL(v1),NUM2DBL(v2),NUM2DBL(step),NUM2INT(nsub),
1200
+ NUM2DBL(tickl),NUM2DBL(tickr), frac,
1201
+ NUM2DBL(disp), NUM2DBL(orient) );
1202
+ return Qnil;
1203
+ }
1204
+
1205
+
1206
+ /*--- auto-generated funcs will be placed here ---*/
1207
+
1208
+
1209
+ void
1210
+ Init_pgplot()
1211
+ {
1212
+ mPgplot = rb_define_module("Pgplot");
1213
+
1214
+ /* The C application programming interface */
1215
+ rb_define_module_function(mPgplot, "pgopen", rb_pgplot_pgopen,-1);
1216
+ rb_define_module_function(mPgplot, "pgbeg", rb_pgplot_pgbeg, -1);
1217
+ rb_define_module_function(mPgplot, "pgenv", rb_pgplot_pgenv, -1);
1218
+ rb_define_module_function(mPgplot, "pgask", rb_pgplot_pgask, -1);
1219
+ rb_define_module_function(mPgplot, "pgline", rb_pgplot_pgline, 2);
1220
+ rb_define_module_function(mPgplot, "pgpoly", rb_pgplot_pgpoly, 2);
1221
+ rb_define_module_function(mPgplot, "pgpt", rb_pgplot_pgpt, -1);
1222
+ rb_define_module_function(mPgplot, "pgpnts", rb_pgplot_pgpnts, 3);
1223
+ rb_define_module_function(mPgplot, "pgbin", rb_pgplot_pgbin, -1);
1224
+ rb_define_module_function(mPgplot, "pghist", rb_pgplot_pghist, -1);
1225
+ rb_define_module_function(mPgplot, "pgerrb", rb_pgplot_pgerrb, -1);
1226
+ rb_define_module_function(mPgplot, "pgerrx", rb_pgplot_pgerrx, -1);
1227
+ rb_define_module_function(mPgplot, "pgerry", rb_pgplot_pgerry, -1);
1228
+ rb_define_module_function(mPgplot, "pgcont", rb_pgplot_pgcont, -1);
1229
+ rb_define_module_function(mPgplot, "pgcons", rb_pgplot_pgcons, -1);
1230
+ rb_define_module_function(mPgplot, "pgconb", rb_pgplot_pgconb, -1);
1231
+ rb_define_module_function(mPgplot, "pgconf", rb_pgplot_pgconf, -1);
1232
+ rb_define_module_function(mPgplot, "pgconl", rb_pgplot_pgconl, -1);
1233
+ rb_define_module_function(mPgplot, "pgvect", rb_pgplot_pgvect, -1);
1234
+ rb_define_module_function(mPgplot, "pgimag", rb_pgplot_pgimag, -1);
1235
+ rb_define_module_function(mPgplot, "pggray", rb_pgplot_pggray, -1);
1236
+ rb_define_module_function(mPgplot, "pgctab", rb_pgplot_pgctab, -1);
1237
+ rb_define_module_function(mPgplot, "pgpixl", rb_pgplot_pgpixl, -1);
1238
+ rb_define_module_function(mPgplot, "pgqinf", rb_pgplot_pgqinf, 1);
1239
+ rb_define_module_function(mPgplot, "pgqdt", rb_pgplot_pgqdt, -1);
1240
+ rb_define_module_function(mPgplot, "pgqtxt", rb_pgplot_pgqtxt, 5);
1241
+ rb_define_module_function(mPgplot, "pgcurs", rb_pgplot_pgcurs, -1);
1242
+ rb_define_module_function(mPgplot, "pgband", rb_pgplot_pgband, -1);
1243
+ rb_define_module_function(mPgplot, "pgolin", rb_pgplot_pgolin, -1);
1244
+ rb_define_module_function(mPgplot, "pgncur", rb_pgplot_pgncur, -1);
1245
+ rb_define_module_function(mPgplot, "pglcur", rb_pgplot_pglcur, -1);
1246
+ rb_define_module_function(mPgplot, "pgtick", rb_pgplot_pgtick, -1);
1247
+ rb_define_module_function(mPgplot, "pgaxis", rb_pgplot_pgaxis, -1);
1248
+
1249
+ /*--- auto-generated defs will be placed here ---*/
1250
+
1251
+ rb_set_end_proc((void(*)(VALUE))(cpgend), Qnil);
1252
+ id_beg = rb_intern("begin");
1253
+ id_end = rb_intern("end");
1254
+ id_x = rb_intern("@x");
1255
+ id_y = rb_intern("@y");
1256
+ id_char = rb_intern("@char");
1257
+
1258
+ /*--- PgCursor ---*/
1259
+ cPgCursor = rb_define_class_under(mPgplot, "PgCursor", rb_cObject);
1260
+ rb_define_method(cPgCursor, "initialize", pgcursor_initialize, -1);
1261
+ rb_define_method(cPgCursor, "to_ary", pgcursor_to_ary, 0);
1262
+ rb_attr(cPgCursor, rb_intern("x"), 1, 0, Qtrue);
1263
+ rb_attr(cPgCursor, rb_intern("y"), 1, 0, Qtrue);
1264
+ rb_attr(cPgCursor, rb_intern("char"), 1, 0, Qtrue);
1265
+ ePgCursorError = rb_define_class("PgCursorError", rb_eStandardError);
1266
+ }