packing_main.c~ 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include "packing.h"
  5. int main(int argc, char **argv){
  6. //check arguments
  7. if (argc != 3){
  8. printf("usage: ./proj3 <input_file> <output_file>\n");
  9. return EXIT_FAILURE;
  10. }
  11. // read data
  12. int numnodes = 0;
  13. int numboxes = 0;
  14. Node *array = load_file(argv[1], &numnodes, &numboxes);
  15. if(array == NULL){ // check for error
  16. printf("File read error.");
  17. return EXIT_FAILURE;
  18. }
  19. // create tree
  20. Node *root = set_pointers(array, numnodes);
  21. // pack
  22. clock_t packingClock = clock(); // track packing time
  23. double packingTime = 0;
  24. set_values(root);
  25. packingClock = clock() - packingClock; // time after packing
  26. packingTime = packingTime + ((double) packingClock) / CLOCKS_PER_SEC;
  27. // print to stdout
  28. printf("Preorder: ");
  29. print_node_numbers_preorder(root);
  30. printf("\n\n");
  31. printf("Inorder: ");
  32. print_node_numbers_inorder(root);
  33. printf("\n\n");
  34. printf("Postorder: ");
  35. print_node_numbers_postorder(root);
  36. printf("\n\n");
  37. printf("Width: %le\n", root->width);
  38. printf("Height: %le\n", root->height);
  39. printf("\n");
  40. printf("X-coordinate: %le\n", array[numboxes - 1].xcord);
  41. printf("Y-coordinate: %le\n", array[numboxes - 1].ycord);
  42. printf("\n");
  43. printf("Elapsed time: %le\n", packingTime);
  44. printf("\n");
  45. // save boxes
  46. save_boxes(argv[2], array, numboxes);
  47. // clean up
  48. free(array); // free memory
  49. return EXIT_SUCCESS; // exit
  50. }