(j3.2006) So that I don't need to do stuff already done....

Rafik Zurob rzurob
Wed Oct 19 19:28:25 EDT 2016


The issue here is that to read the directory, you need to have the 
definition of struct dirent, which may vary by platform.  In C/C++, that's 
ok because you get the right definition by #including <dirent.h>.  But in 
Fortran code, you need to do one of the following:
1. Run the conversion script every time you build on a new platform
2. Base your Fortran dirent derived type on the platform you care about 
and manually change it every time you port to a new platform
3. Write a C wrapper function that takes a struct dirent * and returns a 
struct you define that has the components you need in the order you want, 
and that has a matching Fortran bind(c) derived type.  Every time you need 
to read the value of a struct dirent *, you'd need to call the C function 
to convert to your Fortran derived type.

Regards

Rafik

j3-bounces at mailman.j3-fortran.org wrote on 19/10/2016 09:00:01 AM:

> From: "Clune, Thomas L. (GSFC-6101)" <thomas.l.clune at nasa.gov>
> To: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
> Cc: Van Snyder <Van.Snyder at jpl.nasa.gov>
> Date: 19/10/2016 09:00 AM
> Subject: Re: (j3.2006) So that I don't need to do stuff already done....
> Sent by: j3-bounces at mailman.j3-fortran.org
> 
> Van,
> 
> If I understand correctly, Dan Nagle had an intern that wrote a 
> script to auto generate Fortran wrappers given C header files.   He 
> seemed fairly confident that the process was robust for ?most? 
> things and readily repaired for the exceptions.
> 
> _ Tom
> 
> 
> 
> 
> > On Oct 18, 2016, at 10:28 PM, Bill Long <longb at cray.com> wrote:
> > 
> > Seems like a hard way get a list of the files in a directory.  And
> depends on the file system being POSIX.   Why not do something easy, 
like
> > 
> > program readdir
> >  implicit none
> >  character(1000) :: filename
> >  integer :: u,ios
> > 
> >  call execute_command_line ("ls -1 > names.txt")
> >  open (newunit=u, file="names.txt")
> >  do 
> >     read (u,"(a)", iostat=ios) filename
> >     if (ios /= 0) exit
> >     write (*,*) trim(filename)
> >  end do
> > 
> > end program readdir
> > 
> > 
> > Cheers,
> > Bill
> > 
> > 
> > On Oct 18, 2016, at 9:13 PM, Van Snyder <Van.Snyder at jpl.nasa.gov> 
wrote:
> > 
> >> So that I don't need to do stuff that somebody else has almost 
certainly
> >> already done...
> >> 
> >> Has anybody written interfaces to POSIX routines opendir, readdir and
> >> closedir, and used them to read the file names in a directory?
> >> 
> >> NAG provides wrappers for these routines in f90_unix_dirent (and 
perhaps
> >> others do something similar), but since I'm required to use several
> >> processors I'd prefer something open-source and based on Clause 18.
> >> 
> >> 
> >> _______________________________________________
> >> J3 mailing list
> >> J3 at mailman.j3-fortran.org
> >> http://mailman.j3-fortran.org/mailman/listinfo/j3
> > 
> > Bill Long 
> longb at cray.com
> > Fortran Technical Support  & 
> voice:  651-605-9024
> > Bioinformatics Software Development                     fax: 
651-605-9142
> > Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
> > 
> > 
> > _______________________________________________
> > J3 mailing list
> > J3 at mailman.j3-fortran.org
> > http://mailman.j3-fortran.org/mailman/listinfo/j3
> 
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3





More information about the J3 mailing list