Functions | Variables

translate.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "idl_export.h"
#include "grpc.h"
#include "translate.h"
Include dependency graph for translate.c:

Go to the source code of this file.

Functions

void print_array (int m, int n, double *A)
int trunc_fname (char *fname)
void die_type_mismatch (IDL_VPTR arg_idl, gs_argument_t *argp)
int convert_idl (gs_problem_t *pd, IDL_VPTR *argv_idl)
char ** create_packed_file_array (gs_argument_t *argp, IDL_VPTR arg_idl)
void free_varout (UCHAR *mem)
int find_varout_vector_len (gs_problem_t *pd, gs_argument_t *argp)
IDL_VPTR get_idl_string_from_unterminated_char (int len, char *str)
void copy_varout (gs_problem_t *pd, gs_argument_t *argp, IDL_VPTR arg_idl)
int assign_arg (gs_argument_t *argp, IDL_VPTR argv_idl)
int copy_scalar_input (gs_argument_t *argp, IDL_VPTR arg_idl)
int copy_scalar_output (IDL_VPTR arg_idl, gs_argument_t *argp)
int copy_ptr_input (gs_argument_t *argp, IDL_VPTR arg_idl)
int check_ptr_inout (gs_argument_t *argp, IDL_VPTR arg_idl)
int create_linear_char_matrix (IDL_VPTR arg_idl, gs_argument_t *argp)
int copy_char_vector_output (IDL_VPTR arg_idl, gs_argument_t *argp)
int copy_char_matrix_output (IDL_VPTR arg_idl, gs_argument_t *argp)
int translate_int_array (IDL_VPTR arg_idl, gs_argument_t *argp)
int translate_dcomplex_array (IDL_VPTR arg_idl, gs_argument_t *argp)
int translate_scomplex_array (IDL_VPTR arg_idl, gs_argument_t *argp)
int translate_double_array (IDL_VPTR arg_idl, gs_argument_t *argp)
int translate_float_array (IDL_VPTR arg_idl, gs_argument_t *argp)
int translate_array_input (gs_argument_t *argp, IDL_VPTR arg_idl)
int copy_ptr_output (gs_argument_t *argp, IDL_VPTR arg_idl)
int translate_array_output (gs_argument_t *argp, IDL_VPTR arg_idl)
int store_scalar_to_idl (IDL_VPTR argv_idl, gs_argument_t *argp)
int postproc_argv_c (gs_problem_t *pd, IDL_VPTR *argv_idl)
int is_input_upcasted (IDL_VPTR idl, int gs_data_type, int gs_object_type)

Variables

UCHAR gs_idl_types []

Function Documentation

int assign_arg ( gs_argument_t *  argp,
IDL_VPTR  argv_idl 
)

Copies an argument from the IDL arg list to a GridSolve compatible argument.

Parameters:
argp -- pointer to the GridSolve argument (destination)
argv_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 275 of file translate.c.

{
  if(argp->inout == GS_IN && argp->objecttype == GS_SCALAR) {
    IDL_ENSURE_SCALAR(argv_idl);
    copy_scalar_input(argp, argv_idl);
    return 0;
  }

  if(argp->objecttype == GS_FILE) {
    argp->data = IDL_VarGetString(argv_idl);
    return 0;
  }

  if(argp->objecttype == GS_PACKEDFILE) {
    argp->data = create_packed_file_array(argp, argv_idl);
    return 0;
  }

  if(argp->objecttype == GS_SPARSEMATRIX) {
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
         "Error: Sparse matrices not supported yet.");
  }

  switch(argp->inout) {
    case GS_IN:
      /* Input passed by reference */
      copy_ptr_input(argp, argv_idl);
      break;
    case GS_INOUT:
      /* Inout passed by reference */
      IDL_EXCLUDE_EXPR(argv_idl);
      check_ptr_inout(argp, argv_idl);
      break;
    case GS_OUT:
      /* Output passed by reference */
      IDL_EXCLUDE_EXPR(argv_idl);
      copy_ptr_output(argp, argv_idl);
      break;
    case GS_WORKSPACE:
      /* skip workspace arguments */
      argp->data = NULL;
      break;
    case GS_VAROUT:
      argp->data = &(argv_idl->value.arr);
      break;
    default:
      /* shouldn't hit this case since we checked for bad 
       * values already.
       */
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
         "Error: Bad arg inout type");
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int check_ptr_inout ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

This is an in/out argument, so we require that the data types match. Check for compliance here.

Parameters:
argp -- pointer to the GridSolve argument (destination)
arg_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 512 of file translate.c.

{
  if(gs_idl_types[argp->datatype] != arg_idl->type)
    die_type_mismatch(arg_idl, argp);

  switch(argp->objecttype) {
    case GS_VECTOR:
      if(argp->datatype == GS_CHAR) {
        /* dup the string in case it was assigned from a constant string */

        argp->data = strdup(IDL_VarGetString(arg_idl));
      }
      else
        argp->data = arg_idl->value.arr->data;
      break;
    case GS_MATRIX:
      if(argp->datatype == GS_CHAR)
        translate_array_input(argp, arg_idl);
      else
        argp->data = arg_idl->value.arr->data;
      break;
    case GS_SCALAR:
      copy_scalar_input(argp, arg_idl);
      break;
    case GS_SPARSEMATRIX:
    case GS_FILE:
    case GS_PACKEDFILE:
      /* above cases should have been handled before calling this routine */
    default:
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error: unknown/unsupported object type!");
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int convert_idl ( gs_problem_t *  pd,
IDL_VPTR *  argv_idl 
)

Converts the entire argument list from the IDL call to a GridSolve compatible argument list.

Parameters:
pd -- the GridSolve problem description
argv_idl -- array of IDL arguments
Returns:
0 on success, -1 on failure.

Definition at line 104 of file translate.c.

{
  gs_argument_t *argp;
  int i;

  for(i=0, argp = pd->arglist; argp != NULL; argp = argp->next) {
    if(argp->inout != GS_WORKSPACE) {
      assign_arg(argp, argv_idl[i]);
      i++;
    }
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int copy_char_matrix_output ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

copies a linear char matrix back to an IDL array of strings.

Definition at line 617 of file translate.c.

{
  char *tmpstr, *char_buf;
  int i, j, len;
  IDL_STRING *str_arr = 0 ;
  IDL_VPTR arr_data;
  IDL_MEMINT dims[1];

  char_buf = argp->data;
  dims[0] = argp->rows;
  str_arr = (IDL_STRING *)IDL_MakeTempArray( IDL_TYP_STRING,
     1, dims, IDL_BARR_INI_NOP, &arr_data);

  for(i=0;i<argp->rows;i++) {
    len = strlen(((IDL_STRING *)arg_idl->value.arr->data)[i].s);

    tmpstr = (char *)calloc(len + 1, 1);
    if(!tmpstr)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
        "Error: malloc failed in copy_char_matrix_output()");

    for(j=0;j<argp->cols;j++) {
      if(j < len)
        tmpstr[j] = char_buf[j*argp->rows + i];
    }

    IDL_StrStore(&(str_arr[i]), tmpstr);
  }

  IDL_VarCopy(arr_data, arg_idl);

  return 0;
}

Here is the caller graph for this function:

int copy_char_vector_output ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

copies a linear char vector back to an IDL array of strings.

Definition at line 602 of file translate.c.

{
  IDL_VPTR tmp;

  tmp = get_idl_string_from_unterminated_char(argp->rows, (char *)argp->data);
  IDL_VarCopy(tmp, arg_idl);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int copy_ptr_input ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

Copies a pointer input argument from IDL to a GridSolve compatible argument.

Parameters:
argp -- pointer to the GridSolve argument (destination)
arg_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 482 of file translate.c.

{
  switch(argp->objecttype) {
    case GS_VECTOR:
    case GS_MATRIX:
      translate_array_input(argp, arg_idl); /*include string*/
      break;
    case GS_SCALAR:
    case GS_SPARSEMATRIX:
    case GS_FILE:
    case GS_PACKEDFILE:
      /* above cases should have been handled before calling this routine */
    default:
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error: unknown object type!");
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int copy_ptr_output ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

Set the GS argument's data pointer to have the IDL's data address. Also checks for type mismatch.

Parameters:
argp -- pointer to the GridSolve argument (destination)
argv_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 1009 of file translate.c.

{
  switch(argp->objecttype) {
    case GS_VECTOR:
    case GS_MATRIX:
      if((gs_idl_types[argp->datatype] != arg_idl->type) && (argp->datatype != GS_CHAR))
        die_type_mismatch(arg_idl, argp);
      translate_array_output(argp, arg_idl);
      break;
    case GS_SCALAR:
      /* GS arg has its own space, do nothing. */
      argp->data = &(argp->scalar_val);    
      break;
    case GS_SPARSEMATRIX:
    case GS_FILE:
    case GS_PACKEDFILE:
      /* above cases should have been handled before calling this routine */
    default:
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, "Error: unknown object type!");
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int copy_scalar_input ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

Copies a scalar input argument from IDL to a GridSolve compatible argument.

Parameters:
argp -- pointer to the GridSolve argument (destination)
argv_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 342 of file translate.c.

{
  switch(argp->datatype) {
    case GS_INT: 
      argp->scalar_val.int_val = IDL_LongScalar(arg_idl);
      break;
    case GS_CHAR:
      argp->scalar_val.char_val = *IDL_VarGetString(arg_idl);
      break;
    case GS_FLOAT:
      argp->scalar_val.float_val = (float) IDL_DoubleScalar(arg_idl);
      break;
    case GS_DOUBLE:
      argp->scalar_val.double_val = IDL_DoubleScalar(arg_idl);
      break;
    case GS_SCOMPLEX:
      if(arg_idl->type == IDL_TYP_COMPLEX) {
        argp->scalar_val.scomplex_val.r = arg_idl->value.cmp.r;
        argp->scalar_val.scomplex_val.i = arg_idl->value.cmp.i;
      }
      else if(arg_idl->type == IDL_TYP_DCOMPLEX) {
        argp->scalar_val.scomplex_val.r = (float)arg_idl->value.dcmp.r;
        argp->scalar_val.scomplex_val.i = (float)arg_idl->value.dcmp.i;
      }
      else {
        argp->scalar_val.scomplex_val.r = (float) IDL_DoubleScalar(arg_idl);
        argp->scalar_val.scomplex_val.i = 0.0;
      }
      break;
    case GS_DCOMPLEX:
      if(arg_idl->type == IDL_TYP_COMPLEX) {
        argp->scalar_val.dcomplex_val.r = (double)arg_idl->value.cmp.r;
        argp->scalar_val.dcomplex_val.i = (double)arg_idl->value.cmp.i;
      }
      else if(arg_idl->type == IDL_TYP_DCOMPLEX) {
        argp->scalar_val.dcomplex_val.r = arg_idl->value.dcmp.r;
        argp->scalar_val.dcomplex_val.i = arg_idl->value.dcmp.i;
      }
      else {
        argp->scalar_val.dcomplex_val.r = IDL_DoubleScalar(arg_idl);
        argp->scalar_val.dcomplex_val.i = 0.0;
      }
      break;
    default:
      die_type_mismatch(arg_idl, argp);
  }

  argp->data = &(argp->scalar_val);      

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int copy_scalar_output ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Copies a scalar output argument from IDL to a GridSolve compatible argument. This is called after the GridSolve service has completed and the results have been returned.

Parameters:
arg_idl -- the IDL argument (destination)
argp -- pointer to the GridSolve argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 406 of file translate.c.

{
  double dval_r = 0.0, dval_i = 0.0;

  switch(argp->datatype) {
    case GS_INT:
      dval_r = (double)argp->scalar_val.int_val;
      break;
    case GS_CHAR:
      dval_r = (double)argp->scalar_val.char_val;
      break;
    case GS_FLOAT:
      dval_r = (double)argp->scalar_val.float_val;
      break;
    case GS_DOUBLE:
      dval_r = (double)argp->scalar_val.double_val;
      break;
    case GS_SCOMPLEX:
      dval_r = (double)argp->scalar_val.scomplex_val.r;
      dval_i = (double)argp->scalar_val.scomplex_val.i;
      break;
    case GS_DCOMPLEX:
      dval_r = (double)argp->scalar_val.dcomplex_val.r;
      dval_i = (double)argp->scalar_val.dcomplex_val.i;
      break;
    default:
      die_type_mismatch(arg_idl, argp);
  }

  if(arg_idl->type == IDL_TYP_UNDEF)
    arg_idl->type = gs_idl_types[argp->datatype];

  switch(arg_idl->type) {
    case IDL_TYP_INT:
      arg_idl->value.i = (short) dval_r;
      break;
    case IDL_TYP_LONG:
      arg_idl->value.l = (int) dval_r;
      break;
    case IDL_TYP_STRING:
      arg_idl->value.str.slen = 1;
      arg_idl->value.str.s[0] = (char) dval_r;
      arg_idl->value.str.s[1] = (char) 0;
      break;
    case IDL_TYP_FLOAT:
      arg_idl->value.f = (float) dval_r;
      break;
    case IDL_TYP_DOUBLE:
      arg_idl->value.d = dval_r;
      break;
    case IDL_TYP_COMPLEX:
      arg_idl->value.cmp.r = (float) dval_r;
      arg_idl->value.cmp.i = (float) dval_i;
      break;
    case IDL_TYP_DCOMPLEX:
      arg_idl->value.dcmp.r = dval_r;
      arg_idl->value.dcmp.i = dval_i;
      break;
    default:
      die_type_mismatch(arg_idl, argp);
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void copy_varout ( gs_problem_t *  pd,
gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

Copies varout data back to the IDL variable passed by the user.

Parameters:
pd -- pointer to the problem description structure
argp -- pointer to the gridsolve argument structure for this arg
arg_idl -- the IDL argument

Definition at line 228 of file translate.c.

{
  IDL_MEMINT dims[2];
  IDL_VPTR tmp;

  if(argp->objecttype == GS_VECTOR) {
    int veclen;

    veclen = find_varout_vector_len(pd, argp);

    if(veclen < 0)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
         "Error: could not determine VAROUT length.");

    if(argp->datatype == GS_CHAR) {
      tmp = get_idl_string_from_unterminated_char(veclen, (char *)(arg_idl->value.arr));
      IDL_VarCopy(tmp, arg_idl);
    }
    else {
      dims[0] = veclen;
      tmp = IDL_ImportArray(1, dims, gs_idl_types[argp->datatype],
        (char *)arg_idl->value.arr, free_varout, NULL);
      IDL_VarCopy(tmp, arg_idl);
    }
  }
  else {
    char msg[2048];

    sprintf(msg, "Error in arg %s: VAROUT only supported for vectors.",
      IDL_VarName(arg_idl));
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, msg);
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int create_linear_char_matrix ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Make a rectangular matrix out of a string array. This doesn't malloc new space, so it's suitable for copying input-only char matrices.

Definition at line 554 of file translate.c.

{
  char *char_buf, *str;
  int i, j, len, max_len, n_elts;
  int idl_type, *argv;
  IDL_ARRAY *arr;

  arr = arg_idl->value.arr;
  idl_type = arg_idl->type;
  argv = (int*) &argp->data;

  max_len = 0;

  for(i=0;i<arr->n_elts;i++) {
    len = strlen(((IDL_STRING *)arr->data)[i].s);
    if(len > max_len)
      max_len = len;
  }
  char_buf = (char *)malloc(arr->n_elts * max_len);

  if(!char_buf)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
      "Error: malloc failed in create_linear_char_matrix()");

  n_elts = arr->n_elts;

  for(i=0;i<n_elts;i++) {
    str = ((IDL_STRING *)arr->data)[i].s;
    len = strlen(str);

    for(j=0;j<max_len;j++) {
      if(j >= len)
        char_buf[j*n_elts + i] = ' ';
      else
        char_buf[j*n_elts + i] = str[j];
    }
  }

  *argv = (int)char_buf;

  return 0;
}

Here is the caller graph for this function:

char** create_packed_file_array ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

Creates an array of filenames from the IDL filename array.

Parameters:
argp -- pointer to the GridSolve argument
arg_idl -- the IDL argument
Returns:
a pointer to the new array of filename strings

Definition at line 129 of file translate.c.

{
  char **result;
  int i, nelem;

  IDL_ENSURE_ARRAY(arg_idl);

  nelem = arg_idl->value.arr->n_elts;

  result = (char **)malloc(nelem * sizeof(char *));

  if(!result)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
       "Error: malloc failed in create_packed_file_array().");

  for(i=0;i<nelem;i++)
    result[i] = ((IDL_STRING *)arg_idl->value.arr->data)[i].s;

  return result;
}

Here is the caller graph for this function:

void die_type_mismatch ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Prints type mismatch error message and returns to IDL.

Parameters:
arg_idl -- the IDL argument passed in
argp -- pointer to the GridSolve parameter

Definition at line 77 of file translate.c.

{
  char msg[1024];

  sprintf(msg, "Type mismatch in argument:");
  IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, msg);

  sprintf(msg, "    IDL arg name is '%s', corresponding GridSolve arg name is '%s'",
     IDL_VarName(arg_idl), argp->name);
  IDL_Message(IDL_M_GENERIC, IDL_MSG_INFO, msg);

  sprintf(msg, "    provided type = %s, expected type = %s",
     IDL_TypeName[arg_idl->type], IDL_TypeName[gs_idl_types[argp->datatype]]);
  IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, msg);
}

Here is the caller graph for this function:

int find_varout_vector_len ( gs_problem_t *  pd,
gs_argument_t *  argp 
)

Finds the length of a varout argument.

Parameters:
pd -- pointer to the problem description structure
argp -- pointer to the gridsolve argument structure for this arg
Returns:
the vector length, or -1 on error.

Definition at line 173 of file translate.c.

{
  gs_argument_t *carg;

  for(carg = pd->arglist; carg; carg=carg->next) {
    if((carg->inout == GS_OUT) && (carg->datatype == GS_INT) &&
       (carg->objecttype == GS_SCALAR) &&
       !strcasecmp(carg->name, argp->rowexp))
      return carg->scalar_val.int_val;
  }

  return -1;
}

Here is the caller graph for this function:

void free_varout ( UCHAR *  mem  ) 

Callback for IDL to free memory allocated by GridSolve for varout data.

Parameters:
mem -- pointer to the allocated memory

Definition at line 158 of file translate.c.

{
  free(mem);
}

Here is the caller graph for this function:

IDL_VPTR get_idl_string_from_unterminated_char ( int  len,
char *  str 
)

Gets an IDL string temporary variable from an unterminated string of the given length.

Parameters:
len -- number of characters
str -- the string
Returns:
new IDL temporary variable

Definition at line 198 of file translate.c.

{
  char *nt_str;
  IDL_VPTR tmp;

  /* the variable length char array from gridsolve is not guaranteed
   * to be null terminated, so do that before creating the IDL string.
   */
  nt_str = (char *)malloc(len + 1);
  if(!nt_str)
    IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
       "Error: malloc failed in get_idl_string_from_unterminated_char().");

  strncpy(nt_str, str, len);
  nt_str[len] = 0;

  tmp = IDL_StrToSTRING(nt_str);

  return tmp;
}

Here is the caller graph for this function:

int is_input_upcasted ( IDL_VPTR  idl,
int  gs_data_type,
int  gs_object_type 
)

Determines whether there had to be a type conversion when the input was passed from IDL to GridSolve.

Parameters:
idl -- the IDL argument
gs_data_type -- the data type expected by GridSolve
Returns:
TRUE if the cast was necessary, FALSE otherwise

Definition at line 1209 of file translate.c.

{
  int idl_type;
  int ret;

  ret = 0;
  idl_type = idl->type;

  switch(gs_data_type) {
    case GS_CHAR:
      if(gs_object_type == GS_MATRIX)
        ret = 1;
      break;
    case GS_INT:
      if(idl->type == IDL_TYP_INT || idl_type == IDL_TYP_BYTE)
        ret = 1;
      break;
    case GS_FLOAT:
      if(idl_type == IDL_TYP_BYTE || idl_type == IDL_TYP_INT
         || idl_type == IDL_TYP_LONG)
        ret = 1;
      break;
    case GS_DOUBLE:
      if(idl_type == IDL_TYP_BYTE || idl_type == IDL_TYP_INT
         || idl_type == IDL_TYP_LONG || idl_type == IDL_TYP_FLOAT)
        ret = 1;
      break;
    case GS_DCOMPLEX: 
      if(idl_type == IDL_TYP_COMPLEX || idl_type == IDL_TYP_BYTE 
         || idl_type == IDL_TYP_INT  || idl_type == IDL_TYP_LONG 
         || idl_type == IDL_TYP_FLOAT|| idl_type == IDL_TYP_DOUBLE)
        ret = 1;
      break;
    case GS_SCOMPLEX: 
      if(idl_type == IDL_TYP_BYTE || idl_type == IDL_TYP_INT  
         || idl_type == IDL_TYP_LONG || idl_type == IDL_TYP_FLOAT
         || idl_type == IDL_TYP_DOUBLE)
        ret = 1;
      break;
  }

  return ret;
}

Here is the caller graph for this function:

int postproc_argv_c ( gs_problem_t *  pd,
IDL_VPTR *  argv_idl 
)

After the call has completed, this is called to convert the GridSolve results back to IDL compatible arguments.

Parameters:
pd -- the GridSolve problem description
argv_idl -- array of IDL arguments
Returns:
0 on success, -1 on failure.

Definition at line 1126 of file translate.c.

{
  gs_argument_t*   argp;
  int i;

  for(i=0, argp = pd->arglist; argp != NULL; argp = argp->next) {
    if(argp->inout == GS_WORKSPACE)
      continue;

    if((argp->inout == GS_IN) && (argp->objecttype == GS_SCALAR)) {
      ; /* no upcasting for args passed by value */
    }
    else if(argp->objecttype == GS_FILE) {
      ; /* nothing needs to be done here */
    }
    else if(argp->objecttype == GS_PACKEDFILE) {
      if(argp->data != NULL)
        free(argp->data);
    }
    else if(argp->inout == GS_VAROUT) {
      copy_varout(pd, argp, argv_idl[i]);
    }
    else if(argp->inout == GS_IN) {
      /* This is an input-only object type, so if any space
       * was allocated for it, free that here.
       */

      if(is_input_upcasted(argv_idl[i], argp->datatype, argp->objecttype)) {
        if(argp->data != NULL)
          free(argp->data);
      }
    }
    else {
      /* Either in/out or output object type.  We only care about
       * doing conversions on scalar types.
       */

      if(argp->datatype == GS_CHAR) {
        if(argp->objecttype == GS_MATRIX) {
          if(argp->data != NULL) {
            copy_char_matrix_output(argv_idl[i], argp);
            free(argp->data);
          }
        }
        else if(argp->objecttype == GS_VECTOR) {
          if(argp->data != NULL) {
            copy_char_vector_output(argv_idl[i], argp);
            free(argp->data);
          }
        }
      }

      if(argp->objecttype == GS_SCALAR) {
        store_scalar_to_idl(argv_idl[i], argp);

        if(argp->inout == GS_OUT) {
          /* output only scalar */
          if(gs_idl_types[argp->datatype] != argv_idl[i]->type)
            copy_scalar_output(argv_idl[i], argp);
        }
      }
    }

    /* don't move this increment into the for loop stmt since we don't
     * want it to be incremented for workspace args
     */
    i++;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void print_array ( int  m,
int  n,
double *  A 
)

Prints the matrix. Used for debugging purposes.

Parameters:
m -- number of rows
n -- number of cols
A -- matrix data

Definition at line 37 of file translate.c.

{
  int i, j;
  for(i = 0; i < m; i++) {
    for(j = 0; j < n; j++) {
      printf("%f ", *(A+i*n+j));
    }
    printf("\n");
  }
}

int store_scalar_to_idl ( IDL_VPTR  argv_idl,
gs_argument_t *  argp 
)

Save the scalar from the GridSolve arg back to the IDL arg.

Parameters:
argv_idl -- the IDL argument (destination)
argp -- pointer to the GridSolve argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 1081 of file translate.c.

{
  IDL_VPTR tmp;

  argp->data = &argp->scalar_val;

  switch(argp->datatype) {
    case GS_INT: 
      argv_idl->value.l = argp->scalar_val.int_val;
      break;
    case GS_CHAR:
      tmp = get_idl_string_from_unterminated_char(1, &(argp->scalar_val.char_val));
      IDL_VarCopy(tmp, argv_idl);
      break;
    case GS_FLOAT:
      argv_idl->value.f = argp->scalar_val.float_val;
      break;
    case GS_DOUBLE:
      argv_idl->value.d = argp->scalar_val.double_val;
      break;
    case GS_SCOMPLEX:
      argv_idl->value.cmp.r = argp->scalar_val.scomplex_val.r;
      argv_idl->value.cmp.i = argp->scalar_val.scomplex_val.i;
      break;
    case GS_DCOMPLEX:
      argv_idl->value.dcmp.r = argp->scalar_val.dcomplex_val.r;
      argv_idl->value.dcmp.i = argp->scalar_val.dcomplex_val.i;
      break;
    default:
      die_type_mismatch(argv_idl, argp);
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_array_input ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

Copies an array input argument from IDL to a GridSolve compatible argument.

Parameters:
argp -- pointer to the GridSolve argument (destination)
arg_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 960 of file translate.c.

{
  int rv;

  rv = 0;

  if(argp->datatype != GS_CHAR)
    IDL_ENSURE_ARRAY(arg_idl);

  switch(argp->datatype) {
    case GS_CHAR: /* string */
      if(argp->objecttype == GS_MATRIX)
        rv = create_linear_char_matrix(arg_idl, argp);
      else
        argp->data = IDL_VarGetString(arg_idl);
      break;
    case GS_INT: /* int array */
      rv = translate_int_array(arg_idl, argp);
      break;
    case GS_DCOMPLEX: /* dcomplex array */
      rv = translate_dcomplex_array(arg_idl, argp);
      break;
    case GS_SCOMPLEX: /* complex array */
      rv = translate_scomplex_array(arg_idl, argp);
      break;
    case GS_DOUBLE: /* double array */
      rv = translate_double_array(arg_idl, argp);
      break;
    case GS_FLOAT: /* float array */
      rv = translate_float_array(arg_idl, argp);
      break;
    default:
      die_type_mismatch(arg_idl, argp);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_array_output ( gs_argument_t *  argp,
IDL_VPTR  arg_idl 
)

For array objects, sssign the IDL output buffer to the arg's data pointer.

Parameters:
argp -- pointer to the GridSolve argument (destination)
argv_idl -- the IDL argument (source)
Returns:
0 on success, -1 on failure.

Definition at line 1043 of file translate.c.

{
  if(argp->datatype == GS_CHAR) {
    if(arg_idl->type == IDL_TYP_UNDEF)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
        "Error: can't pass empty variable for output-only string arg.");
    else if(gs_idl_types[argp->datatype] != arg_idl->type)
      die_type_mismatch(arg_idl, argp);

    if(argp->objecttype == GS_MATRIX) {
      create_linear_char_matrix(arg_idl, argp);
    }
    else {
      arg_idl->type = IDL_TYP_STRING;
      argp->data = malloc(arg_idl->value.str.slen);
      if(!argp->data)
        IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
           "Error: malloc failed in translate_array_output().");
    }
  }
  else {
    IDL_ENSURE_ARRAY(arg_idl);
    argp->data = arg_idl->value.arr->data; 
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_dcomplex_array ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Copies a double-precision complex array argument from IDL to a GridSolve compatible argument.

Parameters:
idl_type -- the IDL data type of the argument
arr -- pointer to the IDL array data
argv -- pointer to the GridSolve data pointer that should be set upon return to point to the IDL data
Returns:
0 on success, -1 on failure.

Definition at line 710 of file translate.c.

{
  IDL_DCOMPLEX*   pdcomplex;
  int idl_type, *argv;
  IDL_ARRAY *arr;

  arr = arg_idl->value.arr;
  idl_type = arg_idl->type;
  argv = (int*) &argp->data;

  if(idl_type == IDL_TYP_COMPLEX || idl_type == IDL_TYP_BYTE
      || idl_type == IDL_TYP_INT  || idl_type == IDL_TYP_LONG
      || idl_type == IDL_TYP_FLOAT|| idl_type == IDL_TYP_DOUBLE) {
    int i;
    pdcomplex  = (IDL_DCOMPLEX* )malloc(sizeof(IDL_DCOMPLEX)*arr->n_elts);

    if(!pdcomplex)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
         "Error: malloc failed in translate_dcomplex_array()");

    if(idl_type == IDL_TYP_COMPLEX) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(float, double, 1, arr->data+2*i, &(pdcomplex+i)->r);
        COPY_A_TO_B(float, double, 1, arr->data+2*i+1, &(pdcomplex+i)->i);
      }
    }
    else if(idl_type == IDL_TYP_DOUBLE) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(double, double, 1, arr->data+i, &(pdcomplex+i)->r);
        (pdcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_FLOAT) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(float, double, 1, arr->data+i, &(pdcomplex+i)->r);
        (pdcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_LONG) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(int, double, 1, arr->data+i, &(pdcomplex+i)->r);
        (pdcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_INT) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(short, double, 1, arr->data+i, &(pdcomplex+i)->r);
        (pdcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_BYTE) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(unsigned char, double, 1, arr->data+i, &(pdcomplex+i)->r);
        (pdcomplex+i)->i = 0;
      }
    }
    *argv = (int)pdcomplex;
  }
  else if(idl_type == IDL_TYP_DCOMPLEX) {
    *argv = (int) arr->data;
  }
  else
    die_type_mismatch(arg_idl, argp);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_double_array ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Copies a double-precision array argument from IDL to a GridSolve compatible argument.

Parameters:
idl_type -- the IDL data type of the argument
arr -- pointer to the IDL array data
argv -- pointer to the GridSolve data pointer that should be set upon return to point to the IDL data
Returns:
0 on success, -1 on failure.

Definition at line 864 of file translate.c.

{
  double *dbl_buf;
  int idl_type, *argv;
  IDL_ARRAY *arr;

  arr = arg_idl->value.arr;
  idl_type = arg_idl->type;
  argv = (int*) &argp->data;

  if(idl_type == IDL_TYP_BYTE || idl_type == IDL_TYP_INT ||
      idl_type == IDL_TYP_LONG || idl_type == IDL_TYP_FLOAT) {
    dbl_buf  = (double* )malloc(arr->n_elts*sizeof(double));

    if(!dbl_buf)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
         "Error: malloc failed in translate_double_array()");

    if(idl_type == IDL_TYP_BYTE)
      COPY_A_TO_B(unsigned char, double, arr->n_elts, arr->data, dbl_buf)
    else if(idl_type == IDL_TYP_INT)
      COPY_A_TO_B(short, double, arr->n_elts, arr->data, dbl_buf)
    else if(idl_type == IDL_TYP_LONG)
      COPY_A_TO_B(int, double, arr->n_elts, arr->data, dbl_buf)
    else
      COPY_A_TO_B(float, double, arr->n_elts, arr->data, dbl_buf)
    *argv = (int)dbl_buf;
  }
  else if(idl_type == IDL_TYP_DOUBLE) {
    *argv = (int)arr->data;
  }
  else
    die_type_mismatch(arg_idl, argp);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_float_array ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Copies a single-precision array argument from IDL to a GridSolve compatible argument.

Parameters:
idl_type -- the IDL data type of the argument
arr -- pointer to the IDL array data
argv -- pointer to the GridSolve data pointer that should be set upon return to point to the IDL data
Returns:
0 on success, -1 on failure.

Definition at line 914 of file translate.c.

{
  float *flt_buf;
  int idl_type, *argv;
  IDL_ARRAY *arr;

  arr = arg_idl->value.arr;
  idl_type = arg_idl->type;
  argv = (int*) &argp->data;

  if(idl_type == IDL_TYP_BYTE || idl_type == IDL_TYP_INT ||
      idl_type == IDL_TYP_LONG) {
    flt_buf  = (float* )malloc(arr->n_elts*sizeof(float));

    if(!flt_buf)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
        "Error: malloc failed in translate_float_array()");

    if(idl_type == IDL_TYP_BYTE)
      COPY_A_TO_B(unsigned char, float, arr->n_elts, arr->data, flt_buf)
    else if(idl_type == IDL_TYP_INT)
      COPY_A_TO_B(short, float, arr->n_elts, arr->data, flt_buf)
    else
      COPY_A_TO_B(int, float, arr->n_elts, arr->data, flt_buf)
    *argv = (int) flt_buf;
  }
  else if(idl_type == IDL_TYP_FLOAT) {
    *argv = (int)arr->data;
  }
  else
    die_type_mismatch(arg_idl, argp);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_int_array ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Copies an integer array argument from IDL to a GridSolve compatible argument.

Parameters:
idl_type -- the IDL data type of the argument
arr -- pointer to the IDL array data
argv -- pointer to the GridSolve data pointer that should be set upon return to point to the IDL data
Returns:
0 on success, -1 on failure.

Definition at line 664 of file translate.c.

{
  int idl_type, *int_buf, *argv;
  IDL_ARRAY *arr;

  arr = arg_idl->value.arr;
  idl_type = arg_idl->type;
  argv = (int*) &argp->data;

  if(idl_type == IDL_TYP_INT || idl_type == IDL_TYP_BYTE) {
    int_buf  = (int* )malloc(arr->n_elts*sizeof(int));

    if(!int_buf)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP, 
        "Error: malloc failed in translate_int_array()");

    if(idl_type == IDL_TYP_INT)
      COPY_A_TO_B(short, int, arr->n_elts, arr->data, int_buf)
    else
      COPY_A_TO_B(unsigned char, int, arr->n_elts, arr->data, int_buf)

    *argv = (int)int_buf;
  }
  else  if(idl_type == IDL_TYP_LONG) {
    *argv = (int)arr->data;
  }
  else {
    die_type_mismatch(arg_idl, argp);
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_scomplex_array ( IDL_VPTR  arg_idl,
gs_argument_t *  argp 
)

Copies a single-precision complex array argument from IDL to a GridSolve compatible argument.

Parameters:
idl_type -- the IDL data type of the argument
arr -- pointer to the IDL array data
argv -- pointer to the GridSolve data pointer that should be set upon return to point to the IDL data
Returns:
0 on success, -1 on failure.

Definition at line 790 of file translate.c.

{
  IDL_COMPLEX*    pcomplex;
  int idl_type, *argv;
  IDL_ARRAY *arr;

  arr = arg_idl->value.arr;
  idl_type = arg_idl->type;
  argv = (int*) &argp->data;

  if(idl_type == IDL_TYP_BYTE || idl_type == IDL_TYP_INT
      || idl_type == IDL_TYP_LONG || idl_type == IDL_TYP_FLOAT
      || idl_type == IDL_TYP_DOUBLE) {
    int i;
    pcomplex  = (IDL_COMPLEX* )malloc(sizeof(IDL_COMPLEX)*arr->n_elts);

    if(!pcomplex)
      IDL_Message(IDL_M_GENERIC, IDL_MSG_LONGJMP,
        "Error: malloc failed in translate_scomplex_array()");

    if(idl_type == IDL_TYP_DOUBLE) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(double, double, 1, arr->data+i,   &(pcomplex+i)->r);
        (pcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_FLOAT) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(float, double, 1, arr->data+i,   &(pcomplex+i)->r);
        (pcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_LONG) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(int, double, 1, arr->data+i,   &(pcomplex+i)->r);
        (pcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_INT) {
      for(i = 0; i < arr->n_elts; i++) {
        COPY_A_TO_B(short, double, 1, arr->data+i,   &(pcomplex+i)->r);
        (pcomplex+i)->i = 0;
      }
    }
    else if(idl_type == IDL_TYP_BYTE) {
      for(i = 0; i < arr->n_elts; i++) {
          COPY_A_TO_B(unsigned char, double, 1, arr->data+i,   &(pcomplex+i)->r);
        (pcomplex+i)->i = 0;
      }
    }
    *argv = (int)pcomplex;
  }
  else if(idl_type == IDL_TYP_COMPLEX) {/* matched! */
    *argv = (int) arr->data;
  }
  else
    die_type_mismatch(arg_idl, argp);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int trunc_fname ( char *  fname  ) 

Truncates "()" from the function name if necessary.

Parameters:
fname -- the function name to be truncated
Returns:
0 on success, -1 on failure.

Definition at line 57 of file translate.c.

{
  char *p;

  p = strchr(fname, '(');

  if(p)
    *p = 0;

  return 0;
}

Here is the caller graph for this function:


Variable Documentation

UCHAR gs_idl_types[]
Initial value:
 {
  IDL_TYP_LONG,
  IDL_TYP_FLOAT,
  IDL_TYP_DOUBLE,
  IDL_TYP_COMPLEX,
  IDL_TYP_DCOMPLEX,
  IDL_TYP_STRING,
  IDL_TYP_UNDEF
}

Translate and copy the argvs from IDL to GridSolve C client.

This is part of the IDL Client for GridSolve. This array is a mapping from GridSolve data types to IDL data types

Definition at line 18 of file translate.c.