MISR Toolkit
1.5.1
Util
src
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
35
MTKt_status
MtkDataBufferAllocate
(
36
int
nline,
37
int
nsample,
38
MTKt_DataType
datatype
,
39
MTKt_DataBuffer
*databuf )
40
{
41
MTKt_status
status_code;
/* Return status of this function */
42
MTKt_DataBuffer
dbuf =
MTKT_DATABUFFER_INIT
;
43
/* Data buffer structure */
44
int
datasize[] =
MTKd_DataSize
;
/* Data size by data type */
45
int
i;
/* Index */
46
47
if
(databuf == NULL)
48
MTK_ERR_CODE_JUMP
(
MTK_NULLPTR
);
49
50
if
(nline < 0)
51
MTK_ERR_CODE_JUMP
(
MTK_OUTBOUNDS
);
52
53
if
(nsample < 0)
54
MTK_ERR_CODE_JUMP
(
MTK_OUTBOUNDS
);
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)
65
MTK_ERR_CODE_JUMP
(
MTK_CALLOC_FAILED
);
66
67
/* Allocate 2D buffer */
68
dbuf.
vdata
[0] = (
void
*)calloc(dbuf.
nline
* dbuf.
nsample
, dbuf.
datasize
);
69
if
(dbuf.
vdata
[0] == NULL)
70
MTK_ERR_CODE_JUMP
(
MTK_CALLOC_FAILED
);
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
}
MTK_NULLPTR
Definition:
MisrError.h:19
datatype
HDFFCLIBAPI _fcd _fcd intf intf * datatype
Definition:
hproto_fortran.h:1632
MTKt_DataBuffer::data
MTKt_DataBufferType data
Definition:
MisrUtil.h:104
MTKt_DataType
MTKt_DataType
Definition:
MisrUtil.h:36
MTK_ERR_CODE_JUMP
#define MTK_ERR_CODE_JUMP(code)
Definition:
MisrError.h:175
MTKt_DataBuffer
2-dimensional Data Buffer
Definition:
MisrUtil.h:98
MTKt_DataBuffer::vdata
void ** vdata
Definition:
MisrUtil.h:105
MTKt_DataBuffer::nsample
int nsample
Definition:
MisrUtil.h:100
MTKT_DATABUFFER_INIT
#define MTKT_DATABUFFER_INIT
Definition:
MisrUtil.h:109
MTK_SUCCESS
Definition:
MisrError.h:12
MtkDataBufferAllocate
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
Definition:
MtkDataBufferAllocate.c:35
MTKt_DataBuffer::dataptr
void * dataptr
Definition:
MisrUtil.h:106
MTKt_DataBuffer::datatype
MTKt_DataType datatype
Definition:
MisrUtil.h:102
MTK_OUTBOUNDS
Definition:
MisrError.h:14
MTKd_DataSize
#define MTKd_DataSize
Definition:
MisrUtil.h:34
MTKt_DataBufferType::v
void ** v
Definition:
MisrUtil.h:82
MTK_CALLOC_FAILED
Definition:
MisrError.h:23
MisrUtil.h
MTK_FALSE
Definition:
MisrError.h:7
MTKt_status
MTKt_status
Definition:
MisrError.h:11
MTKt_DataBuffer::datasize
int datasize
Definition:
MisrUtil.h:101
MTKt_DataBuffer::imported
MTKt_boolean imported
Definition:
MisrUtil.h:103
MTKt_DataBuffer::nline
int nline
Definition:
MisrUtil.h:99
MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51