Article 128023 of comp.os.vms:
Path: nntpd.lkg.dec.com!pa.dec.com!decuac.dec.com!haven.umd.edu!ames!hookup!news.mathworks.com!newsfeed.internetmci.com!howland.reston.ans.net!news.sprintlink.net!sundog.tiac.net!laraby.tiac.net!tbutler
From: tbutler@laraby.tiac.net (Tim Butler)
Newsgroups: comp.lang.fortran,comp.os.vms
Subject: Re: Finding file size from DEC Fortran
Date: 27 Aug 95 04:43:52 GMT
Organization: The Internet Access Company
Lines: 56
Message-ID: <tbutler.809498632@laraby.tiac.net>
References: <41i6nm$bnv@trog.dra.hmg.gb> <peter-2608951814570001@piglet.demon.co.uk>
NNTP-Posting-Host: laraby.tiac.net
X-Newsreader: NN version 6.5.0 #1 (NOV)
Xref: nntpd.lkg.dec.com comp.lang.fortran:31637 comp.os.vms:128023

peter@piglet.demon.co.uk (Peter Braidwood) writes:

....
:length records with data and index compression. At present the only way
:that I can find the number of records in the file is by reading each one
:sequentially until I get to the end of the file.

   this is a unix specific solution, but if you can work out the
details of linking in a subroutine written in c, this is how I 
worked out that problem. (It was the same manifestation, I had
users that were reading enormous files twice just so they'd have the
record count.)
   You can get by with just the c version, but I also made a fortran
wrapper to save other from having to handle the null terminated string.

$ cat cfilesize.c
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>

void cfilesize(char *name, int *size)
{
  struct stat sbuf;

  stat(name,&sbuf);
  *size = sbuf.st_size;

  return;
}
$ cat ifsize.f
      integer function ifsize(filnam)
      implicit none
      character*(*) filnam
c
      integer namlen,len2,siz
      logical filex
c
      len2=len(filnam)
      namlen=index(filnam,' ')-1
      if (namlen.lt.0) namlen=len2

      inquire(file=filnam(1:namlen),exist=filex)
      if (filex) then
         call cfilesize(filnam(1:namlen)//char(0),siz)
         ifsize=siz
         return
      else
         ifsize=-1
         return
      endif
      end

--
tim butler
tbutler@tiac.net



