MISR Toolkit  1.5.1
MtkDataBufferAllocate3D.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkDataBufferAllocate3D =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrUtil.h"
18 #include <stdlib.h>
19 
36  int nblock,
37  int nline,
38  int nsample,
40  MTKt_DataBuffer3D *databuf )
41 {
42  MTKt_status status_code; /* Return status of this function */
44  /* Data buffer structure */
45  int datasize[] = MTKd_DataSize; /* Data size by data type */
46  int i; /* Index */
47  int j; /* Index */
48 
49  if (databuf == NULL)
51 
52  if (nline < 0)
54 
55  if (nsample < 0)
57 
58  if (nblock < 0)
60 
61  dbuf.nblock = nblock;
62  dbuf.nline = nline;
63  dbuf.nsample = nsample;
64  dbuf.datasize = datasize[datatype];
65  dbuf.datatype = datatype;
66 
67  /* Create 2D Illiffe vector of sizeof(void *) to point to 3D buffer */
68 
69  /* Allocate 1D Illiffe vector */
70  dbuf.vdata = (void ***)calloc(dbuf.nblock, sizeof(void **));
71  if (dbuf.vdata == NULL)
73 
74  /* Allocate 2D Illiffe vector */
75  dbuf.vdata[0] = (void **)calloc(dbuf.nblock * dbuf.nline, sizeof(void *));
76  if (dbuf.vdata[0] == NULL)
78 
79  /* Connect Illiffe vector */
80  for (i = 1; i < nblock; i++) {
81  dbuf.vdata[i] = (void *)((unsigned char *)(dbuf.vdata[i-1]) +
82  dbuf.nline * sizeof(void *));
83  }
84 
85  /* Create 3D buffer and point the 2D Illiffe vector to it */
86 
87  /* Allocate 3D buffer */
88  dbuf.vdata[0][0] = (void *)calloc(dbuf.nblock * dbuf.nline * dbuf.nsample,
89  dbuf.datasize);
90  if (dbuf.vdata[0][0] == NULL)
92 
93  /* Connect 1D Illiffe vector */
94  for (i = 1; i < nblock; i++) {
95  dbuf.vdata[i][0] = (void *)((unsigned char *)(dbuf.vdata[i-1][0]) +
96  dbuf.nline * dbuf.nsample * dbuf.datasize);
97  }
98 
99  /* Connect 2D Illiffe vector */
100  for (i = 0; i < nblock; i++) {
101  for (j = 1; j < nline; j++) {
102  dbuf.vdata[i][j] = (void *)((unsigned char *)(dbuf.vdata[i][j-1]) +
103  dbuf.nsample * dbuf.datasize);
104  }
105  }
106 
107  /* Hook the union to the void data pointer */
108  dbuf.data.v = dbuf.vdata;
109  /* Hook the data pointer to the data */
110  dbuf.dataptr = dbuf.vdata[0][0];
111 
112  *databuf = dbuf;
113 
114  return MTK_SUCCESS;
115 
116 ERROR_HANDLE:
117  return status_code;
118 }
HDFFCLIBAPI _fcd _fcd intf intf * datatype
MTKt_DataType
Definition: MisrUtil.h:36
void *** vdata
Definition: MisrUtil.h:136
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_status MtkDataBufferAllocate3D(int nblock, int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer3D *databuf)
Allocate 3-dimensional Data Buffer (a buffer stack)
3-dimensional Data Buffer
Definition: MisrUtil.h:129
MTKt_DataType datatype
Definition: MisrUtil.h:134
#define MTKd_DataSize
Definition: MisrUtil.h:34
MTKt_DataBufferType3D data
Definition: MisrUtil.h:135
#define MTKT_DATABUFFER3D_INIT
Definition: MisrUtil.h:140
MTKt_status
Definition: MisrError.h:11

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51