int main(int argc,char ** argv) { char dir[1024]; getcwd(dir,sizeof(dir)); printf("Current Directory: %s\r\n",dir); g_MjpgServer.Init(9870); // load two jpg files Load_File("Motorcycle.jpg",&g_Img1Data, &g_Img1Size); Load_File("Bart.jpg",&g_Img2Data, &g_Img2Size); for (;;) { g_MjpgServer.Send_New_Image(g_Img1Data,g_Img1Size); g_MjpgServer.Process(); usleep(1000000); g_MjpgServer.Send_New_Image(g_Img2Data,g_Img2Size); g_MjpgServer.Process(); usleep(1000000); } return 0; }
int main (int argc, char * * argv) { if (argc != 3) { printf("\nInvalid number of arguments\n"); return EXIT_FAILURE; } char * in_file = argv[1]; char * out_file = argv[2]; int num_b; // number of boxes int num_n; // nubmer of nodes // arr is an array implementation of a binary tree // the root node is the node of index num_n Node * arr = Load_File(in_file, &num_b, &num_n); double x_tot = 0; double y_tot = 0; clock_t pack_t = clock(); Coord * crd = Pack(arr, num_n, num_b, &x_tot, &y_tot); pack_t = clock() - pack_t; printf("\n\nElapsed Time: %le\n\n", ((double) pack_t) / CLOCKS_PER_SEC); Save_File(out_file, arr, crd, num_b); free(arr); free(crd); return EXIT_SUCCESS; }
//--------------------------------------------------------- bool CImport_Clip_Resample::On_Execute(void) { //----------------------------------------------------- CSG_Strings Files; if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) || Files.Get_Count() == 0 ) { return( false ); } //----------------------------------------------------- m_pGrids = Parameters("GRIDS")->asGridList(); m_pGrids->Del_Items(); //----------------------------------------------------- for(int i=0; i<Files.Get_Count() && Process_Get_Okay(); i++) { Load_File(Files[i]); } //----------------------------------------------------- if( m_pGrids->Get_Count() == 0 ) { Error_Set(_TL("no grids have been imported")); } return( true ); }
//--------------------------------------------------------------------------- bool TSharpnessForm1::Load_SP(String Fpath) { char* buffer = Load_File(Fpath); char* pch; pch = strtok (buffer,"\n\t"); int c= 0; AnsiString str[5]; str[0] = "TEXT_DET"; str[1] = "HORZ_THR"; str[2] = "VERT_THR"; str[3] = "EDGE_THR"; str[4] = "GLT_STR"; //hardwre gain while (c < 38 && pch!=NULL){ if(pch == NULL){ ShowMessage("Data Missing."); delete [] buffer; return 0; //資料中的data缺少 } if(c==0){ //TD for(int i = 0; i < OSP->SPChkBox_Nbr; i++){ if(SameText(ChkB[i]->Addr.Name(),str[0])){ ChkB[i]->Chkb->Checked = (StrToInt((AnsiString)pch)>0?1:0); ChkB[i]->Chkb->OnClick; break; } } }else if(c>=1 && c<=3){ //HORZ_THR, VERT_THR, EDGE_THR for(int i = 0; i < OSP->SPScrollBar_Nbr; i++){ if(SameText(ScrlB[i]->Addr.Name(),str[c])){ ScrlB[i]->ScrlB->Position = (StrToInt((AnsiString)pch)); ScrlB[i]->ScrlB->OnChange; break; } } }else if(c==4){ //hardware gain for(int i = 0; i < OSP->SPScrollBar_Nbr; i++){ if(SameText(ScrlB[i]->Addr.Name(),str[c])){ float tmp = (StrToFloat((AnsiString)pch)); ScrlB[i]->ScrlB->Position = int(tmp*4); ScrlB[i]->ScrlB->OnChange; break; } } }else if(c==5){ //swg sb_softgain->Position = StrToFloat((AnsiString)pch)*10; }else{ //tbl SP_lut[c-6] = StrToInt((AnsiString)pch); } pch = strtok (NULL,"\n\t"); c++; if(c>=38) break; } delete [] buffer; return 1; }
int main (int argc, char ** argv) { if (argc != 5) { printf("\nInvalid number of arguments"); return EXIT_FAILURE; } //Assign inputs to variables char * mode = argv[1]; char * in_file = argv[2]; char * seq_file = argv[3]; char * out_file = argv[4]; int Size = 0; long * arr; double N_Comp = 0; double N_Move = 0; clock_t sort_t = 0; //keeps track of sort time clock_t io_sum = 0; //keeps track of total I/O time clock_t io = clock(); arr = Load_File(in_file, &Size); //Load the fille and store the contents in arr io_sum = clock() - io; if (*mode == 'i') { sort_t = clock(); Shell_Insertion_Sort(arr, Size, &N_Comp, &N_Move); sort_t = clock() - sort_t; } else if (*mode == 's') { sort_t = clock(); Shell_Selection_Sort(arr, Size, &N_Comp, &N_Move); sort_t = clock() - sort_t; } else { printf("\nInvalid argument for sort type"); return EXIT_FAILURE; } io = clock(); Print_Seq(seq_file, Size); Save_File(out_file, arr, Size); io_sum += clock() - io; free(arr); printf("Number of comparisons: %le\n", N_Comp); printf("Number of moves: %le\n", N_Move); printf("I/O Time: %le\n", ((double)io_sum) / CLOCKS_PER_SEC); printf("Sorting Time: %le\n", ((double)sort_t) / CLOCKS_PER_SEC); return EXIT_SUCCESS; }
int main (int argc, char * * argv) { if (argc != 3) { printf("\nInvalid number of arguments\n"); return EXIT_FAILURE; } char * in_file = argv[1]; char * out_file = argv[2]; // arr is an array implementation of a binary tree // the root node is the node of index num_n Node * head = Load_File(in_file); clock_t pack_t = clock(); Find_Area(head); double x_new = 0; double y_prev = head -> height; Find_Coords(head, &x_new, &y_prev); pack_t = clock() - pack_t; double x = -1; double y = -1; printf("\nPreorder: \n"); Preorder(head); printf("\n\nInorder: \n"); Inorder(head); printf("\n\nPostorder: \n"); Postorder(head, &x, &y); printf("\n\nWidth: %le\nHeight: %le\n", head -> width, head -> height); printf("\nX-coordinate: %le\nY-coordinate:%le\n", x, y); printf("\nElapsed Time: %le\n\n", ((double) pack_t) / CLOCKS_PER_SEC); FILE * f = fopen(out_file, "w"); Save_File(f, head); fclose(f); Tree_Destroy(head); return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { if(argc != 3) { printf("Incorrect arguments\n"); exit(EXIT_FAILURE); } clock_t io_start; clock_t io_end; clock_t io_time; clock_t sort_start; clock_t sort_end; clock_t sort_time; Node* list = NULL; io_start = clock(); list = Load_File(argv[1]); io_end = clock(); io_time = io_end - io_start; if(list == NULL) { exit(EXIT_FAILURE); } sort_start = clock(); Shell_Sort(list); sort_end = clock(); sort_time = sort_end - sort_start; io_start = clock(); Save_File(argv[2], list); io_end = clock(); io_time += (io_end - io_start); double iotime = (double) io_time / CLOCKS_PER_SEC; double sorttime = (double) sort_time / CLOCKS_PER_SEC; // Report printf("I/O time: %le\n", iotime); printf("Sorting time: %le\n", sorttime); return 0; }
int main(int argc, char* argv[]) { if(argc != 6) { printf("Incorrect arguments\n"); exit(EXIT_FAILURE); } char func = argv[2][0]; int size; double ncomp = 0; double nmove = 0; clock_t io_start; clock_t io_end; clock_t io_time; clock_t sort_start; clock_t sort_end; clock_t sort_time; io_start = clock(); long *Array = Load_File(argv[3], &size); io_end = clock(); io_time = io_end - io_start; if(Array == NULL) { exit(EXIT_FAILURE); } if(argv[1][0] == '1'){ io_start = clock(); Print_Seq_1(argv[4], size); io_end = clock(); io_time += (io_end - io_start); if(func == 'i') { sort_start = clock(); Shell_Insertion_Sort_Seq1(Array, size, &ncomp, &nmove); sort_end = clock(); sort_time = sort_end - sort_start; } else if(func == 'b') { sort_start = clock(); Shell_Bubble_Sort_Seq1(Array, size, &ncomp, &nmove); sort_end = clock(); sort_time = sort_end - sort_start; } else { printf("Incorrect arguments\n"); exit(EXIT_FAILURE); } } else if(argv[1][0] == '2') { Print_Seq_2(argv[4], size); if(func == 'i') { sort_start = clock(); Shell_Insertion_Sort_Seq2(Array, size, &ncomp, &nmove); sort_end = clock(); sort_time = sort_end - sort_start; } else if(func == 'b') { sort_start = clock(); Shell_Bubble_Sort_Seq2(Array, size, &ncomp, &nmove); sort_end = clock(); sort_time = sort_end - sort_start; } else { printf("Incorrect arguments\n"); exit(EXIT_FAILURE); } } else { printf("Incorrect arguments\n"); exit(EXIT_FAILURE); } io_start = clock(); if(Save_File(argv[5], Array, size) != 0) { // will free the array exit(EXIT_FAILURE); } io_end = clock(); io_time += (io_end - io_start); double iotime = io_time / CLOCKS_PER_SEC; double sorttime = sort_time / CLOCKS_PER_SEC; // Report printf("Number of comparisons: %le\n", ncomp); printf("Number of moves: %le\n", nmove); printf("I/O time: %le\n", iotime); printf("Sorting time: %le\n", sorttime); return 0; }
bool THSVFormOrg::Load_HSV(String Fpath) { if (Fpath == NULL) return 0; char *buffer = Load_File(Fpath); if (buffer == NULL) return 0; for (int i = 0; i < 96; i++) { Hue_table[i] = -1; Sat_table[i] = -1; Val_table[i] = 0; } //比對檔案中的Hue_LUT, Sat_LUT, Bri_LUT字串 /*char* str[3]; char* pch; str[0]="Hue_LUT"; str[1]="Sat_LUT"; str[2]="Bri_LUT"; pch = strtok (buffer,"\n\t"); for(int i = 0; i < 3; i++){ while (memcmp(pch,str[i],7)!=0){ if(pch == NULL){ ShowMessage("Can't open Hue table file."); return 0; } pch = strtok (NULL,"\n\t"); } } */ //取出檔案中的數值 int c = 0; char *pch; pch = strtok(buffer, "\n\t"); int Length = lut_addr[0].LutNum(); while (c < Length && pch != NULL) { if (pch == NULL) { ShowMessage("Can't open Hue table file."); return 0; //資料中的data缺少 } if (c % 3 == 0) Hue_table[c / 3] = StrToInt((AnsiString) pch); else if (c % 3 == 1) Sat_table[c / 3] = StrToInt((AnsiString) pch); else Val_table[c / 3] = StrToInt((AnsiString) pch); pch = strtok(NULL, "\n\t"); c++; } delete[]buffer; for (int i = 0; i < 24; i++) { sg_HSV->Cells[1][i + 1] = FloatToStr((double) Hue_table[i] / 768 * 360); sg_HSV->Cells[2][i + 1] = FloatToStr((double) (Sat_table[i]) / 32); sg_HSV->Cells[3][i + 1] = IntToStr(Val_table[i]); } Set_6HSV_grid(); //Hue_LUTWrite(); return 1; }
int main(int argc, char * argv[]) { // Check to make sure the correct number of input arguments are provided if(argc != 5) { printf("Usage: ./proj1 <sorting_method> <input_file> <sequence_file> <output_file>\n"); return EXIT_FAILURE; } // Set these variables to the input arguments (Make things easier) char method = * argv[1]; char * input_file = argv[2]; char * sequence_file = argv[3]; char * output_file = argv[4]; // Used to store values used in this program int Size; long * values; clock_t t_sort, t_load, t_save, t_seq; // Load the file, keeping track of the time it takes to load the file t_load = clock(); values = Load_File(input_file, &Size); t_load = clock() - t_load; // Check to make sure the files was loaded correctly if(values == NULL) { printf("Error loading the input file\n"); return EXIT_FAILURE; } // Print the sequence to a file, keeping track of the time it takes to write to the file t_seq = clock(); int i = Print_Seq(sequence_file, Size); t_seq = clock() - t_seq; // Check to make sure the sequence was correctly output to the file if(i == 0) { printf("Failed to print sequence\n"); free(values); return EXIT_FAILURE; } // Used to keep track of the number of moves and comparisons in the sorting algorithms double N_Comp = 0.0, N_Move = 0.0; // Check for the sorting method chosen by the user // Keep track of the time it takes to sort the values as well t_sort = clock(); if(method == 'i') { Shell_Insertion_Sort(values, Size, &N_Comp, &N_Move); } else if(method == 's') { Shell_Selection_Sort(values, Size, &N_Comp, &N_Move); } else { printf("Sorting method must be either i (Insertion) or s (Selection) sort\n"); free(values); return EXIT_FAILURE; } t_sort = clock() - t_sort; // Save the sorted array to the output file, keeping track of th time it takes as well t_save = clock(); int returned = Save_File(output_file, values, Size); t_save = clock() - t_save; // Check to make sure that the file was correctly output to if (!returned) { printf("Failed to output values to file\n"); free(values); return EXIT_FAILURE; } else if(returned != Size) { printf("Number of values returned not equal to number of values specified\n"); free(values); return EXIT_FAILURE; } // Free the malloced values free(values); // Display all the required information to the screen Screen_Dump(N_Comp, N_Move, (t_save + t_load + t_seq) / CLOCKS_PER_SEC, t_sort); // SUCCESS!!! return EXIT_SUCCESS; }
int main ( int Argc, char **Argv) { // main program - menu for functions with using database double cstart, cend; int Response = 0; int Saved = 0; int Size = 0; double N_Comp = 0; double N_Move = 0; long *Array = NULL; char Filename[MAXFILELEN] = ""; while (1) { printf("\n"); printf("TEST MENU\n"); printf("1. Load array from file\n"); printf("2. Save array to file\n"); printf("3. Shell Sort (Insertion)\n"); printf("4. Improved Bubble Sort\n"); printf("5. Exit\n"); printf("Enter your choice: "); scanf("%d",&Response); getchar(); if (Response == 5) // quit program { if (Array != NULL) { printf("Removing and deallocating array\n"); free((void *)Array); Array = NULL; printf("done!\n"); } return (OK); } if (Response == 1) // load file { if (Array != NULL) { printf("\nRemoving and deallocating array\n"); free((void *)Array); Array = NULL; printf("done!\n"); } printf("\nEnter input file (including path): "); scanf("%s", Filename); Array = Load_File (Filename, &Size); if (Size <= 0) { printf("\nError in inputs, file not loaded..\n"); if (Array != NULL) { printf("Removing and deallocating array\n"); free((void *)Array); Array = NULL; printf("done!\n"); } } else { printf("\nLoaded %d long integers\n", Size); } } if (Response == 2) // save file { if (Array == NULL) { printf("\nMust load in data from file (option 1) before saving one!\n"); } else { printf("\nEnter output file (including path): "); scanf("%s", Filename); Saved = Save_File (Filename, Array, Size); if (Saved != Size) { printf("Error in saving! Only %d out of %d long integers saved\n", Saved, Size); } else { printf("Saved all %d long integers\n", Saved); } } } if ( (Response > 2) && (Response < 5)) { if (Array == NULL) { printf("\nMust load in data from file (option 1) before sorting one!\n"); } else { // initialize time function cstart = (double) clock(); // initialize numbers of comparisons and moves N_Comp = 0; N_Move = 0; switch(Response) { case 3: printf("Sorting by Shell Sort (Insertion)\n"); Shell_Insertion_Sort (Array, Size, &N_Comp, &N_Move); break; case 4: printf("Sorting by Improved Bubble Sort\n"); Improved_Bubble_Sort (Array, Size, &N_Comp, &N_Move); break; } // print results: Time, N_Comp, N_Move cend = (double) clock(); printf("\n"); printf(" Elapsed Time (sec): %f\n", (cend - cstart)/CLOCKS_PER_SEC); printf(" # Comparisons: %f\n", N_Comp); printf(" # Moves: %f\n", N_Move); } } } return (OK); } // main()
int main(int argc, char **argv){ if(argc != 6) //check if there are enough input arguments { return EXIT_FAILURE; } int Size;//Size of the array double N_Comp = 0;//number of comparisions double N_Move = 0;//number of moves clock_t S_time = clock();//the sorting time clock_t I_time = clock();//the I/O time clock_t temp; long *Array = Load_File(argv[3], &Size); I_time = clock() - I_time; //calling different function depends on the input if(atoi(argv[1]) == 1 && argv[2][0] == 'i') { S_time = clock(); Shell_Insertion_Sort_Seq1(Array, Size, &N_Comp, &N_Move); S_time = clock() - S_time; temp = I_time; I_time = clock(); if(Print_Seq_1(argv[4], Size) == -1) { return -1; } I_time = clock() - I_time + temp; } else if(atoi(argv[1]) == 1 && argv[2][0] == 'b') { S_time = clock(); Shell_Bubble_Sort_Seq1(Array, Size, &N_Comp, &N_Move); S_time = clock() - S_time; temp = I_time; I_time = clock(); if(Print_Seq_1(argv[4], Size) == -1) { return -1; } I_time = clock() - I_time + temp; } else if(atoi(argv[1]) == 2 && argv[2][0] == 'i') { S_time = clock(); Shell_Insertion_Sort_Seq2(Array, Size, &N_Comp, &N_Move); S_time = clock() - S_time; temp = I_time; I_time = clock(); if(Print_Seq_2(argv[4], Size) == -1) { return -1; } I_time = clock() - I_time + temp; } else if(atoi(argv[1]) == 2 && argv[2][0] == 'b') { S_time = clock(); Shell_Bubble_Sort_Seq2(Array, Size, &N_Comp, &N_Move); S_time = clock() - S_time; temp = I_time; I_time = clock(); if(Print_Seq_2(argv[4], Size) == -1) { return -1; } I_time = clock() - I_time + temp; } temp = I_time; I_time = clock(); if(Save_File(argv[5], Array, Size) == -1) { return -1; } I_time = clock() - I_time + temp; //print all the necessary result printf("\nNumber of comparisons: %le\n", N_Comp); printf("Number of moves: %le\n", N_Move); printf("I/O time: %le\n", ((double)I_time) / CLOCKS_PER_SEC); printf("Sorting time: %le\n\n", ((double)S_time) / CLOCKS_PER_SEC); return 1;//if reaches here, safe return }