Printing value of variable in .cal file to cmd or .txt file

Hello all,

I hope all are doing well. I hope this is a basic question, if not I am willing to learn.

Is there a command akin to the python ‘print()’ function one could write into a .cal file to get the value of a variable for debugging purposes?

  • Max

Well, you probably wouldn’t want to see the copious output of a print function during rendering. Is that the context you are talking about, or is it something else?

There is a little-known utility called debugcal, which you can use with a rendered image to get some level of debugging like so:

ximage -e auto rendering.hdr | debugcal -f myfile.cal -e 'arg(n)=select(n,A1,A2,A3,A4)' -e '$1=testvar1;$2=testvar2'

You have to assign the A1,A2, etc. arguments to match those in your pattern or whatever you are debugging, and the ‘$1=…’ arguments to match the variables you want to examine. You can then click the middle mouse button or hit the ‘t’ key in ximage over the pixel(s) you want to test. It’s a bit of a manual process, and only works on Unix boxes, but it does work.

Hi Greg,

Thanks for the quick response. I managed to get the debugcal function working, but as you stated the manual process proved too tedious to perform a comprehensive test of the code.

I managed to get perform a comprehensive test by re-building the code in python and iterating through a large array of inputs.

I wanted to quickly respond to your question:
Well, you probably wouldn’t want to see the copious output of a print function during rendering. Is that the context you are talking about, or is it something else?

Yes, that is exactly what I seeked. I have a large angular reflection function that calculates canopy reflection and transmission using various parameters including canopy leaf angle density, canopy size, leaf area density etc. I had hoped to get a large list of outputs and graph the data (or a random sample of the data) to see if the plot shape matched that of expected model output.

OK, well the usual approach for such a task would be to use rcalc with your .cal file and generate the tests inputs you want and output whatever variables you wish to monitor. Rendering isn’t really the best way to go about it, but if you want to drive your sampling with a rendering for whatever reason, you can copy the method used in debugcal to query the necessary fields with rtrace and feed those into rcalc.

Also, you don’t need to drive debugcal with ximage. That’s just the most convenient way to query single pixels, which is usually what I’m trying to do. If you want all the pixels over an image, just use:

vwrays rendering.hdr | debugcal ...