Is there a way to redirect all output to a UNIT=COPY?

For questions and discussion related to graphs, reports, and other output, including issues related to presenting or publishing results.
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

Is there a way to redirect all output to a UNIT=COPY?

Unread post by macro »

I have a lengthy script that runs in batch mode, and I'm trying to get RATS to save the text output (output only, not the output and the compiled code) in a separate text file. Some instructions, like DISPLAY or REPORT, support a UNIT=COPY option that lets me flexibly redirect output to this file. However, other instructions, like PRINT, FORECAST, etc. don't support this option. Is there a way around this?

COPY does provide for somewhat flexible output, but for printing series, I'm limited to FORMAT=FREE, among others, that doesn't replicate the convenient output of the PRINT instruction. If I use another format, I can't append the mix of text, series, and other output that I have to the file.

I can roll my own versions of FORECAST, PRINT, etc. that support this, but this is such a basic feature (redirecting output, and only output, to a text file), and rolling my own is significantly costly, that I'm hoping there's a simpler way to achieve this.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Is there a way to redirect all output to a UNIT=COPY?

Unread post by TomDoan »

Either CHANGE OUTPUT unitname or OPEN OUTPUT filename

https://estima.com/ratshelp/changeinstruction.html
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

Re: Is there a way to redirect all output to a UNIT=COPY?

Unread post by macro »

Thank you; I think this is mostly what I was looking for. Once I've changed the output to a separate file, how do I change the output back to the default .out file? I'm running scripts in batch mode. For example, after this code

Code: Select all

open outfile "results.txt"
change output outfile
linreg lgdpk
# lgdpk{1 to 4} lpotgdpk{1 to 4}

print / lgdpk lpotgdpk
If I add

Code: Select all

close outfile
Then -results.txt- is overwritten. Do I need to define another output unit to switch back to? If I define the default -myscript.out- as an output unit, it'll get overwritten, which isn't what I want. The -append- option to open prevents this, but is there a canonical way to simply switch back to the default output file?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Is there a way to redirect all output to a UNIT=COPY?

Unread post by TomDoan »

There's no defined unit for the initial batch output file. My suggestion if you want to switch between two output files is to start the program with

open outfile1 myscript.out
change output outfile1

then

....
open outfile2 "results.txt"
change output outfile2
...
change output outfile1
Post Reply