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

« back to all changes in this revision

Viewing changes to examples/f95/x22f.f90

  • 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
!      $Id: x22f.f90,v 1.3 2006/05/19 17:15:15 airwin Exp $
 
2
!      Vector plot demo.
 
3
!
 
4
!      Copyright (C) 2004  Alan W. Irwin
 
5
!      Copyright (C) 2004  Andrew Ross
 
6
!
 
7
!      This file is part of PLplot.
 
8
!
 
9
!      PLplot is free software; you can redistribute it and/or modify
 
10
!      it under the terms of the GNU General Library Public License as
 
11
!      published by the Free Software Foundation; either version 2 of the
 
12
!      License, or (at your option) any later version.
 
13
!
 
14
!      PLplot is distributed in the hope that it will be useful,
 
15
!      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
!      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
!      GNU Library General Public License for more details.
 
18
!
 
19
!      You should have received a copy of the GNU Library General Public
 
20
!      License along with PLplot; if not, write to the Free Software
 
21
!      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
22
 
 
23
!      Does several contour plots using different coordinate mappings.
 
24
      use plplot
 
25
      implicit none
 
26
 
 
27
      integer narr
 
28
      logical fill
 
29
      parameter (narr=6)
 
30
      real(kind=plflt) arrow_x(narr),arrow_y(narr), &
 
31
        arrow2_x(narr),arrow2_y(narr)
 
32
 
 
33
      data arrow_x/-0.5_plflt, 0.5_plflt, 0.3_plflt, 0.5_plflt, 0.3_plflt, 0.5_plflt/
 
34
      data arrow_y/0._plflt, 0._plflt, 0.2_plflt, 0._plflt, -0.2_plflt, 0._plflt/
 
35
      data arrow2_x/-0.5_plflt, 0.3_plflt, 0.3_plflt, 0.5_plflt, 0.3_plflt, 0.3_plflt/
 
36
      data arrow2_y/0._plflt, 0._plflt, 0.2_plflt, 0._plflt, -0.2_plflt, 0._plflt/
 
37
 
 
38
!      Process command-line arguments
 
39
      call plparseopts(PL_PARSE_FULL)
 
40
 
 
41
      call plinit
 
42
 
 
43
 
 
44
      call circulation
 
45
 
 
46
      fill = .false.
 
47
 
 
48
!     Set arrow style using arrow_x and arrow_y the
 
49
!     plot using these arrows
 
50
      call plsvect(arrow_x, arrow_y, fill)
 
51
      call constriction
 
52
 
 
53
!     Set arrow style using arrow_x and arrow_y the
 
54
!     plot using these arrows
 
55
      fill = .true.
 
56
      call plsvect(arrow2_x, arrow2_y, fill)
 
57
      call constriction
 
58
 
 
59
      call potential
 
60
 
 
61
      call plend
 
62
 
 
63
      end
 
64
 
 
65
!     vector plot of the circulation around the origin
 
66
      subroutine circulation()
 
67
      use plplot
 
68
      implicit none
 
69
 
 
70
      integer i, j, nx, ny
 
71
      parameter (nx=20, ny=20)
 
72
 
 
73
      real(kind=plflt) u(nx, ny), v(nx, ny), xg(nx,ny), yg(nx,ny)
 
74
 
 
75
      real(kind=plflt) dx, dy, xmin, xmax, ymin, ymax
 
76
      real(kind=plflt) xx, yy, scaling
 
77
 
 
78
      dx = 1.0_plflt
 
79
      dy = 1.0_plflt
 
80
 
 
81
      xmin = -dble(nx)/2.0_plflt*dx
 
82
      xmax = dble(nx)/2.0_plflt*dx
 
83
      ymin = -dble(ny)/2.0_plflt*dy
 
84
      ymax = dble(ny)/2.0_plflt*dy
 
85
 
 
86
      do i=1,nx
 
87
        xx = (dble(i)-nx/2.0_plflt-0.5_plflt)*dx
 
88
        do j=1,ny
 
89
          yy = (dble(j)-ny/2.0_plflt-0.5_plflt)*dy
 
90
          xg(i,j) = xx
 
91
          yg(i,j) = yy
 
92
          u(i,j) = yy
 
93
          v(i,j) = -xx
 
94
        enddo
 
95
      enddo
 
96
 
 
97
      call plenv(xmin, xmax, ymin, ymax, 0, 0)
 
98
      call pllab('(x)', '(y)',  &
 
99
        '#frPLplot Example 22 - circulation')
 
100
      call plcol0(2)
 
101
      scaling = 0.0_plflt
 
102
      call plvect(u,v,scaling,xg,yg)
 
103
      call plcol0(1)
 
104
 
 
105
      end
 
106
 
 
107
!     vector plot of the flow through a constricted pipe
 
108
      subroutine constriction()
 
109
      use plplot, PI => PL_PI
 
110
      implicit none
 
111
 
 
112
      integer i, j, nx, ny
 
113
      parameter (nx=20, ny=20)
 
114
 
 
115
      real(kind=plflt) u(nx, ny), v(nx, ny), xg(nx,ny), yg(nx,ny)
 
116
 
 
117
      real(kind=plflt) dx, dy, xmin, xmax, ymin, ymax
 
118
      real(kind=plflt) xx, yy, Q, b, dbdx, scaling
 
119
 
 
120
      dx = 1.0_plflt
 
121
      dy = 1.0_plflt
 
122
 
 
123
      xmin = -dble(nx)/2.0_plflt*dx
 
124
      xmax = dble(nx)/2.0_plflt*dx
 
125
      ymin = -dble(ny)/2.0_plflt*dy
 
126
      ymax = dble(ny)/2.0_plflt*dy
 
127
 
 
128
      Q = 2.0_plflt
 
129
      do i=1,nx
 
130
        xx = (dble(i)-dble(nx)/2.0_plflt-0.5_plflt)*dx
 
131
        do j=1,ny
 
132
          yy = (dble(j)-dble(ny)/2.0_plflt-0.5_plflt)*dy
 
133
          xg(i,j) = xx
 
134
          yg(i,j) = yy
 
135
          b = ymax/4.0_plflt*(3.0_plflt-cos(PI*xx/xmax))
 
136
          if (abs(yy).lt.b) then
 
137
             dbdx = ymax/4.0_plflt*sin(PI*xx/xmax)*yy/b
 
138
             u(i,j) = Q*ymax/b
 
139
             v(i,j) = u(i,j)*dbdx
 
140
          else
 
141
             u(i,j) = 0.0_plflt
 
142
             v(i,j) = 0.0_plflt
 
143
          endif
 
144
        enddo
 
145
      enddo
 
146
 
 
147
      call plenv(xmin, xmax, ymin, ymax, 0, 0)
 
148
      call pllab('(x)', '(y)',  &
 
149
        '#frPLplot Example 22 - constriction')
 
150
      call plcol0(2)
 
151
      scaling = -0.5_plflt
 
152
      call plvect(u,v,scaling,xg,yg)
 
153
      call plcol0(1)
 
154
 
 
155
      end
 
156
 
 
157
 
 
158
      subroutine potential()
 
159
      use plplot, PI => PL_PI
 
160
      implicit none
 
161
 
 
162
      integer i, j, nr, ntheta, nper, nlevel
 
163
      parameter (nr=20, ntheta=20, nper=100, nlevel=10)
 
164
 
 
165
      real(kind=plflt) u(nr, ntheta), v(nr, ntheta), z(nr, ntheta)
 
166
      real(kind=plflt) xg(nr,ntheta), yg(nr,ntheta)
 
167
      real(kind=plflt) clevel(nlevel), px(nper), py(nper)
 
168
 
 
169
      real(kind=plflt) xmin, xmax, ymin, ymax, zmin, zmax, rmax
 
170
      real(kind=plflt) xx, yy, r, theta, scaling, dz
 
171
 
 
172
      real(kind=plflt) eps, q1, d1, q1i, d1i, q2, d2, q2i, d2i
 
173
      real(kind=plflt) div1, div1i, div2, div2i
 
174
 
 
175
      rmax = dble(nr)
 
176
 
 
177
      eps = 2.0_plflt
 
178
 
 
179
      q1 = 1.0_plflt;
 
180
      d1 = rmax/4.0_plflt;
 
181
 
 
182
      q1i = - q1*rmax/d1;
 
183
      d1i = rmax**2.0_plflt/d1;
 
184
 
 
185
      q2 = -1.0_plflt;
 
186
      d2 = rmax/4.0_plflt;
 
187
 
 
188
      q2i = - q2*rmax/d2;
 
189
      d2i = rmax**2.0_plflt/d2;
 
190
 
 
191
      do i = 1, nr
 
192
         r = 0.5 + dble(i-1)
 
193
        do j = 1, ntheta
 
194
          theta = 2.*PI/dble(ntheta-1)*(dble(j)-0.5)
 
195
          xx = r*cos(theta)
 
196
          yy = r*sin(theta)
 
197
          xg(i,j) = xx
 
198
          yg(i,j) = yy
 
199
          div1 = sqrt((xg(i,j)-d1)**2 + (yg(i,j)-d1)**2 + eps**2)
 
200
          div1i = sqrt((xg(i,j)-d1i)**2 + (yg(i,j)-d1i)**2 + eps**2)
 
201
 
 
202
          div2 = sqrt((xg(i,j)-d2)**2 + (yg(i,j)+d2)**2 + eps**2)
 
203
          div2i = sqrt((xg(i,j)-d2i)**2 + (yg(i,j)+d2i)**2 + eps**2)
 
204
 
 
205
          z(i,j) = q1/div1 + q1i/div1i + q2/div2 + q2i/div2i
 
206
          u(i,j) = -q1*(xx-d1)/div1**3 - q1i*(xx-d1i)/div1i**3 - &
 
207
              q2*(xx-d2)/div2**3 - q2i*(xx-d2i)/div2i**3
 
208
          v(i,j) = -q1*(yy-d1)/div1**3 - q1i*(yy-d1i)/div1i**3 - &
 
209
              q2*(yy+d2)/div2**3 - q2i*(yy+d2i)/div2i**3
 
210
        enddo
 
211
      enddo
 
212
 
 
213
      call a2mnmx(xg, nr, ntheta, xmin, xmax, nr)
 
214
      call a2mnmx(yg, nr, ntheta, ymin, ymax, nr)
 
215
      call a2mnmx(z, nr, ntheta, zmin, zmax, nr)
 
216
 
 
217
      call plenv(xmin, xmax, ymin, ymax, 0, 0)
 
218
      call pllab('(x)', '(y)',  &
 
219
        '#frPLplot Example 22 - potential gradient vector plot')
 
220
 
 
221
!     plot contours of the potential
 
222
      dz = abs(zmax - zmin)/dble (nlevel)
 
223
      do i = 1, nlevel
 
224
         clevel(i) = zmin + (i-0.5_plflt)*dz
 
225
      enddo
 
226
      call plcol0(3)
 
227
      call pllsty(2)
 
228
      call plcont(z,1,nr,1,ntheta,clevel,xg,yg)
 
229
      call pllsty(1)
 
230
      call plcol0(1)
 
231
 
 
232
      call plcol0(2)
 
233
      scaling = 25.0_plflt
 
234
      call plvect(u,v,scaling,xg,yg)
 
235
      call plcol0(1)
 
236
 
 
237
      do i=1,nper
 
238
         theta = 2.0_plflt*PI/dble(nper-1)*dble(i)
 
239
         px(i) = rmax*cos(theta)
 
240
         py(i) = rmax*sin(theta)
 
241
      enddo
 
242
 
 
243
      call plline(px,py)
 
244
 
 
245
      end
 
246
 
 
247
!----------------------------------------------------------------------------
 
248
!      Subroutine a2mnmx
 
249
!      Minimum and the maximum elements of a 2-d array.
 
250
 
 
251
      subroutine a2mnmx(f, nx, ny, fmin, fmax, xdim)
 
252
      use plplot
 
253
      implicit none
 
254
 
 
255
      integer   i, j, nx, ny, xdim
 
256
      real(kind=plflt)    f(xdim, ny), fmin, fmax
 
257
 
 
258
      fmax = f(1, 1)
 
259
      fmin = fmax
 
260
      do j = 1, ny
 
261
        do  i = 1, nx
 
262
          fmax = max(fmax, f(i, j))
 
263
          fmin = min(fmin, f(i, j))
 
264
        enddo
 
265
      enddo
 
266
      end