1 /**
2 * Copyright 1981-2016 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence
5 * Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 *
7 * In applying this licence, ECMWF does not waive the privileges and immunities
8 * granted to it by virtue of its status as an intergovernmental organisation
9 * nor does it submit to any jurisdiction.
10 */
11
12 /*
13 readgrib.c
14 */
15 #include "bufrgrib.h"
16 #include "common/fortint.h"
17
18 #include "fileRead.h"
19
20 #include "sizeRoutines.h"
21
22
readgrib(FILE * file,char * buffer,fortint * grib_prod_len)23 fortint readgrib(FILE * file, char * buffer, fortint * grib_prod_len)
24 /*
25
26 file = file pointer returned from PBOPEN
27
28 buffer = buffer big enough to hold the GRIB product
29
30 grib_prod_len = size of the buffer on input, becomes size in BYTES of
31 the GRIB product read. If the end-of-file is hit, the
32 value is returned unchanged (ie. when the function return
33 code is -1).
34
35 Function returns:
36
37 0 if a GRIB product has been successfully read
38
39 -1 if end-of-file is hit before a GRIB product is read
40
41 -2 if there is an error in the file-handling
42 (eg. if the file contains a truncated GRIB product)
43
44 -3 if the size of buffer is not sufficient for the GRIB product
45
46 */
47 {
48
49 /* Read the GRIB product */
50 fortint length;
51 fortint original_len;
52
53 original_len = *grib_prod_len;
54 length = readprod("GRIB",buffer,&original_len,fileRead,fileSeek,
55 fileTell,file);
56 *grib_prod_len = original_len;
57
58 if ( buffer == NULL )
59 return ( length == -1 ? length : -3 );
60 else
61 return ( length > 0 ? 0 : length );
62
63 }
64