PLplot  5.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sc3d.c
Go to the documentation of this file.
1 // Stub routines for 3d plots.
2 //
3 // Copyright (C) 2004-2014 Alan W. Irwin
4 //
5 // This file is part of PLplot.
6 //
7 // PLplot is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // PLplot is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with PLplot; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 //
22 
23 #include "plstubs.h"
24 
25 // Function prototypes
26 void PLOT3DC__( PLFLT *x, PLFLT *y, PLFLT *z,
27  PLINT *nx, PLINT *ny, PLINT *opt,
28  PLFLT *clevel, PLINT *nlevel, PLINT *lx );
29 void PLOT3DC( PLFLT *x, PLFLT *y, PLFLT *z,
30  PLINT *nx, PLINT *ny, PLINT *opt,
31  PLFLT *clevel, PLINT *nlevel, PLINT *lx );
32 void PLSURF3D( PLFLT *x, PLFLT *y, PLFLT *z,
33  PLINT *nx, PLINT *ny, PLINT *opt,
34  PLFLT *clevel, PLINT *nlevel, PLINT *lx );
35 void PLSURF3DL( PLFLT *x, PLFLT *y, PLFLT *z,
36  PLINT *nx, PLINT *ny, PLINT *opt,
37  PLFLT *clevel, PLINT *nlevel, PLINT *lx,
38  PLINT *indexxmin, PLINT *indexxmax, PLINT *indexymin, PLINT *indexymax );
39 void PLMESH( PLFLT *x, PLFLT *y, PLFLT *z,
40  PLINT *nx, PLINT *ny, PLINT *opt, PLINT *lx );
41 void PLMESHC( PLFLT *x, PLFLT *y, PLFLT *z,
42  PLINT *nx, PLINT *ny, PLINT *opt,
43  PLFLT *clevel, PLINT *nlevel, PLINT *lx );
44 void PLOT3D( PLFLT *x, PLFLT *y, PLFLT *z,
45  PLINT *nx, PLINT *ny, PLINT *opt, PLBOOL *side, PLINT *lx );
46 
47 void
48 PLOT3DC__( PLFLT *x, PLFLT *y, PLFLT *z,
49  PLINT *nx, PLINT *ny, PLINT *opt,
50  PLFLT *clevel, PLINT *nlevel, PLINT *lx )
51 {
52  PLFLT ** a;
53  int i, j;
54 
55 // Create a vectored a array from transpose of the fortran z array.
56  plAlloc2dGrid( &a, *nx, *ny );
57  for ( i = 0; i < *nx; i++ )
58  {
59  for ( j = 0; j < *ny; j++ )
60  {
61  a[i][j] = z[i + j * *lx];
62  }
63  }
64 
65  c_plot3dc( x, y, (const PLFLT * const *) a, *nx, *ny, *opt, clevel, *nlevel );
66 
67 // Clean up memory allocated for a
68  plFree2dGrid( a, *nx, *ny );
69 }
70 
71 void
72 PLOT3DC( PLFLT *x, PLFLT *y, PLFLT *z,
73  PLINT *nx, PLINT *ny, PLINT *opt,
74  PLFLT *clevel, PLINT *nlevel, PLINT *lx )
75 {
76  PLOT3DC__( x, y, z, nx, ny, opt, clevel, nlevel, lx );
77 }
78 
79 void
80 PLSURF3D( PLFLT *x, PLFLT *y, PLFLT *z,
81  PLINT *nx, PLINT *ny, PLINT *opt,
82  PLFLT *clevel, PLINT *nlevel, PLINT *lx )
83 {
84  int i, j;
85  PLFLT **temp;
86 
87  // Create the vectored C matrix from the Fortran matrix
88  // To make things easy we save a temporary copy of the transpose of the
89  // Fortran matrix, so that the first dimension of z corresponds to the x
90  // direction.
91 
92  if ( !( temp = (PLFLT **) malloc( (size_t) *nx * sizeof ( PLFLT * ) ) ) )
93  {
94  plabort( "PLSURF3D: Out of memory" );
95  return;
96  }
97 
98  for ( i = 0; i < *nx; i++ )
99  {
100  if ( !( temp[i] = (PLFLT *) malloc( (size_t) *ny * sizeof ( PLFLT ) ) ) )
101  {
102  int ii;
103 
104  for ( ii = 0; ii < i - 1; ii++ )
105  free( (void *) temp[i] );
106  free( (void *) temp );
107  plabort( "PLSURF3D: Out of memory" );
108  return;
109  }
110  }
111 
112  for ( i = 0; i < *nx; i++ )
113  for ( j = 0; j < *ny; j++ )
114  temp[i][j] = *( z + j * *lx + i );
115 
116  c_plsurf3d( x, y, (const PLFLT * const *) temp, *nx, *ny, *opt, clevel, *nlevel );
117 
118  for ( i = 0; i < *nx; i++ )
119  free( (void *) temp[i] );
120 
121  free( (void *) temp );
122 }
123 
124 void
126  PLINT *nx, PLINT *ny, PLINT *opt,
127  PLFLT *clevel, PLINT *nlevel, PLINT *lx,
128  PLINT *indexxmin, PLINT *indexxmax, PLINT *indexymin, PLINT *indexymax )
129 {
130  int i, j;
131  PLFLT **temp;
132 
133  // Create the vectored C matrix from the Fortran matrix
134  // To make things easy we save a temporary copy of the transpose of the
135  // Fortran matrix, so that the first dimension of z corresponds to the x
136  // direction.
137 
138  if ( !( temp = (PLFLT **) malloc( (size_t) *nx * sizeof ( PLFLT * ) ) ) )
139  {
140  plabort( "PLSURF3D: Out of memory" );
141  return;
142  }
143 
144  for ( i = 0; i < *nx; i++ )
145  {
146  if ( !( temp[i] = (PLFLT *) malloc( (size_t) *ny * sizeof ( PLFLT ) ) ) )
147  {
148  int ii;
149 
150  for ( ii = 0; ii < i - 1; ii++ )
151  free( (void *) temp[i] );
152  free( (void *) temp );
153  plabort( "PLSURF3D: Out of memory" );
154  return;
155  }
156  }
157 
158  for ( i = 0; i < *nx; i++ )
159  for ( j = 0; j < *ny; j++ )
160  temp[i][j] = *( z + j * *lx + i );
161 
162  c_plsurf3dl( x, y, (const PLFLT * const *) temp, *nx, *ny, *opt, clevel, *nlevel,
163  *indexxmin, *indexxmax, indexymin, indexymax );
164 
165  for ( i = 0; i < *nx; i++ )
166  free( (void *) temp[i] );
167 
168  free( (void *) temp );
169 }
170 
171 void
172 PLMESH( PLFLT *x, PLFLT *y, PLFLT *z,
173  PLINT *nx, PLINT *ny, PLINT *opt, PLINT *lx )
174 {
175  PLINT optlocal, nlevel = 0;
176  PLFLT clevel = 0.;
177 
178  optlocal = *opt | MESH;
179  PLOT3DC__( x, y, z, nx, ny, &optlocal, &clevel, &nlevel, lx );
180 }
181 
182 void
183 PLMESHC( PLFLT *x, PLFLT *y, PLFLT *z,
184  PLINT *nx, PLINT *ny, PLINT *opt,
185  PLFLT *clevel, PLINT *nlevel, PLINT *lx )
186 {
187  PLINT optlocal;
188  optlocal = *opt | MESH;
189  PLOT3DC__( x, y, z, nx, ny, &optlocal, clevel, nlevel, lx );
190 }
191 
192 
193 void
194 PLOT3D( PLFLT *x, PLFLT *y, PLFLT *z,
195  PLINT *nx, PLINT *ny, PLINT *opt, PLBOOL *side, PLINT *lx )
196 {
197  PLINT optlocal, nlevel = 0;
198  PLFLT clevel = 0.;
199 
200  optlocal = *opt | ( *side != 0 ? DRAW_SIDES : 0 );
201  PLOT3DC__( x, y, z, nx, ny, &optlocal, &clevel, &nlevel, lx );
202 }
203