So I am writing an ImportExport
converter for a common chemistry file format, and I've run up against a problem that seems to be about shared streams and whatnot. I followed the directions on this page.
To work the example, create a random text file whose contents do not matter.
Export["testfile.txt", "hello"];
The definition for the Import
converter is as follows
ImportExport`RegisterImport["TestFormat", TestFormat`TestFormatImport];
TestFormat`TestFormatImport[filename_String, options___] :=
Module[{temp},
(*Do some stuff, all works just fine*)
temp = ElementData["C", "AtomicNumber"];
{"Test" -> temp}];
All this does is call for the atomic number associated with the symbol C. If you test it out it seems to work just fine:
In[3]:= Import["testfile.txt",{"TestFormat","Test"}]
Out[3]= 6
But any subsequent call to ElementData
gives a stream error:
In[4]:= ElementData["F","AtomicNumber"]
During evaluation of In[4]:= General::openx: InputStream[C:\Users\myusername\AppData\Roaming\Mathematica\Paclets\Repository\ElementData-7.0.28\Data\ElementData.wdx,122] is not open. >>
During evaluation of In[4]:= BinaryRead::openx: InputStream[C:\Users\myusername\AppData\Roaming\Mathematica\Paclets\Repository\ElementData-7.0.28\Data\ElementData.wdx,122] is not open. >>
Out[4]= $Failed
But, if I make a call to ElementData
before I make the Import
command, then the errors go away.
In[1]:= ImportExport`RegisterImport["TestFormat",
TestFormat`TestFormatImport];
TestFormat`TestFormatImport[filename_String, options___] :=
Module[{temp},
(*Do some stuff, all works just fine*)
temp = ElementData["C", "AtomicNumber"];
{"Test" -> temp}];
ElementData["H", "AtomicNumber"]
Import["testfile.txt", {"TestFormat", "Test"}]
ElementData["F", "AtomicNumber"]
Out[3]= 1
Out[4]= 6
Out[5]= 9
This is all well and good, but I don't want to have to randomly make a call to ElementData
before I do an Import
command every time.
What is going on here and how can I fix it?
Thanks
CountryData
and webMathematica... $\endgroup$