forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multiple FILE_OPENW

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Tue Jun 02, 2009 12:52 pm    Post subject: Multiple FILE_OPENW Reply with quote

I want to open a set of files, the number of which can vary, defined at run-time. File names / path names are in Character arrays. Easy enough to set up a do-loop to create a table of buttons, each with its FILE_OPEN callback and adjacent text boxes to display the paths. Problem is, how do I associate each file with the right button and display the file path/name next to its proper button? The do-loop variable is useless for this, as of course it takes its final maximum value once the table is displayed. Have puzzled over this long and hard and got nowhere. Maybe the answer is obvious - although bags of Fortran experience, I'm just a Clearwin+ newbie.
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Jun 02, 2009 7:30 pm    Post subject: Reply with quote

Can you give me some code to start with, perhaps with a fixed and known number of files. Then I might be able to modify the code to use a variable number of files.
Back to top
View user's profile Send private message AIM Address
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Tue Jun 02, 2009 9:45 pm    Post subject: Reply with quote

Here is a cut-down version of the subroutine. The full version also contains prompts for sets of variable numbers of parameters but these work fine because you just type them into the boxes, so they are automatically in the right place.

Code:

      subroutine parmtest
c
c -- common block includes:
c   nf = no. of files wanted
c   flog = array of up to 25 'logical' file names (like 'in1', 'in2', 'out', etc). c               These are displayed as text on the buttons
c   path = array of actual path names to be returned from FILE_OPENW
c                These are to be kept for further use
c   fln2 = array of actual file names extracted from sfpath array by
c               function 'fselected'. These are to be displayed next to the
c               buttons
c
      include 'common'
      external parmgo,parmca,parmhelp,fselected
      integer*4 parmgo,parmca,parmhelp,fselected
c
c -- blank out the paths
      do j=1,25
        path(j)='       '
        fln2(j)='        '
      end do
c     
      if (nf.gt.0) then
c open window with caption
        i=winio@('%ww%bg[white]%ca[em2009 command window]&')
c select files
        i=winio@('%ob[raised,named_c][Files]&')
        do j=1,nf
          i=winio@('%nl%bc[grey]%8^bt@%8rs%nl&',flog(j),
     1   'FILE_OPENW[Open]',path(j),fselected,fln2(j))
        end do
      end if
c
c Info, Go and Cancel buttons
c
      i=winio@('%ff%nl%cn&')
      i=winio@('%bc[yellow]%4^bt[Info]&',parmhelp)
      i=winio@('%bc[green]%4^bt[Go]&',parmgo)
      i=winio@('%bc[red]%8^bt[Cancel]',parmca)
c     
      return
      end


The idea is that the callback function fselected extracts a file name fln2(j) from the path path(j) returned by FILE_OPENW. However, I can't find any way to pass the correct value of j to fselected to enable it to do this. It doesn't help to put it in a common block because it has the wrong value anyway.

Many thanks in advance for any help with this.

- Steve
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Jun 02, 2009 10:14 pm    Post subject: Reply with quote

Steve,

It's easier than you think. If you already know the file name, and path, then you don't need the FILE_OPEN standard callback, as that doesn't actually open a file, it simply puts up the dialog that allows the user to choose a file name. The actual opening is then done with a Fortran OPEN statement.

If your application has a list of (say) from 1 to 10 selectable files, each with a button, you can set that up in a DO loop. (I suggest making the path and file name NOT editable, otherwise you will get a very non-standard look and feel). On pressing the adjacent button, if the window closes, WINIO@ will return the button number. (0 means that the window was closed).

If you want to keep the selection window open, you have to attach a callback to each button. This can be the same callback for all buttons - the trick is to discover which button was pressed! Boy I got in a tangle with this. Here's my solution to the problem:

Code:
      WINAPP
      OPTIONS (INTL)
      PROGRAM TEST
      IMPLICIT DOUBLE PRECISION (A-H, O-Z)
      INCLUDE <WINDOWS.INS>
      EXTERNAL KALLBACK
      CHARACTER*(40) cPATH(10)
      COMMON / HANDLES/ iBUTTON (10)
      COMMON / PATHS  / cPATH
      COMMON / NUMBER / nBUTTONS, iPRESS
      COMMON J, iX, iY, MAIN
      nBUTTONS = 4
      iPRESS = 0
      J = 0
      kY = 0
      cPATH(1) = 'Bromhead'
      cPATH(2) = 'Laidler'
      cPATH(3) = 'Horspool'
      cPATH(4) = 'Campbell'
      IA = WINIO@('%ca[test]%bg[btnface]%hw&',MAIN)

C     ... here is the loop

      DO 100 I=1, nBUTTONS
      IA = WINIO@('%2nl%^bt[Select>]%lc  %40`rs&',KALLBACK,
     &                        iBUTTON(I),cPATH(I))
      IA = WINIO@('Handle is ...  %10`rd&', iBUTTON(I))
 100  CONTINUE
      IA = WINIO@('%2nlButton pressed:  %3`rd&',iPRESS)
      IA = WINIO@('%2nlAction_Y:  %3`rd&',J)
      IA = WINIO@ ('%sf')
      END

      INTEGER FUNCTION KALLBACK()
      IMPLICIT DOUBLE PRECISION (A-H, O-Z)
      INCLUDE <WINDOWS.INS>
      CHARACTER*(40) cPATH(10)
      COMMON / HANDLES/ iBUTTON (10)
      COMMON / PATHS  / cPATH
      COMMON / NUMBER / nBUTTONS, iPRESS
      COMMON J, iX, iY, MAIN
      J = CLEARWIN_INFO@ ('ACTION_Y')   ! gives y position on the screen
      iPRESS = 0
      CALL GET_WINDOW_LOCATION@ (MAIN, jX,jY,jW,jD)
      DO 10 I=1,nBUTTONS
      CALL GET_WINDOW_LOCATION@ (iBUTTON(I), iX,iY,iW,iD)
      kY = iY + jY     
      IF (kY .EQ. J) iPRESS = I
  10  CONTINUE
      CALL WINDOW_UPDATE@ (iPRESS)
      CALL WINDOW_UPDATE@ (J)
      KALLBACK = 1
      END


The only way I could find to do it was to get the position of the button pressed - but that is an absolute y coord, whereas when you ask for the coords of a control, they are given relative to the window - so I also had to find the position of the window, and add that. I'm sure there is an easier way, but I've never had to detect the button pressed inside a callback before, so this is a learning curve for me!

Once you have the button pressed, you know which file to OPEN. It's much easier if you allow the window to close first ...

Eddie
Back to top
View user's profile Send private message
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Wed Jun 03, 2009 8:41 am    Post subject: Reply with quote

Hi, Eddie -

Many thanks.

Unfortunately we don't know the names of the files in advance. All we have is logical file names (like "IN1") which have to be mapped at runtime to the actual file names containing the data to be processed. The subrroutine is for us in a variety of different programs too, which require different numbers of input and output files - so even the number of these logical files can vary.

Thinking of 'look and feel', maybe trying to set things up in this single subroutine is itself the problem. Perhaps what I should be doing is sequentially defining the file names in a series of as many popups as needed.

The idea of identifying which button was pressed by using its position sounds doable but messy - your code indeed could help with this, thanks! However, I think maybe the real answer is to do things in a slightly different way.
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Jun 03, 2009 1:56 pm    Post subject: Reply with quote

I am still not clear about what you are aiming for. There will probably be a simple solution but this may well be at little above the scope of a forum response. We are always willing to consider providing a consultancy service where this is required. Contact Silverfrost directly in the first instance for further information.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Jun 03, 2009 5:38 pm    Post subject: Reply with quote

Steve,

Clearly I didn't understand. I thought you had some file names and paths for a program that uses multiple files, and were allowing the user to select one at a time and change it. In fact, you have no paths or file names, and you want to associate real files with a bunch of internal logical names in one fell swoop.

The normal Windows method is to pick one file at a time. I recommend using GET_FILTERED_FILE@ rather than the 'FILE_OPENx' (x=R or W) standard callback. (GET_FILTERED_FILE@ has the additional benefit that you can specify the caption for the file selection window. With the standard callback, the caption from the calling window is duplicated).

You can start out with a set of "default" file names and extensions (such as "default.dat", "untitled.dat" etc) and then proceed to let the user select individual file names to alter. Sometimes such default names can be constructed from the date and time, although to get file names that can be sorted afterwards you need to be careful to insert leading zeroes, and use month numbers not names.

Where I have seen multiple file selections, they are usually all of the same type - in which case multiple child windows are opened, one for each file. You can select a "root name" from which all the other file names are constructed, usually from permutation of the file name extension. An example of the latter might be to look for a .DAT, and create a .RES (results), a .JPG picture, and so forth. I have done this myself, but after a bit of work, you come to realise that there is no benefit in having separate programs for (say) doing and analysis, then plotting the results - you need all the functions in one analysis. Except for the case of truly massive datasets (3D finite elements leaps to mind), the modern PC has virtually unlimited capacity for code.

From the look of it, a program that needs many files to run seems like a hack - the sort of programs we used to write many years ago. I started with programs that read cards and sometimes paper tape, output to a linepriner and a paper tape - sometimes to a plotter too. Later, all those devices would create a multitude of files duplicating the functions - so that one file would save things to plot with a different program, and so on. Mostly, Windows programs use one file type. They can save, or open or import different types, but a "document" is a single file.

If you map all your logical file names to a cluster of real files (distinguished by extension) as I suggested earlier, then you may find it useful to generate them all in a single folder (subdirectory). SELECT_OPEN_DIALOG_PATH@ is useful in that.

I'm still reeling from the fact that I couldn't get the button pressed from its handle. In CWPLUS.ENH there is a mention of a CLEARWIN return to 'BUTTON_NUMBER', but that relates to the buttons in an %ib control (and anyway, I couldn't find it last night). Perhaps the lateness of the hour had something to do with it.

A final piece of homespun philosophy is that if you really can't find an application (as a model to follow) that does it in the way you want to do it, it is because it is difficult to do and isn't the "Windows way". Once you resign yourself to doing it the Windows way, Clearwin usually has a function for it!

Eddie
Back to top
View user's profile Send private message
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Wed Jun 03, 2009 6:21 pm    Post subject: Reply with quote

Many thanks, Eddie and Paul. I think that the GET_FILTERED_FILE@ approach might well be the more appropriate way to go. Why didn't I think of that in the first place? I had hoped to deal with files the same way as with all the control parameters, effectively setting them in a simple 'control panel' window.

I'm not using a large number of files, just a varying number, depending on what the program needs. All files are of the same type and in the same standard format. I'm implementing and modifying some legacy code to do database management (e.g. a file join taking IN1 and IN2 and generating OUT) as well as applications on these files such as constrained Delaunay triangulation (with e.g. POINTSIN, CONSTRAINTS1, CONSTRAINTS2, POINTSOUT, TRIANGLESOUT). Generally the input files will all be in the same folder so most of the path will be the same - can carry this in a string variable in COMMON. Will have a look at SELECT_OPEN_DIALOG_PATH@ though can't find the documentation in my hardcopy manual which is admittedly rather old.

Will continue experimentation with this on the F95 Personal, but once I start to get somewhere, will probably have to take the plunge and buy an upgrade. My latest 'official' copy is about 2000 vintage. Expensive business for a one-man-band, keeping compilers up-to-date ! Anyway, thanks again - I think your advice is going to help me through this logjam.
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Jun 03, 2009 6:59 pm    Post subject: Reply with quote

The PATH selector is discussed in FTN95.CHM under Win32 platform, then Clearwin, then Library reference, then S ... and apologies, it is SET_ not SELECT_ ...

Eddie
Back to top
View user's profile Send private message
silicondale



Joined: 15 Mar 2007
Posts: 243
Location: Matlock, Derbyshire, UK

PostPosted: Wed Jun 03, 2009 9:11 pm    Post subject: Reply with quote

Thanks - found it !
_________________
(Steve Henley)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group