Silverfrost Forums

Welcome to our forums

How can I open several files at the same time?

17 Aug 2010 2:40 #6786

I want to open several data files at the same time in order to plot all data at once and compare different experimental data on a single graph. However, I do not see how it could be done using Clearwin facilities. Usually, graphing softwares allow to select several files using Ctrl+mouse click and import all data, but after reading the Clearwin Help I did not find any clue about this. Maybe is not possible at all.....?

Agustin

17 Aug 2010 3:04 #6787

Hi Agustin,

The Clearwin routine GET_FILTERED_FILE@ is merely a mechanism for getting a filename (perhaps it would be better to call it GET_FILTERED_FILE[u:2ea6b6847b]NAME[/u:2ea6b6847b]@). The actual opening is done by you, via an 'OPEN' statement. There is nothing to stop you opening file after file this way.

Easier might be to open a file that contains all the linked or related filenames, read it and then do multiple OPENs, or to get a generic name and differentiate between the various input data files by their extensions (e.g. AGUSTIN.001, AGUSTIN.002 etc).

However, programs that open multiple files in this way are dissimilar to many 'pure' Windows programs that have one 'document' per problem.

Multiple document interface programs are usually working on multiple problems of the same type (e.g. Word when it has several documents open).

I agree that I can't find how to select multiple files at the same time using GET_FILTERED_FILE@ (or by any other method). However, you could do separate calls to it, entering the file names into boxes in another window, and then have a 'Go' button that opens them all one after the other in quick succession.

Eddie

17 Aug 2010 5:10 #6789

get_filtered_file@ does not allow you to do multiple file selection.

I have found an undocumented function in the library that allows multiple selection. Give me a few days and I will see if I can find out how it works.

18 Aug 2010 6:15 #6793

Here is a sample program. The first argument is a window handle for the parent window (zero for the desktop). I have set the default path as empty giving the current working directory.

program getfiles
C_EXTERNAL GET_MULTIPLE_FILENAMES@ 'get_multiple_file_names'(VAL,INSTRING,OUTSTRING,VAL,INSTRING,INSTRING,VAL):LOGICAL
logical L,next
character*256 filename,filter,defpath
filter = 'Free Fortran files (*.f90)'//char(0)//'*.f90'//char(0)//'All files (*.*)'//char(0)//'*.*'//char(0)//char(0)
defpath = char(0)
L = .TRUE.
next = .FALSE.
do while(L)
 L=GET_MULTIPLE_FILENAMES@(0,'Dialog Title',filename,256,filter,defpath,next)
 next = .TRUE.
 if(L) print*, trim(filename)
end do
end
18 Aug 2010 12:38 #6796

Did you say 'give me a few days'?. Great job Paul! It works as expected!. Now I have to see how to open files and read data from them, but I guess it will not be hard. I wonder why this possibility has remained undocumented till now....

Thanks a lot!

Agustin

24 Aug 2010 4:26 #6820

I would like to know if this is the most efficient way to use the new get_multiple_filenames@ facility. The only idea I had was to declare a number of arrays in a subroutine and then open one by one using Select Case. This seems for me rather primitive and does not allow to open more files than the number of arrays that is fixed in the subroutine, but I found no better idea. Any suggestions?

Agustin

subroutine get_several_files
C_EXTERNAL GET_MULTIPLE_FILENAMES@ 'get_multiple_file_names'(VAL,INSTRING,OUTSTRING,VAL,INSTRING,INSTRING,VAL):LOGICAL
logical L,next
character*256 filename,filter,defpath
integer :: status,ndata
character a,b
character*128,dimension(10) :: file_names_set
real x1,y1
type array
real*8 x
real*8 y
end type array
type(array),dimension(:), allocatable :: array_1,array_2,array_3,array_4,array_5,array_6
integer *4 :: number_of_files=0
filter = 'Data files (*.dat)'//char(0)//'*.dat'//char(0)//'All files (*.*)'//char(0)//'*.*'//char(0)//char(0)
defpath = char(0)
L = .TRUE.
next = .FALSE.
number_of_files=1
! first select files
do while(L)
  ndata=0
 L=GET_MULTIPLE_FILENAMES@(0,'Dialog Title',filename,256,filter,defpath,next)
 next = .TRUE.
 if(L) then
 file_names_set(number_of_files)=filename
number_of_files=number_of_files+1
endif
end do
!then open files one by one
do i=1,number_of_files
open(32,file=file_names_set(i),status='old',action='read',iostat=status)  
read(32,100) a,b
100 format(2A16)
do
read(32,*,iostat=status) x1,y1
if(status/= 0) exit
  ndata=ndata+1
end do
close(32)
open(32,file=file_names_set(i),status='old',action='read',iostat=status)
select case(i)
  case(1)
read(32,*) a,b
  allocate(array_1(ndata))
do j=1,ndata
  read(32,*) array_1(j)%x,array_1(j)%y
end do
close(32)
  case(2)
read(32,*) a,b
  allocate(array_2(ndata))
do j=1,ndata
  read(32,*) array_2(j)%x,array_2(j)%y
end do
close(32)
!...........up to n cases
end select
ndata=0 !reset ndata for the next file
end do
call plot_files !subroutine for plotting data
end subroutine get_several_files
25 Aug 2010 6:45 #6826

The multiple selection dialog can't be opened a second time! Is it true or have i made a mistake? Here comes the light modified example from Paul i have tried with.

       program getfiles       
       common /test/ files_selected(20)
       character (len=256) :: files_selected       
       integer number_of_files, i, j       
       do j=1,2
         number_of_files = 0
         files_selected  = ' '
         call get_files_on_demand (number_of_files)       
         print*, 'Do-Loop variable=',j,', Number of Files=',number_of_files
         do i = 1,number_of_files
           print*, trim(files_selected(i))
         enddo
       enddo
       end
       subroutine get_files_on_demand (lfd)
       C_EXTERNAL GET_MULTIPLE_FILENAMES@ 'get_multiple_file_names'(VAL,INSTRING,OUTSTRING,VAL,INSTRING,INSTRING,VAL):LOGICAL 
       common /test/ files_selected(20)
       character (len=256) :: files_selected
       logical load, next 
       character*256 filename,filter,defpath 
       filter = 'Free Fortran files (*.f90)'//char(0)//'*.f90'//char(0)//char(0) 
       defpath = char(0) 
       load = .TRUE. 
       next = .FALSE.
       lfd  = 0
       do while(load)
        load = GET_MULTIPLE_FILENAMES@(0,'Dialog Title',filename,256,filter,defpath,next) 
        next = .TRUE.
        if(load) then
          lfd = lfd + 1
          files_selected(lfd) = filename
        endif 
       end do
       return
       end

Paul, can you tell me how to use the multiple selection dialog a second time?

25 Aug 2010 10:21 #6829

I have tested your code and get the same effect. If I simply repeat my code in a main program then it works OK.

The failure occurs in the library when a call is made to the Microsoft API function GetOpenFileName.

My guess is that you will be OK if you put the code into the main program rather than a subroutine. I have seen something like this before where the problem was solved by clearing the floating point stack before making the API call. Unless I am missing something, this is something that I might be able to fix in the library but, for the time being you will need to write the code in a different way.

25 Aug 2010 8:11 #6833

It turns out that my sample program needs a couple of changes...

program getfiles
C_EXTERNAL GET_MULTIPLE_FILENAMES@ 'get_multiple_file_names'(VAL,INSTRING,STRING,VAL,INSTRING,INSTRING,VAL):LOGICAL
logical L,next
character*256 filename,filter,defpath
filter = 'Free Fortran files (*.f90)'//char(0)//'*.f90'//char(0)//'All files (*.*)'//char(0)//'*.*'//char(0)//char(0)
defpath = char(0)
L = .TRUE.
next = .FALSE.
do while(L)
 filename = char(0) 
 L=GET_MULTIPLE_FILENAMES@(0,'Dialog Title',filename,256,filter,defpath,next)
 next = .TRUE.
 if(L) print*, trim(filename)
end do
end

I have changed OUTSTRING to STRING and also provided a blank value for filename on input.

With these changes the call can be repeated.

26 Aug 2010 7:04 #6834

Paul, thanks for your prompt assistance.

27 Aug 2010 9:55 #6848

Paul, the CLEARWIN_INFO@ parameter 'filter_item_selected' gives the selected filter item when using the GET_FILTERED_FILE@ command. Is there any chance to get the selected filter item the same way when using the GET_MULTIPLE_FILENAMES@ command?

27 Aug 2010 5:11 #6849

It is not in the library code at the moment but it would be a simple matter to add it in for the next release.

9 May 2011 7:41 #8197

It does not seem to be present in the 6.10 release, or can it be queried in another way?

9 May 2011 9:53 #8200

I did not add this to the library at the time of my last reply. I may have been waiting for a confirmation that this was requested.

Anyway I have now added the clearwin_info@ data to the library for the next release.

I don't know of any other direct way to get this information.

It is worth noting that clearwin_info@ will not work when it is added to my simple sample code above. You need an active winio@ to get it to work.

9 May 2011 11:45 #8201

Interesting - can you define what an 'active WINIO@' means please? Does it mean that the code needs to be executed within a callback?

I hope this isn't simply me being thick.

Eddie

9 May 2011 2:49 #8202

Having the code within a callback is one way to do this. It may be the only way, I am not sure. You can sometimes do strange things by using %lw and putting the code after the winio@ sequence of continuations.

Please login to reply.