forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Array output to printers

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Michael_Connelly



Joined: 13 Jul 2017
Posts: 10
Location: Sandusky, OH

PostPosted: Fri Jul 21, 2017 12:22 am    Post subject: Array output to printers Reply with quote

I understand how to display array data on the computer screen using appropriate format statements. The data lines up correctly with successive rows having the data right justified and the decimal points and data in appropriate columns.

I am attempting to get the same organized output printed by an hp Officejet Pro 8610 and have not been successful. I believe I know why. The hp printer does not have monospace font. As a result, the number 1 and number 0, for example, have different width’s so a field of printed digits will vary. Is this assessment correct?

Is there any way around this?

How do professionals output hard copy array data? Do they use monospace pin printers?

Disclaimer: I am an inexperience novice at Fortran; just finished Janet Nicholson’s tutorial. However, I am attempting to move on and begin printing hardcopy data. I searched the data base here but cannot find anything at addresses my questions on array or matrix output to printers.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2551
Location: Sydney

PostPosted: Fri Jul 21, 2017 1:20 am    Post subject: Reply with quote

You should be able to select a fixed space font.
You could import some of the text into a word document, select Courier New, size 10 and print the word document.
I find using Word is the easiest way to define the font and manage page numbers etc.

Otherwise you need to include printer control information in your file, which is probably not too hard. That is one of those useless bits of information I was glad to forget about many years ago. I can still remember the sense of achievement when I managed to print continuous charts on the Printronix printer for the first time. We only had 1 printer then, oh and the sheet feeder that was always jamming or had someone else's paper in it. Use Word !!
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Jul 21, 2017 6:14 pm    Post subject: Reply with quote

You can always print to a file, then open it in Notepad. That will format it monospaced and you can print from there. If you imported your data into Excel, you can get Excel to format it for printing in aligned columns. Even if the printer does not have a native monospaced Font, Windows does.

If you use Clearwin+, at the cost of huge effort you can get even proportionally spaced fonts to line up tables appropriately, but this is going beyond mere Fortran.

If you are in reach of me, you can come and be shown how - my hometown is shown against my username.

Eddie

Edit. Drat. Ohio. No chance ...
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Jul 21, 2017 7:59 pm    Post subject: Reply with quote

I had another think about how I do it, hunted through my programs, and found this:

Code:
     INTEGER, EXTERNAL:: NULLISH

     IF (iPrint_on_Default .EQ. 1) THEN
        IB = WINIO@('%ww[invisible]%sc','PRINTER_OPEN1',9, NULLISH)
        ELSE
        IB = WINIO@('%ww[invisible]%sc','PRINTER_OPEN',9, NULLISH)
        ENDIF
   
      WRITE(9,99) ' '    ! etcetera.


iPrint_on_Default is 1 if the default Windows printer is used, anything else brings up the printer selection menu. The bizarre-looking statements are Clearwin+ code to open an invisible-to-the-user Clearwin format window, which on startup (%sc) opens a windows printer driver rather like the OPEN statement in standard Fortran, and as I programmed it, associated logical output unit 9 to it.

'NULLISH' is an INTEGER FUNCTION that returns 0, as in:

Code:
      INTEGER FUNCTION NULLISH()
C     -------------------------
      NULLISH = 0
      RETURN
      END


I can't remember now if the print routine needs INCLUDE <WINDOWS.INS> - it probably does, or if the main program needs to be declared as WINAPP - again, probably does.

This method allows you to use Fortran layout formatting and a Windows monospaced font, because you have opened a windows printer driver for the output of Fortran including all of Fortran's layout commands.

Eddie
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Jul 21, 2017 10:31 pm    Post subject: Reply with quote

And some further thoughts from me:

You may need to CLOSE the unit, i.e. CLOSE(9) to match the fact that I have associated unit 9 with the printer, or else the last page won't come out.

Bizarrely for a novice, the usage in my fragment above is NOT the same as calling the standard subroutines with the same names, i.e.

Code:
      CALL OPEN_PRINTER1@ (handle)
      CALL OPEN_PRINTER@ (handle)


If Paul is reading this, maybe the OPEN statement needs enhancing, for people who don't want a Windows interface, to something like:

Code:
      OPEN(unit=12, file='Windows_default_printer')


- required now you can't use 'PRN' or LPT1:' etc.

Eddie
Back to top
View user's profile Send private message
Michael_Connelly



Joined: 13 Jul 2017
Posts: 10
Location: Sandusky, OH

PostPosted: Sun Jul 23, 2017 3:37 pm    Post subject: Here is where I am at Reply with quote

Thanks for your reply. At this point I do not know where to insert the code you are suggesting in my program. Here is what I have:

[program finmatrix
implicit none
!this program reads 16 numbers from a file, loads the data into an array
!and displays the data from the array on the computer screen and
!prints a copy on the associated printer
EXTERNAL test
common m
integer,allocatable,dimension(:,Smile:: matrix
integer :: i,j,m,n,winio@
m=4
allocate(matrix(m,m))
open(10,file='data123.txt')
do i=1,m
do j=1,m
read(10,*) matrix(i,j)
end do
end do
do i=1,m
write(*,12) (matrix(i,j),j=1,m)
end do
close (10)
n=winio@('%sc','PRINTER_OPEN',7,test)
12 format (20i7)
end program finmatrix

!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

INTEGER FUNCTION test()
integer :: i,j,m
common m
integer,dimension(m,m):: matrix
open(10,file='data123.txt')
do i=1,m
do j=1,m
read(10,*) matrix(i,j)
end do
end do
do i=1,m
WRITE(7,12) (matrix(i,j),j=1,m)
end do
12 format (20i7)
CLOSE(7)
test=2
END

]

Please forgive the inefficient coding but, for me, getting do loops to work, opening and closing files, and doing a lot of other basic stuff is still a big deal! Anyhow, once you have put 16:one-two-three digit numbers into a file named data123.txt this program will display a 4x4 array on the computer screen and print the array on the printer. As I have already alluded the data lines up nicely on the computer screen but, not so well on the printer.

Mike
[/code]
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sun Jul 23, 2017 5:12 pm    Post subject: Reply with quote

Hi Mike,

Your programming style is too modern (i.e. Fortran 90-ish) for me. Here it is in old-fashioned style:

Code:
      OPTIONS (INTL)

      PROGRAM EDDIE
C     -------------
      INTEGER IA(3), IB(3), IC(3)
      INTEGER, EXTERNAL:: NULLISH
      INCLUDE <WINDOWS.INS>

      iPrint_on_Default = 1
      DO 10 I=1,3
      IA(I) = I
      IB(I) = I*I
      IC(I) = I*I*I
 10   CONTINUE   

      IF (iPrint_on_Default .EQ. 1) THEN
        IWIN = WINIO@('%ww[invisible]%sc','PRINTER_OPEN1',12, NULLISH)
        ELSE
        IWIN = WINIO@('%ww[invisible]%sc','PRINTER_OPEN',12, NULLISH)
        ENDIF

       WRITE(*,*) '     1     2     3'   ! windows text screen
       WRITE(*,*) ' -----------------'
       WRITE(*,200) IA, IB, IC

       WRITE(5,*) '     1     2     3'   ! windows text screen
       WRITE(5,*) ' -----------------'
       WRITE(5,200) IA, IB, IC

       WRITE(12,*) '     1     2     3'  ! printer
       WRITE(12,*) ' -----------------'
       WRITE(12,200) IA, IB, IC
 200   FORMAT(1X,3I6)
       CLOSE(12)
       END

       INTEGER FUNCTION NULLISH()
C      -------------------------
       NULLISH = 0
       RETURN


I hadn't realised how much of a novice you are, but if you persevere, I'm sure you'll get it all. It does take time and practice.

The zero returned by the function NULLISH is to make sure that the invisible Clearwin+ window closes itself. Remember to close the output window before running this program a second time. You don't need the directive WINAPP, and iPRINT_on_Default is only to use the default printer in my program, although the test is left in. Make it 0, and you will see the printer selection window pop up.

Best regards

Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Mon Jul 24, 2017 12:25 am    Post subject: Reply with quote

Customer Service Dream Trip No. 1 .....

Michael, maybe Eddie, despite his astonishment at seeing where you are, could be tempted to pop over to you and give you the necessary help with this photo of what looks like a beautiful town on the Lake Erie (Some Mothers Have Extraordinary Offspring anyone ? Smile) shoreline !



Of course he's better get his skates on before the icebergs start floating in from the St Lawrence !!! :O)

Of course, his decision might be swung also by considering this ....



aganst this ....



71deg. in real units Wink is 21 deg. !!!! (take away 32, multiply by 5/9).
So, room temperature Yateley v nice tan in Sandusky .... no competition !

The journey is surprisingly straightforward ....



and if he was to find platform 9 1/2 at Paddington maybe he could arrive directly by train at 'New London', taking on an Italian coffee in Milan en route too !!!!!!!!! ....



Of course he would then be obliged to post in to the group on progress downtown, maybe here ......



Go on Eddie !!!! you know it makes sense Smile Smile Smile

(and I'm sure Paul could wangle the trip too on expenses Wink LOL LOL LOL )

Come to think of it, why isn't there an annual FTN95 Conference !???
I vote for Sandusky as the inaugural event location !
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2551
Location: Sydney

PostPosted: Mon Jul 24, 2017 2:26 am    Post subject: Reply with quote

Hi John,

I had a lovely family lunch at Manly beach on Sunday; 23 degC, sunny, clear blue sky, little wind; mid winter ! I wasn't contemplating Yateley or Sandusky at the time.

Michael,

To be even more modern for Eddie !!
try : write (*,12) matrix(i,1:m)

I'd forget all the print controls and just send the output to a file or run your program as : program > output.txt. Then import/paste the output into word, apply a fixed space font, adjust the margins and print.

You could also post the output on the forum enclosed in Code ... /Code , which is basically the same idea.
Using WINIO@ to select the printer and font etc looks like a lot of work to me, unless there are hundreds of these to report, in which case you could do the file open etc in a loop and write (*,*) char(12) for page feeds.

John
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Jul 24, 2017 11:10 am    Post subject: Reply with quote

Well, that far south, and with that amount of open water, there's probably a mosquito problem. They don't come out in the rain here, and even when they do, they are the tiny species that irritate, rather than big ones carrying potentially fatal diseases like malaria, haemorrhagic dengue fever, Zika, encephalitis (of various kinds, including 'St Louis') etc! Plus there are no poisonous snakes, marsupials, spiders etc as suffered by John Campbell.

Besides, the rain here means I don't have to water the lawn. And if it upsets you that it rains in Yateley, then never, ever, research Salford's weather to see what Paul endures ...

My surprise was that while in reply mode, Mike's details such as location aren't visible. They become visible once the message is posted. Interesting, that is. Hence I've offered several times to help people who turn out to be half a world away. I wouldn't mind the frequent flyer points, if someone else pays the fare.

For a very long time, printers could be accessed via an OPEN statement with the target something like LPT: or PRN: The printers in question would respond properly to Fortran output. Windows-only printers don't respond in the same way to Fortran output, and the Fortran output needs to go through a Windows printer driver.

Oddly enough, direct output to a printer is helpful in many cases. The Clearwin+ solution takes one line, just like an OPEN statement, and once coded, can be cut and pasted anywhere in your programs, happily ever after in a fairytale ending. After that, you can format output as described in any Fortran book. Otherwise, you need to read the FTN95.chm helpfile: many times. Printing from a file is useful, but requires more user steps. Imagine that a receipt in a shop was printed to a file, then printed out from the file in a separate program. It is nowhere near as simple to do Fortran output to a page in Windows graphics mode all lined up in columns when the font is proportionally spaced - indeed, it requires much more knowledge and many more lines of code.

As for modernity, IMPLICIT NONE leaves me without an important key as to what type variables are, free format robs me of the 'outdent' that helps me work out loops, lowercase looks somehow wrong for FORTRAN, and it takes me a lot of effort to reformat someone else's code before I can work on it. If modern Fortran suits you, then use it, I have no objection to that, but don't expect me to. They are new tricks, and sadly, I am an old dog (of the toothless, sad-looking, plodding variety, but which can still, sometimes, get a blind man safely across the road).

John Campbell's 'print a matrix' is fine, but the point of the code isn't the actual printing, rather it is the convoluted, bizarre-looking, WINIO@ stuff which substitutes for the OPEN statement that has been around for decades in various forms. Everything else in the sample code can be done in multiple different ways and probably better.

Eddie
Back to top
View user's profile Send private message
Michael_Connelly



Joined: 13 Jul 2017
Posts: 10
Location: Sandusky, OH

PostPosted: Tue Jul 25, 2017 5:16 pm    Post subject: Reply with quote

Eddie, John

Thanks for the tips and I am moving on.

Eddie, I could not get your program to compile so I modified it until it worked on my computer. I also changed the numbers somewhat to get two and three digit output. The lineup of the printed copy and displayed data still do not correlate. I believe it is my hp printer. I am going to try a monospace font printer an see what happens.


Code:
PROGRAM EDDIE
implicit none
!-------------
INTEGER :: IA(3), IB(3), IC(3),I,iPrint_on_Default,IWIN
INTEGER, EXTERNAL :: NULLISH
character :: a*37,b*38
INCLUDE <WINDOWS.INS>

a='            1           2           3'
b='-------------------------------------'

iPrint_on_Default = 1
DO 10 I=1,3
IA(I) = I
IB(I) = (I*I)-25
IC(I) = (I*I*I)*11
10 continue

IF (iPrint_on_Default .EQ. 1) THEN
IWIN = WINIO@('%ww[invisible]%sc','PRINTER_OPEN1',12, NULLISH)
ELSE
IWIN = WINIO@('%ww[invisible]%sc','PRINTER_OPEN',12, NULLISH)
END IF
! windows text screen
WRITE(*,201) a
WRITE(*,201) b
WRITE(*,200) IA, IB, IC
print *,' '
! windows text screen
WRITE(5,201) a
WRITE(5,201) b
WRITE(5,200) IA, IB, IC
! printer
WRITE(12,201) a
WRITE(12,201) b
WRITE(12,200) IA, IB, IC
200   format(1x,3i12)
201   format(a37)
 
CLOSE(12)
END program EDDIE

!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

INTEGER FUNCTION NULLISH()
!-------------------------
NULLISH = 0
RETURN
end


thanks for your help.
Mike
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Jul 25, 2017 7:21 pm    Post subject: Reply with quote

Hi Mike,

THere's something in your CONFIG that doesn't let you compile fixed format, and something in mine that objects to free format. A bit of judicious spacing, and I got your code to compile, generating aligned output on an HP colour laserjet, a lexmark colour laser, an Epson inkjet and three types of Lexmark inkjets, at which point it dawned on me that maybe you wanted your output in left-aligned columns.

There are various methods to get output numbers aligned left, but many of them rely on 'printing' a number to a character variable and then removing the leading blanks, for example,

character*(8) holder, result
integer=345
write(holder, '(I8)') integer

at which point holder will contain 5 blanks and the 3 digits 345. To left justify the character string, use something like

result = adjustl(holder)

Once you have a row of variables all left aligned, you can print them out before going on to the next row.

FTN95 has several non-standard routines such as TRIM@ that date back to when it was Fortran-77: ADJUSTL is a Fortran-90 intrinsic function. TRIM@ does much the same as ADJUSTL, and NONBLK returns the position of the first non-blank character, e.g.

N = NONBLK (holder) will return 6 for the example given, so that the section of holder to print is holder(6:8)

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group