MISR Toolkit  1.5.1
MtkDataBufferAllocate.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkDataBufferAllocate =
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 nline,
37  int nsample,
39  MTKt_DataBuffer *databuf )
40 {
41  MTKt_status status_code; /* Return status of this function */
43  /* Data buffer structure */
44  int datasize[] = MTKd_DataSize; /* Data size by data type */
45  int i; /* Index */
46 
47  if (databuf == NULL)
49 
50  if (nline < 0)
52 
53  if (nsample < 0)
55 
56  dbuf.nline = nline;
57  dbuf.nsample = nsample;
58  dbuf.datasize = datasize[datatype];
59  dbuf.datatype = datatype;
60  dbuf.imported = MTK_FALSE; /* Data pointer is allocated by Mtk */
61 
62  /* Allocate 1D Illiffe vector */
63  dbuf.vdata = (void **)calloc(dbuf.nline, sizeof(void *));
64  if (dbuf.vdata == NULL)
66 
67  /* Allocate 2D buffer */
68  dbuf.vdata[0] = (void *)calloc(dbuf.nline * dbuf.nsample, dbuf.datasize);
69  if (dbuf.vdata[0] == NULL)
71 
72  /* Connect Illiffe vector */
73  for (i = 1; i < nline; i++) {
74  dbuf.vdata[i] = (void *)((unsigned char *)(dbuf.vdata[i-1]) +
75  dbuf.nsample * dbuf.datasize);
76  }
77 
78  /* Hook the union to the void data pointer */
79  dbuf.data.v = dbuf.vdata;
80  /* Hook the data pointer to the data */
81  dbuf.dataptr = dbuf.vdata[0];
82 
83  *databuf = dbuf;
84 
85  return MTK_SUCCESS;
86 
87 ERROR_HANDLE:
88  return status_code;
89 }
HDFFCLIBAPI _fcd _fcd intf intf * datatype
MTKt_DataBufferType data
Definition: MisrUtil.h:104
MTKt_DataType
Definition: MisrUtil.h:36
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
2-dimensional Data Buffer
Definition: MisrUtil.h:98
void ** vdata
Definition: MisrUtil.h:105
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
void * dataptr
Definition: MisrUtil.h:106
MTKt_DataType datatype
Definition: MisrUtil.h:102
#define MTKd_DataSize
Definition: MisrUtil.h:34
MTKt_status
Definition: MisrError.h:11
MTKt_boolean imported
Definition: MisrUtil.h:103

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