blimpy/guppi.py
def read_header(self):
        """ Read next header (multiple headers in file)

        Returns:
            (header, data_idx) - a dictionary of keyword:value header data and
            also the byte index of where the corresponding data block resides.
        """
        start_idx = self.file_obj.tell()
        key, val = '', ''

        header_dict = {}
        keep_reading = True

        first_line = self.file_obj

        try:
            while keep_reading:
                if start_idx + 80 > self.filesize:
                    keep_reading = False
                    raise EndOfFileError("End Of Data File")
                line = self.file_obj.read(80)
                if PYTHON3:
                    line = line.decode("utf-8")
                # print line
                if line.startswith('END'):
                    keep_reading = False
                    break
                else:
                    key, val = line.split('=')
                    key, val = key.strip(), val.strip()

                    if "'" in val:
                        # Items in quotes are strings
                        val = str(val.strip("'").strip())
                    elif "." in val:
                        # Items with periods are floats (if not a string)
                        val = float(val)
                    else:
                        # Otherwise it's an integer
                        val = int(val)

                header_dict[key] = val
        except ValueError:
            print("CURRENT LINE: ", line)
            print("BLOCK START IDX: ", start_idx)
            print("FILE SIZE: ", self.filesize)
            print("NEXT 512 BYTES: \n")
            print(self.file_obj.read(512))
            raise

        data_idx = self.file_obj.tell()

        # Seek past padding if DIRECTIO is being used
        if "DIRECTIO" in header_dict.keys():
            if int(header_dict["DIRECTIO"]) == 1:
                if data_idx % 512:
                    data_idx += (512 - data_idx % 512)

        self.file_obj.seek(start_idx)
        return header_dict, data_idx
def read_header(self):
        """ Read next header (multiple headers in file)

        Returns:
            (header, data_idx) - a dictionary of keyword:value header data and
            also the byte index of where the corresponding data block resides.
        """
        start_idx = self.file_obj.tell()
        key, val = '', ''

        header_dict = {}
        keep_reading = True

        first_line = self.file_obj

        try:
            while keep_reading:
                if start_idx + 80 > self.filesize:
                    keep_reading = False
                    raise EndOfFileError("End Of Data File")
                line = self.file_obj.read(80)
                if PYTHON3:
                    line = line.decode("utf-8")
                # print line
                if line.startswith('END'):
                    keep_reading = False
                    break
                else:
                    key, val = line.split('=')
                    key, val = key.strip(), val.strip()

                    if "'" in val:
                        # Items in quotes are strings
                        val = str(val.strip("'").strip())
                    elif "." in val:
                        # Items with periods are floats (if not a string)
                        val = float(val)
                    else:
                        # Otherwise it's an integer
                        val = int(val)

                header_dict[key] = val
        except ValueError:
            print("CURRENT LINE: ", line)
            print("BLOCK START IDX: ", start_idx)
            print("FILE SIZE: ", self.filesize)
            print("NEXT 512 BYTES: \n")
            print(self.file_obj.read(512))
            raise

        data_idx = self.file_obj.tell()

        # Seek past padding if DIRECTIO is being used
        if "DIRECTIO" in header_dict.keys():
            if int(header_dict["DIRECTIO"]) == 1:
                if data_idx % 512:
                    data_idx += (512 - data_idx % 512)

        self.file_obj.seek(start_idx)
        return header_dict, data_idx
def read_header ( self ) : start_idx = self . file_obj . tell ( ) key , val = '' , '' header_dict = { } keep_reading = True first_line = self . file_obj try : while keep_reading : if start_idx + 80 > self . filesize : keep_reading = False raise EndOfFileError ( "End Of Data File" ) line = self . file_obj . read ( 80 ) if PYTHON3 : line = line . decode ( "utf-8" ) # print line if line . startswith ( 'END' ) : keep_reading = False break else : key , val = line . split ( '=' ) key , val = key . strip ( ) , val . strip ( ) if "'" in val : # Items in quotes are strings val = str ( val . strip ( "'" ) . strip ( ) ) elif "." in val : # Items with periods are floats (if not a string) val = float ( val ) else : # Otherwise it's an integer val = int ( val ) header_dict [ key ] = val except ValueError : print ( "CURRENT LINE: " , line ) print ( "BLOCK START IDX: " , start_idx ) print ( "FILE SIZE: " , self . filesize ) print ( "NEXT 512 BYTES: \n" ) print ( self . file_obj . read ( 512 ) ) raise data_idx = self . file_obj . tell ( ) # Seek past padding if DIRECTIO is being used if "DIRECTIO" in header_dict . keys ( ) : if int ( header_dict [ "DIRECTIO" ] ) == 1 : if data_idx % 512 : data_idx += ( 512 - data_idx % 512 ) self . file_obj . seek ( start_idx ) return header_dict , data_idx
Read next header (multiple headers in file)

        Returns:
            (header, data_idx) - a dictionary of keyword:value header data and
            also the byte index of where the corresponding data block resides.
Read next header ( multiple headers in file )