1.

Solve : Colour with FORTRAN g95 in Windows XP??

Answer»

Can you have background and foreground text colours in executable programs, compiled with the free FORTRAN compiler g95, to run in Windows XP?

I have old FORTRAN 77 source CODE that when compiled produces a 16 bit executable that can run c/o ntvdm.exe with SIMPLE colours USING ANSI.sys escape sequences with the simple addition of an ansi.sys entry in my \System32\CONFIG.NT file.

I have been given to believe that this technique is not available for the 32 bit executables produced by g95.

This is born out by the fact that screen output from these executables is not in colour.

Is there away to bring colour back to my newly compiled 32 bit executables?In the absence of any expert advice I have tried my approach of try it and see!

So since the 77 code used write(6,'(''escape cope")') to output the ansi escape sequences I tried the following with gfortran but unfortunately with no success.

My FORTRAN program:

program coltest
c Version abc170607
write(6,'(''color 09'')')
write(6,'(''color '',i1,i1)')0,9
10 write(6,*)
write(6,*)
write(6,'('' Some text'')')
write(6,'('' *********'')')
write(6,*)
end

and what you get:

C:\FORTRAN\SourceCode>gfortran -o coltest coltest.for

C:\FORTRAN\SourceCode>coltest
color 09
color 09


Some text
*********

I guess this is no surprise really.

color 09 works at the command prompt but seemingly does not when output with a write statement more's the pity!
As my 90 year old uncle said to me recently, "HOPE springs eternal".
Yes I have had one of those Eureka moments!

So just to complete the picture after some digging and delving I came up with what just may be the obvious and it works!

program coltest
c Version Les200607
character(8 ) command
command(1:8 )='color 08'
CALL SYSTEM(COMMAND)
end program coltest

Compiled with both the g95 and gfortran compilers this LITTLE routine changes the screen background and text colours in accordance with this:

C:\My FORTRAN>color /?
Sets the default console foreground and background colors.

COLOR [attr]

attr Specifies color attribute of console output

Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground. Each digit
can be any of the following values:

0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White

If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.

The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.

Example: "COLOR fc" produces light red on bright white

C:\My FORTRAN>



Regards,

Les.



Discussion

No Comment Found