From 7c2f3f8dab3a21050a2fc74533406c8ad579a3c9 Mon Sep 17 00:00:00 2001
From: jdishaw <jim@dishaw.org>
Date: Mon, 26 Jan 2015 12:48:22 -0500
Subject: [PATCH 1/2] Moved the 2D memory allocation/deallocation routines
 from pdfutils.c to a new file plmem.c

---
 src/CMakeLists.txt |    1 +
 src/pdfutils.c     |  100 --------------------------------------
 src/plmem.c        |  137 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 100 deletions(-)
 create mode 100644 src/plmem.c

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b301c2a..44a9add 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,6 +21,7 @@
 
 set(plplot_LIB_SRCS
   pdfutils.c
+  plmem.c
   plaffine.c
   plarc.c
   plargs.c
diff --git a/src/pdfutils.c b/src/pdfutils.c
index 6801672..1fc0af0 100644
--- a/src/pdfutils.c
+++ b/src/pdfutils.c
@@ -1079,103 +1079,3 @@ print_ieeef( float *vx, U_LONG *vy )
 
     return;
 }
-
-//--------------------------------------------------------------------------
-// plAlloc2dGrid()
-//
-//! Allocates a block of memory for use as a 2-d grid of PLFLT's.
-//! Resulting array can be indexed as f[i][j] anywhere.  This is to be used
-//! instead of PLFLT f[nx][ny], which is less useful.  Note that this type
-//! of allocation is required by the PLplot functions which take a 2-d
-//! grids of PLFLT's as an argument, such as plcont() and plot3d().
-//! Example usage:
-//!
-//!   PLFLT **z;
-//!
-//!   Alloc2dGrid(&z, XPTS, YPTS);
-//!
-//! @param f Location of the storage (address of a **).
-//! @param nx Size of the grid in x.
-//! @param ny Size of the grid in y.
-//!
-//--------------------------------------------------------------------------
-
-void
-plAlloc2dGrid( PLFLT ***f, PLINT nx, PLINT ny )
-{
-    PLINT i;
-
-    if ( ( *f = (PLFLT **) calloc( (size_t) nx, sizeof ( PLFLT * ) ) ) == NULL )
-        plexit( "Memory allocation error in \"plAlloc2dGrid\"" );
-
-    for ( i = 0; i < nx; i++ )
-    {
-        if ( ( ( *f )[i] = (PLFLT *) calloc( (size_t) ny, sizeof ( PLFLT ) ) ) == NULL )
-            plexit( "Memory allocation error in \"plAlloc2dGrid\"" );
-    }
-}
-
-//--------------------------------------------------------------------------
-// Free2dGrid()
-//
-//! Frees a block of memory allocated with Alloc2dGrid().
-//!
-//! @param f The [][] to the storage.
-//! @param nx Size of the grid in x.
-//! @param PL_UNUSED( ny) Not used.
-//--------------------------------------------------------------------------
-
-void
-plFree2dGrid( PLFLT **f, PLINT nx, PLINT PL_UNUSED( ny ) )
-{
-    PLINT i;
-
-    for ( i = 0; i < nx; i++ )
-        free( (void *) f[i] );
-
-    free( (void *) f );
-}
-
-//--------------------------------------------------------------------------
-// MinMax2dGrid()
-//
-//! Finds the maximum and minimum of a 2d matrix allocated with plAllc2dGrid().
-//! NaN and +/- infinity values are ignored.
-//!
-//! param f 2d matrix pointer.
-//! param nx Size of the grid in x.
-//! param ny Size of the grid in y.
-//! param fnmax Maximum value in the matrix.
-//! param fnmin Minimum value in the matrix.
-//!
-//--------------------------------------------------------------------------
-
-void
-plMinMax2dGrid( const PLFLT * const*f, PLINT nx, PLINT ny, PLFLT *fnmax, PLFLT *fnmin )
-{
-    int   i, j;
-    PLFLT m, M;
-
-    if ( !isfinite( f[0][0] ) )
-    {
-        M = -HUGE_VAL;
-        m = HUGE_VAL;
-    }
-    else
-        M = m = f[0][0];
-
-    for ( i = 0; i < nx; i++ )
-    {
-        for ( j = 0; j < ny; j++ )
-        {
-            if ( !isfinite( f[i][j] ) )
-                continue;
-            if ( f[i][j] > M )
-                M = f[i][j];
-            if ( f[i][j] < m )
-                m = f[i][j];
-        }
-    }
-    *fnmax = M;
-    *fnmin = m;
-}
diff --git a/src/plmem.c b/src/plmem.c
new file mode 100644
index 0000000..3d7db9b
--- /dev/null
+++ b/src/plmem.c
@@ -0,0 +1,137 @@
+// xId: pdfutils.c 11966 2011-10-14 07:10:05Z andrewross $
+//
+//  pdf_utils.c
+//
+//  Copyright (C) 1992, 1993, 1994, 1995
+//  Maurice LeBrun			mjl@dino.ph.utexas.edu
+//  Institute for Fusion Studies	University of Texas at Austin
+//
+//  Copyright (C) 2004  Joao Cardoso
+//  Copyright (C) 2004  Alan W. Irwin
+//  Copyright (C) 2004  Andrew Ross
+//
+//  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
+//
+//--------------------------------------------------------------------------
+//
+
+//! @file
+//!  These functions provide allocation and deallocation of two-dimensional
+//!  arrays.  
+//!
+
+#include "plplotP.h"
+
+//--------------------------------------------------------------------------
+// plAlloc2dGrid()
+//
+//! Allocates a block of memory for use as a 2-d grid of PLFLT's.
+//! Resulting array can be indexed as f[i][j] anywhere.  This is to be used
+//! instead of PLFLT f[nx][ny], which is less useful.  Note that this type
+//! of allocation is required by the PLplot functions which take a 2-d
+//! grids of PLFLT's as an argument, such as plcont() and plot3d().
+//! Example usage:
+//!
+//!   PLFLT **z;
+//!
+//!   Alloc2dGrid(&z, XPTS, YPTS);
+//!
+//! @param f Location of the storage (address of a **).
+//! @param nx Size of the grid in x.
+//! @param ny Size of the grid in y.
+//!
+//--------------------------------------------------------------------------
+
+void
+plAlloc2dGrid( PLFLT ***f, PLINT nx, PLINT ny )
+{
+    PLINT i;
+
+    if ( ( *f = (PLFLT **) calloc( (size_t) nx, sizeof ( PLFLT * ) ) ) == NULL )
+        plexit( "Memory allocation error in \"plAlloc2dGrid\"" );
+
+    for ( i = 0; i < nx; i++ )
+    {
+        if ( ( ( *f )[i] = (PLFLT *) calloc( (size_t) ny, sizeof ( PLFLT ) ) ) == NULL )
+            plexit( "Memory allocation error in \"plAlloc2dGrid\"" );
+    }
+}
+
+//--------------------------------------------------------------------------
+// Free2dGrid()
+//
+//! Frees a block of memory allocated with Alloc2dGrid().
+//!
+//! @param f The [][] to the storage.
+//! @param nx Size of the grid in x.
+//! @param PL_UNUSED( ny) Not used.
+//--------------------------------------------------------------------------
+
+void
+plFree2dGrid( PLFLT **f, PLINT nx, PLINT PL_UNUSED( ny ) )
+{
+    PLINT i;
+
+    for ( i = 0; i < nx; i++ )
+        free( (void *) f[i] );
+
+    free( (void *) f );
+}
+
+//--------------------------------------------------------------------------
+// MinMax2dGrid()
+//
+//! Finds the maximum and minimum of a 2d matrix allocated with plAllc2dGrid().
+//! NaN and +/- infinity values are ignored.
+//!
+//! param f 2d matrix pointer.
+//! param nx Size of the grid in x.
+//! param ny Size of the grid in y.
+//! param fnmax Maximum value in the matrix.
+//! param fnmin Minimum value in the matrix.
+//!
+//--------------------------------------------------------------------------
+
+void
+plMinMax2dGrid( const PLFLT * const*f, PLINT nx, PLINT ny, PLFLT *fnmax, PLFLT *fnmin )
+{
+    int   i, j;
+    PLFLT m, M;
+
+    if ( !isfinite( f[0][0] ) )
+    {
+        M = -HUGE_VAL;
+        m = HUGE_VAL;
+    }
+    else
+        M = m = f[0][0];
+
+    for ( i = 0; i < nx; i++ )
+    {
+        for ( j = 0; j < ny; j++ )
+        {
+            if ( !isfinite( f[i][j] ) )
+                continue;
+            if ( f[i][j] > M )
+                M = f[i][j];
+            if ( f[i][j] < m )
+                m = f[i][j];
+        }
+    }
+    *fnmax = M;
+    *fnmin = m;
+}
-- 
1.7.10.4


From 3693482269c8f5b2013ad4ec2c61d31acf85d9c3 Mon Sep 17 00:00:00 2001
From: jdishaw <jim@dishaw.org>
Date: Mon, 26 Jan 2015 12:49:43 -0500
Subject: [PATCH 2/2] Corrected the filename in the header of plmem.c

---
 src/plmem.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/plmem.c b/src/plmem.c
index 3d7db9b..96fcd16 100644
--- a/src/plmem.c
+++ b/src/plmem.c
@@ -1,6 +1,6 @@
-// xId: pdfutils.c 11966 2011-10-14 07:10:05Z andrewross $
+// xId: plmem.c 11966 2011-10-14 07:10:05Z andrewross $
 //
-//  pdf_utils.c
+//  plmem.c
 //
 //  Copyright (C) 1992, 1993, 1994, 1995
 //  Maurice LeBrun			mjl@dino.ph.utexas.edu
-- 
1.7.10.4

