Re: directory listing



On 29 aug, 00:08, fj <francois.j...@xxxxxxx> wrote:
On 28 août, 22:23, gokha...@xxxxxxxxx wrote:> Hello:

Is there a way to obtain a list of files having a specified extension
using Fortran /Intel Fortran 9.1?

Thanks,

-Nachiket

Using the specific Intel library is OK but a "more portable" way
consists in calling the routine SYSTEM available with most compilers.
But it remains necessary to test the operating system :

CHARACTER(10) :: extension="f90"
CHARACTER(255) :: cfile

IF(os == "unix") THEN
CALL system('ls -1 -p *.'//TRIM(extension)//'> list')
ELSE
CALL system('dir /b/ad/on *.'//TRIM(extension)//'> list')
ENDIF

Notice the options used respectively for the os dependent commands
"ls" and "dir" : they provide a very similar result ! After that, you
just have to open the file "list" and read each line using the format
"(A)" :

OPEN(15,file="list") ! of course you can use another unit or even
select a free unit
! or even select a free unit (not used) but this
is another story
n=0
DO
READ(15,"(A)",END=10) cfile
write(*,*) TRIM(cfile)
ENDDO
10 CONTINUE

Small note: the option /ad means select only directories

Interesting idea though.

Regards,

Arjen

.



Relevant Pages

  • Re: directory listing
    ... using Fortran /Intel Fortran 9.1? ... consists in calling the routine SYSTEM available with most compilers. ... CHARACTER:: cfile ... or even select a free unit but this ...
    (comp.lang.fortran)
  • Re: directory listing
    ... using Fortran /Intel Fortran 9.1? ... consists in calling the routine SYSTEM available with most compilers. ... CHARACTER:: cfile ... or even select a free unit but this ...
    (comp.lang.fortran)
  • Re: Program compiled on intel acting weired
    ... > freefilewhich will returns a free unit number for I/O. ... There isn't one in the Fortran standard (though one has been proposed ... And cvf might well have something compiler-specific, which is fine, ...
    (comp.lang.fortran)
  • Re: Most elegant way to read to allocatable array?
    ... The minimal change to Fortran could be a new key in the OPEN ... perform an implicit inquire with the NEWUNIT specifier. ... you to INQUIRE a free unit without immediately opening/assigning to ...
    (comp.lang.fortran)
  • Re: directory listing
    ... using Fortran /Intel Fortran 9.1? ... consists in calling the routine SYSTEM available with most compilers. ...
    (comp.lang.fortran)