GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <string.h> 00004 #include <sys/types.h> 00005 #include <unistd.h> 00006 #include <rpc/types.h> 00007 #include <rpc/xdr.h> 00008 #include "G3d_intern.h" 00009 00010 /*---------------------------------------------------------------------------*/ 00011 00012 int G3d_g3dType2cellType(int g3dType) 00013 { 00014 if (g3dType == FCELL_TYPE) 00015 return FCELL_TYPE; 00016 return DCELL_TYPE; 00017 } 00018 00019 /*---------------------------------------------------------------------------*/ 00020 00021 void 00022 G3d_copyFloat2Double(const float *src, int offsSrc, double *dst, int offsDst, 00023 int nElts) 00024 { 00025 int i; 00026 00027 src += offsSrc; 00028 dst += offsDst; 00029 00030 for (i = 0; i < nElts; i++) 00031 dst[i] = (double)src[i]; 00032 } 00033 00034 /*---------------------------------------------------------------------------*/ 00035 00036 void 00037 G3d_copyDouble2Float(const double *src, int offsSrc, float *dst, int offsDst, 00038 int nElts) 00039 { 00040 int i; 00041 00042 src += offsSrc; 00043 dst += offsDst; 00044 00045 for (i = 0; i < nElts; i++) 00046 dst[i] = (float)src[i]; 00047 } 00048 00049 /*---------------------------------------------------------------------------*/ 00050 00051 void 00052 G3d_copyValues(const void *src, int offsSrc, int typeSrc, void *dst, 00053 int offsDst, int typeDst, int nElts) 00054 { 00055 int eltLength; 00056 00057 if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) { 00058 G3d_copyFloat2Double(src, offsSrc, dst, offsDst, nElts); 00059 return; 00060 } 00061 00062 if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) { 00063 G3d_copyDouble2Float(src, offsSrc, dst, offsDst, nElts); 00064 return; 00065 } 00066 00067 eltLength = G3d_length(typeSrc); 00068 00069 src = G_incr_void_ptr(src, eltLength * offsSrc); 00070 dst = G_incr_void_ptr(dst, eltLength * offsDst); 00071 00072 memcpy(dst, src, nElts * eltLength); 00073 } 00074 00075 /*---------------------------------------------------------------------------*/ 00076 00077 int G3d_length(int t) 00078 { 00079 if (!G3D_IS_CORRECT_TYPE(t)) 00080 G3d_fatalError("G3d_length: invalid type"); 00081 00082 if (t == FCELL_TYPE) 00083 return sizeof(float); 00084 if (t == DCELL_TYPE) 00085 return sizeof(double); 00086 return 0; 00087 } 00088 00089 int G3d_externLength(int t) 00090 { 00091 if (!G3D_IS_CORRECT_TYPE(t)) 00092 G3d_fatalError("G3d_externLength: invalid type"); 00093 00094 if (t == FCELL_TYPE) 00095 return G3D_XDR_FLOAT_LENGTH; 00096 if (t == DCELL_TYPE) 00097 return G3D_XDR_DOUBLE_LENGTH; 00098 return 0; 00099 }