예제 #1
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
// If no args, set cursor to all zeros.	 Else set initial elements of cursor
// to args provided, rest to zeros.
NcBool NcVar::set_cur(long c0, long c1, long c2, long c3, long c4)
{
    long t[6];
    t[0] = c0;
    t[1] = c1;
    t[2] = c2;
    t[3] = c3;
    t[4] = c4;
    t[5] = -1;
    for(int j = 0; j < 6; j++) { // find how many parameters were used
	int i;
	if (t[j] == -1) {
	    if (num_dims() < j)
	      return FALSE;	// too many for variable's dimensionality
	    for (i = 0; i < j; i++) {
		if (t[i] >= get_dim(i)->size() && ! get_dim(i)->is_unlimited())
		  return FALSE;	// too big for dimension
		the_cur[i] = t[i];
	    }
	    for(i = j; i < num_dims(); i++)
	      the_cur[i] = 0;
	    return TRUE;
	}
    }
    return TRUE;
}
예제 #2
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
NcBool NcVar::set_cur(long* cur)
{
    for(int i = 0; i < num_dims(); i++) {
	if (cur[i] >= get_dim(i)->size() && ! get_dim(i)->is_unlimited())
	  return FALSE;
	the_cur[i] = cur[i];
    }
    return TRUE;
}
예제 #3
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
void NcVar::set_rec(NcDim *rdim, long slice)
{
  int i = dim_to_index(rdim);
  // we should fail and gripe about it here....
  if (slice >= get_dim(i)->size() && ! get_dim(i)->is_unlimited())
	  return;  
  cur_rec[i] = slice;
  return;
} 
예제 #4
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
long* NcVar::edges( void ) const	// edge lengths (dimension sizes)
{
    long* evec = new long[num_dims()];
    for(int i=0; i < num_dims(); i++)
      evec[i] = get_dim(i)->size();
    return evec;
}
예제 #5
0
list<MatrixXd> Covariances::marginal(const node_lists_t& node_lists) const {
  const SparseSystem& R = (_slam==NULL) ? _R : _slam->_R;
  if (_slam) {
    _slam->update_starts();
  }

  vector < vector<int> > index_lists(node_lists.size());

  if (R.num_rows()>1) { // skip if _R not calculated yet (eg. before batch step)
    int n=0;
    const int* trans = R.a_to_r();
    for (node_lists_t::const_iterator it_list = node_lists.begin();
        it_list != node_lists.end();
        it_list++, n++) {
      // assemble list of indices
      vector<int> indices;
      for (list<Node*>::const_iterator it = it_list->begin(); it!=it_list->end(); it++) {
        Node* node = *it;
        int start = get_start(node);
        int dim = get_dim(node);
        for (int i=0; i<dim; i++) {
          index_lists[n].push_back(trans[start+i]);
        }
      }
    }
    return cov_marginal(R, _cache, index_lists);
  }
  list<MatrixXd> empty_list;
  return empty_list;
}
예제 #6
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
long NcVar::num_vals( void ) const
{
    long prod = 1;
    for (int d = 0; d < num_dims(); d++)
	prod *= get_dim(d)->size();
    return  prod;
}
예제 #7
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
void NcVar::set_rec(long rec)
{
  // Since we can't ask for the record dimension here
  // just assume [0] is it.....
  set_rec(get_dim(0),rec);
  return;
} 
예제 #8
0
파일: main.c 프로젝트: DarmaN1/Wolf3D
t_wolf	*init_map(char *av)
{
  t_wolf	*wolf;
  t_bunny_ini_scope	*scope;
  t_bunny_ini	*ini;

  if ((wolf = bunny_malloc(sizeof(t_wolf))) == NULL)
    return ((t_wolf *)-1);
  if ((ini = bunny_load_ini(av)) == NULL)
    return ((t_wolf *)-1);
  scope = bunny_ini_first(ini);
  scope = bunny_ini_next(ini, scope);
  wolf->s_name = bunny_ini_scope_name(ini, scope);
  wolf->width = 0;
  wolf->height = 0;
  wolf = get_dim(wolf, ini);
  if (check_air(wolf, ini) == -1)
    return ((t_wolf *)-1);
  wolf = get_map(wolf, ini);
  wolf = get_player(wolf, ini);
  if (init_error(wolf) == -1)
    return ((t_wolf *)-1);
  bunny_delete_ini(ini);
  return (wolf);
}
예제 #9
0
파일: lsearch.cpp 프로젝트: andrejadd/ABC
LSearch::LSearch(int _dim, function_type _funct) : PSO(0.0, ///<The w parameter (influence of old vel - momentum)
  		0.0, ///<The minimum value for w -- decreased by time or level
  		0.0, ///<Influence of personal best
  		0.0, ///<Influence of global best
		0.0, ///<vmax = vmaxRatio*xmax, with vmaxRatio=0 no vmax is enforced 
		0.0, ///<Constriction factor, used by #Bird
  		0, ///<Swarmsize
  		_dim, ///<Dimension of the search space
		0, ///<Height of the pyramid, ignored for #seqSwarm
		0, ///<Branches per node of the pyramid, ignored for #seqSwarm
		0, ///<Swap allowed every swapDelay steps in #PyramidSwarm, ignored for #Swarm
  		_funct, ///<#function_type selection
		noNoise, ///<#noiseStyle_type selection, set in #optFunction
		0.0, ///<sigma parameter for gaussian distributed noise
  		seqSwarm) ///<#swarm_type selection
{

	TRACE_IN("LSearch::LSearch");
	DEBUG("New LSearch :");
	DEBUG1("dim = ",_dim);
	int a=0;

	for (int i=0; i<get_dim(); i++)
		currSolution.push_back(randDoubleRange(optFunction->get_min_x(), optFunction->get_max_x()));
	currentVal = evalFunction(currSolution);
	TRACE_OUT("LSearch::LSearch",0);
}
예제 #10
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
NcDim* NcFile::get_dim( NcToken name ) const
{
    int dimid;
    if(NcError::set_err(
			nc_inq_dimid(the_id, name, &dimid)
			) != NC_NOERR)
	return 0;
    return get_dim(dimid);
}
예제 #11
0
template<typename T> T SegmentTree<T>::get_dim(NVector left, NVector right, int level){
    T ret=zero;
    if(level==dim-1){
        while(left[level]<=right[level]){
            if(left[level]%2==1){
                ret=operation(ret,(*data)[left]);
                left[level]++;
            }

            if(right[level]%2==0){
                ret=operation(ret,(*data)[right]);
                right[level]--;
            }

            right[level]/=2;
            left[level]/=2;
            if(right[level]==left[level])
                return operation(ret,(*data)[left]);
        }
        return ret;
    }

    while(left[level]<=right[level]){
        if(left[level]%2==1){
            NVector new_right=right;
            new_right[level]=left[level];
            ret=operation(ret,get_dim(left,new_right,level+1));
            left[level]++;
        }

        if(right[level]%2==0){
            NVector new_left=left;
            new_left[level]=right[level];
            ret=operation(ret,get_dim(new_left,right,level+1));
            right[level]--;
        }

        right[level]/=2;
        left[level]/=2;
        if(right[level]==left[level])
            return operation(ret,get_dim(left,right,level+1));
    }
    return ret;
}
예제 #12
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
NcValues* NcVar::values( void ) const
{
    int ndims = num_dims();
    size_t crnr[NC_MAX_DIMS];
    size_t edgs[NC_MAX_DIMS];
    for (int i = 0; i < ndims; i++) {
	crnr[i] = 0;
	edgs[i] = get_dim(i)->size();
    }
    NcValues* valp = get_space();
    int status;
    switch (type()) {
    case ncFloat:
	status = NcError::set_err(
				  nc_get_vara_float(the_file->id(), the_id, crnr, edgs, 
				   (float *)valp->base())
				  );
	break;
    case ncDouble:
	status = NcError::set_err(
				  nc_get_vara_double(the_file->id(), the_id, crnr, edgs, 
				    (double *)valp->base())
				  );
	break;
    case ncInt:
	status = NcError::set_err(
				  nc_get_vara_int(the_file->id(), the_id, crnr, edgs, 
				 (int *)valp->base())
				  );
	break;
    case ncShort:
	status = NcError::set_err(
				  nc_get_vara_short(the_file->id(), the_id, crnr, edgs, 
				   (short *)valp->base())
				  );
	break;
    case ncByte:
	status = NcError::set_err(
				  nc_get_vara_schar(the_file->id(), the_id, crnr, edgs, 
				   (signed char *)valp->base())
				  );
	break;
    case ncChar:
	status = NcError::set_err(
				  nc_get_vara_text(the_file->id(), the_id, crnr, edgs, 
				   (char *)valp->base())
				  );
	break;
    case ncNoType:
    default:
	return 0;
    }
    if (status != NC_NOERR)
	return 0;
    return valp;
}
예제 #13
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
int NcVar::dim_to_index(NcDim *rdim)
{
  for (int i=0; i < num_dims() ; i++) {
    if (strcmp(get_dim(i)->name(),rdim->name()) == 0) {
      return i;
    }
  }
  // we should fail and gripe about it here....
  return -1;
}
예제 #14
0
 virtual int get_min_size() const {
   int dim = get_dim(); 
   int minsz = -1; 
   int dx; 
   for (dx = 0; dx < dim; ++dx) {
     int mysz = sz(dx); 
     if (dx == 0 || mysz < minsz) minsz = mysz; 
   }
   return minsz; 
 }
예제 #15
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
NcDim* NcFile::rec_dim( ) const
{
    if (! is_valid())
      return 0;
    int recdim;
    if(NcError::set_err(
			nc_inq_unlimdim(the_id, &recdim)
			) != NC_NOERR)
	return 0;
    return get_dim(recdim);
}
예제 #16
0
 virtual int size() const {
   int dim = get_dim(); 
   if (dim == 0) return 0; 
   
   int region_size = 1; 
   int dx; 
   for (dx = 0; dx < dim; ++dx) {
     int mysz = sz(dx); 
     region_size *= mysz; 
   }
   return region_size; 
 }
예제 #17
0
 inline U32 get_size() const
 {
   if (data_type)
   {
     const U32 size_table[10] = { 1, 1, 2, 2, 4, 4, 8, 8, 4, 8 };
     U32 type = get_type();
     U32 dim = get_dim();
     return size_table[type]*dim;
   }
   else
   {
     return options;
   }
 }
예제 #18
0
list<MatrixXd> Covariances::access(const node_pair_list_t& node_pair_list) const {
  const SparseSystem& R = (_slam==NULL) ? _R : _slam->_R;
  if (_slam) {
    _slam->update_starts();
  }

  if (R.num_rows()>1) { // skip if _R not calculated yet (eg. before batch step)

    // count how many entries in requested blocks
    int num = 0;
    for (node_pair_list_t::const_iterator it = node_pair_list.begin();
         it != node_pair_list.end(); it++) {
      num += get_dim(it->first) * get_dim(it->second);
    }

    // request individual covariance entries
    vector < pair<int, int> > index_list(num);
    const int* trans = R.a_to_r();
    int n = 0;
    for (node_pair_list_t::const_iterator it = node_pair_list.begin();
         it != node_pair_list.end(); it++) {
      int start_r = get_start(it->first);
      int start_c = get_start(it->second);
      int dim_r = get_dim(it->first);
      int dim_c = get_dim(it->second);
      for (int r=0; r<dim_r; r++) {
        for (int c=0; c<dim_c; c++) {
          index_list[n] = make_pair(trans[start_r + r], trans[start_c + c]);
          n++;
        }
      }
    }
    list<double> covs = cov_marginal(R, _cache, index_list);

    // assemble into block matrices
    list<MatrixXd> result;
    list<double>::iterator it_cov = covs.begin();
    for (node_pair_list_t::const_iterator it = node_pair_list.begin();
         it != node_pair_list.end(); it++) {
      int dim_r = get_dim(it->first);
      int dim_c = get_dim(it->second);
      MatrixXd matrix(dim_r, dim_c);
      for (int r=0; r<dim_r; r++) {
        for (int c=0; c<dim_c; c++) {
          matrix(r,c) = *it_cov;
          it_cov++;
        }
      }
      result.push_back(matrix);
    }
    return result;
  }
  list<MatrixXd> empty_list;
  return empty_list;
}
/* update_cost()
 *  - simple updater, uses the rolling history sum as the cost 
 */
void ocin_router_cost_mgr_1domni::update_cost() {
  if (nodes==NULL) {
    nodes = parent_router->nodes;
    //    cout << "nodes in csmgr "<<nodes<<endl;
  }


  string localname = name;

  for (int i=0; i < (_cost_regs[0].size() -1); i++) { // i is output port
    vector <int> costs;

    int cost =0;
    costs.push_back(_cost_regs[0][i].get_hist_sum());// first grab the
                                                // local cost

    vector <int> thiscoord = parent_router->node_info->coord; /* router's
                                                                 multi-dimensional
                                                                 coordinates */
    ocin_router * nextnode;

    // then we recurse the correct direction
    bool done = false;
    while (done != true) {
      stringstream d;           // prosepective downstream node name
      int dir = get_dir(i);
      int dim = get_dim(i);

      // get coordinates of downstream node
      if (dir ==0) {
        thiscoord[dim]++;
      } else {
        thiscoord[dim]--;
      }

      d << thiscoord[0] << "." << thiscoord[1];
      string next = d.str();
      if ((*nodes).find(next) == (*nodes).end()) {
        done = true;            // past the end of the network

        // {
        //   stringstream tmp;
        //   tmp   << "Couldn't find node:" <<thiscoord[0]<<"."<<thiscoord[1]<<endl;
        //   ocin_name_warn(name,tmp.str());
        // }

      } else {
        nextnode = &((*nodes)[next]);
        
        costs.push_back(nextnode->cost_regs[0][i].get_hist_sum());
        // {
        //   stringstream tmp;
        //   tmp   << "Getting cost from node:"<<thiscoord[0]<<"."<<thiscoord[1]<< " in dir of port " << i <<endl;
        //   ocin_name_warn(name,tmp.str());
        // }

      }
    }

    cost = costs.back();        // so we dont div the first one

    // decaying average:
    while(!costs.empty()) {
      cost = (cost + costs.back())/2;
      costs.pop_back();
    }

    _cost_regs[0][i].set_cost(cost);
    
// #ifdef DEBUG	
//     {
//       stringstream tmp;
//       tmp   << "Cost reg @ pout " << i << " = " << cost;
//       ocin_name_debug(name,tmp.str());
//     }
// #endif
    
  }
}
예제 #20
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
long NcVar::rec_size(void) {
    return rec_size(get_dim(0));
}
예제 #21
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
NcValues* NcVar::get_rec(long rec)
{
    return get_rec(get_dim(0), rec);
}
예제 #22
0
파일: netcdf.cpp 프로젝트: mmase/wgrib2
NcValues* NcVar::get_rec(void)
{
    return get_rec(get_dim(0), cur_rec[0]);
}
예제 #23
0
void netcdf::set_unlimited_dim(dim_vector::size_type const & i, int32_t default_dim_length) {

    auto dim_it = get_dim(i);

    set_unlimited_dim(dim_it, default_dim_length);
}
예제 #24
0
void netcdf::set_unlimited_dim(std::string const & name, int32_t default_dim_length) {

    auto dim_it = get_dim(name);

    set_unlimited_dim(dim_it, default_dim_length);
}
예제 #25
0
template<typename T> T SegmentTree<T>::get(NVector left_bound, NVector right_bound){
    NVector left=left_bound+SIZE;
    NVector right=right_bound+SIZE;

    return get_dim(left,right,0);
}
예제 #26
0
파일: main.c 프로젝트: JonHarder/gameOfLife
board start_editor() {
  int h = get_dim("enter height: ");
  clear();
  int w = get_dim("enter width: ");
  curs_set(1);
  noecho();
  cbreak();
  move(20,20);
  int x = 0;
  int x_1 = 0;
  int y = 0;
  board b = init_board(h, w);
  int key;
  print_board(0, 0, b);
  print_instructions();
  move(y,x);
  while((key = getch()) != 113) { // wait until user hits q
    print_board(0, 0, b);
    print_instructions();
    move(y,x);
    if(key == 10) { // enter key
      toggle_alive(b,y,x_1);
      print_board(0,0,b);
      print_instructions();
      y++;
      move(y,x);
      refresh();
    }
    if(key == 32) { // space bar
      toggle_alive(b,y,x_1);
      print_board(0,0,b);
      print_instructions();
      x+=2;
      x_1++;
      move(y,x);
      refresh();
    }
    if(key == 260 && x_1 > 0) { // left arrow key
      x-=2;
      x_1--;
      move(y,x);
    }
    if(key == 261 && x_1 < w-1) { // right arrow key
      x+=2;
      x_1++;
      move(y,x);
    }
    if(key == 259 && y > 0) { // up arrow key
      y-=1;
      move(y,x);
    }
    if(key == 258 && y < h-1) { // down arrow key
      y+=1;
      move(y,x);
    }
    if(key == 544) { // control left
      board newboard = change_board_size(b, -1, 0);
      free_board(b);
      b = newboard;
      w--;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    if(key == 559) {
      board newboard = change_board_size(b, 1, 0);
      free_board(b);
      b = newboard;
      w++;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    if(key == 565) { // control up
      board newboard = change_board_size(b, 0, -1);
      free_board(b);
      b = newboard;
      h--;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    if(key == 524) { // control down
      board newboard = change_board_size(b, 0, 1);
      free_board(b);
      b = newboard;
      h++;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    refresh();
  }
  curs_set(0);
  clear();
  return b;
}
예제 #27
0
 inline BOOL set_no_data(F64 no_data, I32 dim=0) { if ((9 == get_type()) && (dim < get_dim())) { this->no_data[dim].f64 = no_data; options |= 0x01; return TRUE; } return FALSE; }
예제 #28
0
 inline BOOL set_min(F64 min, I32 dim=0) { if ((9 == get_type()) && (dim < get_dim())) { this->min[dim].f64 = min; options |= 0x02; return TRUE; } return FALSE; }
예제 #29
0
 inline BOOL set_max(F64 max, I32 dim=0) { if ((9 == get_type()) && (dim < get_dim())) { this->max[dim].f64 = max; options |= 0x04; return TRUE; } return FALSE; }
예제 #30
0
void Game_Loop::run() {
  const float interval = 1.0 / target_fps;
  double time = SDL_GetTicks() / 1000.0;
  running = true;
  update_state_stack();
  while (running) {
    double current_time = SDL_GetTicks() / 1000.0;

    // Failsafe in case updates keep taking more time than interval and the
    // loop keeps falling back.
    int max_updates = 16;
    if (current_time - time >= interval) {
      while (current_time - time >= interval) {
        running = update_states(interval);
        if (!running)
          break;
        time += interval;
        if (max_updates-- <= 0) {
          // Forget about catching up.
          time = current_time;
          break;
        }
      }

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      auto dim = get_dim();
      glViewport(0, 0, dim[0], dim[1]);
      for (auto& state : states)
        state->draw();
      SDL_GL_SwapBuffers();
    } else {
      // Don't busy wait.
      SDL_Delay(10);
    }
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
      Game_State *top = top_state();
      switch (event.type) {
      case SDL_KEYDOWN:
        if (top)
          top->key_event(event.key.keysym.sym, event.key.keysym.unicode);
        break;
      case SDL_KEYUP:
        if (top)
          top->key_event(-event.key.keysym.sym, -1);
        break;
      case SDL_MOUSEBUTTONDOWN:
      case SDL_MOUSEBUTTONUP:
        if (top)
          top->mouse_event(event.button.x, event.button.y, mouse_button_mask());
        break;
      case SDL_MOUSEMOTION:
        if (top)
          top->mouse_event(event.motion.x, event.motion.y, mouse_button_mask());
        break;
      case SDL_QUIT:
        quit();
        break;
      }
    }
  }
  SDL_Quit();
}