예제 #1
0
파일: flock.c 프로젝트: deepfryed/flock
/* @api private */
VALUE rb_do_treecluster(int argc, VALUE *argv, VALUE self) {
    VALUE size, data, mask, weights, options;
    rb_scan_args(argc, argv, "21", &size, &data, &options);

    if (TYPE(data) != T_ARRAY)
        rb_raise(rb_eArgError, "data should be an array of arrays");

    mask = get_value_option(options, "mask", Qnil);

    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)
        rb_raise(rb_eArgError, "mask should be an array of arrays");

    if (NIL_P(size) || NUM2INT(rb_Integer(size)) > RARRAY_LEN(data))
        rb_raise(rb_eArgError, "size should be > 0 and <= data size");

    int transpose = get_int_option(options, "transpose", 0);

    // s: pairwise single-linkage clustering
    // m: pairwise maximum- (or complete-) linkage clustering
    // a: pairwise average-linkage clustering
    // c: pairwise centroid-linkage clustering
    int method    = get_int_option(options, "method", 'a');

    // e = euclidian,
    // b = city-block distance
    // c = correlation
    // a = absolute value of the correlation
    // u = uncentered correlation
    // x = absolute uncentered correlation
    // s = spearman's rank correlation
    // k = kendall's tau
    int dist      = get_int_option(options, "metric", 'e');

    int i,j;
    int nrows = RARRAY_LEN(data);
    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));
    int nsets = NUM2INT(rb_Integer(size));

    double **cdata    = (double**)malloc(sizeof(double*)*nrows);
    int    **cmask    = (int   **)malloc(sizeof(int   *)*nrows);
    double *cweights  = (double *)malloc(sizeof(double )*ncols);

    int *ccluster, dimx = nrows, dimy = ncols;

    for (i = 0; i < nrows; i++) {
        cdata[i]          = (double*)malloc(sizeof(double)*ncols);
        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);
        for (j = 0; j < ncols; j++) {
            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));
            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));
        }
    }

    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));
    for (i = 0; i < ncols; i++) {
        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));
    }

    if (transpose) {
        dimx  = ncols;
        dimy  = nrows;
    }

    ccluster = (int *)malloc(sizeof(int)*dimx);

    Node *tree   = treecluster(nrows, ncols, cdata, cmask, cweights, transpose, dist, method, 0);
    VALUE result = Qnil, cluster;

    if (tree) {
        cuttree(dimx, tree, nsets, ccluster);

        result  = rb_hash_new();
        cluster = rb_ary_new();

        for (i = 0; i < dimx; i++)
            rb_ary_push(cluster, INT2NUM(ccluster[i]));

        rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);
    }

    for (i = 0; i < nrows; i++) {
        free(cdata[i]);
        free(cmask[i]);
    }

    free(cdata);
    free(cmask);
    free(cweights);
    free(ccluster);

    if (tree)
        free(tree);
    else
        rb_raise(rb_eNoMemError, "treecluster ran out of memory");

    return result;
}
예제 #2
0
파일: flock.c 프로젝트: deepfryed/flock
/* @api private */
VALUE rb_do_kcluster(int argc, VALUE *argv, VALUE self) {
    VALUE size, data, mask, weights, options;
    rb_scan_args(argc, argv, "21", &size, &data, &options);

    if (TYPE(data) != T_ARRAY)
        rb_raise(rb_eArgError, "data should be an array of arrays");

    if (NIL_P(size) || NUM2INT(rb_Integer(size)) > RARRAY_LEN(data))
        rb_raise(rb_eArgError, "size should be > 0 and <= data size");

    mask = get_value_option(options, "mask", Qnil);

    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)
        rb_raise(rb_eArgError, "mask should be an array of arrays");

    int transpose = get_bool_option(options, "transpose", 0);
    int npass     = get_int_option(options, "iterations", DEFAULT_ITERATIONS);

    // a = average, m = means
    int method    = get_int_option(options, "method", 'a');

    // e = euclidian,
    // b = city-block distance
    // c = correlation
    // a = absolute value of the correlation
    // u = uncentered correlation
    // x = absolute uncentered correlation
    // s = spearman's rank correlation
    // k = kendall's tau
    int dist      = get_int_option(options, "metric", 'e');

    // initial assignment
    int assign    = get_int_option(options, "seed",    0);

    int i,j;
    int nrows = RARRAY_LEN(data);
    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));
    int nsets = NUM2INT(rb_Integer(size));

    double **cdata          = (double**)malloc(sizeof(double*)*nrows);
    int    **cmask          = (int   **)malloc(sizeof(int   *)*nrows);
    double *cweights        = (double *)malloc(sizeof(double )*ncols);

    double **ccentroid;
    int *ccluster, **ccentroid_mask, dimx = nrows, dimy = ncols, cdimx = nsets, cdimy = ncols;

    for (i = 0; i < nrows; i++) {
        cdata[i]          = (double*)malloc(sizeof(double)*ncols);
        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);
        for (j = 0; j < ncols; j++) {
            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));
            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));
        }
    }

    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));
    for (i = 0; i < ncols; i++) {
        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));
    }

    if (transpose) {
        dimx  = ncols;
        dimy  = nrows;
        cdimx = nrows;
        cdimy = nsets;
    }

    ccluster       = (int    *)malloc(sizeof(int    )*dimx);
    ccentroid      = (double**)malloc(sizeof(double*)*cdimx);
    ccentroid_mask = (int   **)malloc(sizeof(int   *)*cdimx);

    for (i = 0; i < cdimx; i++) {
      ccentroid[i]      = (double*)malloc(sizeof(double)*cdimy);
      ccentroid_mask[i] = (int   *)malloc(sizeof(int   )*cdimy);
    }

    int    ifound;
    double error;

    kcluster(nsets,
        nrows, ncols, cdata, cmask, cweights, transpose, npass, method, dist, ccluster, &error, &ifound, assign);
    getclustercentroids(nsets,
        nrows, ncols, cdata, cmask, ccluster, ccentroid, ccentroid_mask, transpose, method);

    VALUE result   = rb_hash_new();
    VALUE cluster  = rb_ary_new();
    VALUE centroid = rb_ary_new();

    for (i = 0; i < dimx; i++)
        rb_ary_push(cluster, INT2NUM(ccluster[i]));

    for (i = 0; i < cdimx; i++) {
        VALUE point = rb_ary_new();
        for (j = 0; j < cdimy; j++)
            rb_ary_push(point, DBL2NUM(ccentroid[i][j]));
        rb_ary_push(centroid, point);
    }

    rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);
    rb_hash_aset(result, ID2SYM(rb_intern("centroid")),  centroid);
    rb_hash_aset(result, ID2SYM(rb_intern("error")),     DBL2NUM(error));
    rb_hash_aset(result, ID2SYM(rb_intern("repeated")),  INT2NUM(ifound));

    for (i = 0; i < nrows; i++) {
        free(cdata[i]);
        free(cmask[i]);
    }

    for (i = 0; i < cdimx; i++) {
        free(ccentroid[i]);
        free(ccentroid_mask[i]);
    }

    free(cdata);
    free(cmask);
    free(ccentroid);
    free(ccentroid_mask);
    free(cweights);
    free(ccluster);

    return result;
}
예제 #3
0
파일: flock.c 프로젝트: deepfryed/flock
/* @api private */
VALUE rb_do_self_organizing_map(int argc, VALUE *argv, VALUE self) {
    VALUE nx, ny, data, mask, weights, options;
    rb_scan_args(argc, argv, "31", &nx, &ny, &data, &options);

    if (TYPE(data) != T_ARRAY)
        rb_raise(rb_eArgError, "data should be an array of arrays");

    mask = get_value_option(options, "mask", Qnil);

    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)
        rb_raise(rb_eArgError, "mask should be an array of arrays");

    if (NIL_P(nx) || NUM2INT(rb_Integer(nx)) <= 0)
        rb_raise(rb_eArgError, "nx should be > 0");

    if (NIL_P(ny) || NUM2INT(rb_Integer(ny)) <= 0)
        rb_raise(rb_eArgError, "ny should be > 0");

    int nxgrid    = NUM2INT(rb_Integer(nx));
    int nygrid    = NUM2INT(rb_Integer(ny));
    int transpose = get_int_option(options, "transpose", 0);
    int npass     = get_int_option(options, "iterations", DEFAULT_ITERATIONS);

    // e = euclidian,
    // b = city-block distance
    // c = correlation
    // a = absolute value of the correlation
    // u = uncentered correlation
    // x = absolute uncentered correlation
    // s = spearman's rank correlation
    // k = kendall's tau
    int dist      = get_int_option(options, "metric", 'e');
    double tau    = get_dbl_option(options, "tau", 1.0);

    int i, j, k;
    int nrows = RARRAY_LEN(data);
    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));

    double **cdata          = (double**)malloc(sizeof(double*)*nrows);
    int    **cmask          = (int   **)malloc(sizeof(int   *)*nrows);
    double *cweights        = (double *)malloc(sizeof(double )*ncols);

    int **ccluster;
    double ***ccelldata;
    int dimx = nrows, dimy = ncols;

    if (transpose) {
        dimx = ncols;
        dimy = nrows;
    }

    ccluster = (int **)malloc(sizeof(int*)*dimx);
    for (i = 0; i < dimx; i++)
        ccluster[i] = (int*)malloc(sizeof(int)*2);

    for (i = 0; i < nrows; i++) {
        cdata[i]          = (double*)malloc(sizeof(double)*ncols);
        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);
        for (j = 0; j < ncols; j++) {
            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));
            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));
        }
    }

    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));
    for (i = 0; i < ncols; i++) {
        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));
    }

    ccelldata = (double***)malloc(sizeof(double**)*nxgrid);
    for (i = 0; i < nxgrid; i++) {
        ccelldata[i] = (double **)malloc(sizeof(double*)*nygrid);
        for (j = 0; j < nygrid; j++)
            ccelldata[i][j] = (double *)malloc(sizeof(double)*dimy);
    }

    somcluster(nrows, ncols, cdata, cmask, cweights, transpose, nxgrid, nygrid, tau, npass, dist, ccelldata, ccluster);

    VALUE result   = rb_hash_new();
    VALUE cluster  = rb_ary_new();
    VALUE centroid = rb_ary_new();

    for (i = 0; i < dimx; i++) {
        VALUE gridpoint = rb_ary_new();
        rb_ary_push(gridpoint, INT2NUM(ccluster[i][0]));
        rb_ary_push(gridpoint, INT2NUM(ccluster[i][1]));
        rb_ary_push(cluster, gridpoint);
    }

    for (i = 0; i < nxgrid; i++) {
        for (j = 0; j < nygrid; j++) {
            VALUE point = rb_ary_new();
            for (k = 0; k < dimy; k++)
                rb_ary_push(point, DBL2NUM(ccelldata[i][j][k]));
            rb_ary_push(centroid, point);
        }
    }

    rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);
    rb_hash_aset(result, ID2SYM(rb_intern("centroid")),  centroid);

    for (i = 0; i < nrows; i++) {
        free(cdata[i]);
        free(cmask[i]);
    }

    for (i = 0; i < dimx; i++)
        free(ccluster[i]);

    for (i = 0; i < nxgrid; i++) {
        for (j = 0; j < nygrid; j++)
            free(ccelldata[i][j]);
        free(ccelldata[i]);
    }

    free(cdata);
    free(cmask);
    free(ccelldata);
    free(cweights);
    free(ccluster);

    return result;
}
void xspice_set_spice_server_options(OptionInfoPtr options)
{
    /* environment variables take precedense. If not then take
     * parameters from the config file. */
    int addr_flags;
    int len;
    spice_image_compression_t compression;
    spice_wan_compression_t wan_compr;
    int port = get_int_option(options, OPTION_SPICE_PORT, "XSPICE_PORT");
    int tls_port =
        get_int_option(options, OPTION_SPICE_TLS_PORT, "XSPICE_TLS_PORT");
    const char *password =
        get_str_option(options, OPTION_SPICE_PASSWORD, "XSPICE_PASSWORD");
    int disable_ticketing =
        get_bool_option(options, OPTION_SPICE_DISABLE_TICKETING, "XSPICE_DISABLE_TICKETING");
    const char *x509_dir =
        get_str_option(options, OPTION_SPICE_X509_DIR, "XSPICE_X509_DIR");
    int sasl = get_bool_option(options, OPTION_SPICE_SASL, "XSPICE_SASL");
    const char *x509_key_file_base =
        get_str_option(options, OPTION_SPICE_X509_KEY_FILE,
                       "XSPICE_X509_KEY_FILE");
    char *x509_key_file = NULL;
    const char *x509_cert_file_base =
        get_str_option(options, OPTION_SPICE_X509_CERT_FILE,
                       "XSPICE_X509_CERT_FILE");
    char *x509_cert_file = NULL;
    const char *x509_key_password =
        get_str_option(options, OPTION_SPICE_X509_KEY_PASSWORD,
                    "XSPICE_X509_KEY_PASSWORD");
    const char *tls_ciphers =
        get_str_option(options, OPTION_SPICE_TLS_CIPHERS,
                    "XSPICE_TLS_CIPHERS");
    const char *x509_cacert_file_base =
        get_str_option(options, OPTION_SPICE_CACERT_FILE,
                    "XSPICE_CACERT_FILE");
    char *x509_cacert_file = NULL;
    const char * addr =
        get_str_option(options, OPTION_SPICE_ADDR, "XSPICE_ADDR");
    int ipv4 =
        get_bool_option(options, OPTION_SPICE_IPV4_ONLY, "XSPICE_IPV4_ONLY");
    int ipv6 =
        get_bool_option(options, OPTION_SPICE_IPV6_ONLY, "XSPICE_IPV6_ONLY");
    const char *x509_dh_file =
        get_str_option(options, OPTION_SPICE_DH_FILE, "XSPICE_DH_FILE");
    int disable_copy_paste =
        get_bool_option(options, OPTION_SPICE_DISABLE_COPY_PASTE,
                        "XSPICE_DISABLE_COPY_PASTE");
    const char *image_compression =
        get_str_option(options, OPTION_SPICE_IMAGE_COMPRESSION,
                       "XSPICE_IMAGE_COMPRESSION");
    const char *jpeg_wan_compression =
        get_str_option(options, OPTION_SPICE_JPEG_WAN_COMPRESSION,
                       "XSPICE_JPEG_WAN_COMPRESSION");
    const char *zlib_glz_wan_compression =
        get_str_option(options, OPTION_SPICE_ZLIB_GLZ_WAN_COMPRESSION,
                       "XSPICE_ZLIB_GLZ_WAN_COMPRESSION");
    const char *streaming_video =
        get_str_option(options, OPTION_SPICE_STREAMING_VIDEO,
                       "XSPICE_STREAMING_VIDEO");
    int agent_mouse =
        get_bool_option(options, OPTION_SPICE_AGENT_MOUSE,
                        "XSPICE_AGENT_MOUSE");
    int playback_compression =
        get_bool_option(options, OPTION_SPICE_PLAYBACK_COMPRESSION,
                        "XSPICE_PLAYBACK_COMPRESSION");

    SpiceServer *spice_server = xspice_get_spice_server();

    if (!port && !tls_port) {
        printf("one of tls-port or port must be set\n");
        exit(1);
    }
    printf("xspice: port = %d, tls_port = %d\n", port, tls_port);
    spice_server_set_port(spice_server, port);
    if (disable_ticketing) {
        spice_server_set_noauth(spice_server);
    }
    if (tls_port) {
        if (NULL == x509_dir) {
            x509_dir = ".";
        }
        len = strlen(x509_dir) + 32;

        if (x509_key_file_base) {
            x509_key_file = strdup(x509_key_file_base);
        } else {
            x509_key_file = malloc(len);
            snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE);
        }

        if (x509_cert_file_base) {
            x509_cert_file = strdup(x509_cert_file_base);
        } else {
            x509_cert_file = malloc(len);
            snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE);
        }

        if (x509_cacert_file_base) {
            x509_cacert_file = strdup(x509_cert_file_base);
        } else {
            x509_cacert_file = malloc(len);
            snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE);
        }
    }

    addr_flags = 0;
    if (ipv4) {
        addr_flags |= SPICE_ADDR_FLAG_IPV4_ONLY;
    } else if (ipv6) {
        addr_flags |= SPICE_ADDR_FLAG_IPV6_ONLY;
    }

    spice_server_set_addr(spice_server, addr ? addr : "", addr_flags);
    if (port) {
        spice_server_set_port(spice_server, port);
    }
    if (tls_port) {
        spice_server_set_tls(spice_server, tls_port,
                             x509_cacert_file,
                             x509_cert_file,
                             x509_key_file,
                             x509_key_password,
                             x509_dh_file,
                             tls_ciphers);
    }
    if (password) {
        spice_server_set_ticket(spice_server, password, 0, 0, 0);
    }
    if (sasl) {
#if SPICE_SERVER_VERSION >= 0x000802 /* 0.8.2 */
        if (spice_server_set_sasl_appname(spice_server, "xspice") == -1 ||
            spice_server_set_sasl(spice_server, 1) == -1) {
            fprintf(stderr, "spice: failed to enable sasl\n");
            exit(1);
        }
#else
        fprintf(stderr, "spice: sasl is not available (spice >= 0.8.2 required)\n");
        exit(1);
#endif
    }
    if (disable_ticketing) {
        spice_server_set_noauth(spice_server);
    }

#if SPICE_SERVER_VERSION >= 0x000801
    /* we still don't actually support agent in xspice, but this
     * can't hurt for later, just copied from qemn/ui/spice-core.c */
    if (disable_copy_paste) {
        spice_server_set_agent_copypaste(spice_server, 0);
    }
#endif

    compression = SPICE_IMAGE_COMPRESS_AUTO_GLZ;
    if (image_compression) {
        compression = parse_compression(image_compression);
    }
    spice_server_set_image_compression(spice_server, compression);

    wan_compr = SPICE_WAN_COMPRESSION_AUTO;
    if (jpeg_wan_compression) {
        wan_compr = parse_wan_compression(jpeg_wan_compression);
    }
    spice_server_set_jpeg_compression(spice_server, wan_compr);

    wan_compr = SPICE_WAN_COMPRESSION_AUTO;
    if (zlib_glz_wan_compression) {
        wan_compr = parse_wan_compression(zlib_glz_wan_compression);
    }
    spice_server_set_zlib_glz_compression(spice_server, wan_compr);

    if (streaming_video) {
        int streaming_video_opt = parse_stream_video(streaming_video);
        spice_server_set_streaming_video(spice_server, streaming_video_opt);
    }

    spice_server_set_agent_mouse
        (spice_server, agent_mouse);
    spice_server_set_playback_compression
        (spice_server, playback_compression);

    free(x509_key_file);
    free(x509_cert_file);
    free(x509_cacert_file);
}
예제 #5
0
void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode)
{
   GdkScreen *screen = gdk_screen_get_default();

   gint n_monitors = gdk_screen_get_n_monitors(screen);

   gint pick = get_int_option("monitor");
   if (pick < 0 || pick >= n_monitors)
      pick = random() % n_monitors;
   
   GdkRectangle geom;
   gdk_screen_get_monitor_geometry(screen, pick, &geom);

   xcowsay.screen_width = geom.width;
   xcowsay.screen_height = geom.height;

   g_assert(xcowsay.cow_pixbuf);
   xcowsay.cow = make_shape_from_pixbuf(xcowsay.cow_pixbuf);

   switch (mode) {
   case COWMODE_NORMAL:
   case COWMODE_THINK:
      normal_setup(text, debug, mode);
      break;
   case COWMODE_DREAM:
      dream_setup(text, debug);
      break;
   default:
      fprintf(stderr, "Error: Unsupported cow mode %d\n", mode);
      exit(1);
   }
   
   xcowsay.bubble = make_shape_from_pixbuf(xcowsay.bubble_pixbuf);   
   
   int total_width = shape_width(xcowsay.cow)
      + get_int_option("bubble_x")
      + xcowsay.bubble_width;
   int total_height = max(shape_height(xcowsay.cow), xcowsay.bubble_height);

   int bubble_off = max((xcowsay.bubble_height - shape_height(xcowsay.cow))/2, 0);

   int area_w = xcowsay.screen_width - total_width;
   int area_h = xcowsay.screen_height - total_height;

   // Fit the cow on the screen as best as we can
   // The area can't be be zero or we'd get an FPE
   if (area_w < 1)
      area_w = 1;
   if (area_h < 1)
      area_h = 1;

   int cow_x = get_int_option("at_x");
   if (cow_x < 0)
      cow_x = random() % area_w;
   else if (cow_x >= area_w)
      cow_x = area_w - 1;
   
   int cow_y = get_int_option("at_y");
   if (cow_y < 0)
      cow_y = random() % area_h;
   else if (cow_y >= area_h)
      cow_y = area_h - 1;

   if (get_bool_option("left")) {
      move_shape(xcowsay.cow,
                 geom.x + cow_x + xcowsay.bubble_width,
                 geom.y + bubble_off + cow_y);
      show_shape(xcowsay.cow);
      
      int bx = shape_x(xcowsay.cow) - xcowsay.bubble_width
         + get_int_option("bubble_x");
      int by = shape_y(xcowsay.cow)
         + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2
         + get_int_option("bubble_y");
      move_shape(xcowsay.bubble, bx, by);
   }
   else {
      move_shape(xcowsay.cow,
                 geom.x + cow_x,
                 geom.y + bubble_off + cow_y);
      show_shape(xcowsay.cow);
      
      int bx = shape_x(xcowsay.cow) + shape_width(xcowsay.cow)
         + get_int_option("bubble_x");
      int by = shape_y(xcowsay.cow)
         + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2
         + get_int_option("bubble_y");
      move_shape(xcowsay.bubble, bx, by);
   }
      
   xcowsay.state = csLeadIn;
   xcowsay.transition_timeout = get_int_option("lead_in_time");
   g_timeout_add(TICK_TIMEOUT, tick, NULL);

   close_when_clicked(xcowsay.cow);
   
   if (run_main)
      gtk_main();

   g_object_unref(xcowsay.bubble_pixbuf);
   xcowsay.bubble_pixbuf = NULL;
}
예제 #6
0
ErrorCode ReadCCMIO::load_matset_data(CCMIOID problemID) 
{
    // make sure there are matsets
  if (newMatsets.empty()) return MB_SUCCESS;
  
    // ... walk through each cell type
  CCMIOSize_t i = CCMIOSIZEC(0);
  CCMIOID next;
  std::string opt_string;
  CCMIOError error = kCCMIONoErr;
  
  while (CCMIONextEntity(NULL, problemID, kCCMIOCellType, &i, &next)
         == kCCMIONoErr) {
      // get index, corresponding set, and label with material set tag
    int mindex;
    CCMIOGetEntityIndex(&error, next, &mindex);
    std::map<int,EntityHandle>::iterator mit = newMatsets.find(mindex);
    if (mit == newMatsets.end()) 
        // no actual faces for this matset; continue to next
      continue;
    
    EntityHandle dum_ent = mit->second;
    ErrorCode rval = mbImpl->tag_set_data(mMaterialSetTag, &dum_ent, 1, &mindex);
    CHKERR(rval, "Trouble setting material set tag.");

      // set name
    CCMIOSize_t len;
    CCMIOEntityLabel(&error, next, &len, NULL);
    std::vector<char> opt_string2(GETINT32(len)+1, '\0');
    CCMIOEntityLabel(&error, next, NULL, &opt_string2[0]);
    if (opt_string2.size() >= NAME_TAG_SIZE) opt_string2[NAME_TAG_SIZE-1] = '\0';
    else (opt_string2.resize(NAME_TAG_SIZE, '\0'));
    rval = mbImpl->tag_set_data(mNameTag, &dum_ent, 1, &opt_string2[0]);
    CHKERR(rval, "Trouble setting name tag for material set.");

      // material id
    rval = get_int_option("MaterialId", dum_ent, mMaterialIdTag, next);
    CHKERR(rval, "Trouble getting MaterialId tag.");
    
    rval = get_str_option("MaterialType", dum_ent, mMaterialTypeTag, next);
    CHKERR(rval, "Trouble getting MaterialType tag.");
    
    rval = get_int_option("Radiation", dum_ent, mRadiationTag, next);
    CHKERR(rval, "Trouble getting Radiation option.");

    rval = get_int_option("PorosityId", dum_ent, mPorosityIdTag, next);
    CHKERR(rval, "Trouble getting PorosityId option.");

    rval = get_int_option("SpinId", dum_ent, mSpinIdTag, next);
    CHKERR(rval, "Trouble getting SpinId option.");

    rval = get_int_option("GroupId", dum_ent, mGroupIdTag, next);
    CHKERR(rval, "Trouble getting GroupId option.");

    rval = get_int_option("ColorIdx", dum_ent, mColorIdxTag, next);
    CHKERR(rval, "Trouble getting ColorIdx option.");

    rval = get_int_option("ProcessorId", dum_ent, mProcessorIdTag, next);
    CHKERR(rval, "Trouble getting ProcessorId option.");

    rval = get_int_option("LightMaterial", dum_ent, mLightMaterialTag, next);
    CHKERR(rval, "Trouble getting LightMaterial option.");

    rval = get_int_option("FreeSurfaceMaterial", dum_ent, mFreeSurfaceMaterialTag, next);
    CHKERR(rval, "Trouble getting FreeSurfaceMaterial option.");

    rval = get_dbl_option("Thickness", dum_ent, mThicknessTag, next);
    CHKERR(rval, "Trouble getting Thickness option.");
  }

  return MB_SUCCESS;
}
예제 #7
0
파일: vpnoptions.c 프로젝트: Deanzou/ppp
//-----------------------------------------------------------------------------
//	process_server_prefs
//-----------------------------------------------------------------------------
static int process_server_prefs(struct vpn_params *params)
{
    u_int32_t		lval, len;
    u_char            str[MAXPATHLEN];   
	int				err ;
	struct hostent	*hostent;
	
    get_int_option(params->serverRef, kRASEntServer, kRASPropServerMaximumSessions, &lval, 0);
    if (lval)
        params->max_sessions = lval;
	len = sizeof(str);
    get_str_option(params->serverRef, kRASEntServer, kRASPropServerLogfile, str, sizeof(str), &len, (u_char*)default_log_path);
    if (str[0])
        memcpy(params->log_path, str, len + 1);

    get_int_option(params->serverRef, kRASEntServer, kRASPropServerVerboseLogging, &lval, 0);
    if (lval)
        params->log_verbose = lval;

	// Load balancing parameters
	get_int_option(params->serverRef, kRASEntServer, kRASPropServerLoadBalancingEnabled, &lval, 0);
	if (lval) {
		params->lb_enable = 1;
		
		// will determine the interface from the cluster address
		//len = sizeof(str);
		//get_str_option(params->serverRef, kRASEntServer, kRASPropServerLoadBalancingInterface, str, sizeof(str), &len, "en1");
		//strncpy(params->lb_interface, str, sizeof(params->lb_interface));

		// is priority really useful ?
		//get_int_option(params->serverRef, kRASEntServer, kRASPropServerLoadBalancingPriority, &lval, 5);
		//if (lval < 1) lval = 1;
		//else if (lval > LB_MAX_PRIORITY) lval = LB_MAX_PRIORITY;
		//params->lb_priority = lval;
		
		get_int_option(params->serverRef, kRASEntServer, kRASPropServerLoadBalancingPort, &lval, LB_DEFAULT_PORT);
		params->lb_port = htons(lval);
		len = sizeof(str);
		get_str_option(params->serverRef, kRASEntServer, kRASPropServerLoadBalancingAddress, str, sizeof(str), &len, empty_str);
		// ask the system to look up the given name.
		hostent = getipnodebyname ((char*)str, AF_INET, 0, &err);
		if (!hostent) {
			vpnlog(LOG_ERR, "Incorrect Load Balancing address found '%s'\n", str);
			params->lb_enable = 0;
			
		}
		else {
			struct sockaddr_in src, dst;
			
			params->lb_cluster_address = *(struct in_addr *)hostent->h_addr_list[0];
			freehostent(hostent);
			
			bzero(&dst, sizeof(dst));
			dst.sin_family = PF_INET;
			dst.sin_len = sizeof(dst);
			dst.sin_addr = params->lb_cluster_address;
		
			// look for the interface and primary address of the cluster address			
			if (get_route_interface((struct sockaddr *)&src, (struct sockaddr *)&dst, params->lb_interface)) {
			
				vpnlog(LOG_ERR, "Cannot get load balancing redirect address and interface (errno = %d)\n", errno);
				params->lb_enable = 0;
			}

			params->lb_redirect_address = src.sin_addr;

			
		}
	}
	
    return 0;
}