 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
lawchellie
Joined: 22 Dec 2011 Posts: 8
|
Posted: Mon Apr 16, 2012 10:30 am Post subject: cannot connect to a file! |
|
|
hello guys!
pls how can i connect a source code to a file? have this source code below but cannot connect to the file even when i have it locally. thanks
! a dummy program
implicit none
real:: sum, avg, score1, score2, score3
integer:: counter
open(unit=5, file='in_scr.txt', status='old')
open(unit=6, file='out_scr.txt', status='new')
do 10 counter=1,3
sum=0.0
read(5,20)score1, score2, score3
sum=score1+score2+score3
avg=sum/3
write(6,30)counter, score1, score2, score3
write(6,40)sum, avg
10 continue
stop
20 format(3(f5.2, 2x))
30 format(//, 'student', i2,/, 'score1', 2x, f5.2,/, 'score2', 2x, f5.2,/, 'score3', 2x, f5.2)
40 format(/, 'total and average =', 2x, 2(f6.2, 2x), 'respectively', //)
end |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Mon Apr 16, 2012 11:35 am Post subject: |
|
|
Use different UNIT numbers. 5 and 6 are reserved. Use values that are greater than 6. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Apr 16, 2012 6:10 pm Post subject: |
|
|
Here you go.
Code: |
! a dummy program
implicit none
real:: sum, avg, score1, score2, score3
integer:: counter
open(unit=10, file='in_scr.txt', status='old')
open(unit=11, file='out_scr.txt', status='new')
do 10 counter=1,3
sum=0.0
read(10,20)score1, score2, score3
sum=score1+score2+score3
avg=sum/3
write(11,40)sum, avg
write(11,30)counter, score1, score2, score3
10 continue
stop
20 format(3(f5.2, 2x))
30 format(//, 'student', i2,/, 'score1', 2x, f5.2,/, 'score2', 2x, f5.2,/, 'score3', 2x, f5.2)
40 format(/, 'total and average =', 2x, 2(f6.2, 2x), 'respectively', //)
end
|
_________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
klclark
Joined: 19 Dec 2011 Posts: 10
|
Posted: Fri May 18, 2012 3:39 pm Post subject: open_printer@ and printer_open@ |
|
|
The function "open_printer@" returns a value of "1" which indicates the printer was opened but when trying to write to it I get the error not opened. If you use "printer_open@" using WINIO@ everything works just fine. I would like to use the first example since it would not require additional interaction from the user. Please let me know what I need to do.
**************************************************
FIRST EXAMPLE WHICH DOESN'T WORK.......................
**************************************************
winapp
program testprint02
INCLUDE <windows.ins>
INTEGER HANDLE
HANDLE = 7
!
!
!
i=(OPEN_PRINTER@(HANDLE))
if (i .eq. 1) then
write (HANDLE,10) i
10 format (1x,i5,10x,'testprint02')
endif
close (7)
END
***********************************************
SECOND EXAMPLE WHICH WORKS FINE.....................
***********************************************
winapp
program testprint01
INCLUDE <windows.ins>
EXTERNAL printer
!
!
!
i=winio@('Press this button to print a page: %nl&')
i=winio@('%^bt[Print]&','PRINTER_OPEN',7,printer)
i=winio@('%2nl%cn%bt[OK]')
call testit
close (7)
END
! c-----
INTEGER FUNCTION printer()
write(7,15)'Hello'
15 format(1x,a5)
do i = 1 , 10
print 10, i
10 format (5X,i5)
write (7,10) i
end do
! CLOSE(7)
printer=2
END
subroutine testit
print *,'subroutine testit'
write (7,20)
20 format (1x,'subroutine testit')
end |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Fri May 18, 2012 8:48 pm Post subject: |
|
|
Your first example doesn't work for 2 reasons.
1. Open_PRINTER@ opens a printer for output of graphics, not Fortran formatted text output. You would need to use graphics subroutines to write to it.
2. Handle isn't a unit number, so it cannot be used where you used it in a WRITE statement.
Assuming that you have a standard printer connected via a parallel port (increasingly, printers are Windows-only and computers don't have parallel ports!) then you could try:
Code: | OPEN (7, FILE='LPT:') |
(and sometimes LPT1: works, or maybe PRN: - you would need to experiment).
If you do want to use the WINIO@ Clearwin approach, but you don't want the user to press a button, then use %sc instead of %bt.
Eddie |
|
Back to top |
|
 |
klclark
Joined: 19 Dec 2011 Posts: 10
|
Posted: Fri May 18, 2012 9:45 pm Post subject: |
|
|
I'm not quite sure I did this correctly but I still get a button to push (click on the (X)), no button and I get the printer to work. This is a windows printer. I don't think anyone uses LPT1 or PRN any more, except the real old stuff.
I commented out 2 of the WINIO calls and changed the middle one to %sc where the %bt was before and it still produces a window box which you have to click on the "X" to get the printer output.
winapp
program testprint01
INCLUDE <windows.ins>
EXTERNAL printer
!
!
!
! i=winio@('Press this button to print a page: %nl&')
i=winio@('%sc[Ready to Print?]','PRINTER_OPEN',7,printer)
! i=winio@('%2nl%cn%bt[OK]')
call testit
close (7)
END
! c-----
INTEGER FUNCTION printer()
write(7,15)'Hello'
15 format(1x,a5)
do i = 1 , 10
print 10, i
10 format (5X,i5)
write (7,10) i
end do
! CLOSE(7)
printer=2
END
subroutine testit
print *,'subroutine testit'
write (7,20)
20 format (1x,'subroutine testit')
end |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Fri May 18, 2012 10:19 pm Post subject: |
|
|
Printing starts after you select a printer. Rather than CLOSE(7) I suggest
Code: | I = CLOSE_PRINTER@ (0) |
or
Otherwise output waits until you close the application with the red X (close box). The application would close automatically if you had returned
That old LPT: stuff still works if the hardware supports it.
Eddie |
|
Back to top |
|
 |
klclark
Joined: 19 Dec 2011 Posts: 10
|
Posted: Sat May 19, 2012 3:18 am Post subject: |
|
|
This is great! I used "printer = 0" with no other change and the printer printed. How ever a box was still created on the screen which went away after printing was finished with out me clicking on the "red X". It would be nice if there was no box.
Thank you very much............ |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sat May 19, 2012 12:49 pm Post subject: |
|
|
You want no box (no window)? In that case you need to make it invisible. This needs 2 things: firstly the window itself has to be invisible, and also secondly you don't want it to appear on the taskbar either, so use the code:
Code: | %ww[invisible,toolwindow] |
and you won't see it anywhere!
Eddie |
|
Back to top |
|
 |
klclark
Joined: 19 Dec 2011 Posts: 10
|
Posted: Sat May 19, 2012 3:38 pm Post subject: |
|
|
This is exactly what I wanted. Nice job! |
|
Back to top |
|
 |
|
|
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
|