# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/40_pdz-archeology.ipynb.

# %% auto 0
__all__ = ['PDZ11_STRUCT_DICT', 'check_pdz_type']

# %% ../notebooks/40_pdz-archeology.ipynb 16
from . import file_to_bytes, get_blocks, multiparse, parse 
import struct

# %% ../notebooks/40_pdz-archeology.ipynb 17
PDZ11_STRUCT_DICT = {
    'pdz11_8698_bytes' : {'xformat': '2s-4s-h-34s-d-d-86s-i-i-10s-f-f-188s-Z-148s', 
                          'param_keys': ['pdz-version', '??', 'NumberOfChannels', '??', 'LiveTimeInSeconds', 
                                         'eVPerChannel', '??', 'RawCounts', 'ValidCounts', '??',  'XrayVoltageInkV', 
                                         'XrayFilamentCurrentInMicroAmps', '??', 'PhotonCounts (2048 channels)', '??']}, 
    'pdz11_4454_bytes' : {'xformat': '2s-4s-h-34s-d-d-86s-i-i-10s-f-f-24s-z-148s', 
                          'param_keys': ['pdz-version', '??', 'NumberOfChannels', '??', 'LiveTimeInSeconds', 
                                         'eVPerChannel', '??', 'RawCounts', 'ValidCounts', '??',  'XrayVoltageInkV', 
                                         'XrayFilamentCurrentInMicroAmps', '??', 'PhotonCounts (1024 channels)', '??']} 
}


def check_pdz_type(pdz_file, verbose=True): 
    '''Read first two bytes and file size to check pdz file type.'''

    pdz_bytes = file_to_bytes(pdz_file) 
    file_size = len(pdz_bytes)
    first_two_bytes = struct.unpack('<h', pdz_bytes[0:2])[0] 

    if first_two_bytes == 25: 
        pdz_type = 'pdz25' 
    elif first_two_bytes == 257: 
        if file_size == 8698:
            pdz_type = 'pdz11_8698_bytes'
        elif file_size == 4454:
            pdz_type = 'pdz11_4454_bytes'  
        else: 
            pdz_type = f'pdz11_with_unexpected_filesize_{file_size}_bytes'
    else:
        pdz_type = f'pdz_type_unknown:{first_two_bytes}'
                
    return pdz_type
