~ubuntu-branches/ubuntu/intrepid/plplot/intrepid

« back to all changes in this revision

Viewing changes to doc/docbook/src/fortran.html

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2006-11-04 10:19:34 UTC
  • mfrom: (2.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061104101934-mlirvdg4gpwi6i5q
Tags: 5.6.1-10
* Orphaning the package
* debian/control: Changed the maintainer to the Debian QA Group

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
 
<HTML
3
 
><HEAD
4
 
><TITLE
5
 
>Fortran Language</TITLE
6
 
><META
7
 
NAME="GENERATOR"
8
 
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
9
 
REL="HOME"
10
 
TITLE="The PLplot Plotting Library"
11
 
HREF="index.html"><LINK
12
 
REL="UP"
13
 
TITLE=" Language Bindings "
14
 
HREF="p2080.html"><LINK
15
 
REL="PREVIOUS"
16
 
TITLE="C Language"
17
 
HREF="c.html"><LINK
18
 
REL="NEXT"
19
 
TITLE="A C++ Interface for PLplot"
20
 
HREF="cplusplus.html"><LINK
21
 
REL="STYLESHEET"
22
 
TYPE="text/css"
23
 
HREF="stylesheet.css"></HEAD
24
 
><BODY
25
 
CLASS="chapter"
26
 
BGCOLOR="#FFFFFF"
27
 
TEXT="#000000"
28
 
LINK="#0000FF"
29
 
VLINK="#840084"
30
 
ALINK="#0000FF"
31
 
><DIV
32
 
CLASS="NAVHEADER"
33
 
><TABLE
34
 
SUMMARY="Header navigation table"
35
 
WIDTH="100%"
36
 
BORDER="0"
37
 
CELLPADDING="0"
38
 
CELLSPACING="0"
39
 
><TR
40
 
><TH
41
 
COLSPAN="3"
42
 
ALIGN="center"
43
 
>The PLplot Plotting Library: Programmer's Reference Manual</TH
44
 
></TR
45
 
><TR
46
 
><TD
47
 
WIDTH="10%"
48
 
ALIGN="left"
49
 
VALIGN="bottom"
50
 
><A
51
 
HREF="c.html"
52
 
ACCESSKEY="P"
53
 
>Prev</A
54
 
></TD
55
 
><TD
56
 
WIDTH="80%"
57
 
ALIGN="center"
58
 
VALIGN="bottom"
59
 
></TD
60
 
><TD
61
 
WIDTH="10%"
62
 
ALIGN="right"
63
 
VALIGN="bottom"
64
 
><A
65
 
HREF="cplusplus.html"
66
 
ACCESSKEY="N"
67
 
>Next</A
68
 
></TD
69
 
></TR
70
 
></TABLE
71
 
><HR
72
 
ALIGN="LEFT"
73
 
WIDTH="100%"></DIV
74
 
><DIV
75
 
CLASS="chapter"
76
 
><H1
77
 
><A
78
 
NAME="fortran"
79
 
></A
80
 
>Chapter 8. Fortran Language</H1
81
 
><P
82
 
>As discussed in the preceding section, PLplot's integer representation is a
83
 
PLINT and its floating point representation is a PLFLT.  To the
84
 
Fortran user, this most commonly translates to a type
85
 
<VAR
86
 
CLASS="literal"
87
 
>integer</VAR
88
 
> and
89
 
type <VAR
90
 
CLASS="literal"
91
 
>real</VAR
92
 
>, respectively.  This is somewhat system dependent (and up to
93
 
the installer of the package) so you should check the release notes to be
94
 
sure, or just try it and see what happens.
95
 
  </P
96
 
><P
97
 
>Because the PLplot kernel is written in C, standard C syntax is used in the
98
 
description of each PLplot function.  Thus to understand this manual it is
99
 
helpful to know a little about C, but fortunately the translation is very
100
 
easy and can be summarized here.  As an example, the routine 
101
 
<A
102
 
HREF="plline.html"
103
 
><CODE
104
 
CLASS="function"
105
 
>plline</CODE
106
 
></A
107
 
> call from C would look like:
108
 
<TABLE
109
 
CLASS="verbatim"
110
 
><TR
111
 
><TD
112
 
><PRE
113
 
CLASS="programlisting"
114
 
>       plline(n,x,y);
115
 
</PRE
116
 
></TD
117
 
></TR
118
 
></TABLE
119
 
>
120
 
while from Fortran it would look like:
121
 
<TABLE
122
 
CLASS="verbatim"
123
 
><TR
124
 
><TD
125
 
><PRE
126
 
CLASS="programlisting"
127
 
>       call plline(n,x,y)
128
 
</PRE
129
 
></TD
130
 
></TR
131
 
></TABLE
132
 
>
133
 
typically with <VAR
134
 
CLASS="literal"
135
 
>n</VAR
136
 
> declared as type
137
 
<VAR
138
 
CLASS="literal"
139
 
>integer</VAR
140
 
> and <VAR
141
 
CLASS="literal"
142
 
>x</VAR
143
 
>, <VAR
144
 
CLASS="literal"
145
 
>y</VAR
146
 
>
147
 
declared as type <VAR
148
 
CLASS="literal"
149
 
>real</VAR
150
 
> (arrays in this case).  
151
 
Each C language type
152
 
used in the text translates roughly as follows:
153
 
        <DIV
154
 
CLASS="informaltable"
155
 
><P
156
 
></P
157
 
><A
158
 
NAME="AEN2133"
159
 
></A
160
 
><TABLE
161
 
BORDER="0"
162
 
FRAME="void"
163
 
CLASS="CALSTABLE"
164
 
><COL
165
 
WIDTH="1*"
166
 
ALIGN="center"><COL
167
 
WIDTH="1*"
168
 
ALIGN="center"><TBODY
169
 
><TR
170
 
><TD
171
 
>PLFLT</TD
172
 
><TD
173
 
>real</TD
174
 
></TR
175
 
><TR
176
 
><TD
177
 
>PLINT</TD
178
 
><TD
179
 
>integer</TD
180
 
></TR
181
 
><TR
182
 
><TD
183
 
>char *</TD
184
 
><TD
185
 
>character</TD
186
 
></TR
187
 
><TR
188
 
><TD
189
 
>PLFLT *</TD
190
 
><TD
191
 
>real or real array</TD
192
 
></TR
193
 
><TR
194
 
><TD
195
 
>PLFLT **</TD
196
 
><TD
197
 
>real array</TD
198
 
></TR
199
 
><TR
200
 
><TD
201
 
><VAR
202
 
CLASS="literal"
203
 
>"string"</VAR
204
 
></TD
205
 
><TD
206
 
><VAR
207
 
CLASS="literal"
208
 
>'string'</VAR
209
 
></TD
210
 
></TR
211
 
><TR
212
 
><TD
213
 
>array[0]</TD
214
 
><TD
215
 
>array(1)</TD
216
 
></TR
217
 
></TBODY
218
 
></TABLE
219
 
><P
220
 
></P
221
 
></DIV
222
 
>
223
 
In C there are two ways to pass a variable --- by value (the default) or by
224
 
reference (pointer), whereas only the latter is used by Fortran.
225
 
Therefore when you see references in the text to <SPAN
226
 
CLASS="emphasis"
227
 
><I
228
 
CLASS="emphasis"
229
 
>either</I
230
 
></SPAN
231
 
> an ordinary
232
 
argument or a pointer argument (e.g.  <VAR
233
 
CLASS="literal"
234
 
>*data</VAR
235
 
>), you simply use an
236
 
ordinary Fortran variable or array name.
237
 
  </P
238
 
><P
239
 
>The PLplot library comes with a set of Fortran interface routines that
240
 
allow the exact same call syntax (usually) regardless of whether calling
241
 
from C or Fortran.  In some cases, this means the subroutine name <SPAN
242
 
CLASS="emphasis"
243
 
><I
244
 
CLASS="emphasis"
245
 
>exceeds 8 characters in length</I
246
 
></SPAN
247
 
>.  Nearly every Fortran compiler
248
 
available
249
 
today allows subroutine names longer than 8 characters, so this should not
250
 
be a problem (although if it ever is, in principle a truncated name could
251
 
be defined for that platform).
252
 
  </P
253
 
><P
254
 
>These <SPAN
255
 
CLASS="QUOTE"
256
 
>"stub"</SPAN
257
 
> routines handle transforming the data
258
 
from the normal Fortran representation to that typically used in C.  This
259
 
includes:
260
 
<P
261
 
></P
262
 
><UL
263
 
><LI
264
 
><P
265
 
>Variables passed by value instead of by reference.
266
 
  </P
267
 
><P
268
 
>Fortran passes all subroutine arguments by reference, i.e., a pointer to the
269
 
argument value is pushed on the stack.  In C all values, except for arrays
270
 
(including char arrays), are passed by value, i.e., the argument value
271
 
itself is pushed on the stack.  The stub routine converts the Fortran call
272
 
by reference to a call by value.  As an example, here is how the plpoin stub
273
 
routine works.  In your Fortran program you might have a call to plpoin that
274
 
looks something like
275
 
<TABLE
276
 
CLASS="verbatim"
277
 
><TR
278
 
><TD
279
 
><PRE
280
 
CLASS="programlisting"
281
 
>      call plpoin(6,x,y,9)
282
 
</PRE
283
 
></TD
284
 
></TR
285
 
></TABLE
286
 
>
287
 
where x and y are arrays with 6 elements and you want to plot symbol 9.
288
 
As strange as it seems (at least to C programmers) the constants 6 and
289
 
9 are passed by reference.   This will actually call the following C
290
 
stub routine (included in entirety)
291
 
<TABLE
292
 
CLASS="verbatim"
293
 
><TR
294
 
><TD
295
 
><PRE
296
 
CLASS="programlisting"
297
 
>#include "plplot/plstubs.h"
298
 
 
299
 
void 
300
 
PLPOIN(n, x, y, code)
301
 
PLINT *n, *code;
302
 
PLFLT *x, *y;
303
 
{
304
 
    c_plpoin(*n, x, y, *code);
305
 
}
306
 
</PRE
307
 
></TD
308
 
></TR
309
 
></TABLE
310
 
>
311
 
All this stub routine does is convert the number of points
312
 
(<VAR
313
 
CLASS="literal"
314
 
>*n</VAR
315
 
> and the
316
 
symbol <VAR
317
 
CLASS="literal"
318
 
>*code</VAR
319
 
> to call by value (i.e.  pushes their value on the stack)
320
 
and then calls the C plpoin library routine.
321
 
</P
322
 
></LI
323
 
><LI
324
 
><P
325
 
>Get mapping between Fortran and C namespace right (system dependent).
326
 
  </P
327
 
><P
328
 
>The external symbols (i.e. function and subroutine names) as you see them
329
 
in your program often appear differently to the linker.  For example, the
330
 
Fortran routine names may be converted to uppercase or lowercase, and/or
331
 
have an underscore appended or prepended.  This translation is handled
332
 
entirely via redefinition of the stub routine names, which are macros.
333
 
There are several options for compiling PLplot that simplify getting the
334
 
name translation right (NEEDS DOCUMENTATION IF THESE STILL EXIST).  In any
335
 
case, once the name translation is established during installation, name
336
 
translation is completely transparent to the user.
337
 
</P
338
 
></LI
339
 
><LI
340
 
><P
341
 
>Translation of character string format from Fortran to C.
342
 
  </P
343
 
><P
344
 
>Fortran character strings are passed differently than other quantities, in
345
 
that a string descriptor is pushed on the stack along with the string
346
 
address.  C doesn't want the descriptor, it wants a NULL terminated string.
347
 
For routines that handle strings two stub routines are necessary, one
348
 
written in Fortran and one written in C.  Your Fortran program calls the
349
 
Fortran stub routine first.  This stub converts the character string to a
350
 
null terminated integer array and then calls the C stub routine.  The C
351
 
stub routine converts the integer array (type <VAR
352
 
CLASS="literal"
353
 
>long</VAR
354
 
>) to the usual C
355
 
string representation (which may be different, depending on whether your
356
 
machine uses a big endian or little endian byte ordering; in any case the
357
 
way it is done in PLplot is portable).  See the <VAR
358
 
CLASS="literal"
359
 
>plmtex</VAR
360
 
> stubs for an
361
 
example of this. 
362
 
  </P
363
 
><P
364
 
>Note that the portion of a Fortran character string that exceeds 299
365
 
characters will not be plotted by the text routines (<VAR
366
 
CLASS="literal"
367
 
>plmtex</VAR
368
 
>
369
 
and <VAR
370
 
CLASS="literal"
371
 
>plptex</VAR
372
 
>). 
373
 
</P
374
 
></LI
375
 
><LI
376
 
><P
377
 
>Multidimensional array arguments are changed from row-dominant to
378
 
column-dominant ordering through use of a temporary array.
379
 
  </P
380
 
><P
381
 
>In Fortran, arrays are always stored so that the first index increases most
382
 
rapidly as one steps through memory.  This is called
383
 
<SPAN
384
 
CLASS="QUOTE"
385
 
>"row-dominant"</SPAN
386
 
>
387
 
storage.  In C, on the other hand, the first index increases 
388
 
<SPAN
389
 
CLASS="emphasis"
390
 
><I
391
 
CLASS="emphasis"
392
 
>least</I
393
 
></SPAN
394
 
>
395
 
rapidly, i.e. <SPAN
396
 
CLASS="QUOTE"
397
 
>"column-dominant"</SPAN
398
 
> ordering.  Thus, two dimensional arrays
399
 
(e.g.  as passed to the contour or surface plotting routines) passed into
400
 
PLplot must be transposed in order to get the proper two-dimensional
401
 
relationship to the world coordinates.  This is handled in the C stub
402
 
routines by dynamic memory allocation of a temporary array.  This is then set
403
 
equal to the transpose of the passed in array and passed to the appropriate
404
 
PLplot routine.  The overhead associated with this is normally not important
405
 
but could be a factor if you are using very large 2d arrays.
406
 
</P
407
 
></LI
408
 
></UL
409
 
>
410
 
  </P
411
 
><P
412
 
>This all seems a little messy, but is very user friendly.  Fortran and C
413
 
programmers can use the same basic interface to the library, which is a
414
 
powerful plus for this method.  The fact that stub routines are being used
415
 
is completely transparent to the Fortran programmer.
416
 
  </P
417
 
><P
418
 
>For more information on calling PLplot from Fortran, please see the
419
 
example Fortran programs (<TT
420
 
CLASS="filename"
421
 
>x01f.f</TT
422
 
> through
423
 
<TT
424
 
CLASS="filename"
425
 
>x16f.f</TT
426
 
>) distributed
427
 
with PLplot.
428
 
  </P
429
 
></DIV
430
 
><DIV
431
 
CLASS="NAVFOOTER"
432
 
><HR
433
 
ALIGN="LEFT"
434
 
WIDTH="100%"><TABLE
435
 
SUMMARY="Footer navigation table"
436
 
WIDTH="100%"
437
 
BORDER="0"
438
 
CELLPADDING="0"
439
 
CELLSPACING="0"
440
 
><TR
441
 
><TD
442
 
WIDTH="33%"
443
 
ALIGN="left"
444
 
VALIGN="top"
445
 
><A
446
 
HREF="c.html"
447
 
ACCESSKEY="P"
448
 
>Prev</A
449
 
></TD
450
 
><TD
451
 
WIDTH="34%"
452
 
ALIGN="center"
453
 
VALIGN="top"
454
 
><A
455
 
HREF="index.html"
456
 
ACCESSKEY="H"
457
 
>Home</A
458
 
></TD
459
 
><TD
460
 
WIDTH="33%"
461
 
ALIGN="right"
462
 
VALIGN="top"
463
 
><A
464
 
HREF="cplusplus.html"
465
 
ACCESSKEY="N"
466
 
>Next</A
467
 
></TD
468
 
></TR
469
 
><TR
470
 
><TD
471
 
WIDTH="33%"
472
 
ALIGN="left"
473
 
VALIGN="top"
474
 
>C Language</TD
475
 
><TD
476
 
WIDTH="34%"
477
 
ALIGN="center"
478
 
VALIGN="top"
479
 
><A
480
 
HREF="p2080.html"
481
 
ACCESSKEY="U"
482
 
>Up</A
483
 
></TD
484
 
><TD
485
 
WIDTH="33%"
486
 
ALIGN="right"
487
 
VALIGN="top"
488
 
>A C++ Interface for PLplot</TD
489
 
></TR
490
 
></TABLE
491
 
></DIV
492
 
></BODY
493
 
></HTML
494
 
>
 
 
b'\\ No newline at end of file'