src/grib_accessor_class_bufr_extract_datetime_subsets.c
/* Helper function to construct the array of long for year, month, day etc. */
/* The boolean zero_on_error flag is for the case where codes_get fails and we fill with zeros */
Helper function to construct the array of long for year, month, day etc.
The boolean zero_on_error flag is for the case where codes_get fails and we fill with zeros
Helper function to construct the array of long for year month day etc . The boolean zero_on_error flag is for the case where codes_get fails and we fill with zeros
static int build_long_array(grib_context* c, grib_handle* h, int compressed,
                            long** array, const char* key, long numberOfSubsets, int zero_on_error)
{
    int err = 0;
    long i;
    size_t n = numberOfSubsets;
    *array   = (long*)grib_context_malloc_clear(c, sizeof(long) * numberOfSubsets);
    if (compressed) {
        err = grib_get_long_array(h, key, *array, &n);
        if (zero_on_error) {
            if (err) {
                err         = 0;
                (*array)[0] = 0;
                n           = 1;
            }
        }
        if (err)
            return err;
        if (n != numberOfSubsets) {
            if (n == 1) {
                for (i = 1; i < numberOfSubsets; i++)
                    (*array)[i] = (*array)[0];
            }
            else {
                return GRIB_INTERNAL_ERROR;
            }
        }
    }
    else {
        char keystr[32] = {0,};
        size_t values_len = 0;
        for (i = 0; i < numberOfSubsets; ++i) {
            long lVal = 0;
            sprintf(keystr, "#%ld#%s", i + 1, key);
            err = grib_get_size(h, keystr, &values_len);
            if (err)
                return err;
            if (values_len > 1)
                return GRIB_NOT_IMPLEMENTED;
            err = grib_get_long(h, keystr, &lVal);
            if (err)
                return err;
            (*array)[i] = lVal;
        }
    }
    return err;
}
static int build_long_array ( grib_context * c , grib_handle * h , int compressed , long * * array , const char * key , long numberOfSubsets , int zero_on_error ) { int err = 0 ; long i ; size_t n = numberOfSubsets ; * array = ( long * ) grib_context_malloc_clear ( c , sizeof ( long ) * numberOfSubsets ) ; if ( compressed ) { err = grib_get_long_array ( h , key , * array , & n ) ; if ( zero_on_error ) { if ( err ) { err = 0 ; ( * array ) [ 0 ] = 0 ; n = 1 ; } } if ( err ) return err ; if ( n != numberOfSubsets ) { if ( n == 1 ) { for ( i = 1 ; i < numberOfSubsets ; i ++ ) ( * array ) [ i ] = ( * array ) [ 0 ] ; } else { return GRIB_INTERNAL_ERROR ; } } } else { char keystr [ 32 ] = { 0 , } ; size_t values_len = 0 ; for ( i = 0 ; i < numberOfSubsets ; ++ i ) { long lVal = 0 ; sprintf ( keystr , " " , i + 1 , key ) ; err = grib_get_size ( h , keystr , & values_len ) ; if ( err ) return err ; if ( values_len > 1 ) return GRIB_NOT_IMPLEMENTED ; err = grib_get_long ( h , keystr , & lVal ) ; if ( err ) return err ; ( * array ) [ i ] = lVal ; } } return err ; }
Helper function to construct the array of long for year, month, day etc.
Helper function to construct the array of long for year month day etc .
/* uncompressed */