replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - cannot connect to a file!
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 

cannot connect to a file!

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



Joined: 22 Dec 2011
Posts: 8

PostPosted: Mon Apr 16, 2012 10:30 am    Post subject: cannot connect to a file! Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Mon Apr 16, 2012 11:35 am    Post subject: Reply with quote

Use different UNIT numbers. 5 and 6 are reserved. Use values that are greater than 6.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Mon Apr 16, 2012 6:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
klclark



Joined: 19 Dec 2011
Posts: 10

PostPosted: Fri May 18, 2012 3:39 pm    Post subject: open_printer@ and printer_open@ Reply with quote

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
View user's profile Send private message
LitusSaxonicum



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

PostPosted: Fri May 18, 2012 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
klclark



Joined: 19 Dec 2011
Posts: 10

PostPosted: Fri May 18, 2012 9:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
LitusSaxonicum



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

PostPosted: Fri May 18, 2012 10:19 pm    Post subject: Reply with quote

Printing starts after you select a printer. Rather than CLOSE(7) I suggest

Code:
I = CLOSE_PRINTER@ (0)


or

Code:
CALL NEW_PAGE@



Otherwise output waits until you close the application with the red X (close box). The application would close automatically if you had returned

Code:
printer=0


That old LPT: stuff still works if the hardware supports it.

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



Joined: 19 Dec 2011
Posts: 10

PostPosted: Sat May 19, 2012 3:18 am    Post subject: Reply with quote

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
View user's profile Send private message
LitusSaxonicum



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

PostPosted: Sat May 19, 2012 12:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
klclark



Joined: 19 Dec 2011
Posts: 10

PostPosted: Sat May 19, 2012 3:38 pm    Post subject: Reply with quote

This is exactly what I wanted. Nice job!
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