Beispiel #1
0
/*
   ---------------------------------------------------
   initialize the object, storage freed if repeat call

   created -- 95dec17, cca
   ---------------------------------------------------
*/
void
Coords_init ( 
   Coords   *coords,
   int      type, 
   int      ndim, 
   int      ncoor 
) {
/*
   ---------------
   check the input
   ---------------
*/
if (  coords == NULL 
   || !(type == COORDS_BY_TUPLE || type == COORDS_BY_COORD)
   || ndim < 1 || ncoor <= 0 ) {
   fprintf(stderr, "\n fatal error in Coords_init(%p,%d,%d,%d)"
           "\n bad input\n", coords, type, ndim, ncoor) ;
   exit(-1) ;
}
/*
   --------------
   clear the data
   --------------
*/
Coords_clearData(coords) ;
/*
   -------------------
   set the data fields
   -------------------
*/
coords->type  = type ;
coords->ndim  = ndim ;
coords->ncoor = ncoor ;
coords->coors = FVinit(ndim*ncoor, 0.0) ;

return ; }
Beispiel #2
0
/*
   -------------------------------------------------------
   purpose -- given the pair of arrays (x1[],y1[]), 
              create a pair of arrays (x2[],y2[]) whose
              entries are pairwise chosen from (x1[],y1[])
              and whose distribution is an approximation.

   return value -- the size of the (x2[],y2[]) arrays

   created -- 95sep22, cca
   -------------------------------------------------------
*/
int
FVcompress ( 
   int     size1, 
   float   x1[], 
   float   y1[],
   int     size2, 
   float   x2[], 
   float   y2[] 
) {
float   delta, dx, dy, path, totalPath ;
float   *ds ;
int     i, j ;
/*
   --------------------
   check the input data
   --------------------
*/
if ( size1 <= 0 || size2 <= 0 ) {
   return(0) ;
} else if ( x1 == NULL || y1 == NULL || x2 == NULL || y2 == NULL ) {
   fprintf(stderr, "\n fatal error in FVcompress, invalid data"
           "\n size1 = %d, x1 = %p, y1 = %p"
           "\n size2 = %d, x2 = %p, y2 = %p",
           size1, x1, y1, size2, x2, y2) ;
   exit(-1) ; 
}
/*
   ----------------------------------------
   compute the path length and its segments
   ----------------------------------------
*/
ds = FVinit(size1, 0.0) ;
for ( j = 1 ; j < size1 ; j++ ) {
   dx = x1[j] - x1[j-1] ;
   dy = y1[j] - y1[j-1] ;
   ds[j-1] = sqrt(dx*dx + dy*dy) ;
}
totalPath = FVsum(size1, ds) ;
delta = totalPath / (size2-2) ;
#if MYDEBUG > 0
fprintf(stdout, "\n totalPath = %12.4e, delta = %12.4e, ds",
        totalPath, delta) ;
FVfprintf(stdout, size1, ds) ;
#endif
/*
   ---------------------
   fill the second array
   ---------------------
*/
i = 0 ;
x2[i] = x1[i] ;
y2[i] = y1[i] ;
i++ ;
path  = 0. ;
for ( j = 1 ; j < size1 - 1 ; j++ ) {
   path += ds[j-1] ;
#if MYDEBUG > 0
   fprintf(stdout, "\n j %d, path %12.4e", j, path) ;
#endif
   if ( path >= delta ) {
#if MYDEBUG > 0
      fprintf(stdout, ", accepted") ;
#endif
      x2[i] = x1[j] ;
      y2[i] = y1[j] ;
      i++ ;
      path  = 0. ;
   }
}
x2[i] = x1[size1-1] ;
y2[i] = y1[size1-1] ;
i++ ;
/*
   ------------------------
   free the working storage
   ------------------------
*/
FVfree(ds) ;

return(i) ; }