Clickfit - a GUI interface for fitfun interactive fits

for Fitfun version 7.0 onwards, R. Ghosh, ILL, May 2006

Summary

A file-based communications interface has been added to fitfuns to allow programs linked with this library to be driven from an external GUI program. An example, Clickfit, written in Tcl/Tk is presented below. The windows used within Clickfit are easy to modify, being configured in a separate file, which also has the basic system information required by the graphics library (PGplot).

The initial command line control options are retained, allowing rapid prototype development.


File communications with fitfun version 7

Several files are used for passing commands and information between GUI and the fitfun program. initialisation

A job sequence number is added to the command line when the fortran program is launched. Subroutine PRELUDE, either called in the main program, (or in any case at the start of the fitfun routines) checks the command line for such a jobname eg job433 as the argument after the program name, and if found assumes it must expect commands via the communication files shown below. The first command is sent to the prelude routine and is a character string of data which, like subsequent commands, is copied into a FORTRAN common/comin/bufin where bufin is character*150. This allows a flexible method of furnishing data from commands for use in the fitting program, notably for reading data and data-linked parameters. The PRELUDE routine sets up the communication files. These are deleted on normalprogram termination A sequence number is included in each command, and the corresponding number is returned in the reply file. Further information is also returned in an information file as illustrated below:

for example program fitp, sequence number 433


GUI                                      Fitfun program

writes command m into fitp433.fcd ---->  reads command
                                               |
                                         performs command
                                   usual terminal output to fitp433.log
                                               |
                                         writes status into
                                           fitp433.fif
                                               |
                                         writes reply to m in
notes updated number m in reply                |
file showing command is complete  <-----     fitp433.frp

Polling
The GUI send its message and tests the contents of the reply file, typically every 0.1 secs. If no reply is received after ten seconds it is assumed that the calculation program has failed and that a post mortem should proceed by exmining the log files and the remaining *.fcd, *.frp and *.fif files. Similarly, once started, the fitfun calculation program scans the fitp433.fcd file for a newly numbered command, polling again after a sleep of about 0.1 secs. In this case up to 15 minutes is allowed to elapse before logging a timeout and the program terminates.

Unexpected terminations

The primary cause should be signalled in the log file. In the case of communications being lost between the two programs it is possible that the calculation program continues to run, polling for a possible command until the 15 minute timeout is reached and the program terminates. Since the sequence number for the jobs is incremented each time a subsequent program launch will not interfere with the idling program, which may be terminated manually without prejudice.