PLplot  5.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plmem.c
Go to the documentation of this file.
1 // xId: plmem.c 11966 2011-10-14 07:10:05Z andrewross $
2 //
3 // plmem.c
4 //
5 // Copyright (C) 1992, 1993, 1994, 1995
6 // Maurice LeBrun mjl@dino.ph.utexas.edu
7 // Institute for Fusion Studies University of Texas at Austin
8 //
9 // Copyright (C) 2004 Joao Cardoso
10 // Copyright (C) 2004 Alan W. Irwin
11 // Copyright (C) 2004 Andrew Ross
12 //
13 // This file is part of PLplot.
14 //
15 // PLplot is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU Library General Public License as published
17 // by the Free Software Foundation; either version 2 of the License, or
18 // (at your option) any later version.
19 //
20 // PLplot is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU Library General Public License for more details.
24 //
25 // You should have received a copy of the GNU Library General Public License
26 // along with PLplot; if not, write to the Free Software
27 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 //
29 //--------------------------------------------------------------------------
30 //
31 
36 
37 #include "plplotP.h"
38 
39 //--------------------------------------------------------------------------
40 // plAlloc2dGrid()
41 //
57 //--------------------------------------------------------------------------
58 
59 void
60 plAlloc2dGrid( PLFLT ***f, PLINT nx, PLINT ny )
61 {
62  PLINT i;
63 
64  if ( ( *f = (PLFLT **) calloc( (size_t) nx, sizeof ( PLFLT * ) ) ) == NULL )
65  plexit( "Memory allocation error in \"plAlloc2dGrid\"" );
66 
67  for ( i = 0; i < nx; i++ )
68  {
69  if ( ( ( *f )[i] = (PLFLT *) calloc( (size_t) ny, sizeof ( PLFLT ) ) ) == NULL )
70  plexit( "Memory allocation error in \"plAlloc2dGrid\"" );
71  }
72 }
73 
74 //--------------------------------------------------------------------------
75 // Free2dGrid()
76 //
82 //--------------------------------------------------------------------------
83 
84 void
86 {
87  PLINT i;
88 
89  for ( i = 0; i < nx; i++ )
90  free( (void *) f[i] );
91 
92  free( (void *) f );
93 }
94 
95 //--------------------------------------------------------------------------
96 // MinMax2dGrid()
97 //
107 //--------------------------------------------------------------------------
108 
109 void
110 plMinMax2dGrid( PLFLT_MATRIX f, PLINT nx, PLINT ny, PLFLT *fnmax, PLFLT *fnmin )
111 {
112  int i, j;
113  PLFLT m, M;
114 
115  if ( !isfinite( f[0][0] ) )
116  {
117  M = -HUGE_VAL;
118  m = HUGE_VAL;
119  }
120  else
121  M = m = f[0][0];
122 
123  for ( i = 0; i < nx; i++ )
124  {
125  for ( j = 0; j < ny; j++ )
126  {
127  if ( !isfinite( f[i][j] ) )
128  continue;
129  if ( f[i][j] > M )
130  M = f[i][j];
131  if ( f[i][j] < m )
132  m = f[i][j];
133  }
134  }
135  *fnmax = M;
136  *fnmin = m;
137 }
void plexit(PLCHAR_VECTOR errormsg)
Definition: plctrl.c:1948
const PLFLT *const * PLFLT_MATRIX
Definition: plplot.h:255
#define HUGE_VAL
Definition: plplotP.h:274
int PLINT
Definition: plplot.h:174
#define M
Definition: mt19937ar.c:56
void plFree2dGrid(PLFLT **f, PLINT nx, PLINT PL_UNUSED(ny))
Definition: plmem.c:85
#define isfinite(x)
Definition: plplotP.h:268
#define PL_UNUSED(x)
Definition: plplot.h:128
float PLFLT
Definition: plplot.h:157
void plAlloc2dGrid(PLFLT ***f, PLINT nx, PLINT ny)
Definition: plmem.c:60
void plMinMax2dGrid(PLFLT_MATRIX f, PLINT nx, PLINT ny, PLFLT *fnmax, PLFLT *fnmin)
Definition: plmem.c:110