I've developed an importer and exporter for FreeSurfer's MGH
/MGZ
file format; the specific format isn't important, but I was wondering if there is a 'correct' way to tell Mathematica that file names ending with ".mgh" should be automatically imported using my MGH importer?
Mathematica obviously does this for its built-in importers (e.g., Import["abc.csv"]
is equivalent to Import["abc.csv", "CSV"]
), so it seems like it should be possible, but I haven't been able to find any information about this in Mathematica's documentation.
One solution, which seems inelegant to me, is this:
Unprotect[Import];
Import[name_String /; StringMatchQ[name, __ ~~ ".mgh" ~~ EndOfString]] :=
Import[name, "MGH"];
Import[name_String /; StringMatchQ[name, __ ~~ ".mgz" ~~ EndOfString]] :=
Import[name, {"GZip", "MGH"}];
Protect[Import];
Is there a more principled way of going about this?