コード例 #1
0
static int compare(grib_accessor* a, grib_accessor* b) {
  int retval=0;
  double *aval=0;
  double *bval=0;

  size_t alen = (size_t)grib_value_count(a);
  size_t blen = (size_t)grib_value_count(b);

  if (alen != blen) return GRIB_COUNT_MISMATCH;

  aval=grib_context_malloc(a->parent->h->context,alen*sizeof(double));
  bval=grib_context_malloc(b->parent->h->context,blen*sizeof(double));

  b->dirty=1;
  a->dirty=1;

  grib_unpack_double(a,aval,&alen);
  grib_unpack_double(b,bval,&blen);

  retval = GRIB_SUCCESS;
  while (alen != 0) {
    if (*bval != *aval) retval = GRIB_DOUBLE_VALUE_MISMATCH;
    alen--;
  }

  grib_context_free(a->parent->h->context,aval);
  grib_context_free(b->parent->h->context,bval);

  return GRIB_SUCCESS;
}
コード例 #2
0
static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment)
{
    grib_dumper_debug *self = (grib_dumper_debug*)d;
    double value; size_t size = 1;
    int err = grib_unpack_double(a,&value,&size);
    int i;

    if( a->length == 0  &&
            (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0)
        return;

    set_begin_end(d,a);

    for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");

    if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a))
        fprintf(self->dumper.out,"%ld-%ld %s %s = MISSING",self->begin,self->theEnd,a->creator->op, a->name);
    else
        fprintf(self->dumper.out,"%ld-%ld %s %s = %g",self->begin,self->theEnd,a->creator->op, a->name,value);
    if(comment) fprintf(self->dumper.out," [%s]",comment);
    if(err)
        fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_debug::dump_double]",err,grib_get_error_message(err));
    aliases(d,a);
    fprintf(self->dumper.out,"\n");
}
コード例 #3
0
static int unpack_string(grib_accessor*a , char*  v, size_t *len){

  double val = 0;
  size_t l = 1;
  char repres[1024];

  grib_unpack_double (a , &val, &l);

  sprintf(repres,"%.0f", val);

  l = strlen(repres)+1;

  if(l >*len ){
    grib_context_log(a->parent->h->context, GRIB_LOG_ERROR, "grib_accessor_long : unpack_string : Buffer too small for %s ", a->name );

    *len = l;
    return GRIB_BUFFER_TOO_SMALL;
  }
  grib_context_log(a->parent->h->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting double %s to string  ", a->name);

  *len = l;

  strcpy(v,repres);
  return GRIB_SUCCESS;


}
コード例 #4
0
static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment)
{
  grib_dumper_serialize *self = (grib_dumper_serialize*)d;
  double value; size_t size = 1;
  int err = grib_unpack_double(a,&value,&size);

  if(  (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 )
    return;

  if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 &&
      (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0)
    return;


  if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_DOUBLE))
    fprintf(self->dumper.out,"%s = MISSING", a->name);
  else
    fprintf(self->dumper.out,"%s = %g",a->name,value);

  if ( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 )  fprintf(self->dumper.out," (read_only)");

#if 0
  if(comment) fprintf(self->dumper.out," [%s]",comment);
#endif
  if(err)
    fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_double]",err,grib_get_error_message(err));
  fprintf(self->dumper.out,"\n");

}
コード例 #5
0
static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment)
{
  grib_dumper_default *self = (grib_dumper_default*)d;
  double value; size_t size = 1;
  int err = grib_unpack_double(a,&value,&size);


  if ( (a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0)
    return;

  print_offset(self->dumper.out,d,a);

  if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"# type %s \n",a->creator->op);
  }

  aliases(d,a);
  if(comment) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"# %s \n",comment);
  }


  if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"#-READ ONLY- ");
  } else
    fprintf(self->dumper.out,"  ");

  if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a) )
    fprintf(self->dumper.out,"%s = MISSING;",a->name);
  else
    fprintf(self->dumper.out,"%s = %g;",a->name,value);


  if(err) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"# *** ERR=%d (%s) [grib_dumper_default::dump_double]",err,grib_get_error_message(err));
  }

  fprintf(self->dumper.out,"\n");
}
コード例 #6
0
static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment)
{
  grib_dumper_c_code *self = (grib_dumper_c_code*)d;
  double value; size_t size = 1;
  int err = grib_unpack_double(a,&value,&size);
  if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)
    return;

  if(a->length == 0)
    return;

#if 0
  if(comment) fprintf(self->dumper.out,"/* %s */\n",comment);
#endif

  fprintf(self->dumper.out,"    GRIB_CHECK(grib_set_double(h,\"%s\",%g),%d);\n",a->name,value,0);

  if(err)
    fprintf(self->dumper.out," /*  Error accessing %s (%s) */",a->name,grib_get_error_message(err));
}
コード例 #7
0
static void dump_values(grib_dumper* d,grib_accessor* a)
{
    grib_dumper_debug *self = (grib_dumper_debug*)d;
    int i,k,err =0;
    int more = 0;
    double*  buf = NULL;
    size_t size=0;
    long count=0;

    if( a->length == 0  &&
            (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0)
        return;

    grib_value_count(a,&count);
    size=count;
    if(size == 1){
        dump_double(d,a,NULL);
        return ;
    }
    buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double));

    set_begin_end(d,a);

    for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");
    fprintf(self->dumper.out,"%ld-%ld %s %s = (%ld,%ld)",self->begin,self->theEnd,a->creator->op, a->name,(long)size,a->length);
    aliases(d,a);
    fprintf(self->dumper.out," {");

    if(!buf)
    {
        if(size == 0)
            fprintf(self->dumper.out,"}\n");
        else
            fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size);
        return;
    }

    fprintf(self->dumper.out,"\n");

    err =  grib_unpack_double(a,buf,&size);

    if(err){
        grib_context_free(d->handle->context,buf);
        fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_debug::dump_values]\n}",err,grib_get_error_message(err));
        return ;
    }

    if(size > 100) {
        more = size - 100;
        size = 100;
    }


    k = 0;
    while(k < size)
    {
#if 1
        int j;
        for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," ");
        for(j = 0; j < 8 && k < size; j++, k++)
        {
            fprintf(self->dumper.out,"%10g",buf[k]);
            if(k != size-1)
                fprintf(self->dumper.out,", ");
        }
        fprintf(self->dumper.out,"\n");
#else

        fprintf(self->dumper.out,"%d %g\n",k,buf[k]);

#endif

    }
    if(more)
    {
        for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," ");
        fprintf(self->dumper.out,"... %d more values\n",more);
    }

    for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");
    fprintf(self->dumper.out,"} # %s %s \n",a->creator->op, a->name);
    grib_context_free(d->handle->context,buf);
}
コード例 #8
0
static void dump_values(grib_dumper* d,grib_accessor* a)
{
  grib_dumper_default *self = (grib_dumper_default*)d;
  int k,err =0;
  int more = 0;
  double*  buf = NULL;
  size_t size=0;
  long count=0;

  if ( (a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0)
    return;

  grib_value_count(a,&count);
  size=count;
  if(size == 1){
    dump_double(d,a,NULL);
    return ;
  }
  buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double));

   print_offset(self->dumper.out,d,a);

  if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"# type %s \n",a->creator->op);
  }

  aliases(d,a);

  if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"#-READ ONLY- ");
  } else
    fprintf(self->dumper.out,"  ");

  fprintf(self->dumper.out,"%s(%ld) = ",a->name,(long)size);
  aliases(d,a);
  fprintf(self->dumper.out," {");

  if(!buf)
  {
    if(size == 0)
      fprintf(self->dumper.out,"}\n");
    else
      fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size);
    return;
  }

  fprintf(self->dumper.out,"\n");

  err =  grib_unpack_double(a,buf,&size);

  if(err){
    grib_context_free(d->handle->context,buf);
    fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_default::dump_values]\n}",err,grib_get_error_message(err));
    return ;
  }

  if(!(d->option_flags & GRIB_DUMP_FLAG_ALL_DATA) && size > 100) {
    more = size - 100;
    size = 100;
  }

  k = 0;
  while(k < size)  {
#if 1
    int j;
    fprintf(self->dumper.out,"  ");
    for(j = 0; j < 5 && k < size; j++, k++)  {
      fprintf(self->dumper.out,"%.10e",buf[k]);
      if(k != size-1)
        fprintf(self->dumper.out,", ");
    }
    fprintf(self->dumper.out,"\n");
#else

    fprintf(self->dumper.out,"%d %g\n",k,buf[k]);

#endif

  }  if(more)  {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"... %d more values\n",more);
  }

  fprintf(self->dumper.out,"  ");
  fprintf(self->dumper.out,"} \n");
  grib_context_free(d->handle->context,buf);
}
コード例 #9
0
static void dump_values(grib_dumper* d,grib_accessor* a)
{
  grib_dumper_c_code *self = (grib_dumper_c_code*)d;
  int k,err =0;
  double*  buf = NULL;
  int type=0;
  char stype[10];
  size_t size=0;
  stype[0]='\0';

  if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)
      || ((a->flags & GRIB_ACCESSOR_FLAG_DATA)
          && (d->option_flags & GRIB_DUMP_FLAG_NO_DATA)   ) )
    return;

  size=grib_value_count(a);
  if(size == 1){
    dump_double(d,a,NULL);
    return ;
  }

  type=grib_accessor_get_native_type(a);
  switch (type) {
     case GRIB_TYPE_LONG:
       sprintf(stype,"%s","long");
       break;
     case GRIB_TYPE_DOUBLE:
       sprintf(stype,"%s","double");
       break;
     default:
       return;
  }

  buf = grib_context_malloc(d->handle->context,size * sizeof(double));
  if(!buf)
  {
    fprintf(self->dumper.out,"/* %s: cannot malloc(%ld) */\n",a->name,(long)size);
    return;
  }

  err =  grib_unpack_double(a,buf,&size);

  if(err){
    grib_context_free(d->handle->context,buf);
    fprintf(self->dumper.out," /*  Error accessing %s (%s) */",a->name,grib_get_error_message(err));
    return ;
  }

  fprintf(self->dumper.out,"    size = %ld;\n",(long)size);
  fprintf(self->dumper.out,"    v%s    = (%s*)calloc(size,sizeof(%s));\n",stype,stype,stype);
  fprintf(self->dumper.out,"    if(!v%s) {\n",stype);
  fprintf(self->dumper.out,"        fprintf(stderr,\"failed to allocate %%d bytes\\n\",size*sizeof(%s));\n",stype);
  fprintf(self->dumper.out,"        exit(1);\n");
  fprintf(self->dumper.out,"    }\n");


  fprintf(self->dumper.out,"\n   ");
  k = 0;
  while(k < size)
  {
    fprintf(self->dumper.out," v%s[%4d] = %7g;",stype,k,buf[k]);
    k++;
    if(k%4 == 0) fprintf(self->dumper.out,"\n   ");

  }
  if(size%4) fprintf(self->dumper.out,"\n");
  fprintf(self->dumper.out,"\n");
  fprintf(self->dumper.out,"    GRIB_CHECK(grib_set_%s_array(h,\"%s\",v%s,size),%d);\n",stype,a->name,stype,0);
  fprintf(self->dumper.out,"    free(v%s);\n",stype);

  grib_context_free(d->handle->context,buf);
}
コード例 #10
0
static void dump_values(grib_dumper* d,grib_accessor* a)
{
  grib_dumper_serialize *self = (grib_dumper_serialize*)d;
  int k,err =0;
  double*  buf = NULL;
  int last=0;
  int columns=4;
  char* values_format=NULL;
  char* default_format="%.16e";
  char* columns_str=NULL;
  size_t len=0;
  char* pc=NULL;
  char* pcf=NULL;
  size_t size=0;
  long count=0;
  values_format=default_format;

  if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY))
    return;

  grib_value_count(a,&count);
  size=count;

  if (self->format) {
    if (self->format[0]=='\"') values_format=self->format+1;
    else values_format=self->format;
    last=strlen(values_format)-1;
    if (values_format[last]=='\"') values_format[last]='\0';
  }


  pc = values_format;
  pcf = values_format;
  while( *pc!='\0' && *pc != '%') pc++;
  if (strlen(pc) > 1 ) {
    values_format=pc;
    len=pc-pcf;
  } else {
    values_format=default_format;
    len=0;
  }

  if (len>0) {
    columns_str=(char*)malloc((len+1)*sizeof(char));
    columns_str=(char*)memcpy(columns_str,pcf,len);
    columns_str[len]='\0';
    columns=atoi(columns_str);
    free(columns_str);
  }

  if(size == 1){
    dump_double(d,a,NULL);
    return ;
  }

  if ((d->option_flags & GRIB_DUMP_FLAG_VALUES) == 0 ) return;

  buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double));

  fprintf(self->dumper.out,"%s (%ld) {",a->name,(long)size);

  if(!buf)
  {
    if(size == 0)
      fprintf(self->dumper.out,"}\n");
    else
      fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size);
    return;
  }

  fprintf(self->dumper.out,"\n");

  err =  grib_unpack_double(a,buf,&size);

  if(err){
    grib_context_free(d->handle->context,buf);
    fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_values]\n}",err,grib_get_error_message(err));
    return ;
  }

  k = 0;
  while(k < size)
  {
    int j;
    for(j = 0; j < columns && k < size; j++, k++)
    {
      fprintf(self->dumper.out,values_format,buf[k]);
      if(k != size-1)
        fprintf(self->dumper.out,", ");
    }
    fprintf(self->dumper.out,"\n");
  }
  fprintf(self->dumper.out,"}\n");
  grib_context_free(d->handle->context,buf);
}