![fortran read last line from file fortran read last line from file](https://wiki.eclipse.org/images/f/fd/Photran-fortran-declaration-view.png)
! All Rights Reserved ! Released under the GNU General Public License version 2 ! Contact: ! Purple Sage Computing Solutions, Inc. ! Copyright 2001 Purple Sage Computing Solutions, Inc. !- ! modeled loosely on d2u.c, a similar utility written in C.
#FORTRAN READ LAST LINE FROM FILE SOFTWARE#
! ! You should have received a copy of the GNU General Public ! License along with this program if not, write to the Free ! Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. See the GNU ! General Public License for more details. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Urban, 20090622 !- ! Purpose: An example of a simple utility that uses stream I/O per Fortran 2003 ! Author: urbanjost ! Date: Mon !- ! REQUIRES: !#URL !- ! LICENSE: ! This program is free software you can redistribute it and/or ! modify it under the terms of the GNU General Public ! License as published by the Free Software Foundation either ! version 2 of the License, or (at your option) any later version. ( ) and if I succeed in implementing block stream IO, I will share the results here.!- !ident convert printable ASCII files between Unix and DOS line terminator conventions. For now, I am going to avoid formatted Stream IO, but if anyone has any experience with formatted stream access, I would appreciate sharing it here.
![fortran read last line from file fortran read last line from file](https://images.slideplayer.com/26/8770581/slides/slide_11.jpg)
(or perhaps with some more complex delimiter) then how should it be read back into memory from a file via stream access. That is something that I have not used in the past, and I am not quite sure if I understand fully how it works, in particular, when IO is formatted. The second major insight came from and to use stream access instead of sequential (which seems to be a great efficient solution for reading backward) and keep a record of the line starts. I had the idea of with sequential IO, and I have noticed in tests that block IO is much faster ( ), which is likely, not surprising to many here. (The program basically estimates the new allocation required when it runs out of memory and reallocates the arrays). But for any demanding real problem where the number of lines goes beyond tens or hundreds of millions (which can happen frequently), the memory (re)allocation can fail (and has failed in my tests). Indeed, that's what I have been doing for testing. I share skepticism about your file size upper For a 1-10 million that works very well. If the file is written with formatted I/O, and the record lengths vary, there isn't an efficient way to do it with straightforward standard suggestion of keeping track of locations is a good one, and is similar to the optimization I implemented on VAX, but it requires reading forward through the file, periodically (every 1000?) recording the current position (INQUIRE will tell you) so that you can position to that, then reading every record in that block, recording its position, and only then can you start to work backwards. If you open for APPEND access, you may need two BACKSPACEs when starting out, one to back over the "ENDFILE record" (which is virtual). I am not aware that the Intel implementation does anything other than rewind and forward space, which would be horrible for your case. When I worked on the VAX FORTRAN RTL, I implemented an optimized form of BACKSPACE that reduced the number of seeks, but it would not cope well with what you are doing.