next up previous contents
Next: Execution Times Up: Software Previous: void rm_error_message(int s, char   Contents


Sample Program

This program demonstrates the use of the API. It could be compiled with the command

gcc -o rm_sample -I$COMMONINC rm_sample.c $COMMONLIB/rm.o

/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <rm.h>

int main(void) {

  int antlist[RM_ARRAY_SIZE];
  int status, antenna, i;
  char name[RM_NAME_LENGTH];
  char **namelist;
  int num_alloc;

  double dval_array[RM_ARRAY_SIZE],dval;
  short  sval_array[RM_ARRAY_SIZE],sval;

  /* intialize */
  status = rm_open(antlist);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_open()");
    exit(1);
  }

  /* report the list of available antennas */
  printf("available antennas: ");
  i=0;
  while(antlist[i] != RM_ANT_LIST_END) printf("%d ",antlist[i++]);
  printf("\n");
  
  /* report the list of allocation names */
  status = rm_get_num_alloc(&num_alloc);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_get_num_alloc()");
    exit(1);
  }

  namelist = (char **)malloc(num_alloc*sizeof(char *));
  for(i=0; i<num_alloc; i++) 
    namelist[i] = (char *)malloc(RM_NAME_LENGTH);

  status = rm_get_alloc_names(namelist);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_get_alloc_names()");
    exit(1);
  }
  printf("Allocation list (%d entries):\n",num_alloc);
  for(i=0; i<num_alloc; i++) 
    printf("  %s\n",namelist[i]);

  /* write the double precision value 1.234 to */
  /* RM_HOUR_ANGLE_HR_D on antenna 1 */
  dval = 1.234;
  status = rm_write(RM_ANT_1, "RM_HOUR_ANGLE_HR_D", &dval);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_write()");
    exit(1);
  }

  /* write the short integer value 1 to RM_YIG1_LOCKED_S for */
  /* all antennas which have cards in this crate; send notification to */
  /* the receiving ends */
  i=0;
  while(antlist[i] != RM_ANT_LIST_END) sval_array[ antlist[i++] ] = 1;

  status = rm_write_notify(RM_ANT_ALL, "RM_YIG1_LOCKED_S", sval_array);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_write_notify()");
    exit(1);
  }

  /* read the double precision float from RM_HOUR_ANGLE_HR_D */
  /* for antenna 7 */ 
  status = rm_read(RM_ANT_1, "RM_HOUR_ANGLE_HR_D", &dval);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_read()");
    exit(1);
  }

  /* read the double precision float values at RM_HOUR_ANGLE_HR_D */
  /* for all antennas */
  status = rm_read(RM_ANT_ALL, "RM_HOUR_ANGLE_HR_D", dval_array);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_read()");
    exit(1);
  }
  i=0;
  while(antlist[i] != RM_ANT_LIST_END) 
    printf("value at \"%s\" for antenna %d is %f\n",
	   "RM_HOUR_ANGLE_HR_D", i, dval_array[ antlist[i++] ]);

  /* wait for the data to change at RM_YIG1_LOCKED_S on any antenna */
  status = rm_monitor(RM_ANT_ALL, "RM_YIG1_LOCKED_S");
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_monitor()");
    exit(1);
  }
  
  status = rm_read_wait(&antenna, name, &sval);
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_read_wait()");
    exit(1);
  }
  printf("Data changed at \"%s\", antenna %d; new value is %d\n",
          name, antenna, sval);

  /* finished */
  status = rm_close();
  if(status != RM_SUCCESS) {
    rm_error_message(status, "rm_close()");
    exit(1);
  }

  return(0);
}



2008-06-18