src/bview-server.c

The Basilisk View server

This simple server waits for Basilisk View commands on standard input and returns PPM images on standard output.

Optional file names of either Basilisk View command files (with the .bv extension) or Basilisk snapshot files can be given on the command line.

It can run in parallel using MPI.

It is typically connected to a client such as bview-client.py, as automated by the bview script.

Installation

The server is not installed by default and relies on additional libraries which need to be installed first.

Once either libfb_osmesa.a or libfb_glx.a have been installed, the config file needs to define the OPENGLIBS environment variable accordingly i.e. using either

OPENGLIBS = -lfb_osmesa -lGLU -lOSMesa

or

OPENGLIBS = -lfb_glx -lGLU -lGLEW -lGL -lX11

See config.gcc for an example. Once this variable is defined in config, the Basilisk servers can be compiled using:

cd $BASILISK
make bview-servers

Implementation

#include "view.h"

int main (int argc, char * argv[])
{
  Array * history = array_new();
  
  for (int i = 1; i < argc; i++) {
    if (strlen (argv[i]) >= 3 &&
	!strcmp (&argv[i][strlen(argv[i]) - 3], ".bv")) {
      if (!load (file = argv[i], history = history))
	exit (1);
    }
    else {
      if (!restore (file = argv[i], list = all)) {
	fprintf (stderr, "bview-server: could not restore from '%s'\n", argv[i]);
	exit (1);
      }
      fields_stats();
    }
  }

  if (history->len)
    save (fp = stdout);
    
  char line[256];
  FILE * interactive = stdout;
  do {
    line[0] = '\0';
    if (pid() == 0)
      fgets (line, 256, stdin);
#if _MPI
    MPI_Bcast (line, 256, MPI_BYTE, 0, MPI_COMM_WORLD);
#endif
    if (!strcmp (line, "interactive (true);\n"))
      interactive = stdout, line[0] = '\0';
    else if (!strcmp (line, "interactive (false);\n"))
      interactive = NULL, line[0] = '\0';
  } while (process_line (line, history, interactive));
  array_free (history);
}