WSTester updated to work plus hopefully all the other changes that need to go into...
[jabaws.git] / binaries / src / ViennaRNA / RNAforester / g2-0.70 / src / g2_fif.c
1 /*****************************************************************************
2 **  Copyright (C) 1998-2001  Ljubomir Milanovic & Horst Wagner
3 **  This file is part of the g2 library
4 **
5 **  This library is free software; you can redistribute it and/or
6 **  modify it under the terms of the GNU Lesser General Public
7 **  License as published by the Free Software Foundation; either
8 **  version 2.1 of the License, or (at your option) any later version.
9 **
10 **  This library is distributed in the hope that it will be useful,
11 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 **  Lesser General Public License for more details.
14 **
15 **  You should have received a copy of the GNU Lesser General Public
16 **  License along with this library; if not, write to the Free Software
17 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 ******************************************************************************/
19 #include <stdio.h>
20 #include <string.h>
21 #include "g2.h"
22 #include "g2_util.h"
23
24 /*
25  *
26  * g2 Fortran Interface
27  *
28  */
29 #ifdef LINUX
30 #define FIF(funame) funame ## __
31 #else
32 #define FIF(funame) funame ## _
33 #endif
34
35 #define F_REAL         float    /* everything is float (real) !!!!!!!!!!!!!! */
36 #define F_CHAR         char     /* only char is char */
37 #define F_CHAR_LENGTH  int      /* and char length is integer (it is automatically supplied */
38
39
40 /**********************************************************/
41
42 #ifdef DO_PS
43
44 #include "PS/g2_PS.h"
45
46
47
48
49
50 F_REAL FIF(g2_open_ps)(F_CHAR *text, F_REAL *paper, F_REAL *orientation,
51                        F_CHAR_LENGTH length)
52 {
53     char *str;
54     int rv;
55
56     str=g2_malloc((length+1)*sizeof(char));
57     strncpy(str, text, length);
58     str[length]='\0';
59     rv=g2_open_PS(str, dtoi(*paper), dtoi(*orientation));
60     g2_free(str);
61     
62     return (F_REAL)rv;
63 }
64
65 #endif /* DO_PS */
66
67 /**********************************************************/
68
69 #ifdef DO_X11
70
71 #include "X11/g2_X11.h"
72
73 F_REAL FIF(g2_open_x11)(F_REAL *width, F_REAL *height)
74 {
75     return (F_REAL)g2_open_X11(*width, *height);
76 }
77
78 /* g2_open_x11x is missing */
79
80 #endif /* DO_X11 */
81
82 /**********************************************************/
83
84 #ifdef DO_GD
85
86 #include "GD/g2_gd.h"
87
88 F_REAL FIF(g2_open_gd)(F_CHAR *text, F_REAL *width, F_REAL *height, F_REAL *gd_type,
89                         F_CHAR_LENGTH length)
90 {
91     char *str;
92     int rv;
93     
94     str=g2_malloc((length+1)*sizeof(char));
95     strncpy(str, text, length);
96     str[length]='\0';
97
98     rv=g2_open_gd(str, *width, *height, *gd_type);
99     
100     g2_free(str);
101     
102     return (F_REAL)rv;
103 }
104
105 #endif /* DO_GD */
106
107 /**********************************************************/
108
109
110 F_REAL FIF(g2_open_vd)(void)
111 {
112     return (F_REAL)g2_open_vd();
113 }
114
115
116 void FIF(g2_attach)(F_REAL *vd_dev, F_REAL *dev)
117 {
118     g2_attach(dtoi(*vd_dev), dtoi(*dev));
119 }
120
121
122 void FIF(g2_detach)(F_REAL *vd_dev, F_REAL *dev)
123 {
124     g2_detach(dtoi(*vd_dev), dtoi(*dev));
125 }
126
127
128
129 void FIF(g2_close)(F_REAL *dev)
130 {
131     g2_close(dtoi(*dev));
132 }
133
134
135 void FIF(g2_set_auto_flush)(F_REAL *dev, F_REAL *on_off)
136 {
137     g2_set_auto_flush(dtoi(*dev), dtoi(*on_off));
138 }
139
140
141 void FIF(g2_set_coordinate_system)(F_REAL *dev,
142                                    F_REAL *x_origin, F_REAL *y_origin,
143                                    F_REAL *x_mul,    F_REAL *y_mul)
144 {
145     g2_set_coordinate_system(dtoi(*dev),
146                              *x_origin, *y_origin,
147                              *x_mul,    *y_mul);
148 }
149
150
151 F_REAL FIF(g2_ld)(void)
152 {
153     return (F_REAL)g2_ld();
154 }
155
156
157 void FIF(g2_set_ld)(F_REAL *dev)
158 {
159     g2_set_ld(dtoi(*dev));
160 }
161
162
163
164 void FIF(g2_flush)(F_REAL *dev)
165 {
166     g2_flush(dtoi(*dev));
167 }
168
169
170 void FIF(g2_save)(F_REAL *dev)
171 {
172     g2_save(dtoi(*dev));
173 }
174
175
176
177
178 void FIF(g2_arc)(F_REAL *dev, F_REAL *x, F_REAL *y,
179                  F_REAL *r1, F_REAL *r2, F_REAL *a1, F_REAL *a2)
180 {
181     g2_arc(dtoi(*dev), *x,  *y, *r1,  *r2,  *a1,  *a2);
182 }
183
184
185 void FIF(g2_circle)(F_REAL *dev, F_REAL *x, F_REAL *y, F_REAL *r)
186 {
187     g2_circle(dtoi(*dev), *x, *y, *r);
188 }
189
190
191 void FIF(g2_clear)(F_REAL *dev)
192 {
193     g2_clear(dtoi(*dev));
194 }
195
196
197 void FIF(g2_clear_palette)(F_REAL *dev)
198 {
199     g2_clear_palette(dtoi(*dev));
200 }
201
202
203 void FIF(g2_string)(F_REAL *dev, F_REAL *x, F_REAL *y, F_CHAR *text,
204                     F_CHAR_LENGTH length)
205 {
206     char *str;
207     str=g2_malloc((length+1)*sizeof(char));
208     strncpy(str, text, length);
209     str[length]='\0';
210     g2_string(dtoi(*dev), *x, *y, str);
211     g2_free(str);
212 }
213
214
215 void FIF(g2_ellipse)(F_REAL *dev, F_REAL *x, F_REAL *y, F_REAL *r1, F_REAL *r2)
216 {
217     g2_ellipse(dtoi(*dev), *x, *y, *r1, *r2);
218 }
219
220
221 void FIF(g2_filled_arc)(F_REAL *dev, F_REAL *x, F_REAL *y,
222                         F_REAL *r1, F_REAL *r2,
223                         F_REAL *a1, F_REAL *a2)
224 {
225     g2_filled_arc(dtoi(*dev), *x, *y, *r1, *r2, *a1, *a2);
226 }
227
228
229 void FIF(g2_filled_circle)(F_REAL *dev, F_REAL *x, F_REAL *y, F_REAL *r)
230 {
231     g2_filled_circle(dtoi(*dev), *x, *y, *r);
232 }
233
234
235 void FIF(g2_filled_ellipse)(F_REAL *dev, F_REAL *x, F_REAL *y, F_REAL *r1, F_REAL *r2)
236 {
237     g2_filled_ellipse(dtoi(*dev), *x, *y, *r1, *r2);
238 }
239
240
241 void FIF(g2_filled_triangle)(F_REAL *dev, F_REAL *x1, F_REAL *y1,
242                              F_REAL *x2, F_REAL *y2,
243                              F_REAL *x3, F_REAL *y3)
244 {
245     g2_filled_triangle(dtoi(*dev), *x1, *y1, *x2, *y2, *x3, *y3);
246 }
247
248
249 F_REAL  FIF(g2_ink)(F_REAL *dev, F_REAL *red, F_REAL *green, F_REAL *blue)
250 {
251     return (F_REAL)g2_ink(dtoi(*dev), *red, *green, *blue);
252 }
253
254
255 void FIF(g2_line)(F_REAL *dev, F_REAL *x1, F_REAL *y1, F_REAL *x2, F_REAL *y2)
256 {
257     g2_line(dtoi(*dev), *x1, *y1, *x2, *y2);
258 }
259
260
261 void FIF(g2_poly_line)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
262 {
263     double *d;
264     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
265     g2_poly_line(dtoi(*dev), dtoi(*N_pt), d);
266     g2_free(d);
267 }
268
269
270 void FIF(g2_polygon)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
271 {
272     double *d;
273     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
274     g2_polygon(dtoi(*dev), dtoi(*N_pt), d);
275     g2_free(d);
276 }
277
278
279 void FIF(g2_filled_polygon)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
280 {
281     double *d;
282     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
283     g2_filled_polygon(dtoi(*dev), dtoi(*N_pt), d);
284     g2_free(d);
285 }
286
287
288 void FIF(g2_line_r)(F_REAL *dev, F_REAL *dx, F_REAL *dy)
289 {
290     g2_line_r(dtoi(*dev), *dx, *dy);
291 }
292
293
294 void FIF(g2_line_to)(F_REAL *dev, F_REAL *x, F_REAL *y)
295 {
296     g2_line_to(dtoi(*dev), *x, *y);
297 }
298
299
300 void FIF(g2_move)(F_REAL *dev, F_REAL *x, F_REAL *y)
301 {
302     g2_move(dtoi(*dev), *x, *y);
303 }
304
305
306 void FIF(g2_move_r)(F_REAL *dev, F_REAL *dx, F_REAL *dy)
307 {
308     g2_move_r(dtoi(*dev), *dx, *dy);
309 }
310
311
312 void FIF(g2_pen)(F_REAL *dev, F_REAL *color)
313 {
314     g2_pen(dtoi(*dev), dtoi(*color));
315 }
316
317
318 void FIF(g2_plot)(F_REAL *dev, F_REAL *x, F_REAL *y)
319 {
320     g2_plot(dtoi(*dev), *x, *y);
321 }
322
323
324 void FIF(g2_plot_r)(F_REAL *dev, F_REAL *dx, F_REAL *dy)
325 {
326     g2_plot_r(dtoi(*dev), *dx, *dy);
327 }
328
329
330 void FIF(g2_rectangle)(F_REAL *dev,
331                        F_REAL *x1, F_REAL *y1,
332                        F_REAL *x2, F_REAL *y2)
333 {
334     g2_rectangle(dtoi(*dev), *x1, *y1, *x2, *y2);
335 }
336
337
338 void FIF(g2_filled_rectangle)(F_REAL *dev,
339                               F_REAL *x1, F_REAL *y1,
340                               F_REAL *x2, F_REAL *y2)
341 {
342     g2_filled_rectangle(dtoi(*dev), *x1, *y1, *x2, *y2);
343 }
344
345
346 void FIF(g2_reset_palette)(F_REAL *dev)
347 {
348     g2_reset_palette(dtoi(*dev));
349 }
350
351
352 void FIF(g2_set_background)(F_REAL *dev, F_REAL *color)
353 {
354     g2_set_background(dtoi(*dev), dtoi(*color));
355 }
356
357
358 void FIF(g2_set_dash)(F_REAL *dev, F_REAL *N, F_REAL *dashes)
359 {
360     double *d;
361     d=g2_floatp2doublep(dashes, dtoi(*N));
362     g2_set_dash(dtoi(*dev), dtoi(*N), d);
363     g2_free(d);
364 }
365
366
367 void FIF(g2_set_font_size)(F_REAL *dev, F_REAL *size)
368 {
369     g2_set_font_size(dtoi(*dev), *size);
370 }
371
372
373 void FIF(g2_set_line_width)(F_REAL *dev, F_REAL *w)
374 {
375     g2_set_line_width(dtoi(*dev), *w);
376 }
377
378
379 void FIF(g2_triangle)(F_REAL *dev, F_REAL *x1, F_REAL *y1,
380                       F_REAL *x2, F_REAL *y2,
381                       F_REAL *x3, F_REAL *y3)
382 {
383     g2_triangle(dtoi(*dev), *x1, *y1, *x2, *y2, *x3, *y3);
384 }
385
386
387 void FIF(g2_set_qp)(F_REAL *dev, F_REAL *d, F_REAL *shape)
388 {
389     g2_set_QP(dtoi(*dev), *d, dtoi(*shape));
390 }
391
392
393 void FIF(g2_plot_qp)(F_REAL *dev, F_REAL *x, F_REAL *y)
394 {
395     g2_plot_QP(dtoi(*dev), *x, *y);
396 }
397
398
399 /* thanks to Yuri Sbitnev for contributing the g2_image code for FORTRAN */
400 void FIF(g2_image)(F_REAL *dev, F_REAL *x, F_REAL *y, F_REAL *x_size, F_REAL *y_size,
401                    F_REAL *pens)
402 {
403     int i, j, xs, ys;
404     int *mypens;
405     xs=dtoi(*x_size);
406     ys=dtoi(*y_size);
407     mypens=(int *) g2_malloc(xs*ys*sizeof(int));
408     for(j=0;j<ys;j++) 
409       for(i=0;i<xs;i++) 
410         mypens[j*xs+i]=dtoi(pens[j*xs+i]);         /* pens[dtoi(*y_size)][dtoi(*x_size)] */
411     g2_image(dtoi(*dev), *x, *y, xs, ys, mypens);
412     g2_free(mypens);
413 }
414
415
416
417
418
419
420 void FIF(g2_spline)(F_REAL *dev, F_REAL *N_pt, F_REAL *points, F_REAL *o)
421 {
422     double *d;
423     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
424     g2_spline(dtoi(*dev), dtoi(*N_pt), d, dtoi(*o));
425     g2_free(d);
426 }
427
428 void FIF(g2_b_spline)(F_REAL *dev, F_REAL *N_pt, F_REAL *points, F_REAL *o)
429 {
430     double *d;
431     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
432     g2_b_spline(dtoi(*dev), dtoi(*N_pt), d, dtoi(*o));
433     g2_free(d);
434 }
435
436 void FIF(g2_raspln)(F_REAL *dev, F_REAL *N_pt, F_REAL *points, F_REAL *tn)
437 {
438     double *d;
439     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
440     g2_raspln(dtoi(*dev), dtoi(*N_pt), d, *tn);
441     g2_free(d);
442 }
443
444 void FIF(g2_para_3)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
445 {
446     double *d;
447     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
448     g2_para_3(dtoi(*dev), dtoi(*N_pt), d);
449     g2_free(d);
450 }
451
452 void FIF(g2_para_5)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
453 {
454     double *d;
455     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
456     g2_para_5(dtoi(*dev), dtoi(*N_pt), d);
457     g2_free(d);
458 }
459
460 void FIF(g2_filled_spline)(F_REAL *dev, F_REAL *N_pt, F_REAL *points, F_REAL *o)
461 {
462     double *d;
463     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
464     g2_filled_spline(dtoi(*dev), dtoi(*N_pt), d, dtoi(*o));
465     g2_free(d);
466 }
467
468 void FIF(g2_filled_b_spline)(F_REAL *dev, F_REAL *N_pt, F_REAL *points, F_REAL *o)
469 {
470     double *d;
471     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
472     g2_filled_b_spline(dtoi(*dev), dtoi(*N_pt), d, dtoi(*o));
473     g2_free(d);
474 }
475
476 void FIF(g2_filled_raspln)(F_REAL *dev, F_REAL *N_pt, F_REAL *points, F_REAL *tn)
477 {
478     double *d;
479     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
480     g2_filled_raspln(dtoi(*dev), dtoi(*N_pt), d, *tn);
481     g2_free(d);
482 }
483
484 void FIF(g2_filled_para_3)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
485 {
486     double *d;
487     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
488     g2_filled_para_3(dtoi(*dev), dtoi(*N_pt), d);
489     g2_free(d);
490 }
491
492 void FIF(g2_filled_para_5)(F_REAL *dev, F_REAL *N_pt, F_REAL *points)
493 {
494     double *d;
495     d=g2_floatp2doublep(points, dtoi(*N_pt)*2);
496     g2_filled_para_5(dtoi(*dev), dtoi(*N_pt), d);
497     g2_free(d);
498 }
499