Beispiel #1
0
void output_matrix_long(long diffl, long tree1, long tree2, long trees_in_1,
    long trees_in_2)
{
  if ( tree1 == 1 && ((tree2 - 1) % get_num_columns() == 0 || tree2 == 1 )) {
    if ( (tree_pairing == ALL_IN_FIRST && tree2 + get_num_columns() - 1
          < trees_in_1) ||
         (tree_pairing == ALL_IN_1_AND_2 && tree2 + get_num_columns() - 1
          < trees_in_2)) {
      print_matrix_heading(tree2, tree2 + get_num_columns() - 1);
    } else {
      if ( tree_pairing == ALL_IN_FIRST)
        print_matrix_heading(tree2, trees_in_1);
      else
        print_matrix_heading(tree2, trees_in_2);
    }
  }
  if ( (tree2 - 1) % get_num_columns() == 0 || tree2 == 1) {
    print_line_heading(tree1);
  }
  fprintf(outfile, "%4ld  ", diffl);
  if ((tree_pairing == ALL_IN_FIRST && tree1 == trees_in_1 && tree2 == 
      trees_in_1) || (tree_pairing == ALL_IN_1_AND_2 && tree1 == trees_in_1 &&
        tree2 == trees_in_2))
    fprintf(outfile, "\n\n\n");
} /* output_matrix_long */
Beispiel #2
0
void TablePrinter::PrintHeader(){
  PrintHorizontalLine();
  *out_stream_ << "|";

  for (int i=0; i<get_num_columns(); ++i){
    *out_stream_ << std::setw(column_widths_.at(i)) << column_headers_.at(i).substr(0, column_widths_.at(i));
    if (i != get_num_columns()-1){
      *out_stream_ << separator_;
    }
  }

  *out_stream_ << "|\n";
  PrintHorizontalLine();
}
void table_printer::print_header()
{
    print_horizontal_line();
    *m_out_stream << "|";
    for (int i=0; i < get_num_columns(); ++i) {
        *m_out_stream << std::setw(m_column_widths.at(i)) <<
            m_column_headers.at(i).substr(0, m_column_widths.at(i));
        if (i != get_num_columns() - 1) {
            *m_out_stream << m_separator;
        }
    }
    *m_out_stream << "|\n";
    print_horizontal_line();
}
Beispiel #4
0
// Write the texture, using a virtual method call appropriate to the particular
// camera type.  NOTE: At least the first time this function is called,
// we must write a complete texture, which may be larger than the actual bytes
// allocated for the image.  After the first time, and if we don't change the
// image size to be larger, we can use the subimage call to only write the
// pixels we have.
bool edt_server::write_to_opengl_texture(GLuint tex_id)
{
  // Note: Check the GLubyte or GLushort or whatever in the temporary buffer!
  const GLint   NUM_COMPONENTS = 1;
  const GLenum  FORMAT = GL_LUMINANCE;
  const GLenum  TYPE = GL_UNSIGNED_BYTE;
  const void*   BASE_BUFFER = d_buffer;
  const void*   SUBSET_BUFFER = &d_buffer[NUM_COMPONENTS * ( _minX + get_num_columns()*_minY )];

  return write_to_opengl_texture_generic(tex_id, NUM_COMPONENTS, FORMAT, TYPE,
    BASE_BUFFER, SUBSET_BUFFER, _minX, _minY, _maxX, _maxY);
}
Beispiel #5
0
bool edt_server::write_opengl_texture_to_quad()
{
  double xfrac = static_cast<double>(get_num_columns()) / _opengl_texture_size_x;
  double yfrac = static_cast<double>(get_num_rows()) / _opengl_texture_size_y;

  // Flip over while writing.
  // Set the texture and vertex coordinates and write the quad to OpenGL.
  glBegin(GL_QUADS);
    glTexCoord2d(0.0, yfrac);
    glVertex2d(-1.0, -1.0);

    glTexCoord2d(xfrac, yfrac);
    glVertex2d(1.0, -1.0);

    glTexCoord2d(xfrac, 0.0);
    glVertex2d(1.0, 1.0);

    glTexCoord2d(0.0, 0.0);
    glVertex2d(-1.0, 1.0);
  glEnd();

  return true;
}
Beispiel #6
0
int main(int argc, char *argv[]){
    FILE *fp;
    char *line = NULL;
    size_t len = 0;
    ssize_t read;
    static int simple_flag;
    int c;


    while ((c = getopt(argc, argv, "s") ) != -1) {
        switch (c) {
            case 's': simple_flag = 1; break;
            default:
                simple_flag = 0;
        }
    }

    char *hor_thicc;
    char *hor_thinn;
    char *vert;

    if (simple_flag == 0) {
        hor_thicc = "=";
        hor_thinn = "-";
        vert = "|";
    } else {
        hor_thicc = "=";
        hor_thinn = " ";
        vert = "|";
    }

    // printf("simple: %d %d\n", simple_flag, optind);
    

    fp = fopen(argv[optind], "r");
    if (fp == NULL)
        exit(EXIT_FAILURE);

    // PASS I: Get the number of columns, the number of headers, and the number of rows
    int num_lines = -1;
    int num_headers = 0;
    int num_columns = 0;
    while ((read = getline(&line, &len, fp)) != -1) {
        if (num_lines == -1){
            num_headers = get_num_columns(line);
        }
        int line_columns = get_num_columns(line);
        if( line_columns > num_columns )
            num_columns = line_columns;

        //printf("%s", line);
        num_lines++;
    }
    //printf("num headers: %d\n", num_headers);
    //printf("num lines: %d\n", num_lines);
    //printf("num columns: %d\n", num_columns);


    // PASS II: Get the length of the longest string in each column
    fp = fopen(argv[optind], "r");
    if (fp == NULL)
        exit(EXIT_FAILURE);
   
    size_t most_longest[num_columns];
    for (int i = 0; i < num_columns; i++) {
         most_longest[i] = 0;
    }
    while ((read = getline(&line, &len, fp)) != -1) {
        size_t *longest;
        longest = get_longest(line, num_columns);

       // for (int i = 0; i < num_columns; i++) {
       //     printf("%zu,", longest[i]);
       // }
       // puts("");

        for(int i = 0; i < num_columns; i++) {
            if(longest[i] > most_longest[i])
                most_longest[i] = longest[i];
        }
        free(longest);
    }
    //for (int i = 0; i < num_columns; i++) {
    //    printf("%zu,", most_longest[i]);
    //}

    // SECTION I: Get some more information
    size_t total_width = 0;
    for(int i = 0; i < num_columns; i++){
        total_width += most_longest[i];
    }

    total_width += (num_columns + 1);

    //puts("");


    // PASS III: Print her!!
    fp = fopen(argv[optind], "r");
    if (fp == NULL)
        exit(EXIT_FAILURE);

    //char* headers[num_headers];
    //char* lines[num_lines][num_columns];
    int index = 0;
    const char s = ',';
    int temp_var = 0;
    print_many(hor_thicc, total_width, vert);
    while ((read = getline(&line, &len, fp)) != -1) {

        // If the last character of the line is a newline, replace it with a NULL byte
        if(line[strlen(line)-1] == 10){
            line[strlen(line)-1] = 0;
        }
        
        if (temp_var != 2 || simple_flag == 0){
            printf("%s", vert);
            temp_var++ ;
        }

        // Print defined columns
        int colnum = 0;                                  // The current column, 0 indexed
        unsigned int pos = 0;                            // The absolute position in the line
        for(colnum = 0; colnum < num_columns; colnum++){ // For every column
            unsigned int col_len = 0;                    // Length of data in column
            while (line[pos] != s && line[pos] != 0 && pos < strlen(line)){    // While the current index isn't , or 0
                printf("%c", line[pos]);                 // Print the current character
                pos++;
                col_len++;
            }
            pos++;  // For the comma
            //printf("%d", col_len);
            size_t pad_this_many =  most_longest[colnum] - col_len; // Find out how much to pad
            for(unsigned int j = 0; j<pad_this_many; j++){   // Pad it
                printf(" ");
            }
            printf("%s", vert);  // Close column
        }

        // Print undefined columns
        /*
        while(colnum != num_columns){
           for(unsigned int l = 0; l<most_longest[colnum]; l++){
               printf(" ");
           }
           printf("|");
           colnum++;
        }
        */
        puts("");


        // Print dividing line
        if (index < num_lines) {
            printf("%s", vert);
            for(int i = 0; i<num_columns; i++) {
               for(unsigned int j = 0; j<most_longest[i];j++){
                   if(index==0){
                       printf("%s", hor_thicc);
                   }
                   if(index!=0&&simple_flag==0){
                       printf("%s", hor_thinn);
                   }
               }
               if (index == 0 || simple_flag ==0)
                   printf("%s", vert);

            }
            if (index == 0  || simple_flag==0)
              puts("");
        }

      index++;
    }
    print_many(hor_thicc, total_width, vert);
   

    free(line);
    exit(EXIT_SUCCESS);
}
Beispiel #7
0
void compute_distances(pattern_elm ***pattern_array, long trees_in_1,
                long trees_in_2)
{
  /* Compute symmetric distances between arrays of trees */

  long  tree_index, end_tree, index1, index2, index3;
  group_type **treeA, **treeB;
  long patternsz1, patternsz2;
  double *length1 = NULL, *length2 = NULL; 
  int num_columns = get_num_columns();

  index1 = 0;

  /* Put together space for treeA and treeB */
  treeA = (group_type **) Malloc (setsz * sizeof (group_type *));
  treeB = (group_type **) Malloc (setsz * sizeof (group_type *));

  print_header(trees_in_1, trees_in_2);

  switch (tree_pairing) {

      case ADJACENT_PAIRS: 
        /* For every tree, compute the distance between it and the tree
            at the next location; do this in both directions */
      end_tree = trees_in_1 - 1;
      for (tree_index = 0 ; tree_index < end_tree ; tree_index += 2) {

        assign_tree (treeA, pattern_array, tree_index, &patternsz1);
        assign_tree (treeB, pattern_array, tree_index + 1, &patternsz2);
        assign_lengths(&length1, pattern_array, tree_index);
        assign_lengths(&length2, pattern_array, tree_index + 1);
        tree_diff (treeA, treeB, length1, length2, patternsz1, patternsz2,
            tree_index+1, tree_index+2, trees_in_1, trees_in_2);
        if (tree_index + 2 == end_tree)
          printf("\nWARNING: extra tree at the end of input tree file.\n");
      }
      break;
  
    case ALL_IN_FIRST: 
          /* For every tree, compute the distance between it and every
              other tree in that file. */
      end_tree   = trees_in_1;
      if ( output_scheme != FULL_MATRIX ) {
        /* verbose or sparse output */
        for (index1 = 0 ; index1 < end_tree ; index1++) {
          assign_tree (treeA, pattern_array, index1, &patternsz1);
          assign_lengths(&length1, pattern_array, index1);
  
          for (index2 = 0 ; index2 < end_tree ; index2++) {
            assign_tree (treeB, pattern_array, index2, &patternsz2);
            assign_lengths(&length2, pattern_array, index2);
            tree_diff (treeA, treeB, length1, length2, patternsz1, patternsz2,
                index1 + 1, index2 + 1, trees_in_1, trees_in_2);
          }
        }
      }
      else {
        /* full matrix output */
        for ( index3 = 0 ; index3 < trees_in_1 ; index3 += num_columns) {
          for ( index1 = 0 ; index1 < trees_in_1 ; index1++) {
          assign_tree (treeA, pattern_array, index1, &patternsz1);
          assign_lengths(&length1, pattern_array, index1);
            for ( index2 = index3 ; 
                index2 < index3 + num_columns && index2 < trees_in_1 ;
                index2++) {
              assign_tree (treeB, pattern_array, index2, &patternsz2);
              assign_lengths(&length2, pattern_array, index2);
              tree_diff (treeA, treeB, length1, length2, patternsz1, patternsz2,
                  index1 + 1, index2 + 1, trees_in_1, trees_in_2);
            }
          }
        }
      }
      break;

    case CORR_IN_1_AND_2:
      if (trees_in_1 != trees_in_2) {
        /* Set end tree to the smaller of the two totals. */
        end_tree = trees_in_1 > trees_in_2 ? trees_in_2 : trees_in_1;
	
        /* Print something out to the outfile and to the terminal. */
        fprintf(outfile,
            "\n\n"
            "*** Warning: differing number of trees in first and second\n"
            "*** tree files.  Only computing %ld pairs.\n"
            "\n",
            end_tree
        );
        printf(
            "\n"
            " *** Warning: differing number of trees in first and second\n"
            " *** tree files.  Only computing %ld pairs.\n"
            "\n",
            end_tree
        );
  
      }
      else
        end_tree = trees_in_1;
  
      for (tree_index = 0 ; tree_index < end_tree ; tree_index++) {
      /* For every tree, compute the distance between it and the
            tree at the parallel location in the other file; do this in
            both directions */
  
        assign_tree (treeA, pattern_array, tree_index, &patternsz1);
        assign_lengths(&length1, pattern_array, tree_index);
        /* (tree_index + trees_in_1) will be the corresponding tree in
            the second file. */
        assign_tree (treeB, pattern_array, tree_index + trees_in_1, &patternsz2);
        assign_lengths(&length2, pattern_array, tree_index + trees_in_1);
        tree_diff (treeA, treeB, length1, length2, patternsz1, patternsz2,
          tree_index + 1, 0, trees_in_1, trees_in_2);
      }
      break; 

    case ALL_IN_1_AND_2:
      end_tree = trees_in_1 + trees_in_2;
      
      if ( output_scheme != FULL_MATRIX ) {
        for (tree_index = 0 ; tree_index < trees_in_1 ; tree_index++) {
          /* For every tree in the first file, compute the distance
              between it and every tree in the second file. */
          assign_tree (treeA, pattern_array, tree_index, &patternsz1);
          assign_lengths(&length1, pattern_array, tree_index);
          for (index2 = trees_in_1 ; index2 < end_tree ; index2++) {
            assign_tree (treeB, pattern_array, index2, &patternsz2);
            assign_lengths(&length2, pattern_array, index2);
            tree_diff(treeA, treeB, length1, length2, patternsz1, patternsz2,
                tree_index + 1 , index2 + 1, trees_in_1, trees_in_2);
          }
        }
        for ( ; tree_index < end_tree ; tree_index++) {
          /* For every tree in the second file, compute the distance
              between it and every tree in the first file. */
  
          assign_tree (treeA, pattern_array, tree_index, &patternsz1);
          assign_lengths(&length1, pattern_array, tree_index);
  
          for (index2 = 0 ; index2 < trees_in_1 ; index2++) {
            assign_tree (treeB, pattern_array, index2, &patternsz2);
            assign_lengths(&length2, pattern_array, index2);
            tree_diff (treeA, treeB, length1, length2 , patternsz1, patternsz2,
                tree_index + 1, index2 + 1, trees_in_1, trees_in_2);
          }
        }
      } else {
        for ( index3 = trees_in_1 ; index3 < end_tree ; index3 += num_columns) {
          for ( index1 = 0 ; index1 < trees_in_1 ; index1++) {
          assign_tree (treeA, pattern_array, index1, &patternsz1);
          assign_lengths(&length1, pattern_array, index1);
            for ( index2 = index3 ; 
                index2 < index3 + num_columns && index2 < end_tree ;
                index2++) {
              assign_tree (treeB, pattern_array, index2, &patternsz2);
              assign_lengths(&length2, pattern_array, index2);
              tree_diff (treeA, treeB, length1, length2, patternsz1, patternsz2,
                  index1 + 1, index2 - trees_in_1 + 1, trees_in_1, trees_in_2);
            }
          }
        }
      }
      break; 
  }
  /* Free up treeA and treeB */
  free (treeA);
  free (treeB);        
}  /* compute_distances */