[vtkusers] file readers: determine file type before Update()?

David E DeMarle dave.demarle at kitware.com
Tue May 15 09:51:18 EDT 2012


Many (but not all) readers have a CanReadFile() method for this purpose.

In ParaView we run through a list of readers that match the file
extension like you are doing, and call CanReadFile() on the matching
readers that have the method, before resorting to a calling the first
(or rather last so plugins get first shot) reader left in the list.

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909


On Tue, May 15, 2012 at 9:05 AM, Nico Schlömer <nico.schloemer at gmail.com> wrote:
> Hi,
>
> for reading data from VTK/pVTK/Exodus/... files, is there any way to
> determine the file format before calling Update() on the reader (and
> error out)?
> What I've currently got is
>
>    if extension == '.vtu':
>        # Set up VTU reader
>    elif extension == '.vtk':
>        # Set up VTK reader
>    elif extension in [ '.ex2', '.exo', '.e' ]:
>        # Set up exodus reader
>    else:
>        raise RuntimeError( 'Unknown file type \'%s\'.' % filename )
>
> but this is going wrong if the extension doesn't coincide with the
> file type, and is getting messy for parallel file format.
>
> Any hints?
>
> Cheers,
> Nico
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list