Chandra-MARX / marx

Chandra X-ray Observatory ray-trace simulator
http://space.mit.edu/cxc/marx/
5 stars 4 forks source link

in some specific casees, marx needs to be run in TTY and not with a pipe connected to Stdin #78

Open hamogu opened 8 months ago

hamogu commented 8 months ago

I'm encountering this when I call marx through from Python through subprocess.run. I don't think it's Python specific and I can probably use shell constructs, too, to trigger the same behavior, but I'm just going to stick with the "Calling from Python" here as an example.

I noticed that MARX fails with stdin is NOT a tty. is certain parameters are passed. Most parameters are fine, but a certain subset of them triggers this, if marx is not called from a shell, e.g.: subprocess.run(['marx', 'SpectrumType="FILE"', 'SpectrumFile=abspowerlaw.spec'). It works fine, if there is no SpectrumFile parameters. Tracing around the code a bit, it comes down to _pf_query_current_value in pfquery.c which is triggered for reading from parameters in marx.par that are of type "f" (file). Note, that this does not apply to fits files (e.g. the ASPSOL file), which are read as parameter type "string" and then that file name string is passed to jdfits. However, text files are read with the pfiles modules that's part of marx which triggers this.

While the pfiles module is written to require a TTY, I don't see fundamentally why it has to be. On the other hand, I'm somewhat reluctant to change the C implementation of something that works for just a tiny bit on increased convenience for calling marx from Python.

For my immediate use case, I can work around that by changing the syntax slightly and passing it all to a new shell: subprocess.run(['marx SpectrumType="FILE" SpectrumFile=abspowerlaw.spec'], shell=True).