GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71769
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2009
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  SEG->address(SEG, row, col, &n, &index);
44  if ((i = seg_pagein(SEG, n)) < 0)
45  return -1;
46 
47  memcpy(buf, &SEG->scb[i].buf[index], SEG->len);
48 
49  return 1;
50 }
int Segment_get(SEGMENT *SEG, void *buf, off_t row, off_t col)
Get value from segment file.
Definition: segment/get.c:39
int len
Definition: segment.h:24
char * buf
Definition: segment.h:47
int(* address)()
Definition: segment.h:40
int seg_pagein(SEGMENT *SEG, int n)
Internal use only.
Definition: pagein.c:37
struct SEGMENT::scb * scb