Dear all,
A quick question, e.g., I compile two files droplet.f90 DOeng_7.f and build run.exe as below,
gfortran -o run.exe -O3 droplet.f90 DOeng_7.f
Then the command window will show all the warning and error messages if any. However, instead of displaying such information in the command window, can I save them to a file? like call it out.txt?
I have tried
gfortran -o run.exe -O3 droplet.f90 DOeng_7.f > out.txt
But it does not seem to work.
Does anyone know how to do it?
Thank you very much in advance!
Use 2> file.txt to send stderr to file.txt.
For example, for bad.f90
program main
implicit none
integer i,j
i = 2
print*,i
end program main
after the command
gfortran -Wall bad.f90 2> gfortran_err.txt
the contents of gfortran_err.txt are
bad.f90:3:11:
3 | integer i,j
| 1
Warning: Unused variable 'j' declared at (1) [-Wunused-variable]
1 Like
In windows cmd.exe, I use a set of .bat files to compile and build my programs using gfortran.
I stopped using make, as I can no longer make a coffee in the time to compile and link, while the .bat file is easy to vary compile options between files.
You can also use “2>&1” so all reports are in the one %tce% file, such as in part of my recompile.bat file.
set tce=compile_gf.tce
set compile=gfortran
set basic=-c -fimplicit-none -fallow-argument-mismatch -O2 -march=native -ffast-math
set vec=-c -fimplicit-none -fallow-argument-mismatch -O3 -march=native -ffast-math -funroll-loops --param max-unroll-times=2
set omp=-fopenmp -fstack-arrays
del myprog.exe
del *.mod
del *.o
del *.obj
now >%tce%
rem build_stamp
make_label_gf
%compile% compile_options.f90 %vec% %omp% >>%tce% 2>&1
%compile% myprog.f90 %basic% %omp% >>%tce% 2>&1
%compile% commands.f90 %basic% >>%tce% 2>&1
%compile% accnt.f90 %basic% >>%tce% 2>&1
%compile% omp_utils.f90 %basic% %omp% >>%tce% 2>&1
%compile% stack_utils.f90 %basic% %omp% >>%tce% 2>&1
%compile% reduce_1bk.f90 %vec% %omp% >>%tce% 2>&1
%compile% crout_cache.f90 %vec% %omp% >>%tce% 2>&1
%compile% reduce_stats.f90 %vec% >>%tce% 2>&1
%compile% wait_on_jeq.f90 -c -O1 -fopenmp >>%tce% 2>&1
... other routines
call lsap_gf
notepad compile_gf.tce
I also have a relink file : lsap_gf.bat, which update another %tce% log history that is retained.
rem lsap_gf.bat : rebuild myprog.exe
set tce=load_gf.tce
set load=gfortran
set stack_options=-Wl,-stack,536870912,-Map=myprog.map
del myprog.map
del myprog.exe
now >>%tce%
%load% @load_gf.txt -fopenmp -fstack-arrays %stack_options% >>%tce% 2>&1
dir myprog.* /od >>%tce%
notepad %tce%
“now” (date time stamp to %tce%) and “make_label_gf” (generates compile_options.f90) are program I use to document the build.
The %stack_options% is used to reset the stack size; an option I found difficult to find in the documentation.
“load_gf.txt” is an extensive list of .o files from a number of directories and -o myprog.exe, it is simple but effective.
1 Like
@thank you @Beliavsky and @JohnCampbell ! That really helps!
May I ask @JohnCampbell, what is the advantage of using bat (which looks very fancy by the way) over Makefile?
Using bat files is my personal preference, as I like the clarity of the layout and flexibility during program development, such as removing optimisation from an omp critical code; wait_on_jeq.f90.
It demonstrates an approach for your original post.
I am not recommending as an alternative to make.
1 Like
Just a note that on Unix-like systems an alternative is the “script” command, which captures all output; some terminal emulators and commands like “screen” and “tmux” allow turning logging on and off, and that if users use non-POSIX shells (ie. tcsh/csh) note that the redirection syntax is different. Because I have used many shells in the past I often use little commands like “quiet” and “logit” as a prefix for simple commands, but that is probably not for everyone. They are little scripts like
#!/bin/bash
exec 2>&1
$* |less
and logit uses a tee(1) command instead of less (note if you redirect the output to a file less(1) does not page) and so on.
screen(1) and tmux(1) are particularly handy as they not only let you multiplex a single terminal window but allow you to turn logging on and off to different files on demand, and start terminal sessions on one machine (ie. at work or a desktop PC, and then take them over at home or a laptop and vice-versa, …) .
script(1) output is replayable so it can be interesting for making a demo of a terminal session without having to make a movie.
The more Fortran-ic info is that the latest version of fpm(1) captures the build info into log files. In upcoming versions you should be able to review that without having to recompile, capture the latest version of all the logs for reviewing, and so on. So some of the viewing options are not in place but you can find a build log for each file in the build directory (perhaps a nice project for a plugin utility to allow reviewing the logs).
1 Like