GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
g3dmisc.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <rpc/types.h>
7 #include <rpc/xdr.h>
8 #include "G3d_intern.h"
9 
10 /*---------------------------------------------------------------------------*/
11 
12 int G3d_g3dType2cellType(int g3dType)
13 {
14  if (g3dType == FCELL_TYPE)
15  return FCELL_TYPE;
16  return DCELL_TYPE;
17 }
18 
19 /*---------------------------------------------------------------------------*/
20 
21 void
22 G3d_copyFloat2Double(const float *src, int offsSrc, double *dst, int offsDst,
23  int nElts)
24 {
25  int i;
26 
27  src += offsSrc;
28  dst += offsDst;
29 
30  for (i = 0; i < nElts; i++)
31  dst[i] = (double)src[i];
32 }
33 
34 /*---------------------------------------------------------------------------*/
35 
36 void
37 G3d_copyDouble2Float(const double *src, int offsSrc, float *dst, int offsDst,
38  int nElts)
39 {
40  int i;
41 
42  src += offsSrc;
43  dst += offsDst;
44 
45  for (i = 0; i < nElts; i++)
46  dst[i] = (float)src[i];
47 }
48 
49 /*---------------------------------------------------------------------------*/
50 
51 void
52 G3d_copyValues(const void *src, int offsSrc, int typeSrc, void *dst,
53  int offsDst, int typeDst, int nElts)
54 {
55  int eltLength;
56 
57  if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
58  G3d_copyFloat2Double(src, offsSrc, dst, offsDst, nElts);
59  return;
60  }
61 
62  if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
63  G3d_copyDouble2Float(src, offsSrc, dst, offsDst, nElts);
64  return;
65  }
66 
67  eltLength = G3d_length(typeSrc);
68 
69  src = G_incr_void_ptr(src, eltLength * offsSrc);
70  dst = G_incr_void_ptr(dst, eltLength * offsDst);
71 
72  memcpy(dst, src, nElts * eltLength);
73 }
74 
75 /*---------------------------------------------------------------------------*/
76 
77 int G3d_length(int t)
78 {
79  if (!G3D_IS_CORRECT_TYPE(t))
80  G3d_fatalError("G3d_length: invalid type");
81 
82  if (t == FCELL_TYPE)
83  return sizeof(float);
84  if (t == DCELL_TYPE)
85  return sizeof(double);
86  return 0;
87 }
88 
89 int G3d_externLength(int t)
90 {
91  if (!G3D_IS_CORRECT_TYPE(t))
92  G3d_fatalError("G3d_externLength: invalid type");
93 
94  if (t == FCELL_TYPE)
95  return G3D_XDR_FLOAT_LENGTH;
96  if (t == DCELL_TYPE)
97  return G3D_XDR_DOUBLE_LENGTH;
98  return 0;
99 }
int G3d_g3dType2cellType(int g3dType)
Definition: g3dmisc.c:12
int G3d_externLength(int t)
Definition: g3dmisc.c:89
void G3d_copyDouble2Float(const double *src, int offsSrc, float *dst, int offsDst, int nElts)
Definition: g3dmisc.c:37
#define G3D_XDR_FLOAT_LENGTH
Definition: G3d_intern.h:15
void * G_incr_void_ptr(const void *ptr, const size_t size)
Advance void pointer.
Definition: gis/raster.c:33
void G3d_copyValues(const void *src, int offsSrc, int typeSrc, void *dst, int offsDst, int typeDst, int nElts)
Definition: g3dmisc.c:52
#define G3D_IS_CORRECT_TYPE(t)
Definition: G3d_intern.h:17
void G3d_copyFloat2Double(const float *src, int offsSrc, double *dst, int offsDst, int nElts)
Definition: g3dmisc.c:22
int G3d_length(int t)
Definition: g3dmisc.c:77
#define G3D_XDR_DOUBLE_LENGTH
Definition: G3d_intern.h:14
void G3d_fatalError(const char *,...)
This function prints the error message msg, and terminates the program with an error status...
Definition: g3derror.c:58