コード例 #1
0
ファイル: spice_rub.c プロジェクト: Arafatk/spice_rub
static VALUE radrec(VALUE self, VALUE range, VALUE right_ascension, VALUE declination) {
  double vector[3];

  radrec_c(NUM2DBL(range), NUM2DBL(right_ascension), NUM2DBL(declination), vector);
  
  return rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) vector, 3);
}
コード例 #2
0
ファイル: spice_rub.c プロジェクト: Arafatk/spice_rub
static VALUE sphrec(VALUE self, VALUE radius, VALUE colatitude, VALUE longitude) {
  double vector[3];

  sphrec_c(NUM2DBL(radius), NUM2DBL(colatitude), NUM2DBL(longitude), vector);
  
  return rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) vector, 3);
}
コード例 #3
0
ファイル: spice_rub.c プロジェクト: Arafatk/spice_rub
static VALUE pgrrec(VALUE self, VALUE body, VALUE longitude, VALUE latitude, VALUE altitude, VALUE radius_equatorial, VALUE flattening) {
  double vector[3];

  pgrrec_c(RB_SYM2STR(body), NUM2DBL(radius_equatorial), NUM2DBL(flattening), NUM2DBL(longitude), NUM2DBL(latitude), NUM2DBL(altitude), vector);

  if(spice_error(SPICE_ERROR_SHORT)) return Qnil;

  return rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) vector, 3);
}
コード例 #4
0
ファイル: spice_rub.c プロジェクト: Arafatk/spice_rub
static VALUE subslr(VALUE self, VALUE method, VALUE target, VALUE et, VALUE fixref, VALUE abcorr, VALUE obsrvr) {
  //Output
  double sub_solar_epoch,
         surface_point[3],
         surface_vector[3];

  //Arrays that we return to Ruby
  VALUE rb_vector = rb_ary_new();
  VALUE rb_point  = rb_ary_new();

  subslr_c(StringValuePtr(method), RB_SYM2STR(target), NUM2DBL(et), RB_SYM2STR(fixref), RB_SYM2STR(abcorr), RB_SYM2STR(obsrvr), surface_point, &sub_solar_epoch, surface_vector);

  if(spice_error(SPICE_ERROR_SHORT)) return Qnil;

  rb_point = rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) surface_point, 3);
  rb_vector = rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) surface_vector, 3);

  return rb_ary_new3(3, rb_point, rb_vector, DBL2NUM(sub_solar_epoch));
}
コード例 #5
0
ファイル: spice_rub.c プロジェクト: Arafatk/spice_rub
static VALUE getfov(VALUE self, VALUE instid, VALUE room, VALUE shapelen, VALUE framelen) {
  int count, vector_count;
  //Maximum size of SPICE ID is 32 chars
  char * shape = ALLOC_N(char, shapelen);
  char * frame = ALLOC_N(char, framelen);
  
  //Upper bound on boundary vectors is uncertain
  double boundary_sight[3];
  double boundary_vectors [10][3];
  
  VALUE rb_bounds; 
  VALUE rb_sight_vector = rb_ary_new();
  VALUE rb_shape, rb_frame;

  getfov_c(FIX2INT(instid), FIX2INT(room), FIX2INT(shapelen), FIX2INT(framelen), shape, frame, boundary_sight, &vector_count, boundary_vectors);
  
  if(spice_error(SPICE_ERROR_SHORT)) {
    return Qnil;
  }
  
  rb_sight_vector = rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) boundary_sight, 3); 

  rb_bounds = rb_ary_new2(vector_count);

  for (count = 0; count < vector_count; count++) {
    rb_ary_push(rb_bounds, rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) boundary_vectors[count], 3));
  }

  rb_shape = RB_STR2SYM(shape);
  rb_frame = RB_STR2SYM(frame);

  xfree(shape);
  xfree(frame);

  if(spice_error(SPICE_ERROR_SHORT)) return Qnil; 
  
  return rb_ary_new3(5, rb_shape, rb_frame, rb_sight_vector, rb_bounds, INT2FIX(vector_count));
}
コード例 #6
0
ファイル: spice_rub.c プロジェクト: Arafatk/spice_rub
/*

void sincpt_c :

Given an observer and a direction vector defining a ray, compute 
the surface intercept of the ray on a target body at a specified 
epoch, optionally corrected for light time and stellar 
aberration. 


void sincpt_c (    ConstSpiceChar      * method,
                   ConstSpiceChar      * target,
                   SpiceDouble           et,
                   ConstSpiceChar      * fixref,
                   ConstSpiceChar      * abcorr,
                   ConstSpiceChar      * obsrvr,
                   ConstSpiceChar      * dref,
                   ConstSpiceDouble      dvec   [3],
                   SpiceDouble           spoint [3],
                   SpiceDouble         * trgepc,
                   SpiceDouble           srfvec [3],
                   SpiceBoolean        * found       )

*/
static VALUE sincpt(VALUE self, VALUE method, VALUE target, VALUE et, VALUE fixref, VALUE abcorr, VALUE obsrvr, VALUE dref, VALUE dvec) {
  //C containers to pass on to SPICE function
  
  /* Input
   argv[0] -> Target
   argv[1] -> Ephemeris Time
   argv[2] -> Fixed Reference
   argv[3] -> Aberration Correcton *IGNORED* if Arguments passed is 	
   argv[4] -> Observer Body Name
   argv[5] -> Reference Frame of Ray's direction vector
   argv[6] -> Ray's direction Vector
  */
  //Output parameters
  SpiceBoolean found;
  double intercept_epoch,
         surface_point[3],
         surface_vector[3];

  //Arrays that we return to Ruby
  VALUE rb_vector;
  VALUE rb_point;

  sincpt_c(StringValuePtr(method), StringValuePtr(target), NUM2DBL(et), StringValuePtr(fixref), StringValuePtr(abcorr), StringValuePtr(obsrvr), StringValuePtr(dref), NM_STORAGE_DENSE(dvec)->elements, surface_point, &intercept_epoch, surface_vector, &found);

  if(!found) {
  	return Qfalse;
  }

  else if(spice_error(SPICE_ERROR_SHORT)) {
  	return Qnil;
  }
  
  rb_point = rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) surface_point, 3);
  rb_vector = rb_nmatrix_dense_create(FLOAT64, (size_t *) VECTOR_SHAPE, 2, (void *) surface_vector, 3);


  return rb_ary_new3(3, rb_point, rb_vector, DBL2NUM(intercept_epoch));
}
コード例 #7
0
ファイル: gsl_nmatrix.c プロジェクト: Zenexer/rb-gsl
static VALUE rb_gsl_matrix_int_to_nmatrix(VALUE obj, VALUE klass) {
  gsl_matrix *m = NULL;
  Data_Get_Struct(obj, gsl_matrix, m);

  return rb_nmatrix_dense_create(NM_INT64, &(m->size1), 2, m->data, m->size1 * m->size2);
}
コード例 #8
0
ファイル: gsl_nmatrix.c プロジェクト: Zenexer/rb-gsl
static VALUE rb_gsl_matrix_complex_to_nmatrix(VALUE obj, VALUE klass) {
  gsl_matrix *m = NULL;
  Data_Get_Struct(obj, gsl_matrix, m);

  return rb_nmatrix_dense_create(NM_COMPLEX128, &(m->size1), 2, m->data, m->size1 * m->size2);
}
コード例 #9
0
ファイル: function.c プロジェクト: AbhimanyuAryan/rb-gsl
/*
 * Calculates a function at x, and returns the rusult.
 */
static VALUE rb_gsl_function_eval(VALUE obj, VALUE x)
{
  gsl_function *F = NULL;
  VALUE ary, proc, params, result, arynew, x2;
  gsl_vector *v = NULL, *vnew = NULL;
  gsl_matrix *m = NULL, *mnew = NULL;
  size_t i, j, n;
  Data_Get_Struct(obj, gsl_function, F);
  ary = (VALUE) F->params;
  proc = rb_ary_entry(ary, 0);
  params = rb_ary_entry(ary, 1);
  if (CLASS_OF(x) == rb_cRange) x = rb_gsl_range2ary(x);
  switch (TYPE(x)) {
  case T_FIXNUM:
  case T_BIGNUM:
  case T_FLOAT:
    if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x);
    else result = rb_funcall(proc, RBGSL_ID_call, 2, x, params);
    return result;
    break;
  case T_ARRAY:
    //    n = RARRAY(x)->len;
    n = RARRAY_LEN(x);
    arynew = rb_ary_new2(n);
    for (i = 0; i < n; i++) {
      x2 = rb_ary_entry(x, i);
      Need_Float(x2);
      if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
      else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
      rb_ary_store(arynew, i, result);
    }
    return arynew;
    break;
  default:
#ifdef HAVE_NARRAY_H
    if (NA_IsNArray(x)) {
      double *ptr1, *ptr2;
      struct NARRAY *na;
      GetNArray(x, na);
      ptr1 = (double *) na->ptr;
      n = na->total;
      ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(x));
      ptr2 = NA_PTR_TYPE(ary, double*);
      for (i = 0; i < n; i++) {
        x2 = rb_float_new(ptr1[i]);
        if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
        else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
        ptr2[i] = NUM2DBL(result);
      }
      return ary;
    }
#endif
#ifdef HAVE_NMATRIX_H
    if (NM_IsNMatrix(x)) {
      double *ptr1, *ptr2;
      NM_DENSE_STORAGE *nm;
      nm = NM_STORAGE_DENSE(x);
      ptr1 = (double *) nm->elements;
      n = NM_DENSE_COUNT(x);
      ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
      ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
      for (i = 0; i < n; i++) {
        x2 = rb_float_new(ptr1[i]);
        if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
        else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
        ptr2[i] = NUM2DBL(result);
      }
      return ary;
    }
#endif
    if (VECTOR_P(x)) {
      Data_Get_Struct(x, gsl_vector, v);
      vnew = gsl_vector_alloc(v->size);
      for (i = 0; i < v->size; i++) {
        x2 = rb_float_new(gsl_vector_get(v, i));
        if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
        else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
        gsl_vector_set(vnew, i, NUM2DBL(result));
      }
      return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
    } else if (MATRIX_P(x)) {
      Data_Get_Struct(x, gsl_matrix, m);
      mnew = gsl_matrix_alloc(m->size1, m->size2);
      for (i = 0; i < m->size1; i++) {
        for (j = 0; j < m->size2; j++) {
          x2 = rb_float_new(gsl_matrix_get(m, i, j));
          if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
          else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
          gsl_matrix_set(mnew, i, j, NUM2DBL(result));
        }
      }
      return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
    } else {
      rb_raise(rb_eTypeError, "wrong argument type");
    }
    break;
  }
  /* never reach here */
  return Qnil;
}