GRIB-292: added test case

This commit is contained in:
Shahram Najm 2013-07-03 18:48:15 +01:00
parent e010ba538b
commit f859cd51cc
3 changed files with 82 additions and 21 deletions

View File

@ -3,7 +3,7 @@ AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@ @FORCE_32_CFLAGS@
TESTS = copy_message.sh get.sh get_data.sh get_pl.sh get_pv.sh keys_iterator.sh \ TESTS = copy_message.sh get.sh get_data.sh get_pl.sh get_pv.sh keys_iterator.sh \
nearest.sh precision.sh multi_write.sh multi.sh print_data.sh set.sh set_bitmap.sh set_missing.sh \ nearest.sh precision.sh multi_write.sh multi.sh print_data.sh set.sh set_bitmap.sh set_missing.sh \
set_pv.sh samples.sh count_messages.sh read_message.sh index.sh get_set_uuid.sh set_pv.sh samples.sh count_messages.sh read_message.sh read_from_file.sh index.sh get_set_uuid.sh
noinst_PROGRAMS = index copy_message get get_data get_pl get_pv keys_iterator \ noinst_PROGRAMS = index copy_message get get_data get_pl get_pv keys_iterator \
multi_write multi nearest precision print_data set set_bitmap set_missing \ multi_write multi nearest precision print_data set set_bitmap set_missing \

View File

@ -6,47 +6,92 @@
! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by ! 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. ! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
! !
! ! Get message lengths using two different interfaces
! See GRIB-292
! !
program read_from_file program read_from_file
use grib_api use grib_api
implicit none
character(len=32) :: input_grib_file
integer,dimension(26) :: message_lengths ! expected message lengths
input_grib_file = '../../data/v.grib2'
message_lengths = (/ 95917, 96963, 97308, 97386, 97215, 97440, 98451, 98629, 98448, &
99186, 97517, 97466, 99307, 98460,101491, 99361,100292, 96838, &
91093, 83247, 78244, 74872, 72663, 69305, 69881, 68572 /)
! Get the grib message length using two different interfaces
call read_using_size_t()
call read_using_integer()
print *,'Passed'
contains
!======================================
subroutine read_using_size_t
implicit none implicit none
integer :: size,intsize integer :: size,intsize
parameter (intsize=5000000,size=intsize*4) parameter (intsize=5000000,size=intsize*4)
integer :: ifile integer :: ifile
integer :: iret integer :: iret
integer :: count1=0 integer :: count1=0
character(len=256) :: filename
integer(kind=4),dimension(intsize) :: buffer integer(kind=4),dimension(intsize) :: buffer
!character,dimension(size) :: buffer integer(kind=kindOfSize_t) :: len1 ! For large messages
integer(kind=kindOfSize_t) :: len1
! Message identifier.
integer :: igrib
ifile=5 ifile=5
call grib_open_file(ifile, input_grib_file, 'r')
call grib_open_file(ifile,'../../data/collection.grib1','r')
! Loop on all the messages in a file.
len1=size len1=size
call grib_read_from_file(ifile,buffer,len1,iret) call grib_read_from_file(ifile, buffer, len1, iret)
! call grib_new_from_file(ifile,igrib, iret)
do while (iret==GRIB_SUCCESS) do while (iret==GRIB_SUCCESS)
count1=count1+1 count1=count1+1
print *, '===== Message #',count1,' len=',len1 if (len1 /= message_lengths(count1)) then
write(*,'(a,i3,a,i8,a,i8)') 'Error: Message #',count1,' length=', len1,'. Expected=',message_lengths(count1)
stop
end if
len1=size len1=size
call grib_read_from_file(ifile,buffer,len1,iret) call grib_read_from_file(ifile, buffer, len1, iret)
! call grib_new_from_file(ifile,igrib, iret)
end do end do
if (iret/=GRIB_END_OF_FILE) then if (iret/=GRIB_END_OF_FILE) then
call grib_check(iret,'read_from_file','') call grib_check(iret,'read_from_file','')
endif endif
call grib_close_file(ifile) call grib_close_file(ifile)
end subroutine read_using_size_t
!======================================
subroutine read_using_integer
implicit none
integer :: size,intsize
parameter (intsize=5000000,size=intsize*4)
integer :: ifile
integer :: iret
integer :: count1=0
integer(kind=4),dimension(intsize) :: buffer
integer :: len1
ifile=5
call grib_open_file(ifile, input_grib_file, 'r')
len1=size
call grib_read_from_file(ifile, buffer, len1, iret)
do while (iret==GRIB_SUCCESS)
count1=count1+1
if (len1 /= message_lengths(count1)) then
write(*,'(a,i3,a,i8,a,i8)') 'Error: Message #',count1,' length=', len1,'. Expected=',message_lengths(count1)
stop
end if
len1=size
call grib_read_from_file(ifile, buffer, len1, iret)
end do
if (iret/=GRIB_END_OF_FILE) then
call grib_check(iret,'read_from_file','')
endif
call grib_close_file(ifile)
end subroutine read_using_integer
!======================================
end program end program

16
examples/F90/read_from_file.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
# Copyright 2005-2013 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
#
# Check program completed successfully. We have to resort to testing
# the output as there is no way in Fortran to set the exit code
#
${examples_dir}read_from_file | grep 'Passed' >/dev/null