예제 #1
0
static int    unpack_double   (grib_accessor* a, double* val, size_t *len)
{
  grib_accessor_sum* self = (grib_accessor_sum*)a;
  int ret = 0;
  size_t size=0;
  double* values=0;
  long i;
  long count=0;

  ret=value_count(a,&count);
  if (ret) return ret;
  size=count;

  if (size==0) {
  	*val=0;
	return ret;
  }
  values=(double*)grib_context_malloc_clear(a->parent->h->context,sizeof(double)*size);
  if (!values) return GRIB_OUT_OF_MEMORY;

  grib_get_double_array(a->parent->h,self->values,values,&size);

  *val=0;
  for (i=0;i<size;i++) 
  	*val+=values[i];

  grib_context_free(a->parent->h->context,values);

  return ret;
}
static int    pack_long   (grib_accessor* a, const long* val, size_t *len)
{
	grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a;
	int ret = 0;
	long off = 0;
	long numberOfBits=0;
	size_t buflen  = 0;
	unsigned char *buf = NULL;
	unsigned long i = 0;
	unsigned long rlen = value_count(a);

	if(*len != rlen) {
		  ret=grib_set_long(a->parent->h,self->numberOfElements,rlen);
	}

	ret=grib_get_long(a->parent->h,self->numberOfBits,&numberOfBits);
	if (ret) return ret;

	buflen = compute_byte_count(a);
	buf = grib_context_malloc_clear(a->parent->h->context,buflen+sizeof(long));

	for(i=0; i < rlen;i++)
		grib_encode_signed_longb(buf, val[i] ,  &off,  numberOfBits);

	grib_buffer_replace(a, buf, buflen,1,1);

	grib_context_free(a->parent->h->context,buf);

	return ret;

}
static int    unpack_long   (grib_accessor* a, long* val, size_t *len)
{
	grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a;
	int i;
	int ret=0;
	long pos = a->offset*8;
	long rlen = value_count(a);
	long numberOfBits = 0;

	if(*len < rlen)
	{
		grib_context_log(a->parent->h->context, GRIB_LOG_ERROR, 
			" wrong size (%ld) for %s it contains %d values ",*len, a->name , rlen);
		*len = 0;
		return GRIB_ARRAY_TOO_SMALL;
	}

	ret=grib_get_long(a->parent->h,self->numberOfBits,&numberOfBits);
	if (ret) return ret;

	if (numberOfBits==0) {
	    int i;
	    for (i=0;i<rlen;i++) val[i]=0;
	    return GRIB_SUCCESS;
	}


	for (i=0;i<rlen;i++) 
		val[i] =  grib_decode_signed_longb(a->parent->h->buffer->data,  &pos,  numberOfBits);

	*len = rlen;

	return GRIB_SUCCESS;
}
static int    unpack_double   (grib_accessor* a, double* val, size_t *len)
{
    grib_context* c=a->context;
    int ret = 0;
    double* v=val;
    double lat,lon,value;
    size_t size=0;
    long count=0;
    grib_iterator* iter=grib_iterator_new(grib_handle_of_accessor(a),0,&ret);
    if (ret!=GRIB_SUCCESS) {
        if (iter) grib_iterator_delete(iter);
        grib_context_log(c,GRIB_LOG_ERROR,"unable to create iterator");
        return ret;
    }

    size=0;
    ret=value_count(a,&count);
    if (ret) return ret;
    size=count;

    if (*len<size) {
        if (iter) grib_iterator_delete(iter);
        return GRIB_ARRAY_TOO_SMALL;
    }

    while(grib_iterator_next(iter,&lat,&lon,&value)) {
        *(v++)=lat;*(v++)=lon;*(v++)=value;
    }

    grib_iterator_delete(iter);

    *len=size;

    return ret;
}
예제 #5
0
static int    unpack_long   (grib_accessor* a, long* val, size_t *len)
{
  grib_accessor_sum* self = (grib_accessor_sum*)a;
  int ret = 0;
  size_t size=0;
  long* values=0;
  long i;

  size=value_count(a);
  if (size==0) {
  	*val=0;
	return ret;
  }
  values=grib_context_malloc_clear(a->parent->h->context,sizeof(long)*size);
  if (!values) return GRIB_OUT_OF_MEMORY;

  grib_get_long_array(a->parent->h,self->values,values,&size);

  *val=0;
  for (i=0;i<size;i++) 
  	*val+=values[i];

  grib_context_free(a->parent->h->context,values);

  return ret;
}
static int    pack_long   (grib_accessor* a, const long* val, size_t *len)
{
    grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a;
    int ret = 0;
    long off = 0;
    long numberOfBits=0;
    size_t buflen  = 0;
    unsigned char *buf = NULL;
    unsigned long i = 0;
    unsigned long rlen = value_count(a);

    /*
    if(*len < rlen)
    {
    	grib_context_log(a->parent->h->context, GRIB_LOG_ERROR,
    		"Wrong size for %s it contains %d values ", a->name , rlen );
    	return GRIB_ARRAY_TOO_SMALL;
    }
    */
    if (*len!=rlen)
        ret=grib_set_long(a->parent->h,self->numberOfElements,*len);

    ret=grib_get_long(a->parent->h,self->numberOfBits,&numberOfBits);
    if (ret) return ret;
    if (numberOfBits==0) {
        grib_buffer_replace(a, NULL, 0,1,1);
        return GRIB_SUCCESS;
    }

    buflen = compute_byte_count(a);
    buf = grib_context_malloc_clear(a->parent->h->context,buflen+sizeof(long));

    for(i=0; i < *len; i++)
        grib_encode_unsigned_longb(buf, val[i] ,  &off,  numberOfBits);

    grib_buffer_replace(a, buf, buflen,1,1);

    grib_context_free(a->parent->h->context,buf);

    return ret;

}
static int    unpack_double   (grib_accessor* a, double* val, size_t *len)
{
  grib_context* c=a->parent->h->context;
  grib_accessor_latitudes* self = (grib_accessor_latitudes*)a;
  int ret = 0;
  double* v=val;
  double dummy=0;
  size_t size=0;
  grib_iterator* iter=NULL;

  self->save=1;
  size=value_count(a);
  if (*len<size) return GRIB_ARRAY_TOO_SMALL;
  self->save=0;

  /* self->lats are computed in _value_count*/
  if (self->lats) {
    int i;
    *len=self->size;
    for (i=0;i<size;i++) val[i]=self->lats[i];
    grib_context_free(c,self->lats);
    self->lats=NULL;
    self->size=0;
    return GRIB_SUCCESS;
  }

  iter=grib_iterator_new(a->parent->h,0,&ret);
  if (ret!=GRIB_SUCCESS) {
    if (iter) grib_iterator_delete(iter);
    grib_context_log(c,GRIB_LOG_ERROR,"unable to create iterator");
    return ret;
  }

  while(grib_iterator_next(iter,v++,&dummy,&dummy)) {}
  grib_iterator_delete(iter);

  *len=size;

  return ret;
}
예제 #8
0
파일: dtree.c 프로젝트: pimms/aidt
static void
majority_result(const struct sample *samples, int count, unsigned *field, int *val)
{
    int unique;
    int *vals = unique_values(samples, count, &unique, SAMPLE_RESULT_FIELD);
    int *occurs = (int*)malloc(sizeof(int) * unique);
    for (int i=0; i<unique; i++)
        occurs[i] = value_count(samples, count, vals[i], SAMPLE_RESULT_FIELD);

    *field = SAMPLE_RESULT_FIELD;
    *val = -1;
    int best = 0;
    for (int i=0; i<unique; i++) {
        if (occurs[i] > best) {
            *val = vals[i];
            best = occurs[i];
        }
    }

    free(vals);
    free(occurs);
}
예제 #9
0
FieldBinding::FieldBinding(const ::google::protobuf::FieldDescriptor* descriptor, SoapServerInternal* server)
	: m_name(descriptor->name())
	, m_type(descriptor->type_name())
	, m_offset(-1)
	, m_size(-1)
  , m_flags(0)
{
  if (descriptor->is_optional())
  {
    m_flags |= FF_Optional;
  }

  if (descriptor->is_repeated())
  {
    m_flags |= FF_Repeated;
  }

  switch (descriptor->type())
  {
  case ::google::protobuf::FieldDescriptor::TYPE_STRING:
    m_type = "string";
    break;

  case ::google::protobuf::FieldDescriptor::TYPE_BOOL:
    m_type = "boolean";
    break;

  case ::google::protobuf::FieldDescriptor::TYPE_BYTES:
    m_type = "hexBinary";
    break;

  case ::google::protobuf::FieldDescriptor::TYPE_UINT64:
  case ::google::protobuf::FieldDescriptor::TYPE_FIXED64:
    m_type = "unsignedLong";
    break;

  case ::google::protobuf::FieldDescriptor::TYPE_UINT32:
  case ::google::protobuf::FieldDescriptor::TYPE_FIXED32:
    m_type = "unsignedInt";
    break;

  case ::google::protobuf::FieldDescriptor::TYPE_SFIXED32:
  case ::google::protobuf::FieldDescriptor::TYPE_INT32:
    m_type = "int";
    break;

  case ::google::protobuf::FieldDescriptor::TYPE_SFIXED64:
  case ::google::protobuf::FieldDescriptor::TYPE_INT64:
    m_type = "long";
    break;
  };

  if (descriptor->enum_type())
  {
    m_flags |= FF_Enum;

    auto ed = descriptor->enum_type();

    for (int x = 0; x < ed->value_count(); ++x)
    {
      m_enumValues.push_back(ed->value(x)->name());
    }
  }

  if (descriptor->message_type())
  {
    m_flags |= FF_Class;
    m_type = descriptor->message_type()->name();
    server->GetClassBinding(descriptor->message_type());
  }
}