#!/usr/bin/env python
#
# Grib content manager
# When the grib_checker is no longer needed this makes manage GRIB files
# a simple task
# Shorter version of grib content within grib_checker
#
# Barcerlona Supercomputing Center - Centro Nacional de Supercomputacion
#        Earth Sciences Department - Computational Earth Sciences
#     
#     Authors: Ivan Jose Cernicharo Ortiz (ivan.cernicharo@bsc.es)
#             -
#             -
#

import sys

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 = filename.split("/")[-1]
        self.log = ''

    def return_all_msg(self):
        import eccodes as ecc
        # 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))

        return all_mssg

if __name__ == "__main__":
    sys.exit()