Silverfrost Forums

Welcome to our forums

DIRENT@ problem on FTN 8.95.0

21 Jul 2023 3:43 #30467

The example program from the manual:

PROGRAM DIRENT CHARACTER (LEN=20)::PAT,FILE INTEGER (KIND=2)::ATTR,DATE,TIME,EC INTEGER (KIND=3)::SIZE CALL COUA@('Input directory pattern:') READ '(A)',PAT EC=0 DO WHILE(EC == 0) CALL DIRENT@(PAT,0,FILE,ATTR,DATE,TIME,SIZE,EC) IF (EC == 0) PRINT '(A,I6,I6,I6,I6)',FILE, ATTR, DATE, TIME, SIZE !Do not call DIRENT@(PAT2,...) from here END DO END PROGRAM DIRENT

Does not work for either x64 or Win32

For x64 I get DIRENT@ is an undefined symbol during linking. For Win32 the program links OK, but on running there is an error: In DIRENT@ - dummied out at present

21 Jul 2023 7:16 (Edited: 22 Jul 2023 7:40) #30468

Use get_filtered_file@

Extracted from the code :

title = 'Select File'
path = '.'
file_name = 'a.rtg'
filter_names(1) = 'RTG files'
filters(1) = '*.rtg'
filter_names(2) = 'All files'
filters(2) = '*.*'
number_of_filters = 2
must_exist = .true.

call get_filtered_file@(title, file_name, path, filter_names, filters, number_of_filters, must_exist)

file_nameRTGsel    = file_name

https://i.postimg.cc/SNvdmsVx/Screenshot111.png

22 Jul 2023 6:54 #30469

The routine to use is FILES@.

It looks like DIRENT@ is an FTN77 routine that should not be in the FTN95 documentation.

22 Jul 2023 7:01 #30470

Hopefully this post of using files8@ answers some questions PROGRAM DIRENT_test

! SUBROUTINE FILES@(PAT, N, NMAX, FILES, ATTR, DATE, TIME, FILE_SIZE) 
  integer*2, parameter :: nmax = 1024
  CHARACTER (LEN=128) PAT,FILES(NMAX) 
  INTEGER (KIND=2) N, i
  INTEGER (KIND=2) ATTR(NMAX), DATE(NMAX), TIME(NMAX) 
!  INTEGER (KIND=3) FSIZE(NMAX)
  REAL    (KIND=2) FSIZE(NMAX)
  integer (KIND=4) jsize
  character :: cattr*6, cdate*10, ctime*8

  CALL COUA@('Input directory pattern:')
  READ '(A)',PAT

  call FILES8@ (PAT, N, NMAX, FILES, ATTR, DATE, TIME, FSIZE) 

  DO i = 1,n
    cattr = attr_string (attr(i))
    cdate = date_string (date(i))
    ctime = time_string (time(i))
    jsize = fsize(i)
    write (*,11) i, cattr, cdate, ctime, jsize, trim(FILES(i))
  END DO
  write (*,*) n, ' files located for ', trim(pat)
 11 format (i4, a8, a12, a9, i13, 2x, A)
  
  contains
  
  character*10 function date_string (dos_date)
! https://forums.silverfrost.com/Forum/Topic/142&highlight=compressed+date
    character*10 string
    integer*2 dos_date
    integer   date_day, date_month, date_year
    date_day   = ibits(dos_date, 0, 5)
    date_month = ibits(dos_date, 5, 4)
    date_year  = ibits(dos_date, 9, 7) + 1980
    write ( string,fmt='(i2,'/',i2.2,'/',i4)' ) date_day, date_month, date_year
    date_string = string
  end function date_string

  character*8 function time_string (dos_time)
    character*8 string
    integer*2 dos_time
    integer time_second, time_minute, time_hour
    time_second = ibits(dos_time,  0, 5)*2
    time_minute = ibits(dos_time,  5, 6)
    time_hour   = ibits(dos_time, 11, 5)
    write ( string,fmt='(i2,':',i2.2,':',i2.2)' ) time_hour, time_minute, time_second
    time_string = string
  end function time_string

  character*6 function attr_string ( dos_attr )
    use msw32prm
!  https://forums.silverfrost.com/Forum/Topic/143&highlight=file+attributes

    character*6 string
    integer*2 dos_attr
    string = ' '
    if (iand(dos_attr, FILE_ATTRIBUTE_DIRECTORY) > 0) string = trim(string) // 'D'  ! ' directory'  16
    if (iand(dos_attr, FILE_ATTRIBUTE_HIDDEN)    > 0) string = trim(string) // 'H'  ! ' hidden'      2
    if (iand(dos_attr, FILE_ATTRIBUTE_NORMAL)    > 0) string = trim(string) // 'N'  ! ' normal'    128
    if (iand(dos_attr, FILE_ATTRIBUTE_READONLY)  > 0) string = trim(string) // 'R'  ! ' read only'   1
    if (iand(dos_attr, FILE_ATTRIBUTE_ARCHIVE)   > 0) string = trim(string) // 'A'  ! ' archive'    32
    if (iand(dos_attr, FILE_ATTRIBUTE_SYSTEM)    > 0) string = trim(string) // 'S'  ! ' system'      4
    if (iand(dos_attr, FILE_ATTRIBUTE_TEMPORARY) > 0) string = trim(string) // 'T'  ! ' temporary' 256
    attr_string = string
  end function attr_string

END PROGRAM DIRENT_test
22 Jul 2023 7:20 #30471

FILES8@ is very useful but a bit quirky, as it supports up to nmax = 2^31-1 files. (Presumably DOS file system is the same)

I have used character (len=256) files(nmax), although larger might be supported, check DOS FILE name limit ?

Not sure why FILES8@ is real*8 size ?

Once you get the hang of pat options, you can scan the whole disk, subject to Windows security restrictions. If a file has a directory attribute, you can then recursively search that tree and off you go.

I use it to search a disk and list all files, eg modified since a certain date. Note time is given in UTC, which can be difficult to update to local time, especially if the file date/time is near midnight on 1-Jan or worse midnight on 1-Mar

23 Jul 2023 10:18 #30472

Wouldn't it be a great idea if someone went through the documentation for the old FTN77 libraries, identifying which routines still work, which ones don't work, and which ones have been superceded?

Eddie

24 Jul 2023 6:20 #30473

Eddie

I think that DIRENT is exceptional. It is in the export table for salflibc.dll so it was assumed that it had been ported to FTN95 and therefore included in the documentation. It was never implement because FILES@ (or FILES8@) is better.

The documentation is intended to include all relevant routines. Possible exceptions are routines like RS (right shift) that ought to be replaced by Standard Fortran 90 routines and low level routines like LOC and CORE4.

24 Jul 2023 8:21 #30474

Hi Paul,

Well, that is (or are) maybe the ones that don't work. What I also suspect is that there are many useful routines in the support for FTN77. Not everyone knows about FTN77, or even that its documentation is online.

Eddie

24 Jul 2023 4:33 #30475

Thank you for the suggestions. I have rewritten my program, different from the manual example, to use FILES@, and everything is working now.

Patrick

Please login to reply.