next up previous contents index
Next: Using FIT2D with Shared Up: FIT2D as a Sub-Process Previous: FIT2D as a Sub-Process


Using FIT2D in ``Command-line'' Mode

When using FIT2D as a sub-process it is often needed to pass commands as character strings and not as graphical mouse cursor input. To do this FIT2D can be started in command mode using the -com (or +com, -COM, +COM) command line option.

e.g. From an ``ANSI-C'' program FIT2D could be started as a sub-process using the following command:

  /* Open FIT2D as a sub-process with input through a pipe */
  command = (FILE *) popen ("fit2d -com", "w");

  /* Check sub-process has been started O.K. */
  if (command == NULL) {
    printf ("Problem starting sub-process");
    exit (0);
  }

This then means that all user input is then send to the FIT2D sub-process as character strings:

e.g. The commands to open FIT2D, set the program arrays to $2048\times 1024$ and enter the IMAGE PROCESSING (GENERAL) interface could be sent with the following code:

  fprintf (command, "I ACCEPT\n");
  fprintf (command, "X-DIMENSION\n");
  fprintf (command, "2048\n");
  fprintf (command, "Y-DIMENSION\n");
  fprintf (command, "1024\n");
  fprintf (command, "O.K.\n");
  fprintf (command, "IMAGE PROCESSING (GENERAL)\n");
  fflush (command);

Note: The ``finish line'' character is necessary for each command, and the fflush (command) command is necessary to ensure that the information is send to the FIT2D sub-process.

Having entered an appropriate interface and input a data file, the ``region of interest'' could be set from pixel (200, 100) to (500, 400) using the ZOOM IN command with the following calls:

  fprintf (command, "ZOOM IN\n");
  fprintf (command, "2\n");
  fprintf (command, "200.0\n");
  fprintf (command, "100.0\n");
  fprintf (command, "500.0\n");
  fprintf (command, "400.0\n");
  fflush (command);

When processing is finished, FIT2D should be exited and the ``pipe'' closed. On a Linux system this could be performed with the following code:

  /* Exit interface */
  fprintf (command, "EXIT\n");

  /* Close FIT2D */
  fprintf (command, "EXIT FIT2D\n");
  fprintf (command, "YES\n");
  fflush (command);

  /* Close pipe */
  pclose (command);

Hint: To get sequences of commands correct, use the CREATE MACRO option in the MACROS / LOG FILE interface to create a macro of the sequence of commands. This is then the text, or equivalent, to send to FIT2D using the fprintf command.

(On Linux systems man popen provides documentation on using ``pipes'' to sub-processes. General use of pipes and sub-processes is outside the scope of this manual; please refer to system and other documentation.)


next up previous contents index
Next: Using FIT2D with Shared Up: FIT2D as a Sub-Process Previous: FIT2D as a Sub-Process
Andrew Hammersley
2004-01-09