From f859cd51cc942a01174f64becf88dcc52f191403 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 3 Jul 2013 18:48:15 +0100 Subject: [PATCH] GRIB-292: added test case --- examples/F90/Makefile.am | 2 +- examples/F90/read_from_file.f90 | 85 +++++++++++++++++++++++++-------- examples/F90/read_from_file.sh | 16 +++++++ 3 files changed, 82 insertions(+), 21 deletions(-) create mode 100755 examples/F90/read_from_file.sh diff --git a/examples/F90/Makefile.am b/examples/F90/Makefile.am index 9d592b7e9..8f2925ea6 100644 --- a/examples/F90/Makefile.am +++ b/examples/F90/Makefile.am @@ -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 \ 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 \ multi_write multi nearest precision print_data set set_bitmap set_missing \ diff --git a/examples/F90/read_from_file.f90 b/examples/F90/read_from_file.f90 index ed1fcb18a..6e8cbd6ae 100644 --- a/examples/F90/read_from_file.f90 +++ b/examples/F90/read_from_file.f90 @@ -6,47 +6,92 @@ ! 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. ! -! +! Get message lengths using two different interfaces +! See GRIB-292 ! program read_from_file 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 integer :: size,intsize parameter (intsize=5000000,size=intsize*4) integer :: ifile integer :: iret - integer :: count1=0 - character(len=256) :: filename + integer :: count1=0 integer(kind=4),dimension(intsize) :: buffer - !character,dimension(size) :: buffer - integer(kind=kindOfSize_t) :: len1 - -! Message identifier. - integer :: igrib + integer(kind=kindOfSize_t) :: len1 ! For large messages ifile=5 - - call grib_open_file(ifile,'../../data/collection.grib1','r') - -! Loop on all the messages in a file. + call grib_open_file(ifile, input_grib_file, 'r') len1=size - call grib_read_from_file(ifile,buffer,len1,iret) - ! call grib_new_from_file(ifile,igrib, iret) + call grib_read_from_file(ifile, buffer, len1, iret) do while (iret==GRIB_SUCCESS) 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 - call grib_read_from_file(ifile,buffer,len1,iret) - ! call grib_new_from_file(ifile,igrib, iret) - + 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 - + endif 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 diff --git a/examples/F90/read_from_file.sh b/examples/F90/read_from_file.sh new file mode 100755 index 000000000..aaa6b6e0a --- /dev/null +++ b/examples/F90/read_from_file.sh @@ -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