Home > Archive > Fortran > September 2005 > Printing with F95
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi!
I am trying to implement printing to my Laserjet with the basic f90 F
complier from Fortran store bought some 3-4 years ago. OS NT4 . I am
new to this so please don=B4t flame me...
I recall from University times (Sweden in the early nineties) that a
Pascal complier that ran on a Mac had write and writel as different
commands to print it to screen versus imagewriter.
What would that be in the fortran world?
Anyone having a clue?
TIA
Regards, Matti
| |
| Dick Russell 2005-09-21, 7:57 am |
|
masa wrote:
> Hi!
>
> I am trying to implement printing to my Laserjet with the basic f90 F
> complier from Fortran store bought some 3-4 years ago. OS NT4 . I am
> new to this so please don=B4t flame me...
>
> I recall from University times (Sweden in the early nineties) that a
> Pascal complier that ran on a Mac had write and writel as different
> commands to print it to screen versus imagewriter.
>
> What would that be in the fortran world?
>
> Anyone having a clue?
>
> TIA
>
> Regards, Matti
Basically, you use an OPEN statement to connect an I/O statement's
logical unit number to a file or device. The WRITE statement does the
writing, specifying the logical unit number to use, format, and list of
variables to write. As a simple example, assume unit 3 is to be used
for logical unit number for the printer. A good idea is to use an
integer variable in the WRITE statements and give it an initial value
up front, in case you need to change the selection of unit number later
on. You might then have something like this:
INTEGER PRUN
PRUN=3D3
OPEN (PRUN, FILE=3D'PRN') ! this could be 'LPT1' depending on
! implementation of the Fortran system
....
WRITE(PRUN,21)XYZ
21 FORMAT(' The value of XYX is', F10.2)
END
| |
| e p chandler 2005-09-21, 6:59 pm |
|
Dick Russell wrote:
> masa wrote:
>
> Basically, you use an OPEN statement to connect an I/O statement's
> logical unit number to a file or device. The WRITE statement does the
> writing, specifying the logical unit number to use, format, and list of
> variables to write. As a simple example, assume unit 3 is to be used
> for logical unit number for the printer. A good idea is to use an
> integer variable in the WRITE statements and give it an initial value
> up front, in case you need to change the selection of unit number later
> on. You might then have something like this:
>
> INTEGER PRUN
> PRUN=3D3
> OPEN (PRUN, FILE=3D'PRN') ! this could be 'LPT1' depending on
> ! implementation of the Fortran system
> ....
> WRITE(PRUN,21)XYZ
> 21 FORMAT(' The value of XYX is', F10.2)
> END
Note that "F" is more restrictive than the Fortran 77 code above.
---- cut here ----
program test
open(unit=3D7,file=3D"prn",status=3D"old", &
action=3D"write",position=3D"rewind")
write(unit=3D7,fmt=3D"(a)")"hello, world"
write(unit=3D7,fmt=3D"(a)")char(12)
close(unit=3D7)
end program test
---- cut here ----
I just tested this on Win XP with a Deskjet 500. Older Laserjets are
character mode printers so they should work the same way.
Writing char(12) issues a form feed which ejects the page.
In Fortran, unless you specify otherwise [advance=3D"no"], write is like
the Pascal Writeln() instead of the Pascal Write().
-- Elliot
e-mail: epc8 at juno.com
HTH!
| |
| beliavsky@aol.com 2005-09-21, 7:00 pm |
| masa wrote:
> Hi!
>
> I am trying to implement printing to my Laserjet with the basic f90 F
> complier from Fortran store bought some 3-4 years ago. OS NT4 .
I'd like to mention that you can get a free newer version of F from
http://www.fortran.com/F/compilers.html , and that the free g95
compiler also has an F mode.
> I am new to this so please don=B4t flame me...
Don't worry, the people who flame in this newsgroup target the most
knowledgable and experienced.
| |
|
| How do I know what logical unit number to use?
It=B4s a PC and the printer is a HP lasrjet 5 Si MX connected directly
to the LPT1 port.
/Matti
| |
|
|
masa schreef:
> How do I know what logical unit number to use?
> It=B4s a PC and the printer is a HP lasrjet 5 Si MX connected directly
> to the LPT1 port.
>
> /Matti
You may use any number from 1 to 99
I prefer numbers from 10 up, because compilers may reserve
certain numbers for preconnected files, std_in, std_out, etc.
[JvO]
| |
| Herman D. Knoble 2005-09-22, 6:58 pm |
| And if the printer is a networked printer before running
the Fortran program issue:
net use lpt1: \\path\hplj8100 /PERSISTENT:NO
where path is the workgroup or domain of the printer.
Skip
On 21 Sep 2005 06:47:31 -0700, "e p chandler" <epc8@juno.com> wrote:
-|
-|Dick Russell wrote:
-|> masa wrote:
-|> > Hi!
-|> >
-|> > I am trying to implement printing to my Laserjet with the basic f90 F
-|> > complier from Fortran store bought some 3-4 years ago. OS NT4 . I am
-|> > new to this so please donīt flame me...
-|> >
-|> > I recall from University times (Sweden in the early nineties) that a
-|> > Pascal complier that ran on a Mac had write and writel as different
-|> > commands to print it to screen versus imagewriter.
-|> >
-|> > What would that be in the fortran world?
-|> >
-|> > Anyone having a clue?
-|> >
-|> > TIA
-|> >
-|> > Regards, Matti
-|>
-|> Basically, you use an OPEN statement to connect an I/O statement's
-|> logical unit number to a file or device. The WRITE statement does the
-|> writing, specifying the logical unit number to use, format, and list of
-|> variables to write. As a simple example, assume unit 3 is to be used
-|> for logical unit number for the printer. A good idea is to use an
-|> integer variable in the WRITE statements and give it an initial value
-|> up front, in case you need to change the selection of unit number later
-|> on. You might then have something like this:
-|>
-|> INTEGER PRUN
-|> PRUN=3
-|> OPEN (PRUN, FILE='PRN') ! this could be 'LPT1' depending on
-|> ! implementation of the Fortran system
-|> ....
-|> WRITE(PRUN,21)XYZ
-|> 21 FORMAT(' The value of XYX is', F10.2)
-|> END
-|
-|Note that "F" is more restrictive than the Fortran 77 code above.
-|
-|---- cut here ----
-|
-|program test
-|
-|open(unit=7,file="prn",status="old", &
-| action="write",position="rewind")
-|write(unit=7,fmt="(a)")"hello, world"
-|write(unit=7,fmt="(a)")char(12)
-|close(unit=7)
-|
-|end program test
-|
-|---- cut here ----
-|
-|I just tested this on Win XP with a Deskjet 500. Older Laserjets are
-|character mode printers so they should work the same way.
-|
-|Writing char(12) issues a form feed which ejects the page.
-|
-|In Fortran, unless you specify otherwise [advance="no"], write is like
-|the Pascal Writeln() instead of the Pascal Write().
-|
-|-- Elliot
-|
-|e-mail: epc8 at juno.com
-|
-|HTH!
| |
| Michael Prager 2005-09-22, 6:58 pm |
| "[JvO]" <jvo_36@hotmail.com> wrote:
>You may use any number from 1 to 99
>
>I prefer numbers from 10 up, because compilers may reserve
>certain numbers for preconnected files, std_in, std_out, etc.
Yes. I'd go further. Because so many compilers do give special
meanings to low unit numbers, I suggest you NEVER use unit
numbers < 10.
--
Mike Prager, NOAA, Beaufort, NC
Address spam-trapped; remove color to reply.
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.
| |
| Richard E Maine 2005-09-22, 6:58 pm |
| In article <1127375611.313493.75540@g14g2000cwa.googlegroups.com>,
"[JvO]" <jvo_36@hotmail.com> wrote:
> masa schreef:
>
>
> You may use any number from 1 to 99
>
> I prefer numbers from 10 up, because compilers may reserve
> certain numbers for preconnected files, std in, std out, etc.
To elaborate, because it appears to me that the OP doesn't realize...
The choice of unit number is purely an internal matter that has little
to do with where the file is going. There is no such thing as a special
unit number for the printer. Basically the choice is yours, subject only
to the requirements of sticking to unit numbers that the compiler
supports and that don't conflict with special purposes; what JvO gave
you are guidelines for those requirements.
Most compilers do assign a few special unit numbers - notably for
standard input and standard output. This depends on the specific
compiler, not the language in general (though there are a few very
common choices that are almost defacto standards). But you won't find a
special number for a printer on a Windows box with any compiler today.
Things were very different in the past - say the 50's and 60's and even
somewhat into the 70'.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| andy2O 2005-09-22, 6:58 pm |
| masa wrote:
> How do I know what logical unit number to use?
> It=B4s a PC and the printer is a HP lasrjet 5 Si MX connected directly
> to the LPT1 port.
>
> /Matti
Hi Matti,
You've made a simple misunderstanding - very easily corrected!
The section of the sample codes that Elliot and Dick posted which refer
to the printer is NOT the unit number.
It is infact the choice of a special filename in the file=3D section of
the OPEN(....) command which specifies the printer. In Elliot's case it
seems his printer port is called PRN, so he used file=3D"PRN" in his
sample to connect to his printer.
As your printer is on port LPT1, then you probably want to use
file=3D"LPT1" within the OPEN statement instead to connect to you
printer, as Dick suggested in a comment within his sample code.
The correct special filename which connects to the printer can vary
from system to system, so you might want to make it easy to change this
within your program if the code will run on other computers.
As someone else said, you can use any unit number up to 99, but you
would be sensible to choose a number above 10, and to make sure that
unit number is not used by any other unrelated data input/output
routines in your code.
Hope that helps.
Andy
| |
| glen herrmannsfeldt 2005-09-22, 6:58 pm |
| Richard E Maine wrote:
(snip regarding unit numbers)
> Most compilers do assign a few special unit numbers - notably for
> standard input and standard output. This depends on the specific
> compiler, not the language in general (though there are a few very
> common choices that are almost defacto standards). But you won't find a
> special number for a printer on a Windows box with any compiler today.
> Things were very different in the past - say the 50's and 60's and even
> somewhat into the 70'.
Popular for a long time, and probably still, is 5 for standard input,
(a little more general than the unix/C stdin), and 6 for output.
Then 7 for the card punch, but that probably isn't so common today.
-- glen
| |
|
| Hi again fellows,
I compiled the code (using unit 12 instead of 7) and it worked
perfectly.
Thanks all for the help!
/Matti
|
|
|
|
|