File: sc3d.c

package info (click to toggle)
plplot 5.10.0%2Bdfsg2-0.4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 25,792 kB
  • ctags: 13,517
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,208; makefile: 210; lisp: 75; sed: 25; fortran: 7
file content (154 lines) | stat: -rw-r--r-- 4,578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// $Id: sc3d.c 12095 2011-12-03 08:56:15Z andrewross $
//
//      Stub routines for 3d plots.
//
// Copyright (C) 2004  Alan W. Irwin
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//

#include "plstubs.h"

// Function prototypes
void PLOT3DC__( PLFLT *x, PLFLT *y, PLFLT *z,
                PLINT *nx, PLINT *ny, PLINT *opt,
                PLFLT *clevel, PLINT *nlevel, PLINT *lx );
void PLOT3DC( PLFLT *x, PLFLT *y, PLFLT *z,
              PLINT *nx, PLINT *ny, PLINT *opt,
              PLFLT *clevel, PLINT *nlevel, PLINT *lx );
void PLSURF3D( PLFLT *x, PLFLT *y, PLFLT *z,
               PLINT *nx, PLINT *ny, PLINT *opt,
               PLFLT *clevel, PLINT *nlevel, PLINT *lx );
void PLMESH( PLFLT *x, PLFLT *y, PLFLT *z,
             PLINT *nx, PLINT *ny, PLINT *opt, PLINT *lx );
void PLMESHC( PLFLT *x, PLFLT *y, PLFLT *z,
              PLINT *nx, PLINT *ny, PLINT *opt,
              PLFLT *clevel, PLINT *nlevel, PLINT *lx );
void PLOT3D( PLFLT *x, PLFLT *y, PLFLT *z,
             PLINT *nx, PLINT *ny, PLINT *opt, PLBOOL *side, PLINT *lx );

void
PLOT3DC__( PLFLT *x, PLFLT *y, PLFLT *z,
           PLINT *nx, PLINT *ny, PLINT *opt,
           PLFLT *clevel, PLINT *nlevel, PLINT *lx )
{
    PLFLT ** a;
    int   i, j;

// Create a vectored a array from transpose of the fortran z array.
    plAlloc2dGrid( &a, *nx, *ny );
    for ( i = 0; i < *nx; i++ )
    {
        for ( j = 0; j < *ny; j++ )
        {
            a[i][j] = z[i + j * *lx];
        }
    }

    c_plot3dc( x, y, (const PLFLT * const *) a, *nx, *ny, *opt, clevel, *nlevel );

// Clean up memory allocated for a
    plFree2dGrid( a, *nx, *ny );
}

void
PLOT3DC( PLFLT *x, PLFLT *y, PLFLT *z,
         PLINT *nx, PLINT *ny, PLINT *opt,
         PLFLT *clevel, PLINT *nlevel, PLINT *lx )
{
    PLOT3DC__( x, y, z, nx, ny, opt, clevel, nlevel, lx );
}

void
PLSURF3D( PLFLT *x, PLFLT *y, PLFLT *z,
          PLINT *nx, PLINT *ny, PLINT *opt,
          PLFLT *clevel, PLINT *nlevel, PLINT *lx )
{
    int   i, j;
    PLFLT **temp;

    // Create the vectored C matrix from the Fortran matrix
    // To make things easy we save a temporary copy of the transpose of the
    // Fortran matrix, so that the first dimension of z corresponds to the x
    // direction.

    if ( !( temp = (PLFLT **) malloc( (size_t) *nx * sizeof ( PLFLT * ) ) ) )
    {
        plabort( "PLSURF3D: Out of memory" );
        return;
    }

    for ( i = 0; i < *nx; i++ )
    {
        if ( !( temp[i] = (PLFLT *) malloc( (size_t) *ny * sizeof ( PLFLT ) ) ) )
        {
            int ii;

            for ( ii = 0; ii < i - 1; ii++ )
                free( (void *) temp[i] );
            free( (void *) temp );
            plabort( "PLSURF3D: Out of memory" );
            return;
        }
    }

    for ( i = 0; i < *nx; i++ )
        for ( j = 0; j < *ny; j++ )
            temp[i][j] = *( z + j * *lx + i );

    c_plsurf3d( x, y, (const PLFLT * const *) temp, *nx, *ny, *opt, clevel, *nlevel );

    for ( i = 0; i < *nx; i++ )
        free( (void *) temp[i] );

    free( (void *) temp );
}

void
PLMESH( PLFLT *x, PLFLT *y, PLFLT *z,
        PLINT *nx, PLINT *ny, PLINT *opt, PLINT *lx )
{
    PLINT optlocal, nlevel = 0;
    PLFLT clevel = 0.;

    optlocal = *opt | MESH;
    PLOT3DC__( x, y, z, nx, ny, &optlocal, &clevel, &nlevel, lx );
}

void
PLMESHC( PLFLT *x, PLFLT *y, PLFLT *z,
         PLINT *nx, PLINT *ny, PLINT *opt,
         PLFLT *clevel, PLINT *nlevel, PLINT *lx )
{
    PLINT optlocal;
    optlocal = *opt | MESH;
    PLOT3DC__( x, y, z, nx, ny, &optlocal, clevel, nlevel, lx );
}


void
PLOT3D( PLFLT *x, PLFLT *y, PLFLT *z,
        PLINT *nx, PLINT *ny, PLINT *opt, PLBOOL *side, PLINT *lx )
{
    PLINT optlocal, nlevel = 0;
    PLFLT clevel = 0.;

    optlocal = *opt | ( *side != 0 ? DRAW_SIDES : 0 );
    PLOT3DC__( x, y, z, nx, ny, &optlocal, &clevel, &nlevel, lx );
}