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