GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-d6dec75dd4
segment/get.c
Go to the documentation of this file.
1
/**
2
* \file lib/segment/get.c
3
*
4
* \brief Get segment routines.
5
*
6
* This program is free software under the GNU General Public License
7
* (>=v2). Read the file COPYING that comes with GRASS for details.
8
*
9
* \author GRASS GIS Development Team
10
*
11
* \date 2005-2018
12
*/
13
14
#include <string.h>
15
#include "local_proto.h"
16
17
/*bugfix: buf: char* vs int* -> wrong pointer arithmetics!!!. Pierre de Mouveaux
18
* - 09 april 2000 */
19
/* int Segment_get (SEGMENT *SEG, register int *buf,int row,int col) */
20
21
/**
22
* \brief Get value from segment file.
23
*
24
* Provides random read access to the segmented data. It gets
25
* <i>len</i> bytes of data into <b>buf</b> from the segment file
26
* <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in the
27
* original data matrix.
28
*
29
* \param[in] SEG segment
30
* \param[in,out] buf value return buffer
31
* \param[in] row
32
* \param[in] col
33
* \return 1 of successful
34
* \return -1 if unable to seek or read segment file
35
*/
36
37
int
Segment_get
(
SEGMENT
*SEG,
void
*buf, off_t row, off_t col)
38
{
39
int
index, n, i;
40
41
if
(SEG->
cache
) {
42
memcpy(buf, SEG->
cache
+ ((
size_t
)row * SEG->
ncols
+ col) * SEG->
len
,
43
SEG->
len
);
44
45
return
1;
46
}
47
48
SEG->
address
(SEG, row, col, &n, &index);
49
if
((i =
seg_pagein
(SEG, n)) < 0)
50
return
-1;
51
52
memcpy(buf, &SEG->
scb
[i].
buf
[index], SEG->
len
);
53
54
return
1;
55
}
seg_pagein
int seg_pagein(SEGMENT *SEG, int n)
Internal use only.
Definition:
pagein.c:35
Segment_get
int Segment_get(SEGMENT *SEG, void *buf, off_t row, off_t col)
Get value from segment file.
Definition:
segment/get.c:37
SEGMENT::scb::buf
char * buf
Definition:
segment.h:46
SEGMENT
Definition:
segment.h:19
SEGMENT::len
int len
Definition:
segment.h:23
SEGMENT::address
int(* address)(const struct SEGMENT *, off_t, off_t, int *, int *)
Definition:
segment.h:39
SEGMENT::scb
struct SEGMENT::scb * scb
SEGMENT::ncols
off_t ncols
Definition:
segment.h:22
SEGMENT::cache
char * cache
Definition:
segment.h:61
lib
segment
get.c
Generated on Sat Dec 21 2024 07:31:22 for GRASS GIS 8 Programmer's Manual by
1.9.1