Direct access files - deleting last record 
Author Message
 Direct access files - deleting last record

I want to open a direct access file, delete the last record, and close the file.
Any ideas?

 Barry



Sat, 17 Aug 1996 17:29:53 GMT  
 Direct access files - deleting last record

Quote:

>I want to open a direct access file, delete the last record, and close the file.
>Any ideas?

Not feasible in standard fortran (77, but I don't think Fortran 90 is
any different in this regard). You just can't delete a record from a
direct access file. What you can do is somehow keep a table of which
records of a particular direct access file are valid, and mark the
record you want to "delete" as invalid and available for reuse. The
actual implementation of this is up to you; there are many ways of
doing it.
        You may also be able to manipulate your file at the operating
system level to truncate it just before the last record. On a Unix
system, the following (untested) C program may be handy:

#include <sys/types.h>
#include <stdlib.h>
int main (argc, argv)
    int argc;
    char *argv[];
{
    long int length; /* Record length in bytes */
    long int nrec;   /* Number of records to be left in the file */
    int status;
    if (argc != 4) return 1; /* Invalid number of arguments. */
    length = atol(argv[1]);
    nrec = atol(argv[2]);
    status = truncate (argv[3], (off_t)(nrec*length));
    if (!status) { perror("truncate"); return 2; }
    return 0;

Quote:
}

Use as: truncate <record-length> <record-count> <pathname>
If you wish to compute the record-count argument from the current size
of the file, that is also possible (with a call to stat() to obtain
the file size).
The above program may need to be adjusted if your Fortran
implementation stores direct access files in an unusual way.
--



Sun, 18 Aug 1996 00:47:02 GMT  
 Direct access files - deleting last record


Quote:

> I want to open a direct access file, delete the last record, and close the file.
> Any ideas?

Tough one.

Standard (77) Fortran has no mechanisms to determine how many records are
on a newly-opened direct access file, nor to determine the record number of
the last record, nor to delete a record.

One could, by convention, store the record number of the last record in,
say, the first record; but there's still no way to physically delete it,
although one could rewrite the record with something to indicate that the
record had been "logically" deleted.

I don't believe Fortran 90 has addressed any of these "deficiencies".

Quote:
>  Barry


--
"PHENOMENAL COSMIC POWER; itty-bitty living space."  --Robin Williams in
_Aladdin_, on the pros and cons of being a Genie.


Sun, 18 Aug 1996 18:06:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. direct access file record length

2. F2k8+/- : Direct Access File Record Locking

3. record length for direct access files

4. compressing records in a direct access file

5. Can the last record in a direct access file be shorter than the record length?

6. Deleting last record of dataset ?

7. How do I access a file's last accessed attribute

8. Direct Access Database Record Structures

9. Direct Access Record Size vs. Disk Sector Size

10. Write a direct access record data in f90

11. SGI Fortran direct access record length?

12. Record length specifier for direct access

 

 
Powered by phpBB® Forum Software