neuronsimulator / nrn

NEURON Simulator
http://nrn.readthedocs.io
Other
389 stars 115 forks source link

std::cerr and std::cout break output; they are not equivalent to Fprintf calls #3052

Closed ramcdougal closed 5 days ago

ramcdougal commented 3 weeks ago

I'm not sure when this happened, but I noticed that std::cerr and std::cout have crept into the code base.

These are not equivalent to Fprintf.

Capital Fprintf exists because it allows us to route NEURON's output to appear in a Jupyter notebook or in a MATLAB console by passing a function pointer for handling the printing to nrnpy_set_pr_etal.

See e.g., https://github.com/neuronsimulator/nrn/blob/c918f6b9ff9be32828e882ed51106d8449e7cb6c/share/lib/python/neuron/__init__.py#L1647

and its following lines for Python, or the following for MATLAB:

https://github.com/mcdougallab/matlabneuroninterface/blob/89c6283de6c5b243ef4a517793e46f2457e5b934/source/nrnmatlab.cpp#L48

ramcdougal commented 3 weeks ago

Before we had Fprintf, calling e.g., h.topology() from a Jupyter notebook would cause the results to appear in the terminal not in the notebook.

As far as I can tell, anything sent to std::cout when running via clib from MATLAB in Windows goes nowhere.

ramcdougal commented 3 weeks ago

Possibly relevant (found by Matze): https://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file

pramodk commented 1 week ago

@alkino : maybe you could take a look?