GRIB-513: Remove the deprecated function: grib_handle_new_from_template

This commit is contained in:
Shahram Najm 2014-03-21 16:25:30 +00:00
parent de090fd224
commit 56e8d3e90e
21 changed files with 66 additions and 168 deletions

View File

@ -11,7 +11,7 @@
/*
* C Implementation: set_data
*
* Description: set the data contained in a grib file
* Description: set the data contained in a GRIB file
*
*/
#include <stdio.h>
@ -19,51 +19,53 @@
#include "grib_api.h"
void usage(char* prog) {
printf("usage: %s out.grib\n",prog);
exit(1);
void usage(char* prog)
{
printf("usage: %s out.grib\n",prog);
exit(1);
}
int main(int argc, char** argv) {
int i;
double *values = NULL;
size_t values_len= 0;
int main(int argc, char** argv)
{
int i;
double *values = NULL;
size_t values_len= 0;
const char* filename = "regular_ll_pl_grib1";
grib_handle *h = NULL;
double d,e;
long count;
const char* sample_filename = "regular_ll_pl_grib1";
grib_handle *h = NULL;
double d,e;
long count;
if (argc!=2) usage(argv[0]);
/* create new handle from a message in a file*/
h = grib_handle_new_from_template(0,"regular_ll_pl_grib1");
if (h == NULL) {
printf("Error: unable to create handle from file %s\n",filename);
exit(1);
}
if (argc!=2) usage(argv[0]);
/* create new handle from message in sample file */
h = grib_handle_new_from_samples(0, sample_filename);
if (h == NULL) {
printf("Error: unable to create handle from sample file %s\n", sample_filename);
exit(1);
}
values_len=10000;
values = malloc(values_len*sizeof(double));
d=10e-8;
e=d;
count=1;
for (i=0;i<values_len;i++) {
if (count>1000) {e*=10; count=1;}
values[i]=d;
printf("%g \n",values[i]);
d+=e;
count++;
}
values_len=10000;
values = malloc(values_len*sizeof(double));
d=10e-8;
e=d;
count=1;
for (i=0;i<values_len;i++) {
if (count>1000) {e*=10; count=1;}
values[i]=d;
printf("%g \n",values[i]);
d+=e;
count++;
}
GRIB_CHECK(grib_set_long(h,"bitsPerValue",16),0);
GRIB_CHECK(grib_set_long(h,"bitsPerValue",16),0);
/* set data values*/
GRIB_CHECK(grib_set_double_array(h,"values",values,values_len),0);
/* set data values*/
GRIB_CHECK(grib_set_double_array(h,"values",values,values_len),0);
grib_write_message(h,argv[1],"w");
grib_write_message(h,argv[1],"w");
free(values);
grib_handle_delete(h);
free(values);
grib_handle_delete(h);
return 0;
return 0;
}

View File

@ -144,7 +144,7 @@
!
!************************************************************
!
IRT= grib_new_from_template_(GBID2,"GRIB2")
IRT= grib_new_from_samples_(GBID2,"GRIB2")
ISFOFFS=-9999
IRT=grib_set_int_(GBID2,"editionNumber",2)
IRT=grib_set_int_(GBID2,"dataRepresentationTemplateNumber",IVAL)

View File

@ -14,7 +14,6 @@ integer, external :: grib_f_keys_iterator_get_name, &
grib_f_keys_iterator_rewind
integer, external :: grib_f_new_from_message, &
grib_f_new_from_message_copy, &
grib_f_new_from_template, &
grib_f_new_from_samples, &
grib_f_read_any_from_file, &
grib_f_new_from_file, &

View File

@ -6,8 +6,6 @@
external grib_read_file
integer grib_new_from_message
external grib_new_from_message
integer grib_new_from_template
external grib_new_from_template
integer grib_clone
external grib_clone
integer grib_new_from_file

View File

@ -10,7 +10,7 @@ public :: grib_skip_computed, &
grib_skip_read_only
public :: grib_keys_iterator_get_name, &
grib_keys_iterator_rewind
public :: grib_new_from_message, grib_new_from_template, &
public :: grib_new_from_message, &
grib_new_from_samples, grib_new_from_file, &
grib_read_from_file,grib_headers_only_new_from_file
public :: grib_release

View File

@ -207,14 +207,6 @@ int grib_new_from_samples__(int* gid, char* name , int lname){
return grib_f_new_from_samples_( gid, name , lname);
}
int grib_new_from_template_(int* gid, char* name , int lname){
return grib_f_new_from_template_( gid, name , lname);
}
int grib_new_from_template__(int* gid, char* name , int lname){
return grib_f_new_from_template_( gid, name , lname);
}
int grib_clone_(int* gidsrc,int* giddest){
return grib_f_clone_(gidsrc, giddest);
}

View File

@ -1388,37 +1388,6 @@
endif
end subroutine grib_new_from_samples
!> THIS FUNCTION IS DEPRECATED AND IT WILL DISAPPEAR FROM THE VERSION 2.0
!> Create a new valid gribid from a template.
!>
!> Valid templates are stored in the directory pointed by the\n
!> environment variable GRIB_TEMPLATES_PATH or in a templates\n
!> default directory if this variable is not defined.\n
!> To know where the templates directory is run the grib_info tool.\n
!>
!> In case of error, if the status parameter (optional) is not given, the program will
!> exit with an error message.\n Otherwise the error message can be
!> gathered with @ref grib_get_error_string.
!>
!>
!> \b Examples: \ref template.f90 "template.f90"
!>
!> @param gribid id of the grib loaded in memory
!> @param templatename name of the template to be used
!> @param status GRIB_SUCCESS if OK, integer value on error
subroutine grib_new_from_template ( gribid, templatename, status )
integer(kind=kindOfInt), intent(out) :: gribid
character(len=*), intent(in) :: templatename
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
iret=grib_f_new_from_template ( gribid, templatename )
if (present(status)) then
status = iret
else
call grib_check(iret,'grib_new_from_template','('//templatename//')')
endif
end subroutine grib_new_from_template
!> Free the memory for the message referred as gribid.
!>

View File

@ -1220,29 +1220,6 @@ int grib_f_new_from_samples(int* gid, char* name , int lname){
return grib_f_new_from_samples_( gid, name , lname);
}
int grib_f_new_from_template_(int* gid, char* name , int lname){
char fname[1024];
grib_handle *h = NULL;
h = grib_handle_new_from_template(NULL,cast_char(fname,name,lname));
/* grib_context_set_debug(h->context,1);*/
if(h){
push_handle(h,gid);
return GRIB_SUCCESS;
}
*gid = -1;
return GRIB_INTERNAL_ERROR;
}
int grib_f_new_from_template__(int* gid, char* name , int lname){
return grib_f_new_from_template_( gid, name , lname);
}
int grib_f_new_from_template(int* gid, char* name , int lname){
return grib_f_new_from_template_( gid, name , lname);
}
int grib_f_clone_(int* gidsrc,int* giddest){
grib_handle *src = get_handle(*gidsrc);
grib_handle *dest = NULL;

View File

@ -91,9 +91,6 @@ int grib_f_new_from_message_copy(int *gid, void *buffer, size_t *bufsize);
int grib_f_new_from_samples_(int *gid, char *name, int lname);
int grib_f_new_from_samples__(int *gid, char *name, int lname);
int grib_f_new_from_samples(int *gid, char *name, int lname);
int grib_f_new_from_template_(int *gid, char *name, int lname);
int grib_f_new_from_template__(int *gid, char *name, int lname);
int grib_f_new_from_template(int *gid, char *name, int lname);
int grib_f_clone_(int *gidsrc, int *giddest);
int grib_f_clone__(int *gidsrc, int *giddest);
int grib_f_clone(int *gidsrc, int *giddest);

View File

@ -945,21 +945,6 @@ int grib_c_new_from_samples(int* gid, char* name){
return GRIB_FILE_NOT_FOUND;
}
int grib_c_new_from_template(int* gid, char* name){
grib_handle *h = NULL;
h = grib_handle_new_from_template(NULL,name);
/* grib_context_set_debug(h->context,1);*/
if(h){
push_handle(h,gid);
return GRIB_SUCCESS;
}
*gid = -1;
return GRIB_INTERNAL_ERROR;
}
int grib_c_clone(int* gidsrc,int* giddest){
grib_handle *src = get_handle(*gidsrc);
grib_handle *dest = NULL;

View File

@ -27,7 +27,6 @@ int grib_c_keys_iterator_rewind(int *kiter);
int grib_c_new_from_message(int *gid, void *buffer, size_t *bufsize);
int grib_c_new_from_message_copy(int *gid, void *buffer, size_t *bufsize);
int grib_c_new_from_samples(int *gid, char *name);
int grib_c_new_from_template(int *gid, char *name);
int grib_c_clone(int *gidsrc, int *giddest);
int grib_c_copy_namespace(int *gidsrc, char *name, int *giddest);
int grib_c_count_in_file(FILE *f, int *n);

View File

@ -460,16 +460,6 @@ grib_handle* grib_handle_new_from_multi_message(grib_context* c,void** data,
grib_handle* grib_handle_new_from_message_copy(grib_context* c, const void* data, size_t data_len);
/**
* Create a handle from a read_only template resource.
* The message is copied at the creation of the handle
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param res_name : the resource name
* @return the new handle, NULL if the resource is invalid or a problem is encountered
*/
grib_handle* grib_handle_new_from_template (grib_context* c, const char* res_name) ;
/**
* Create a handle from a message contained in a samples directory.
* The message is copied at the creation of the handle

View File

@ -8,8 +8,6 @@
external grib_new_from_message
integer grib_new_from_samples
external grib_new_from_samples
integer grib_new_from_template
external grib_new_from_template
integer grib_clone
external grib_clone
integer grib_new_from_file

View File

@ -738,7 +738,6 @@ void grib_empty_section(grib_context *c, grib_section *b);
void grib_section_delete(grib_context *c, grib_section *b);
int grib_handle_delete(grib_handle *h);
grib_handle *grib_new_handle(grib_context *c);
grib_handle *grib_handle_new_from_template(grib_context *c, const char *name);
grib_handle *grib_handle_new_from_samples(grib_context *c, const char *name);
int grib_write_message(grib_handle *h, const char *file, const char *mode);
grib_handle *grib_handle_clone(grib_handle *h);

View File

@ -242,13 +242,6 @@ static grib_handle* grib_handle_create ( grib_handle *gl, grib_context* c,void*
}
grib_handle* grib_handle_new_from_template ( grib_context* c, const char* name )
{
if ( !c ) c=grib_context_get_default();
/*grib_context_log(c,GRIB_LOG_WARNING,"grib_handle_new_from_template function is deprecated, please use grib_handle_new_from_samples\n");*/
return grib_handle_new_from_samples ( c,name );
}
grib_handle* grib_handle_new_from_samples ( grib_context* c, const char* name )
{
grib_handle* g = 0;
@ -274,31 +267,31 @@ grib_handle* grib_handle_new_from_samples ( grib_context* c, const char* name )
int grib_write_message(grib_handle* h,const char* file,const char* mode)
{
FILE* fh=0;
int err;
const void *buffer; size_t size;
FILE* fh=0;
int err;
const void *buffer; size_t size;
fh=fopen(file,mode);
if (!fh) {
perror(file);
return GRIB_IO_PROBLEM;
}
err=grib_get_message(h,&buffer,&size);
fh=fopen(file,mode);
if (!fh) {
perror(file);
return GRIB_IO_PROBLEM;
}
err=grib_get_message(h,&buffer,&size);
if (err) {
fclose(fh);
return err;
}
if(fwrite(buffer,1,size,fh) != size) {
perror(file);
if(fwrite(buffer,1,size,fh) != size) {
perror(file);
fclose(fh);
return GRIB_IO_PROBLEM;
}
if (fclose(fh) != 0) {
perror(file);
return GRIB_IO_PROBLEM;
}
return 0;
return GRIB_IO_PROBLEM;
}
if (fclose(fh) != 0) {
perror(file);
return GRIB_IO_PROBLEM;
}
return 0;
}
grib_handle* grib_handle_clone ( grib_handle* h )

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[])
gc = grib_context_get_default();
gh=grib_handle_new_from_template(NULL,"GRIB1");
gh=grib_handle_new_from_samples(NULL,"GRIB1");
if (!gh) {
printf("Error: unable to create grib_handle\n");

View File

@ -44,7 +44,7 @@ int main(int argc, char *argv[])
return ret;
#else
grib_handle* gh = grib_handle_new_from_template(NULL,"latlon");
grib_handle* gh = grib_handle_new_from_samples(NULL,"latlon");
grib_set_long(gh,"editionNumber",2);
grib_dump_content(gh,stdout,NULL,0,NULL);
return 0;

View File

@ -194,7 +194,7 @@ int i;
exit(1);
}
grib_handle_delete(grib_handle_new_from_template(c,"latlon"));
grib_handle_delete(grib_handle_new_from_samples(c,"latlon"));
rewind(f);

View File

@ -15,7 +15,7 @@ int main(int argc, char *argv[])
long numberOfPointsAlongAParallel,numberOfPointsAlongAMeridian,numberOfPoints,i,j,k;
int option_flags;
h = grib_handle_new_from_template(0,"bitmap");
h = grib_handle_new_from_samples(0,"bitmap");
if(!h) {
printf("ERROR: Unable to create grib handle\n");
exit(1);

View File

@ -345,7 +345,7 @@ int main(int argc,const char** argv)
exit(1);
}
h = grib_handle_new_from_template(NULL,"GRIB2");
h = grib_handle_new_from_samples(NULL,"GRIB2");
if(!h) {
fprintf(stderr,"Cannot create grib handle\n");
exit(1);

View File

@ -48,7 +48,7 @@ static void check(int code,const char* name)
static grib_handle* handle()
{
if(h == 0)
h = grib_handle_new_from_template(NULL,"GRIB1");
h = grib_handle_new_from_samples(NULL,"GRIB1");
/* grib_dump_content(h,stdout,"debug",~0,NULL); */
return h;
}