예제 #1
0
파일: DV.c 프로젝트: damiannz/spooles
/*
   ---------------------------------------------------------
   purpose -- allocate a double array with size entries
              and fill with value dval
   
   return value -- a pointer to the start of the array

   created : 95sep22, cca
   ---------------------------------------------------------
*/
double *
DVinit ( 
   int      size, 
   double   dval 
) {
double   *y = NULL ;
if ( size > 0 ) {
   y = DVinit2(size) ;
   DVfill(size, y, dval) ;
}
return(y) ; }
예제 #2
0
파일: init.c 프로젝트: fransklaver/SPOOLES
/*
   ---------------------------------------------
   simplest initialization method

   if entries != NULL
      the object does not own the entries,
      it just points to the entries base address
   else if size > 0
      the object will own the entries, 
      it allocates a vector of size doubles's.
   else 
      nothing happens
   endif

   created -- 96aug28, cca
   ---------------------------------------------
*/
void
DV_init (
   DV       *dv,
   int      size,
   double   *entries 
) {
if ( dv == NULL || size < 0 ) {
   fprintf(stderr, "\n fatal error in DV_init(%p,%d,%p)"
           "\n bad input\n", dv, size, entries) ;
   spoolesFatal();
}
/*
   --------------
   clear any data
   --------------
*/
DV_clearData(dv) ;
/*
   -----------------------------
   set the size and maximum size
   -----------------------------
*/
dv->maxsize = dv->size = size ;
/*
   -------------------------
   set vector and owner flag
   -------------------------
*/
if ( entries != NULL ) {
   dv->owned = 0 ;
   dv->vec   = entries ; 
} else if ( size > 0 ) {
   dv->owned = 1 ;
/*
   dv->vec   = DVinit(size, 0.0) ;
*/
   dv->vec   = DVinit2(size) ;
}
return ; }
예제 #3
0
파일: DV.c 프로젝트: damiannz/spooles
/*
   ------------------------------
   purpose -- to permute a vector
              y[*] := y[index[*]]

   created -- 95sep22, cca
   ------------------------------
*/
void
DVperm ( 
   int      size, 
   double   y[], 
   int      index[] 
) {
if ( size > 0 ) {
   if ( y == NULL || index == NULL ) {
      fprintf(stderr, "\n fatal error in DVperm, invalid data"
              "\n size = %d, y = %p, index = %p\n", size, y, index) ;
      exit(-1) ;
   } else {
      double   *x ;
      int      i ;
      x = DVinit2(size) ;
      DVcopy(size, x, y) ;
      for ( i = 0 ; i < size ; i++ ) {
         y[i] = x[index[i]] ; 
      }
      DVfree(x) ;
   }
}
return ; }
예제 #4
0
파일: init.c 프로젝트: fransklaver/SPOOLES
/*
   ----------------------------------
   set the maximum size of the vector

   created -- 96dec08, cca
   ----------------------------------
*/
void
DV_setMaxsize (
   DV    *dv,
   int   newmaxsize
) {
/*
   ---------------
   check the input
   ---------------
*/
if ( dv == NULL || newmaxsize < 0 ) {
   fprintf(stderr, "\n fatal error in DV_setMaxsize(%p,%d)"
           "\n bad input\n", dv, newmaxsize) ;
   spoolesFatal();
}
if ( dv->maxsize > 0 && dv->owned == 0 ) {
   fprintf(stderr, "\n fatal error in DV_setMaxsize(%p,%d)"
           "\n dv->maxsize = %d, dv->owned = %d\n", 
           dv, newmaxsize, dv->maxsize, dv->owned) ;
   spoolesFatal();
}
if ( dv->maxsize != newmaxsize ) {
/*
   -----------------------------------
   allocate new storage for the vector
   -----------------------------------
*/
   double   *vec ;
/*
   vec = DVinit(newmaxsize, 0.0) ;
*/
   vec = DVinit2(newmaxsize) ;
   if ( dv->size > 0 ) {
/*
      ---------------------------------
      copy old entries into new entries
      ---------------------------------
*/
      if ( dv->vec == NULL ) {
         fprintf(stderr, "\n fatal error in DV_setMaxsize(%p,%d)"
                 "\n dv->size = %d, dv->vec is NULL\n", 
                 dv, newmaxsize, dv->size) ;
         spoolesFatal();
      }
      if ( dv->size <= newmaxsize ) {
         DVcopy(dv->size, vec, dv->vec) ;
      } else {
/*
         -----------------------
         note, data is truncated
         -----------------------
*/
         DVcopy(newmaxsize, vec, dv->vec) ;
         dv->size = newmaxsize ;
      }
   }
   if ( dv->vec != NULL ) {
/*
      ----------------
      free old entries
      ----------------
*/
      DVfree(dv->vec) ;
   }
/*
   ----------
   set fields
   ----------
*/
   dv->maxsize = newmaxsize ;
   dv->owned   = 1 ;
   dv->vec     = vec ;
}
return ; }