|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Little-Acorn
Joined: 06 Jul 2008 Posts: 111 Location: San Diego
|
Posted: Thu Dec 08, 2011 11:16 pm Post subject: Copying a text file from one disk drive to another withFTN95 |
|
|
I've written a large program which, upon startup, will have to open a file on one disk drive (a remote one on our system), and copy it to another disk drive (the local C: drive on the computer the program is running on).
I can only access the remote file by using the ATTACH@ routine. I have experimented with ways of doing that, and it works well.
But for various reason I cannot just read in the entire file, then turn and write out the entire file. Instead I must read in one line (approx. 200 characters, it varies) from the remote file, then write that line to the file on the local C: drive, then read the next line from the remote file, then write to the C: drive etc.
Is there a way of doing this without ATTACH@ing the remote file, opening it, reading one line, closing the remote file, ATTACH@ing the local file, opening it, writing the (single) line, closing the local file, ATTACH@ing the remote file, opening it again, reading past the first line and reading in the second line, closing the remote file, ATTACH@ing the local file, opening it in APPEND mode, writing the second line to the end of it, closing the local file, ATTACH@ing the remote file, etc. etc.?
In other words, is it possible for me to have a file on a remote drive open for reading, and a file on a local drive open for writing, at the same time? (When I have had two files on the same local C: drive, it has been easy to have both open in this way. But what about one on the local C: drive and the other on the remote Z: drive that needs an ATTACH@ statement?)
There are 10,000 lines or more. It seems like a huge amount of overhead involved in transferring each line. But is most of that "overhead" really just a few bit flips, which don't take much more "real time" than it would take to copy a local file to another local file with no ATTACH@'s, and just one OPEN for each file, then read,write,read,write, etc.?
If there really is a lot of overhead in the method I described, then is there any more streamlined way of doing this?
--------------------------------------
A related question: How big is the clipboard? Would it be possible to use the READ command and then the COPY_TO_CLIPBOARD@ command many times, to copy the enitre 2GB remote text file to the clipboard? And then use the COPY_FROM_CLIPBOARD@ and the WRITE commands many times, to write the entire file from the clipboard to the local file? |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Thu Dec 08, 2011 11:40 pm Post subject: |
|
|
I may have missed your need for ATTCH@, but you should be able to open the files, giving their tree name, without the need for attaching. I would expect the following example should work in most cases: Code: | character line*256
integer*4 i, iostat,l
!
open (unit=11, file='g:\directory\file.txt', action='READ', iostat=iostat)
open (unit=12, file='c:\local_directory\file.txt', iostat=iostat)
!
l = 0
do i = 1,huge(i)
read (11,fmt='(a)',iostat=iostat) line
if (iostat/=0) exit
write (12,fmt='(a)') trim (line)
l = max (l,len_trim(line))
end do
write (*,*) 'end of file at line',i-1,' error code =',iostat
write (*,*) 'max line length =',l,' (256)'
end |
You could add more code to test the value of iostat, or convert the file names into character variables to make it more robust.
John
PS : Alternatively just open the file directly on the network drive and read from there. You may need to review OPEN to allow multiple read access. This is discussed in the OPEN documentation. I am not aware of a reason for not being able to open the network file, as I have described, although you may have one. |
|
Back to top |
|
|
Little-Acorn
Joined: 06 Jul 2008 Posts: 111 Location: San Diego
|
Posted: Fri Dec 09, 2011 2:16 am Post subject: |
|
|
Well, now I feel dumb. The remote drive is mapped as the Z: drive, and I had tried several methods of doing a directory search on Z: using front slashes, back slashes etc. None seemed to work.
And now I just tried a few more, and bingo, one worked.
So this whole thread addresses a problem that (it turns out) doesn't exist.
My apologies for costing you a lot of brain cycles over it. You fellows keep helping me no matter how dumb my questions are.
As Master Shifu said, there is now a level zero. (Can you tell I have a 5-year-old and 13-year-old son?) |
|
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
|