Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran updating number problem

  1. Aug 22, 2011 #1
    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?
     
  2. jcsd
  3. Aug 22, 2011 #2

    Mark44

    Staff: Mentor

    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.
     
  4. Aug 22, 2011 #3

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  5. Aug 22, 2011 #4
    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.
     
  6. Aug 22, 2011 #5

    Mark44

    Staff: Mentor

    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.
     
  7. Aug 22, 2011 #6

    rcgldr

    User Avatar
    Homework Helper

    Example C program that outputs numbers from 0 to 99999 on the same line:

    Code (Text):

    #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);
    }
     
     
    Last edited: Aug 22, 2011
  8. Aug 23, 2011 #7
    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 :/
     
    Last edited: Aug 23, 2011
  9. Aug 23, 2011 #8

    rcgldr

    User Avatar
    Homework Helper

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran updating number problem
  1. Problems In Fortran (Replies: 2)

  2. Fortran problem (Replies: 1)

Loading...