How do you save the value of a global to a text file with Intersystems Caché? - intersystems-cache

In the terminal, I am printing the value of a global with zw ^MYGLOBAL.
How do I save this output to a text file?

Quick nasty way:
s f="c:\file.txt" o f:"wns" u f zw ^MYGLOBAL c f
The same thing, more verbosely:
set f="c:\file.txt"
open f:"wns"
use f
zwrite ^MYGLOBAL
close f

As you already mentioned yourself the easiest way to output global/local recursively is using ZWRITE command. Output of which could be redirected if you OPEN file and then USE it, redirecting all write to principal device to this filename.
But as Sergey #SSH mentioned elsewhere, the better approach is to use %GO utility (which essentially does the job similar to ZWRITE but output of which could be read later using %GI utility. If you want more effeciency in handling binary data then recomended approach is to output global(s) using %GOF and read them back using %GIF

Not exactly a ZW format, but try
do $system.OBJ.Export("Global.GLB","backup.xml")

Another option is to use the ^%GO utility. This way, you will be able to import your globals back with ^%GI.
do ^%GO

To turn on logging, in the terminal click File → Logging, or Alt + L.
This saves all the output of the terminal to a log file, until you turn off logging.

Related

how to append to a file using scala/breeze library

I wish to write to a file the output row of result matrix (produced in iterations) so that I can support checkpointing.
I figured we can use the csvwrite command to write the entire matrix to a file but how can I append to a file?
I am looking for something like below:
breeze.linalg.csvwrite(new File("small.txt"),myMatrix(currRow,::).t.asDenseMatrix)
However the above command overwrites the file each time the command is executed.
There's nothing built-in to Breeze. (Contributions welcome!)
you can use breeze.io.CSVWriter.write directly if you would like.

Matlab script should output to file and to the console

What is the best way to save the output of a MATLAB script to a file AND output it to the console? I do not want to use diary b/c sometimes I try things out between script runs. Right now I use fprintf to output either to the console or to a log file. Can I do both without writing the same fprintf for both outputs?
I may be in the wrong direction, but suppose you want to output something to the console, and save it, here is what you could do:
s = 'abcd'; %The thing you want to show and save
s % Just show it
save s % Save it to file
If however, you need a specific output that only comes from the print command. Here is what I would do:
Print to a variable
Save that variable
Show that variable
This way you only need the print once.
If that also does not work out for you, you could try to write a function where you do the print, at least then you can avoid code duplication.

Gnuplot incremental filename using macro

Hell,
I need to plot points out of my c++ application.
So I simply save my points to a points.txt
and then run system("gnuplot 'plotmakro'");
which contains:
set output 'plot.png' set terminal png
set grid set multiplot
plot pointsa.txt' ', 'pointb.txt'
Is there a solution so that I get plot2.png, plot3.png when running the makro again?
As far as I understand your problem two possible solutions come to my mind:
sed the output of your gnuplot script to another location before running gnuplot with the newly created script or
output the png to some arbitrary file like tmp_plot.png and change the file name after gnuplot is done to your liking.
However, with both suggestions I somehow feel that there is a nicer and cleaner solution to your problem. Maybe you want to think about your interface between your application an gnuplot...

printing text into a file in Matlab

I want to log the running of my program, specifically the running time of each part. At this moment I print to the screen using disp. Is there a way so that some of the things I print would also be printed into a text file?
You can use the DIARY command, that captures everything from the command window.
There are other solutions to this problem where you write to one or more logfiles opened when your program is running. This provides a permanent record without polluting your work space or diary. It also works well if you compile your MATLAB application.
Jan Simon has a nice solution at MATLAB Central which uses a persistant file id so the log to file mechanism can be used again and again throughout an application with many functions without passing the file id about.
Others at MATLAB Central (here and here) have developed class based solutions with more features.
Also, fprintf.

Write a figure to a file automatically in MATLAB

Does anyone know if it's possible to automatically write a figure out to a .eps file in MATLAB?
I'm running a script that produces a large number of graphs, and it'd be nice if I didn't have to manually save each one!
print function does that:
Print figure or save to specific file format...
print(filename,formattype) saves the current figure to a file using the specified file format, such as print('BarPlot','-dpng'). If the file name does not include an extension, then print appends the appropriate one.
print(filename,formattype,formatoptions) specifies additional options that are available for some formats.
print prints the current figure to the default printer...
print or saveas will do the trick.
saveas(fig_handle, 'filename','eps')
print('-deps',fig_handle)
print -deps 1
If you want to specify the output file name, you're better off using saveas.
This was answered in this other question, using the PRINT command. Although that question dealt with making .tiff images, it should be straightforward to modify the code given in those answers to write a .eps.
Suppose, you are generating N numbers of figures in a loop, then you should try the command line:
saveas(gca,sprintf('Figure%02d.pdf',N )); it produces N figures Figure1.pdf - FigureN.pdf
saveas(gca,sprintf('Figure%02d.eps',N )); it produces N figures Figure1.eps - FigureN.eps
in place of gca one can use gcf also. First command line is a better solution.
Hope this will solve your issue.