I am trying to write the entire wave (ie, time vs values) into a text file. The problem is that I am overwriting the file with the latest values of waves. What I need to do is to append the information in one file, as I execute my ocean script.
Here is my piece of code:
(some code here)
;run analysisanalysis( 'tran ?stop "500n" ?errpreset "moderate");save all the waveformssave( 'all );run the simulationrun();select the results nowselectResult( 'tran );print the data to a text filem0=vm("/mult_output<0>")m1=vm("/mult_output<1>")m2=vm("/mult_output<2>")m3=vm("/mult_output<3>")m4=vm("/mult_output<4>")m5=vm("/mult_output<5>")m6=vm("/mult_output<6>")m7=vm("/mult_output<7>")m8=vm("/mult_output<8>")m9=vm("/mult_output<9>")m10=vm("/mult_output<10>")m11=vm("/mult_output<11>")m12=vm("/mult_output<12>")m13=vm("/mult_output<13>")m14=vm("/mult_output<14>")m15=vm("/mult_output<15>")
;*********First Print**************ocnPrint( ?output "results.txt" ?numberNotation 'scientific ?numSpaces 1 m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 );ocnPrint( output_file ?numberNotation 'scientific ?numSpaces 1 m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 )drain( output_file )c0=vm("/cmp_out<0>")c1=vm("/cmp_out<1>")c2=vm("/cmp_out<2>")c3=vm("/cmp_out<3>")c4=vm("/cmp_out<4>")c5=vm("/cmp_out<5>")c6=vm("/cmp_out<6>")c7=vm("/cmp_out<7>")c8=vm("/cmp_out<8>")c9=vm("/cmp_out<9>")c10=vm("/cmp_out<10>")c11=vm("/cmp_out<11>")c12=vm("/cmp_out<12>")c13=vm("/cmp_out<13>")c14=vm("/cmp_out<14>")c15=vm("/cmp_out<15>");***************Second Print**********************ocnPrint( ?output "results.txt" ?numberNotation 'scientific ?numSpaces 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 );ocnPrint( output_file ?numberNotation 'scientific ?numSpaces 1 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 )close( output_file )
So, what happens here is that the information written by the second print statement overwrites the first one. I also tried the p_port method (the lines have been commented), as it outputs to the screen.
I tried fprintf also, but, it always write only the last of the values in the signal vector.
Can someone please suggest something?
Thanks a lot!
I have not played with this just now, but I am somewhat surprised that using the p_port input to the ocnPrint function does not work.
The way that I would expect to use this is to open the file in append mode, print to it with multiple ocnPrint statements and even fprintf statements, and then close the port. Something like:
filePtr = outfile("myfile" "a")
;; some code, then print
ocnPrint( ?output filePtr ... )
;; some more code, then print
ocnPrint( ?output filePtr ... )
;; even more code, then print
frintf( filePtr ... )
;; done, close the file handle
close( filePtr )
If you call ocnPrint with a filename for ?outfile, then I believe that it would open the file in "w" (write) mode each time and effectively overwrite the contents of the file each time.
I hope that the above helps.
hi, i got one question regarding to the ocnprint. the following is my script
ocnPrint(?output "/home/result.txt" f1,q1)ocnPrint(?output "/home/result.txt" f2,q2)ocnPrint(?output "/home/result.txt" f3,q3)
i would like to print the f2 and q2 in the next line of f1 and q1, but i realize that the latest print will replace the older one, how can i use the "append" command to fix my problem??
thank you for your advice