mirror of https://github.com/ecmwf/eccodes.git
GRIB-395: grib_count_in_file() function does not support multi-field messages
This commit is contained in:
parent
1b9ea7d288
commit
f3cb55b49e
|
@ -27,6 +27,7 @@ list( APPEND tests
|
||||||
grib_set_pv
|
grib_set_pv
|
||||||
samples
|
samples
|
||||||
count_messages
|
count_messages
|
||||||
|
grib_count_messages_multi
|
||||||
read_message
|
read_message
|
||||||
read_from_file
|
read_from_file
|
||||||
get_set_uuid
|
get_set_uuid
|
||||||
|
|
|
@ -38,7 +38,7 @@ program get
|
||||||
|
|
||||||
! Load the messages from the file.
|
! Load the messages from the file.
|
||||||
DO i=1,n
|
DO i=1,n
|
||||||
call codes_grib_new_from_file(ifile,igrib(i), iret)
|
call codes_grib_new_from_file(ifile,igrib(i), iret)
|
||||||
END DO
|
END DO
|
||||||
|
|
||||||
! we can close the file
|
! we can close the file
|
||||||
|
@ -46,59 +46,59 @@ program get
|
||||||
|
|
||||||
! Loop on all the messages in memory
|
! Loop on all the messages in memory
|
||||||
DO i=1,n
|
DO i=1,n
|
||||||
write(*,*) 'processing message number ',i
|
write(*,*) 'processing message number ',i
|
||||||
! get as a integer
|
! get as a integer
|
||||||
call codes_get(igrib(i),'Ni',numberOfPointsAlongAParallel)
|
call codes_get(igrib(i),'Ni',numberOfPointsAlongAParallel)
|
||||||
write(*,*) 'numberOfPointsAlongAParallel=', &
|
write(*,*) 'numberOfPointsAlongAParallel=', &
|
||||||
numberOfPointsAlongAParallel
|
numberOfPointsAlongAParallel
|
||||||
|
|
||||||
! get as a integer
|
! get as a integer
|
||||||
call codes_get(igrib(i),'Nj',numberOfPointsAlongAMeridian)
|
call codes_get(igrib(i),'Nj',numberOfPointsAlongAMeridian)
|
||||||
write(*,*) 'numberOfPointsAlongAMeridian=', &
|
write(*,*) 'numberOfPointsAlongAMeridian=', &
|
||||||
numberOfPointsAlongAMeridian
|
numberOfPointsAlongAMeridian
|
||||||
|
|
||||||
! get as a real
|
! get as a real
|
||||||
call codes_get(igrib(i), 'latitudeOfFirstGridPointInDegrees', &
|
call codes_get(igrib(i), 'latitudeOfFirstGridPointInDegrees', &
|
||||||
latitudeOfFirstPointInDegrees)
|
latitudeOfFirstPointInDegrees)
|
||||||
write(*,*) 'latitudeOfFirstGridPointInDegrees=', &
|
write(*,*) 'latitudeOfFirstGridPointInDegrees=', &
|
||||||
latitudeOfFirstPointInDegrees
|
latitudeOfFirstPointInDegrees
|
||||||
|
|
||||||
! get as a real
|
! get as a real
|
||||||
call codes_get(igrib(i), 'longitudeOfFirstGridPointInDegrees', &
|
call codes_get(igrib(i), 'longitudeOfFirstGridPointInDegrees', &
|
||||||
longitudeOfFirstPointInDegrees)
|
longitudeOfFirstPointInDegrees)
|
||||||
write(*,*) 'longitudeOfFirstGridPointInDegrees=', &
|
write(*,*) 'longitudeOfFirstGridPointInDegrees=', &
|
||||||
longitudeOfFirstPointInDegrees
|
longitudeOfFirstPointInDegrees
|
||||||
|
|
||||||
! get as a real
|
! get as a real
|
||||||
call codes_get(igrib(i), 'latitudeOfLastGridPointInDegrees', &
|
call codes_get(igrib(i), 'latitudeOfLastGridPointInDegrees', &
|
||||||
latitudeOfLastPointInDegrees)
|
latitudeOfLastPointInDegrees)
|
||||||
write(*,*) 'latitudeOfLastGridPointInDegrees=', &
|
write(*,*) 'latitudeOfLastGridPointInDegrees=', &
|
||||||
latitudeOfLastPointInDegrees
|
latitudeOfLastPointInDegrees
|
||||||
|
|
||||||
! get as a real
|
! get as a real
|
||||||
call codes_get(igrib(i), 'longitudeOfLastGridPointInDegrees', &
|
call codes_get(igrib(i), 'longitudeOfLastGridPointInDegrees', &
|
||||||
longitudeOfLastPointInDegrees)
|
longitudeOfLastPointInDegrees)
|
||||||
write(*,*) 'longitudeOfLastGridPointInDegrees=', &
|
write(*,*) 'longitudeOfLastGridPointInDegrees=', &
|
||||||
longitudeOfLastPointInDegrees
|
longitudeOfLastPointInDegrees
|
||||||
|
|
||||||
|
|
||||||
! get the size of the values array
|
! get the size of the values array
|
||||||
call codes_get_size(igrib(i),'values',numberOfValues)
|
call codes_get_size(igrib(i),'values',numberOfValues)
|
||||||
write(*,*) 'numberOfValues=',numberOfValues
|
write(*,*) 'numberOfValues=',numberOfValues
|
||||||
|
|
||||||
allocate(values(numberOfValues), stat=iret)
|
allocate(values(numberOfValues), stat=iret)
|
||||||
! get data values
|
! get data values
|
||||||
call codes_get(igrib(i),'values',values)
|
call codes_get(igrib(i),'values',values)
|
||||||
call codes_get(igrib(i),'min',min_val) ! can also be obtained through minval(values)
|
call codes_get(igrib(i),'min',min_val) ! can also be obtained through minval(values)
|
||||||
call codes_get(igrib(i),'max',max_val) ! can also be obtained through maxval(values)
|
call codes_get(igrib(i),'max',max_val) ! can also be obtained through maxval(values)
|
||||||
call codes_get(igrib(i),'average',average) ! can also be obtained through maxval(values)
|
call codes_get(igrib(i),'average',average) ! can also be obtained through maxval(values)
|
||||||
|
|
||||||
write(*,*)'There are ',numberOfValues, &
|
write(*,*)'There are ',numberOfValues, &
|
||||||
' average is ',average, &
|
' average is ',average, &
|
||||||
' min is ', min_val, &
|
' min is ', min_val, &
|
||||||
' max is ', max_val
|
' max is ', max_val
|
||||||
write(*,*) '---------------------'
|
write(*,*) '---------------------'
|
||||||
deallocate(values)
|
deallocate(values)
|
||||||
END DO
|
END DO
|
||||||
|
|
||||||
DO i=1,n
|
DO i=1,n
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
! Copyright 2005-2016 ECMWF.
|
||||||
|
!
|
||||||
|
! This software is licensed under the terms of the Apache Licence Version 2.0
|
||||||
|
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
!
|
||||||
|
! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
||||||
|
! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||||
|
!
|
||||||
|
! Description: count messages in a file with GRIB2 multi-field messages
|
||||||
|
!
|
||||||
|
!
|
||||||
|
program grib_count_messages_multi
|
||||||
|
use eccodes
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
integer :: ifile
|
||||||
|
character(len=100) :: grib_file
|
||||||
|
integer :: n,stat
|
||||||
|
character(len=1) :: multi_flag
|
||||||
|
|
||||||
|
call getarg(1,multi_flag)
|
||||||
|
call getarg(2,grib_file)
|
||||||
|
|
||||||
|
if (multi_flag/="0") call codes_grib_multi_support_on()
|
||||||
|
|
||||||
|
call codes_open_file(ifile,grib_file,'r')
|
||||||
|
|
||||||
|
! count the messages in the file
|
||||||
|
call codes_count_in_file(ifile,n,stat)
|
||||||
|
|
||||||
|
print *,n
|
||||||
|
|
||||||
|
call codes_close_file(ifile)
|
||||||
|
end program grib_count_messages_multi
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright 2005-2016 ECMWF.
|
||||||
|
#
|
||||||
|
# This software is licensed under the terms of the Apache Licence Version 2.0
|
||||||
|
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
#
|
||||||
|
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
||||||
|
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||||
|
|
||||||
|
. ./include.sh
|
||||||
|
|
||||||
|
INPUT="../../data/multi.grib2"
|
||||||
|
|
||||||
|
# Without multi-field support
|
||||||
|
c=`${examples_dir}eccodes_f_grib_count_messages_multi 0 $INPUT | tr -d ' '`
|
||||||
|
[ "$c" = "30" ]
|
||||||
|
|
||||||
|
# With multi-field support (more messages should be counted)
|
||||||
|
c=`${examples_dir}eccodes_f_grib_count_messages_multi 1 $INPUT | tr -d ' '`
|
||||||
|
[ "$c" = "56" ]
|
484
src/grib_io.c
484
src/grib_io.c
|
@ -724,7 +724,7 @@ static int read_BUFR(reader *r)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_any(reader *r,int grib_ok,int bufr_ok, int hdf5_ok, int wrap_ok)
|
static int read_any(reader *r, int grib_ok, int bufr_ok, int hdf5_ok, int wrap_ok)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -857,101 +857,101 @@ static int read_any_gts(reader *r)
|
||||||
|
|
||||||
static int read_any_taf(reader *r)
|
static int read_any_taf(reader *r)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
unsigned char* buffer=NULL;
|
unsigned char* buffer=NULL;
|
||||||
unsigned long magic = 0;
|
unsigned long magic = 0;
|
||||||
unsigned long start = 0x54414620;
|
unsigned long start = 0x54414620;
|
||||||
unsigned char tmp[1000]={0,}; /* Should be enough */
|
unsigned char tmp[1000]={0,}; /* Should be enough */
|
||||||
size_t message_size=0;
|
size_t message_size=0;
|
||||||
size_t already_read=0;
|
size_t already_read=0;
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0)
|
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0)
|
||||||
{
|
{
|
||||||
magic <<= 8;
|
magic <<= 8;
|
||||||
magic |= c;
|
magic |= c;
|
||||||
magic &= 0xffffffff;
|
magic &= 0xffffffff;
|
||||||
|
|
||||||
if (magic == start) {
|
if (magic == start) {
|
||||||
tmp[i++]=0x54;
|
tmp[i++]=0x54;
|
||||||
tmp[i++]=0x41;
|
tmp[i++]=0x41;
|
||||||
tmp[i++]=0x46;
|
tmp[i++]=0x46;
|
||||||
tmp[i++]=0x20;
|
tmp[i++]=0x20;
|
||||||
|
|
||||||
r->offset=r->tell(r->read_data)-4;
|
r->offset=r->tell(r->read_data)-4;
|
||||||
|
|
||||||
already_read=4;
|
already_read=4;
|
||||||
message_size=already_read;
|
message_size=already_read;
|
||||||
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0) {
|
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0) {
|
||||||
message_size++;
|
message_size++;
|
||||||
if (c == '=') {
|
if (c == '=') {
|
||||||
r->seek(r->read_data,already_read-message_size);
|
r->seek(r->read_data,already_read-message_size);
|
||||||
buffer = (unsigned char*)r->alloc(r->alloc_data,&message_size,&err);
|
buffer = (unsigned char*)r->alloc(r->alloc_data,&message_size,&err);
|
||||||
if (!buffer) return GRIB_OUT_OF_MEMORY;
|
if (!buffer) return GRIB_OUT_OF_MEMORY;
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
memcpy(buffer,tmp,already_read);
|
memcpy(buffer,tmp,already_read);
|
||||||
r->read(r->read_data,buffer+already_read,message_size-already_read,&err);
|
r->read(r->read_data,buffer+already_read,message_size-already_read,&err);
|
||||||
r->message_size=message_size;
|
r->message_size=message_size;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_any_metar(reader *r)
|
static int read_any_metar(reader *r)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
unsigned char* buffer=NULL;
|
unsigned char* buffer=NULL;
|
||||||
unsigned long magic = 0;
|
unsigned long magic = 0;
|
||||||
unsigned long start = 0x4d455441;
|
unsigned long start = 0x4d455441;
|
||||||
unsigned char tmp[32]={0,}; /* Should be enough */
|
unsigned char tmp[32]={0,}; /* Should be enough */
|
||||||
size_t message_size=0;
|
size_t message_size=0;
|
||||||
size_t already_read=0;
|
size_t already_read=0;
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0)
|
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0)
|
||||||
{
|
{
|
||||||
magic <<= 8;
|
magic <<= 8;
|
||||||
magic |= c;
|
magic |= c;
|
||||||
magic &= 0xffffffff;
|
magic &= 0xffffffff;
|
||||||
|
|
||||||
if (magic == start) {
|
if (magic == start) {
|
||||||
if (r->read(r->read_data,&c,1,&err) != 1 || err!=0)
|
if (r->read(r->read_data,&c,1,&err) != 1 || err!=0)
|
||||||
break;
|
break;
|
||||||
if (c == 'R' ) {
|
if (c == 'R' ) {
|
||||||
tmp[i++]=0x4d;
|
tmp[i++]=0x4d;
|
||||||
tmp[i++]=0x45;
|
tmp[i++]=0x45;
|
||||||
tmp[i++]=0x54;
|
tmp[i++]=0x54;
|
||||||
tmp[i++]=0x41;
|
tmp[i++]=0x41;
|
||||||
tmp[i++]='R';
|
tmp[i++]='R';
|
||||||
|
|
||||||
r->offset=r->tell(r->read_data)-4;
|
r->offset=r->tell(r->read_data)-4;
|
||||||
|
|
||||||
already_read=5;
|
already_read=5;
|
||||||
message_size=already_read;
|
message_size=already_read;
|
||||||
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0) {
|
while(r->read(r->read_data,&c,1,&err) == 1 && err == 0) {
|
||||||
message_size++;
|
message_size++;
|
||||||
if (c == '=') {
|
if (c == '=') {
|
||||||
r->seek(r->read_data,already_read-message_size);
|
r->seek(r->read_data,already_read-message_size);
|
||||||
buffer = (unsigned char*)r->alloc(r->alloc_data,&message_size,&err);
|
buffer = (unsigned char*)r->alloc(r->alloc_data,&message_size,&err);
|
||||||
if (!buffer) return GRIB_OUT_OF_MEMORY;
|
if (!buffer) return GRIB_OUT_OF_MEMORY;
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
memcpy(buffer,tmp,already_read);
|
memcpy(buffer,tmp,already_read);
|
||||||
r->read(r->read_data,buffer+already_read,message_size-already_read,&err);
|
r->read(r->read_data,buffer+already_read,message_size-already_read,&err);
|
||||||
r->message_size=message_size;
|
r->message_size=message_size;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t stdio_tell(void* data)
|
off_t stdio_tell(void* data)
|
||||||
|
@ -1019,15 +1019,15 @@ int _wmo_read_any_from_file(FILE* f,void* buffer,size_t* len,int grib_ok,int buf
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any(&r, grib_ok, bufr_ok, hdf5_ok, wrap_ok);
|
err = read_any(&r, grib_ok, bufr_ok, hdf5_ok, wrap_ok);
|
||||||
*len = r.message_size;
|
*len = r.message_size;
|
||||||
|
@ -1037,7 +1037,7 @@ int _wmo_read_any_from_file(FILE* f,void* buffer,size_t* len,int grib_ok,int buf
|
||||||
|
|
||||||
int wmo_read_any_from_file(FILE* f,void* buffer,size_t* len)
|
int wmo_read_any_from_file(FILE* f,void* buffer,size_t* len)
|
||||||
{
|
{
|
||||||
return _wmo_read_any_from_file(f, buffer, len, 1, 1, 1 ,1);
|
return _wmo_read_any_from_file(f, buffer, len, 1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wmo_read_grib_from_file(FILE* f,void* buffer,size_t* len)
|
int wmo_read_grib_from_file(FILE* f,void* buffer,size_t* len)
|
||||||
|
@ -1059,15 +1059,15 @@ int wmo_read_gts_from_file(FILE* f,void* buffer,size_t* len)
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any_gts(&r);
|
err = read_any_gts(&r);
|
||||||
*len = r.message_size;
|
*len = r.message_size;
|
||||||
|
@ -1077,50 +1077,50 @@ int wmo_read_gts_from_file(FILE* f,void* buffer,size_t* len)
|
||||||
|
|
||||||
int wmo_read_taf_from_file(FILE* f,void* buffer,size_t* len)
|
int wmo_read_taf_from_file(FILE* f,void* buffer,size_t* len)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
user_buffer u;
|
user_buffer u;
|
||||||
reader r;
|
reader r;
|
||||||
|
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any_taf(&r);
|
err = read_any_taf(&r);
|
||||||
*len = r.message_size;
|
*len = r.message_size;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wmo_read_metar_from_file(FILE* f,void* buffer,size_t* len)
|
int wmo_read_metar_from_file(FILE* f,void* buffer,size_t* len)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
user_buffer u;
|
user_buffer u;
|
||||||
reader r;
|
reader r;
|
||||||
|
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start= &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any_metar(&r);
|
err = read_any_metar(&r);
|
||||||
*len = r.message_size;
|
*len = r.message_size;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================== */
|
/*================== */
|
||||||
|
@ -1173,15 +1173,15 @@ int wmo_read_any_from_stream(void* stream_data,long (*stream_proc)(void*,void* b
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = &s;
|
r.read_data = &s;
|
||||||
r.read = &stream_read;
|
r.read = &stream_read;
|
||||||
r.seek = &stream_seek;
|
r.seek = &stream_seek;
|
||||||
r.seek_from_start= &stream_seek;
|
r.seek_from_start = &stream_seek;
|
||||||
r.tell = &stream_tell;
|
r.tell = &stream_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any(&r, 1, 1, 1, 1);
|
err = read_any(&r, 1, 1, 1, 1);
|
||||||
*len = r.message_size;
|
*len = r.message_size;
|
||||||
|
@ -1209,15 +1209,15 @@ void *wmo_read_gts_from_file_malloc(FILE* f,int headers_only,size_t *size,off_t
|
||||||
u.buffer = NULL;
|
u.buffer = NULL;
|
||||||
r.offset = 0;
|
r.offset = 0;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start= &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &allocate_buffer;
|
r.alloc = &allocate_buffer;
|
||||||
r.headers_only = headers_only;
|
r.headers_only = headers_only;
|
||||||
|
|
||||||
*err = read_any_gts(&r);
|
*err = read_any_gts(&r);
|
||||||
*size = r.message_size;
|
*size = r.message_size;
|
||||||
|
@ -1228,48 +1228,48 @@ void *wmo_read_gts_from_file_malloc(FILE* f,int headers_only,size_t *size,off_t
|
||||||
|
|
||||||
void *wmo_read_taf_from_file_malloc(FILE* f,int headers_only,size_t *size,off_t *offset,int* err)
|
void *wmo_read_taf_from_file_malloc(FILE* f,int headers_only,size_t *size,off_t *offset,int* err)
|
||||||
{
|
{
|
||||||
alloc_buffer u;
|
alloc_buffer u;
|
||||||
reader r;
|
reader r;
|
||||||
|
|
||||||
u.buffer = NULL;
|
u.buffer = NULL;
|
||||||
|
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &allocate_buffer;
|
r.alloc = &allocate_buffer;
|
||||||
r.headers_only = headers_only;
|
r.headers_only = headers_only;
|
||||||
|
|
||||||
*err = read_any_taf(&r);
|
|
||||||
*size = r.message_size;
|
|
||||||
*offset = r.offset;
|
|
||||||
|
|
||||||
return u.buffer;
|
*err = read_any_taf(&r);
|
||||||
|
*size = r.message_size;
|
||||||
|
*offset = r.offset;
|
||||||
|
|
||||||
|
return u.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *wmo_read_metar_from_file_malloc(FILE* f,int headers_only,size_t *size,off_t *offset,int* err)
|
void *wmo_read_metar_from_file_malloc(FILE* f,int headers_only,size_t *size,off_t *offset,int* err)
|
||||||
{
|
{
|
||||||
alloc_buffer u;
|
alloc_buffer u;
|
||||||
reader r;
|
reader r;
|
||||||
|
|
||||||
u.buffer = NULL;
|
u.buffer = NULL;
|
||||||
|
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &allocate_buffer;
|
r.alloc = &allocate_buffer;
|
||||||
r.headers_only = headers_only;
|
r.headers_only = headers_only;
|
||||||
|
|
||||||
*err = read_any_metar(&r);
|
|
||||||
*size = r.message_size;
|
|
||||||
*offset = r.offset;
|
|
||||||
|
|
||||||
return u.buffer;
|
*err = read_any_metar(&r);
|
||||||
|
*size = r.message_size;
|
||||||
|
*offset = r.offset;
|
||||||
|
|
||||||
|
return u.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *_wmo_read_any_from_file_malloc(FILE* f,int* err,size_t *size,off_t *offset,
|
static void *_wmo_read_any_from_file_malloc(FILE* f,int* err,size_t *size,off_t *offset,
|
||||||
|
@ -1281,16 +1281,16 @@ static void *_wmo_read_any_from_file_malloc(FILE* f,int* err,size_t *size,off_t
|
||||||
u.buffer = NULL;
|
u.buffer = NULL;
|
||||||
u.size = 0;
|
u.size = 0;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &allocate_buffer;
|
r.alloc = &allocate_buffer;
|
||||||
r.headers_only = headers_only;
|
r.headers_only = headers_only;
|
||||||
r.offset = 0;
|
r.offset = 0;
|
||||||
|
|
||||||
*err = read_any(&r, grib_ok, bufr_ok, hdf5_ok, wrap_ok);
|
*err = read_any(&r, grib_ok, bufr_ok, hdf5_ok, wrap_ok);
|
||||||
*size = r.message_size;
|
*size = r.message_size;
|
||||||
|
@ -1343,15 +1343,15 @@ int grib_read_any_headers_only_from_file(grib_context* ctx,FILE* f,void* buffer,
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 1;
|
r.headers_only = 1;
|
||||||
|
|
||||||
err = read_any(&r, 1, GRIB_API_READS_BUFR, GRIB_API_READS_HDF5, GRIB_API_READS_WRAP);
|
err = read_any(&r, 1, GRIB_API_READS_BUFR, GRIB_API_READS_HDF5, GRIB_API_READS_WRAP);
|
||||||
|
|
||||||
|
@ -1370,15 +1370,15 @@ int grib_read_any_from_file(grib_context* ctx,FILE* f,void* buffer,size_t* len)
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = f;
|
r.read_data = f;
|
||||||
r.read = &stdio_read;
|
r.read = &stdio_read;
|
||||||
r.seek = &stdio_seek;
|
r.seek = &stdio_seek;
|
||||||
r.seek_from_start = &stdio_seek_from_start;
|
r.seek_from_start = &stdio_seek_from_start;
|
||||||
r.tell = &stdio_tell;
|
r.tell = &stdio_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
offset=ftello(f);
|
offset=ftello(f);
|
||||||
|
|
||||||
|
@ -1443,15 +1443,15 @@ int grib_read_any_from_memory_alloc(grib_context* ctx,unsigned char** data,size_
|
||||||
u.length = 0;
|
u.length = 0;
|
||||||
u.ctx = ctx ? ctx : grib_context_get_default();
|
u.ctx = ctx ? ctx : grib_context_get_default();
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = &m;
|
r.read_data = &m;
|
||||||
r.read = &memory_read;
|
r.read = &memory_read;
|
||||||
r.seek = &memory_seek;
|
r.seek = &memory_seek;
|
||||||
r.seek_from_start = &memory_seek;
|
r.seek_from_start = &memory_seek;
|
||||||
r.tell = &memory_tell;
|
r.tell = &memory_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &context_allocate_buffer;
|
r.alloc = &context_allocate_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any(&r, 1, GRIB_API_READS_BUFR, GRIB_API_READS_HDF5, GRIB_API_READS_WRAP);
|
err = read_any(&r, 1, GRIB_API_READS_BUFR, GRIB_API_READS_HDF5, GRIB_API_READS_WRAP);
|
||||||
*buffer = u.buffer;
|
*buffer = u.buffer;
|
||||||
|
@ -1476,15 +1476,15 @@ int grib_read_any_from_memory(grib_context* ctx,unsigned char** data,size_t* dat
|
||||||
u.user_buffer = buffer;
|
u.user_buffer = buffer;
|
||||||
u.buffer_size = *len;
|
u.buffer_size = *len;
|
||||||
|
|
||||||
r.message_size = 0;
|
r.message_size = 0;
|
||||||
r.read_data = &m;
|
r.read_data = &m;
|
||||||
r.read = &memory_read;
|
r.read = &memory_read;
|
||||||
r.seek = &memory_seek;
|
r.seek = &memory_seek;
|
||||||
r.seek_from_start = &memory_seek;
|
r.seek_from_start = &memory_seek;
|
||||||
r.tell = &memory_tell;
|
r.tell = &memory_tell;
|
||||||
r.alloc_data = &u;
|
r.alloc_data = &u;
|
||||||
r.alloc = &user_provider_buffer;
|
r.alloc = &user_provider_buffer;
|
||||||
r.headers_only = 0;
|
r.headers_only = 0;
|
||||||
|
|
||||||
err = read_any(&r, 1, GRIB_API_READS_BUFR, GRIB_API_READS_HDF5, GRIB_API_READS_WRAP);
|
err = read_any(&r, 1, GRIB_API_READS_BUFR, GRIB_API_READS_HDF5, GRIB_API_READS_WRAP);
|
||||||
*len = r.message_size;
|
*len = r.message_size;
|
||||||
|
@ -1492,25 +1492,37 @@ int grib_read_any_from_memory(grib_context* ctx,unsigned char** data,size_t* dat
|
||||||
*data_length = m.data_len;
|
*data_length = m.data_len;
|
||||||
*data = m.data;
|
*data = m.data;
|
||||||
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int grib_count_in_file(grib_context* c, FILE* f,int* n)
|
int grib_count_in_file(grib_context* c, FILE* f,int* n)
|
||||||
{
|
{
|
||||||
int err=0;
|
int err=0;
|
||||||
void* mesg=NULL;
|
|
||||||
size_t size=0;
|
|
||||||
off_t offset=0;
|
|
||||||
*n=0;
|
*n=0;
|
||||||
if (!c) c=grib_context_get_default();
|
if (!c) c=grib_context_get_default();
|
||||||
|
|
||||||
while ( (mesg=wmo_read_any_from_file_malloc ( f,0, &size,&offset,&err))!=NULL && err==GRIB_SUCCESS) {
|
if ( c->multi_support_on )
|
||||||
grib_context_free(c,mesg);
|
{
|
||||||
(*n)++;
|
/* GRIB-395 */
|
||||||
|
grib_handle* h=NULL;
|
||||||
|
while ((h=grib_handle_new_from_file(c, f , &err))!=NULL) {
|
||||||
|
grib_handle_delete(h);
|
||||||
|
(*n)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
void* mesg=NULL;
|
||||||
|
size_t size=0;
|
||||||
|
off_t offset=0;
|
||||||
|
while ( (mesg=wmo_read_any_from_file_malloc ( f,0, &size,&offset,&err))!=NULL && err==GRIB_SUCCESS) {
|
||||||
|
grib_context_free(c,mesg);
|
||||||
|
(*n)++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rewind(f);
|
rewind(f);
|
||||||
|
|
||||||
return err==GRIB_END_OF_FILE ? 0 : err;
|
return err==GRIB_END_OF_FILE ? 0 : err;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue