"endline" symbol in wave generated .txt
neogin
I want to generate a .txt from a text wave. It works well, but the generated txt file is formatted in one single line with "endline" symbol (an empty square) instead of multiple lines. The device in which I need to load the .txt doesn't seem to understand the file, whereas it understands the same .txt manually typed. Is there a way to get rid of those "endline" symbol ?
here's a part of my code :
Make/T/O/N=2000 Prgm
[...]
Do
prgm[3+i]="SetSync 2"
prgm[4+i]="Slewxy "+num2str(Xfin)+" "+num2str(posy)+" "+num2str(t0)
prgm[5+i]="UnSetSync 2"
prgm[6+i]="Slewxy "+num2str(Xfin)+" "+num2str(posy+step)+" "+num2str(t0/10)
prgm[7+i]="SetSync 2"
prgm[8+i]="Slewxy "+num2str(posx)+" "+num2str(posy+step)+" "+num2str(t0)
prgm[9+i]="UnSetSync 2"
prgm[10+i]="Slewxy "+num2str(posx)+" "+num2str(posy+2*step)+" "+num2str(t0/10)
posy=posy+2*step
i+=8
While (i<lignes*4)
[...]
Save/G Prgm as "Prgm.txt"
KillWaves Prgm
[...]
Do
prgm[3+i]="SetSync 2"
prgm[4+i]="Slewxy "+num2str(Xfin)+" "+num2str(posy)+" "+num2str(t0)
prgm[5+i]="UnSetSync 2"
prgm[6+i]="Slewxy "+num2str(Xfin)+" "+num2str(posy+step)+" "+num2str(t0/10)
prgm[7+i]="SetSync 2"
prgm[8+i]="Slewxy "+num2str(posx)+" "+num2str(posy+step)+" "+num2str(t0)
prgm[9+i]="UnSetSync 2"
prgm[10+i]="Slewxy "+num2str(posx)+" "+num2str(posy+2*step)+" "+num2str(t0/10)
posy=posy+2*step
i+=8
While (i<lignes*4)
[...]
Save/G Prgm as "Prgm.txt"
KillWaves Prgm
cheers,
Gautier
Add the /M="\r\n" flag to the Save command:
Save/G/M="\r\n" Prgm as "Prgm.txt"
May 3, 2010 at 08:33 am - Permalink
A cleaner option may be to use the sprintf command with the inbuilt formatting that you want for the numbers and an included a "carriage return" at the end of each line ...
sprintf prgm[3+i], "SetSync 2\r"
sprintf prgm[4+i], "Slewxy %g %g %g\r", Xfin, posy, t0
....
while(...)
Since you are writing line-by-line, as needed, you can also avoid having to generate a text wave by dumping everything directly to a string.
...
do
sprintf strprgm, "SetSync 2\r"
sprintf strprgm, "Slewxy %g %g %g\r", Xfin, posy, t0
....
while(...)
Finally, if you do not need the intermediate text, you might write the strings directly to a file on a line-by-line basis.
...
do
fprintf refnum, "SetSync 2\r"
fprintf refnum, "Slewxy %g %g %g\r", Xfin, posy, t0
....
while(...)
close refNum
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 3, 2010 at 08:44 am - Permalink
This does not work for me, it is throwing the error "expected string variable name". I think one has to use an intermediate string:
sprintf str, "SetSync 2\r"
prgm[3]=str
Another interesting thing in this context: It doesn't seem to be possible to save text waves containing NUL byte strings with the /G, /J or /T flag.
save/g prgm
gives an "out of memory" error,
make/o/t prgm=num2char(p+1)
can be saved.May 4, 2010 at 05:17 am - Permalink
Thanks guys,
G.
May 4, 2010 at 01:18 am - Permalink