Example: graDemo.c

This section demonstrates how Spectra can be called from a c program. We assume that this is done on a PC where Spectra is installed.

This is the Makefile:

SRC_DIR=/usr/local/experiment/Spectra/src
TANGO_LIB = -L/usr/lib/x86_64-linux-gnu -ltango -llog4tango -lomniORB4 -lomniDynamic4 -lomnithread
SIS3100_LIB=-L/usr/lib -l_sis3100
PYTHON_LIB=-L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7
GPIB_LIB=-L/usr/lib -lgpib
TINE_LIB=-L/usr/lib -ltinemt -ltbufsrv
PERL_LIB=-Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu -lperl -ldl -lm -lpthread -lc -lcrypt

LIB_DIR=/usr/local/experiment/Spectra/lib

LIBS=$(SRC_DIR)/cmc_dummy.o \
    $(SRC_DIR)/can_dummy.o \
    -L$(LIB_DIR) -lgra -ltng_ifc -ladslib \
    $(PERL_LIB) \
    $(SIS3100_LIB) $(PYTHON_LIB) $(GPIB_LIB) $(TINE_LIB) \
    -lnsl -ldl -lm -lc -lpthread -lstdc++ \
    $(TANGO_LIB) -ljsoncpp \
    -L/usr/X11R6/lib -lX11 

all: graDemo

graDemo.o: graDemo.c 
	gcc -c -o graDemo.o -I/usr/local/experiment/Spectra/src graDemo.c

graDemo: graDemo.o
	g++ graDemo.o $(LIBS) -o graDemo

This is the main function:

#include <stdio.h>
#include <math.h>
#include "gra_common.h"

int main( int argc, char **arg, char **env)
{
  info__scan *info; 
  float *x, *y;
  int i;
  
  /*
    Initialization: Analyze the command line arguments and
            determine the directory for the help file, etc. 
    */
  gra_init( argc, arg);

  /*
    create a SCAN, set the y-values to sin() and display it
    */
  gra_command( " crea test 0 10 100");
  gra_command( " calc test = sin(test)");
  gra_command( " display;wait");

  if( !gra_return_info_address( "test", &info))
    {
      printf( " GQE test does not exist \n");
      return;
    }

  /*
    fetch the data addresses
    */
  gra_return_data_address( "test", &x, &y);

  /*
    clear screen
    */
  gra_command( "cls");

  /*
    stop the interactive mode, i.e.: A DISPLAY
    is not preceded by a CLS
    */
  gra_stop_inter();
  for( i=0; i < 100; i++)
    {
      y[i] = cos(x[i]);
      info->curr_index = i + 1;
      gra_display();
    }
  gra_start_inter();

  /*
    change the y-values and re-display
    */
  for( i=0; i < 100; i++)
    {
      y[i] = tan(x[i]);
    }
  gra_command( "auto/y;display;say \" Press <ret> to continue \"");
  gra_keyw(1);

  /*
    enter the interactive SPECTRA
    */
  gra_entry();

  return 1;
}