is there fast way to find one file type, gds or oasis ?

edited October 2015 in Ruby Scripting
Hi All,
I have some files to process and they are named as xxx.db.
Some are gds files. and some are oasis files.

Some files are very large, 2G maybe.
I only want to know the file type,
so I think we don't need to load it all, just read head info maybe.

How to write a script to report the file type quickly?

Comments

  • edited November -1

    Hi,

    it's entirely sufficient to read the first few bytes. OASIS and GDS have a specific signature.

    I'll give you more details if you like.

    Matthias

  • edited October 2015

    Hi dion,

    here are the details:

    KLayout detects the file format looking at the first four bytes:

    • GDS: 0x00, 0x06, 0x00, 0x02
    • OASIS: 0x25, 0x53, 0x45, 0x4d

    The Linux "file" tool is able to detect GDS2 and OASIS files as well (I have tried version 5.14), so on Linux it's very simple to scan the file types within a shell script.

    Matthias

  • edited November -1
    Hi Matthias,
    Thanks for your reply.
    We use old linux (centos 4.6) with file version 4.10, which could not detect OASIS.

    However, I add API for klayout to report file type before reading the stream.

    extern std::string stream_format(const std::string &filename)
    {
    tl::InputStream stream (filename);
    db::Reader reader (stream);
    return reader.format();
    }

    Then call it in python, it worked.

    Thanks,
    Dion
Sign In or Register to comment.