import argparse

def inspectSMMat():
    parser = argparse.ArgumentParser(description="Inspect SM matrix file")
    parser.add_argument("filename", type=str, help="Path to the SM matrix file")
    args = parser.parse_args()

    try:
        with open(args.filename, 'rb') as f:
            magic = f.read(4)
            if magic == b'BLCK':
                print(f"{args.filename} is a valid block form SM matrix file.")
                from SSEDebug.smRead.smread import loadBlockMatrix as matreader
            if magic == b"CSRB":
                print(f"{args.filename} is a valid CSR form SM matrix file.")
                from SSEDebug.smRead.smread import loadSparseMatrix as matreader
            else:
                raise ValueError(f"Unknown file format: {magic}")

        sm = matreader(args.filename)
        from SSEDebug.smRead import analyze_sparse_matrix
        analyze_sparse_matrix(sm)

    except ValueError as e:
        print(f"Invalid file format: {e}")
    except FileNotFoundError:
        print(f"File not found: {args.filename}")
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        print("Finished inspecting the SM matrix file.")
