Does Julia have format IO like Fortran or even better?

I am 100% sure that Julia have more efficient format IO than Fortran.
But could any one advice how to do format IO, or like, is there some packages to use so that the output could be nicer? Thanks!

For example, in a Fortran code, by using things like t30, t40, I can do,

    write (6,'(''MPI number of cores ='',t30,i20)') nproc()
    write (6,'(''random number seed ='',t30,i20)') irn
    write (6,'(''hbar^2/2m ='',t40,f10.5)') hbar
    write (6,'(''time step ='',t40,g15.7)') dt
    write (6,'(''npart ='',t40,i10)') npart
    write (6,'(''nproton ='',t40,i10)') nprot 
    write (6,'(''potential number ='',t40,i10)') lpot
    write (6,'(''table size ='',t40,i10)') ntab   
    write (6,'(''bisection order ='',t40,i10)') mmax
    write (6,'(''reptation beads number ='',t40,i10)') nrepmax   
    write (6,'(''start from sites ='',t40,l10)') isite
    write (6,'(''equilibration blocks ='',t40,i10)') neq
    write (6,'(''averaging blocks ='',t40,i10)') nav
    write (6,'(''nsteps/blocks ='',t40,i10)') nstep
    write (6,'(''stepdecor ='',t40,i10)') nstepdecor
    write (6,'(''nchorizo ='',t40,i10)') nchorizo
    write (6,'(''stepmove1 ='',t40,f10.5)') mov1step
    write (6,'(''stepmove2 ='',t40,f10.5)') mov2step 
    write (6,'(''stepshift ='',t40,f10.5)') shftstep
    write (6,'(''x0step ='',t40,f10.5)') x0step
    write (6,'(''potential range ='',t40,f10.5)') rangev
    write (6,'(''one particle density rho range ='',t40,f10.5)') rangerho
    write (6,'(''bin # of rho ='',t40,i10)') nrhobin
    write (6,'(''correlation check ='',t40,l10)') icorrchk
    write (6,'(''EM force ='',t40,l10)') iem
    write (6,'(''Spin-Orbit force ='',t40,l10)') spinorbit
    write (6,'(''bisection (reptation) upper bar='',t40,f10.5)') rbisect 
    write (6,'(''move 1 by 1 upper bar='',t40,f10.5)') rmov1 
    write (6,'(''move all beads upper bar='',t40,f10.5)') rmov2 
    write (6,'(''shift beads upper bar='',t40,f10.5)') rmov3 
    write (6,'(''move all + shift beads upper bar='',t40,f10.5)') rmov23 
    write (6,'(''Path IO ='',t40,l10)') pathio

The output can be aligned like below

Resume Mode =                         F
MPI # of cores =                             5120
random number seed =                     88888888
hbar^2/2m =                              20.73500
time step =                              0.1000000E-03
npart =                                         4
nproton =                                       2
lpot =                                          2
table size =                                50000
bisection order =                               2
# of reptation beads =                          0
start from sites =                              T
equilibration blocks =                          5
averaging blocks =                          50000
nsteps/blocks =                              2000
stepdecor =                                   125
nchorizo =                                     20
stepmove1 =                               0.01000
stepmove2 =                               0.00020
stepmoveshift =                           0.03000
x0step =                                  0.50000
potential range =                        15.00000
one particle density rho range =          5.00000
bin # of rho =                                100
correlation check =                             F
EM force =                                      T
Spin-Orbit force =                              T
bisection (reptation) upper bar=         -1.00000
move 1 by 1 upper bar=                    0.70000
move all beads upper bar=                 0.80000
shift beads upper bar=                    0.90000
move all + shift beads upper bar=         1.00000

In Fortran, I can also define some format in a module,

module formats
    use constants
    implicit none
    character(len=128), public :: fmt_k_label,fmt_sigma,fmt_weight,fmt_muk,fmt_muk_sig,fmt_muV,fmt_muV_sig &
                                 ,fmt_k_label_iter,fmt_weight_iter,fmt_muk_iter,fmt_muk_sig_iter &
                                 ,fmt_mc_muk_acc_iter,fmt_mc_muV_acc_iter &
                                 ,fmt_muV_iter,fmt_muV_sig_iter,fmt_line,fmt_star &
    subroutine format_init(kmixin)
    integer(kind=i8) :: kmixin,width
    width = kmixin*29

	write(fmt_k_label, '(a, i0, a)') '(''Mixture Label :'',t20,',kmixin,'(i12,1x))' 
	write(fmt_weight, '(a, i0, a)') '(''Weight ='',t20,',kmixin,'(f12.5,1x))' 
	write(fmt_muk, '(a, i0, a)') '(''Mu_k ='',t20,',kmixin,'(f12.5,1x))' 
	write(fmt_muk_sig, '(a, i0, a)') '(''Sigma Mu_k ='',t20,',kmixin,'(f12.5,1x))' 
	write(fmt_muV, '(a, i0, a)') '(''Mu_V ='',t20,',kmixin,'(f12.5,1x))' 
    write(fmt_muV_sig, '(a, i0, a)') '(''Sigma Mu_V ='',t20,',kmixin,'(f12.5,1x))'  
    write(fmt_sigma, '(a)') '(''Sigma ='',t20, f12.5,'' +-'',f12.5)' 
    write(fmt_k_label_iter, '(a, i0, a)') '(''Mixture Label :'',t20,',kmixin,'(i14,14x,''|''))' 
    write(fmt_mc_muk_acc_iter, '(a, i0, a)') '(''Mu_k MC acc rate ='',t20,',kmixin,'(6x,f8.3,''%'',13x,''|''))' 
    write(fmt_mc_muV_acc_iter, '(a, i0, a)') '(''Mu_V MC acc rate ='',t20,',kmixin,'(6x,f8.3,''%'',13x,''|''))' 
    write(fmt_weight_iter, '(a, i0, a)') '(''Weight ='',t20,',kmixin,'(2x,f12.5,14x,''|''))' 
    write(fmt_muk_iter, '(a, i0, a)') '(''Mu_k ='',t20,',kmixin,'(  f12.5,'' +-'',f12.5,1x,''|''   ))' 
    write(fmt_muk_sig_iter, '(a, i0, a)') '(''Sig Mu_k ='',t20,',kmixin,'(  f12.5,'' +-'',f12.5,1x,''|''))' 
    write(fmt_muV_iter, '(a, i0, a)') '(''Mu_V ='',t20,',kmixin,'(  f12.5,'' +-'',f12.5,1x,''|''   ))' 
    write(fmt_muV_sig_iter, '(a, i0, a)') '(''Sig Mu_V ='',t20,',kmixin,'(  f12.5,'' +-'',f12.5,1x,''|''))' 
    write(fmt_line, '(a, i0, a)') '(19(''-''),',width,'(''-'')  )'
    write(fmt_star, '(a, i0, a)') '(19(''*''),',width,'(''*'')  )'
    write(fmt_weight_full, '(a, i0, a)') '(''Weight ='',t20,',kmixin,'(  f12.5,'' +-'',f12.5,1x,''|''   ))' 
    end subroutine format_init

Then in the code I can do things like,

write(6,fmt_k_label) (k,k=1,kmix)|
write(6,fmt_weight) (weight(k),k=1,kmix)|
write(6,fmt_muk) (mu(k,1),k=1,kmix)|
write(6,fmt_muk_sig) (sigma(k,1,1),k=1,kmix)|
write(6,fmt_muV) (mu(k,2),k=1,kmix)|
write(6,fmt_muV_sig) (sigma(k,2,2),k=1,kmix)|

Is there some Julia command or package can also output values aligned or formatted?
In one word, make the output look nice.
Thanks in advance!

PrettyTables.jl and TabularDisplay.jl

1 Like

See the Printf standard library.

1 Like