1.

Solve : Colour with FORTRAN g95 in Windows XP??

Answer» <html><body><p>Can you have background and foreground text colours in executable programs, compiled with the free FORTRAN compiler g95, to run in Windows XP? <br/><br/>I have old FORTRAN 77 source <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a> that when compiled produces a 16 bit executable that can run c/o ntvdm.exe with <a href="https://interviewquestions.tuteehub.com/tag/simple-1208262" style="font-weight:bold;" target="_blank" title="Click to know more about SIMPLE">SIMPLE</a> colours <a href="https://interviewquestions.tuteehub.com/tag/using-1441597" style="font-weight:bold;" target="_blank" title="Click to know more about USING">USING</a> ANSI.sys escape sequences with the simple addition of an ansi.sys entry in my \System32\CONFIG.NT file. <br/><br/>I have been given to believe that this technique is not available for the 32 bit executables produced by g95. <br/><br/>This is born out by the fact that screen output from these executables is not in colour.<br/><br/>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! <br/><br/>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.<br/><br/>My FORTRAN program:<br/><br/> program coltest<br/>c Version abc170607<br/> write(6,'(''color 09'')')<br/> write(6,'(''color '',i1,i1)')0,9<br/>10 write(6,*)<br/> write(6,*)<br/> write(6,'('' Some text'')')<br/> write(6,'('' *********'')')<br/> write(6,*)<br/> end<br/><br/>and what you get:<br/><br/>C:\FORTRAN\SourceCode&gt;gfortran -o coltest coltest.for<br/><br/>C:\FORTRAN\SourceCode&gt;coltest<br/>color 09<br/>color 09<br/><br/><br/>Some text<br/>*********<br/><br/>I guess this is no surprise really. <br/><br/>color 09 works at the command prompt but seemingly does not when output with a write statement more's the pity!<br/>As my 90 year old uncle said to me recently, "<a href="https://interviewquestions.tuteehub.com/tag/hope-25911" style="font-weight:bold;" target="_blank" title="Click to know more about HOPE">HOPE</a> springs eternal". <br/>Yes I have had one of those Eureka moments! <br/><br/>So just to complete the picture after some digging and delving I came up with what just may be the obvious and it works!<br/><br/> program coltest<br/>c Version Les200607<br/> character(8 ) command<br/> command(1:8 )='color 08'<br/> CALL SYSTEM(COMMAND)<br/> end program coltest<br/><br/>Compiled with both the g95 and gfortran compilers this <a href="https://interviewquestions.tuteehub.com/tag/little-1075899" style="font-weight:bold;" target="_blank" title="Click to know more about LITTLE">LITTLE</a> routine changes the screen background and text colours in accordance with this:<br/><br/>C:\My FORTRAN&gt;color /?<br/>Sets the default console foreground and background colors.<br/><br/>COLOR [attr]<br/><br/> attr Specifies color attribute of console output<br/><br/>Color attributes are specified by TWO hex digits -- the first<br/>corresponds to the background; the second the foreground. Each digit<br/>can be any of the following values:<br/><br/> 0 = Black 8 = Gray<br/> 1 = Blue 9 = Light Blue<br/> 2 = Green A = Light Green<br/> 3 = Aqua B = Light Aqua<br/> 4 = Red C = Light Red<br/> 5 = Purple D = Light Purple<br/> 6 = Yellow E = Light Yellow<br/> 7 = White F = Bright White<br/><br/>If no argument is given, this command restores the color to what it was<br/>when CMD.EXE started. This value either comes from the current console<br/>window, the /T command line switch or from the DefaultColor registry<br/>value.<br/><br/>The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute<br/>the COLOR command with a foreground and background color that are the<br/>same.<br/><br/>Example: "COLOR fc" produces light red on bright white<br/><br/>C:\My FORTRAN&gt;<br/><br/><br/><br/>Regards,<br/><br/>Les.<br/></p></body></html>


Discussion

No Comment Found