Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
Macros | Functions
array2.c File Reference

Allocate and free 2D arrays. More...

#include <stdlib.h>

Go to the source code of this file.

Macros

#define NULL   ((void *)0)
 

Functions

char ** blArray2D (int size, int dim1, int dim2)
 
void blFreeArray2D (char **array, int dim1, int dim2)
 

Detailed Description

Allocate and free 2D arrays.

Version
V1.5
Date
07/07.14
Author
Dr. Andrew C. R. Martin
Institute of Structural & Molecular Biology, University College London, Gower Street, London. WC1E 6BT.
andre.nosp@m.w@bi.nosp@m.oinf..nosp@m.org..nosp@m.uk andre.nosp@m.w.ma.nosp@m.rtin@.nosp@m.ucl..nosp@m.ac.uk

This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.

The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.

The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.

Description:

Creates a 2D array where the first dimension is a set of pointers. This is better for passing into subroutines than the conventional C method of simply declaring:

TYPE matrix[10][10];

which, when passed to a function, loses the concept of dimensions unless the matrix is explicitly defined with these dimension in the function.

This routine creates an array of pointers to 1-D arrays and can thus be passed to functions successfully.

Usage:

matrix = (TYPE **)Array2D(sizeof(TYPE), nrows, ncolumns);

matrix = (float **)Array2D(sizeof(float), 10, 10);

Returns NULL (having freed any allocated memory) if there is a problem.

Revision History:

Definition in file array2.c.

Macro Definition Documentation

#define NULL   ((void *)0)

Definition at line 99 of file array2.c.

Function Documentation

char** blArray2D ( int  size,
int  dim1,
int  dim2 
)
Parameters
[in]sizeSize of an array element
[in]dim1First dimension (number of rows)
[in]dim2Second dimension (number of columns)
Returns
Array of pointers. Must be cast to required type

Create a 2D array of elements of size `size' with dimensions `dim1' rows by `dim2' columns.

  • 07.10.92 Original
  • 12.07.93 Tidied and commented
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 130 of file array2.c.

void blFreeArray2D ( char **  array,
int  dim1,
int  dim2 
)
Parameters
[in]arrayArray of pointers to be freed
[in]dim1First dimension (number of rows)
[in]dim2Second dimension (number of columns)

Frees a 2D array with dimensions `dim1' rows by `dim2' columns.

  • 07.10.92 Original
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 174 of file array2.c.