1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ I am curious, did you make any progress? I am just facing a very similar problem, with CountryData and webMathematica... $\endgroup$ – Pinguin Dirk Oct 10 '13 at 8:13
  • $\begingroup$ I just asked a "similar" question, see mathematica.stackexchange.com/questions/33783/…. Probably close to dupe, but hopefully this will bring us closer to the solution $\endgroup$ – Pinguin Dirk Oct 10 '13 at 9:06
  • $\begingroup$ No progress on this yet. I heard from someone else that wasn't able to reproduce my error. So I need to try it on my home PC to see if it is just a problem with my local installation or if it's more general. $\endgroup$ – Jason B. Oct 10 '13 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.