Do you want to use this output as input in another program, or to use in 
Julia later? In the latter case, take a look at the HDF5 package 
<https://github.com/timholy/HDF5.jl/>.

In the former case, i.e. if you can't do anything about the requirements on 
the output format, you'll probably want to use the *@printf 
<http://docs.julialang.org/en/latest/stdlib/base/?highlight=%40printf#Base.@printf>*
 
macro.

// Tomas

On Monday, June 2, 2014 1:15:18 PM UTC+2, İrem Altan wrote:
>
> Hi,
>
> I've been trying to print some results to a file using the print() 
> function. I use Julia 0.2 on Ubuntu 12.04I have two main issues. One is 
> that when I have a variable like 0.23423, it prints it out as .23423. I 
> really need to have the zero in front. Is there any way to format the 
> output?  Also, using println() or using print() with "\n" creates a blank 
> line between entries sometimes. The following is the output:
>
> 216
> i= 1
> C .5234394743625429    .5348102985731046    .5303962884823974
>
> C .5937281782231966    .5972417695393426    1.5252239360542204
>
> C .5435565414726229    .5763812186804881    2.5267672674153956
>
>
> And the code is:
>
> ff=open("positions","w")
>
> println(ff,n)
> for t=1:tsteps
>     if (t % psteps) == 0
>         print(".")
>     end
>     k,pot = integrate(r,v,f)
>     push!(ke,k)
>     push!(pe,pot)
>     push!(etot,pot+k)
>
>     if (t % 1) ==0 
>     print(ff,"i= ")
>     println(ff,t)
>     for i=1:n
>         print(ff,"C ")
>         println(ff,r[i,:])
>      end
>     end
>
> end
> close(ff)
>
> I would like to have the output in the following form:
>
> 216
> i= 1
> C 0.5234394743625429    0.5348102985731046    0.5303962884823974
> C 0.5937281782231966    0.5972417695393426    1.5252239360542204
> C 0.5435565414726229    0.5763812186804881    2.5267672674153956
>
> I have been trying to figure this out for days. I'd be grateful if you 
> could help me out.
>
> Thanks,
> Irem
>

Reply via email to