PDA

View Full Version : Fortran updating number problem


gmcke1
Aug22-11, 05:58 PM
Hello,
I am wondering if there is a way to update a number without printing a bunch of stuff in the CMD window. For example this is what I don't want (below). I don't want a long list of totals..

Total = 1
Total = 2
Total = 3
Total = 4

This is what I do want.

Total = # <=== I want that number to keep updating without printing a bunch of totals.

Anyone know how to do this?

Mark44
Aug22-11, 06:32 PM
Hello,
I am wondering if there is a way to update a number without printing a bunch of stuff in the CMD window. For example this is what I don't want (below). I don't want a long list of totals..

Total = 1
Total = 2
Total = 3
Total = 4

This is what I do want.

Total = # <=== I want that number to keep updating without printing a bunch of totals.

Anyone know how to do this?
Presumably you have a loop of some kind where you're keeping a running total of something. What you don't want is to print the intermediate values of your variable inside your loop. You do want to print the value of this variable after the loop is finished.

rcgldr
Aug22-11, 07:32 PM
I'm guessing that you just want to update the screen image. You could try outputting an initial fixed size string, then for each update, output some fixed number of hex "08" (backspaces), then a fixed sized numeric output. On a windows console program, you could just prefix the string with a hex "0D" (return) and not include a linefeed or newline (hex "0A") at the end of the string. Otherwise, you'll need to use some screen oriented library to set the cursor position on each output.

gmcke1
Aug22-11, 08:01 PM
First off, sorry about reporting those comments. I thought the report button said "reply" lol. Ok Mark, I do want to see each numerical value change through each pass of the loop but I don't want it to print down the screen in the cmd window. For rcgldr not 100% sure what you just said but I'm going to try and figure it out and see what I come up with. Thanks for the responses. I appreciate it.

Mark44
Aug22-11, 08:07 PM
Not a problem. I don't think I understood what you were asking. What rcgldr is proposing is that you print the intermediate numbers at the same location on the screen, so that they don't scroll down the screen. If that's what you're looking for, you need to control the cursor in the command window so that it backs over the number it previously printed, and then prints a new number in the same place as the old one was.

rcgldr
Aug22-11, 09:29 PM
Example C program that outputs numbers from 0 to 99999 on the same line:


#include <stdio.h>
int main(int argc, char **argv)
{
int i;
printf("\n");
printf("i = ");
printf(" "); // 5 spaces
for(i = 0; i < 100000; i++)
printf("\x08\x08\x08\x08\x08%5d", i);
printf("\n");
return(0);
}

gmcke1
Aug23-11, 10:33 AM
Yes Mark, that's exactly what I'm looking for. Unfortunately back in Computational Tools 1 my professor skipped over Control Characters, so I'm not really sure how to use the the 1, Blank, 0, and + . I'm assuming I have to use the + because that is for printing over the previous line. rcgldr I'm not really familiar with C :/

rcgldr
Aug23-11, 03:58 PM
Try the + as a leading character and rewriting the entire line. Your Fortran compliler may have an "advance = no" option and TL# (tab left # characters) option. You'll need to look this up in your Fortran reference guide.