[ncl-talk] Overwriting Previous Line on Command Line from NCL

Alan Brammer abrammer at albany.edu
Thu Feb 18 10:45:17 MST 2016


I actually did exactly this last week,  I made an expanding bar but here is the same idea as you desired.  The crucial bit is using tput to move the cursor up 1 line,  tput cuu1 .  This will “break" if any other output prints to the terminal.  Similar to most other programs that do the same visualisation.   You could make it more complex with other tput commands. 

This works both on my mac and linux server.  Your mileage may vary though depending on your systems tput


undef("progress_bar")
procedure progress_bar(x, n)
local xf
begin

xf =x + 1.   ;; convert to float and offset for 0 index
system("tput cuu1 && echo '"+sprintf("% 5.1f", 100*xf/n)+"% Completed" +"'")

end




n=15
do i=0, n-1
sleep(1)
progress_bar(i, n)
end do




Alan. 




> On 18 Feb 2016, at 12:26, Samuel Roback <scroback at ncsu.edu> wrote:
> 
> Hi,
> 
> I'm attempting to show the progress through a loop in NCL. Instead of writing the percentage completed to a new line during each loop iteration using print(), I want to overwrite the previous line.
> 
> For more clarification I'd like something that is constantly being overwritten to show the current progress:
> 
> 35.3% Completed
> 
> Rather than something like this:
> 
> 35.2% Completed
> 35.3% Completed
> 35.4% Completed
> etc.
> 
> I've searched through the function codes that manipulate strings, but I couldn't find anything. Is this even possible via NCL? 
> 
> Thanks
> 
> -Sam
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk



More information about the ncl-talk mailing list