The machinery for Import
allows custom converters to be defined for importing different file formats. The examples in the link provide details for writing such a converter:
ImportExport`RegisterImport["myFmt", {
(*register the import of sub-elements*)
{"Header", s_String} :> (myFmtImportHeader[s][##] &),
{"Data", s_String} :> (myFmtImportData[s][##] &),
(*register default*)
myFmtDefaultImporter}, {}]
myFmtDefaultImporter[file_String, opts___?OptionQ] :=
Module[{data, header},
header = fnHeader[file, opts];
data = fnData[file, opts];
{"Header" -> header, "Data" -> data}]
Here, the sub-elements are hooked in as sub-values:
myFmtImportHeader[s_String][file_String, opts___?OptionQ] :=
Module[{header}, header = myFmtReadHeader[file, opts];
"Header" -> header]
My question is, what should the syntax look like for more complicated functions that take parameters? For instance, the built-in TIFF routines can handle various specifications for elements and parameters, such as:
Import["ExampleData/lena.tif", {"TIFF", "Thumbnail", Tiny}]
Import["ExampleData/lena.tif", {"TIFF", "Thumbnail", {1,1}}]
Import["ExampleData/lena.tif", {"TIFF", "ThumbnailList", 1, Tiny}]
If I have an import function:
fnReadImages[file_, frames_, opts___]
How can I register it so I can call it with something like:
Import[file, {"myFmt", "Images", frames}]
where frames is an integer, list of integers, or a keyword passed to the function?