#!/usr/bin/env python
#
# Data Quality Checker also known as DQC
#
# Read the README.md for more detailed information
#
#       Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
#       Earth Sciences Department - Computational Earth Sciences
#     
#     Authors: 
#       Joan Sala Calero (joan.sala@bsc.es)
#       Ivan Jose Cernicharo Ortiz (ivan.cernicharo@bsc.es)

import eccodes as ecc
import os

class grib_content:
    """grib_content object class is intented to be a content
    manager for GRIB files
    """
    def __init__(self, filename):
        self.name = filename
        self.grib_msgs = self.return_all_msg()
        self.pname = os.path.basename(filename)
        self.log = ''

    def return_all_msg(self):
        # This funtion returns all messages within a GRIB file
        all_mssg = list()
        content =  ecc.GribFile(self.name)
        
        for i in range(len(content)):
            all_mssg.append(ecc.GribMessage(content))
        content = None
        
        return all_mssg
