tags:

views:

72

answers:

2

I have a FORTRAN program output I want to redirect to file. I've done this before and use

$myprog.out>>out.txt 2>&1

and for some reason this is not working. I test it with a another simple test program

$myprog.test>>out.txt 2>&1

and it works

I run myprog.out and the output goes to screen as usual but redirecting it seems to fail! It was working and now seems to have stopped working. It's very strange. I commented out a few print statements that I no longer wanted, recompiled and then band redirect does not work.

There is clearly something different going on with my output but how to diagnose where it is going?

A: 

With >> you are appending the output of your program to out.txt every time you run it.

Can you just try scrolling to the end of out.txt and see if your output is there?

Rahul
Thanks, yep I know about >> appends, the same result (or failure of a result) happens with > but I'm just using >> because this is the line in a script that is failing so I'm just trying to get this line to work. I start off with a empty file out.txt so it's not an issue.
Tommy
Thanks Dennis and example of an output line is
Tommy
print *,'||||||| runtime = ', runtime, ' ||||||||||'
Tommy
A: 

You probably need to flush your output. See for example this SO topic. How to do that depends on your compiler I guess. Because only Fortran 2003 Standard includes flush() statement and the ability to determine numbers that corresponds to stdout/stderr units.

However in gfortran (for example) you can use flush() intrinsic procedure with the equivalents of Unix file descriptors: UNIT=5 for stdin, UNIT=6 for stdout and UNIT=0 for stderr.

PROGRAM main

  PRINT *, "Hello!"
  CALL flush(6)
  CALL flush(0)

END PROGRAM main
kemiisto
Thanks. I'll give that a go and report back. I've just been experimenting with playing with units 0,5 and 6
Tommy
Thanks just got up and it worked. Thank you very much Kemiisto
Tommy
@Tommy: "When you have decided which answer is the most helpful to you, mark it as the accepted answer by clicking on the check box outline to the left of the answer." From SO FAQ (http://stackoverflow.com/faq)
kemiisto