Fortran updating number problem

  • Context: Fortran 
  • Thread starter Thread starter gmcke1
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around how to update a number in a Fortran program without printing intermediate values to the command window, focusing on techniques for controlling console output during loops.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • Some participants suggest that the user likely has a loop where they are calculating a running total and want to avoid printing intermediate values during the loop.
  • One participant proposes using backspaces and carriage returns to overwrite the previous output on the same line in the command window.
  • Another participant expresses a desire to see each numerical value change without scrolling down the screen, indicating a need for cursor control in the command window.
  • A code example in C is provided, demonstrating how to print numbers on the same line using backspaces.
  • One participant acknowledges a lack of familiarity with control characters and seeks clarification on their usage in the context of Fortran.
  • Another participant suggests using specific options in the Fortran compiler to manage output formatting.

Areas of Agreement / Disagreement

Participants generally agree on the goal of updating the displayed number without cluttering the command window with intermediate outputs. However, there are differing opinions on the best method to achieve this, and some participants express uncertainty about specific techniques and control characters.

Contextual Notes

Some participants mention a lack of familiarity with control characters and specific Fortran compiler options, indicating potential limitations in their understanding of the topic.

gmcke1
Messages
9
Reaction score
0
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?
 
Technology news on Phys.org
gmcke1 said:
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.
 
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.
 
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.
 
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.
 
Example C program that outputs numbers from 0 to 99999 on the same line:

Code:
#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:
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:
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.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 11 ·
Replies
11
Views
12K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K