MISR Toolkit
1.5.1
Util
src
MtkDataBufferImport.c
Go to the documentation of this file.
1
/*===========================================================================
2
= =
3
= MtkDataBufferImport =
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
MtkDataBufferImport
(
36
int
nline,
37
int
nsample,
38
MTKt_DataType
datatype
,
39
void
*
dataptr
,
40
MTKt_DataBuffer
*databuf )
41
{
42
MTKt_status
status_code;
/* Return status of this function */
43
MTKt_DataBuffer
dbuf =
MTKT_DATABUFFER_INIT
;
44
/* Data buffer structure */
45
int
datasize[] =
MTKd_DataSize
;
/* Data size by data type */
46
int
i;
/* Index */
47
48
if
(databuf == NULL)
49
MTK_ERR_CODE_JUMP
(
MTK_NULLPTR
);
50
51
if
(dataptr == NULL)
52
MTK_ERR_CODE_JUMP
(
MTK_NULLPTR
);
53
54
if
(nline < 0)
55
MTK_ERR_CODE_JUMP
(
MTK_OUTBOUNDS
);
56
57
if
(nsample < 0)
58
MTK_ERR_CODE_JUMP
(
MTK_OUTBOUNDS
);
59
60
dbuf.
nline
= nline;
61
dbuf.
nsample
= nsample;
62
dbuf.
datasize
= datasize[
datatype
];
63
dbuf.
datatype
=
datatype
;
64
dbuf.
imported
=
MTK_TRUE
;
/* Data pointer is allocated outside Mtk */
65
66
/* Allocate 1D Illiffe vector */
67
dbuf.
vdata
= (
void
**)calloc(dbuf.
nline
,
sizeof
(
void
*));
68
if
(dbuf.
vdata
== NULL)
69
MTK_ERR_CODE_JUMP
(
MTK_CALLOC_FAILED
);
70
71
/* Allocate 2D buffer */
72
dbuf.
vdata
[0] =
dataptr
;
73
74
/* Connect Illiffe vector */
75
for
(i = 1; i < nline; i++) {
76
dbuf.
vdata
[i] = (
void
*)((
unsigned
char
*)(dbuf.
vdata
[i-1]) +
77
dbuf.
nsample
* dbuf.
datasize
);
78
}
79
80
/* Hook the union to the void data pointer */
81
dbuf.
data
.
v
= dbuf.
vdata
;
82
/* Hook the data pointer to the data */
83
dbuf.
dataptr
= dbuf.
vdata
[0];
84
85
*databuf = dbuf;
86
87
return
MTK_SUCCESS
;
88
89
ERROR_HANDLE:
90
return
status_code;
91
}
MtkDataBufferImport
MTKt_status MtkDataBufferImport(int nline, int nsample, MTKt_DataType datatype, void *dataptr, MTKt_DataBuffer *databuf)
Import Data Buffer.
Definition:
MtkDataBufferImport.c:35
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
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
MTK_TRUE
Definition:
MisrError.h:8
MTKt_DataBufferType::v
void ** v
Definition:
MisrUtil.h:82
MTK_CALLOC_FAILED
Definition:
MisrError.h:23
MisrUtil.h
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
dataptr
int const JOCTET * dataptr
Definition:
jpeglib.h:950
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