static void init  (grib_accessor* a,const long len, grib_arguments* param)
{
    grib_accessor_codeflag* self = (grib_accessor_codeflag*)a;
    a->length = len;
    self->tablename = grib_arguments_get_string(a->parent->h,param,0);
    Assert(a->length>=0);
}
static void init(grib_accessor* a, const long len, grib_arguments* params) {
  int n=0;
  grib_accessor_codetable* self  = (grib_accessor_codetable*)a;
  grib_action* act=(grib_action*)(a->creator);

  self->tablename = grib_arguments_get_string(a->parent->h,params,n++);
  self->masterDir = grib_arguments_get_name(a->parent->h,params,n++);
  self->localDir = grib_arguments_get_name(a->parent->h,params,n++);

  /*if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
    printf("-------- %s type string (%ld)\n",a->name,a->flags);*/

  if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) {
    a->length = 0;
	if (!a->vvalue) 
		a->vvalue = grib_context_malloc_clear(a->parent->h->context,sizeof(grib_virtual_value));
    a->vvalue->type=grib_accessor_get_native_type(a);
    a->vvalue->length=len;
    if (act->default_value!=NULL) {
      const char* p = 0;
      size_t len = 1;
      long l;
      int ret=0;
      double d;
      char tmp[1024];
      grib_expression* expression=grib_arguments_get_expression(a->parent->h,act->default_value,0);
      int type = grib_expression_native_type(a->parent->h,expression);
      switch(type) {
        case GRIB_TYPE_DOUBLE:
          grib_expression_evaluate_double(a->parent->h,expression,&d);
          grib_pack_double(a,&d,&len);
          break;

        case GRIB_TYPE_LONG:
          grib_expression_evaluate_long(a->parent->h,expression,&l);
          grib_pack_long(a,&l,&len);
          break;

        default:
          len = sizeof(tmp);
          p = grib_expression_evaluate_string(a->parent->h,expression,tmp,&len,&ret);
          if (ret != GRIB_SUCCESS) {
			  grib_context_log(a->parent->h->context,GRIB_LOG_FATAL,
							   "unable to evaluate %s as string",a->name);
          }
          len = strlen(p)+1;
          pack_string(a,p,&len);
          break;
      }
    }
  } else
    a->length = len;

}
static void init(grib_accessor* a, const long len, grib_arguments* params)
{
    int n=0;
    grib_accessor_dictionary* self  = (grib_accessor_dictionary*)a;

    self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a),params,n++);
    self->key = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
    self->column = grib_arguments_get_long(grib_handle_of_accessor(a),params,n++);
    self->masterDir = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
    self->localDir = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);

    a->length = 0;
    a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;

}
static int    unpack_string(grib_accessor* a, char* val, size_t *len)
{
	grib_accessor_sprintf* self = (grib_accessor_sprintf*)a;

	char result[1024]  ;
	char sres[1024]  ;
	long ires = 0;
	double dres= 0;

	int  i = 0;
	size_t replen = 1024;

	int ret = GRIB_SUCCESS;

	int carg= 0;
	int is_missing = 0;
	const char* uname = NULL;
	const char* tempname = NULL;


	uname = grib_arguments_get_string(a->parent->h,self->args,carg++);
	sprintf(result,"%s",""); 

	for(i=0;i<strlen(uname);i++)
	{

		if(uname[i]=='%'){
			int precision=999;
			i++;
			if (uname[i]=='.') {
				char *theEnd=NULL,*start;
				start=(char*)&(uname[++i]);
				precision=strtol(start,&theEnd,10);
				Assert(*theEnd!=0);
				while (uname[i] != *theEnd) i++;
			} 
			switch(uname[i]){

				case 'd':
					tempname = grib_arguments_get_name(a->parent->h,self->args,carg++);

					if((ret = grib_get_long_internal(a->parent->h,tempname,&ires)) != GRIB_SUCCESS)
						return ret;
					/* Bug GRIB-56: Check to see if the key is missing */
					is_missing = grib_is_missing(a->parent->h,tempname,&ret);
					if (ret != GRIB_SUCCESS)
						return ret;
					if (is_missing) {
						sprintf(result, "%sMISSING",result);
					}
					else {
						/* Not missing so print it */
						if (precision!=999) {
							sprintf(result,"%s%.*ld",result,precision, ires); 
						} else {
							sprintf(result,"%s%ld",result, ires); 
						}
					}
					break;

				case 'g':
					tempname = grib_arguments_get_name(a->parent->h,self->args,carg++);
					if((ret = grib_get_double_internal(a->parent->h,tempname,&dres)) != GRIB_SUCCESS) 
						return ret;
					sprintf(result,"%s%g",result, dres); 


					break;

				case 's':
					tempname = grib_arguments_get_name(a->parent->h,self->args,carg++);
					if((ret = grib_get_string_internal(a->parent->h,tempname,sres, &replen )) != GRIB_SUCCESS)
						return ret;
					sprintf(result,"%s%s",result, sres); 
					replen = 1024;


			}
		}
		else
			sprintf(result,"%s%c",result, uname[i]);


	}

	replen = strlen(result)+1;

	if(*len < replen){
		*len = replen;
		return GRIB_ARRAY_TOO_SMALL;
	}
	*len = replen;

	sprintf(val,"%s",result);

	return GRIB_SUCCESS;
}