//main function for running program int main() { bool is_permission = false; int attempt_number = 1; char password[] = PASSWORD; char password_attempt[100]; print_intro(); //password attempt loop do { print_security_level(attempt_number); scanf("%99s", password_attempt); is_permission = check_password(password, password_attempt); //print cases for password attempt if(is_permission == false && attempt_number == MAX_ATTEMPT) { print_password_denied(attempt_number, MAX_ATTEMPT); system("qlmanage -p ./data/ned.gif"); animate(); } else if(is_permission == true) print_access(); else { print_password_denied(attempt_number, MAX_ATTEMPT); attempt_number++; } }while(is_permission == false); return 0; }
int main(int argc, char *argv[]) { PetscErrorCode ierr; int i; grid *grd; MPI_Init(&argc,&argv); option options = parse_options(argc, argv); if (options.problem == JUMP) { grd = grid_create(-1, 1, options.nx, -1, 1, options.ny, -1, 1, options.nz); } else { grd = grid_create(0, 1, options.nx, 0, 1, options.ny, 0, 1, options.nz); } if (options.periodic > -1) grd->periodic[options.periodic] = 1; int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) print_intro(&options); map *mp = map_create(options.map); grid_apply_map(grd, mp); problem *pb = problem_create(options.problem, grd->nd, mp->id); solver *sol = solver_create(grd, pb); ierr = solver_init(sol, grd);CHKERRQ(ierr); ierr = solver_run(sol);CHKERRQ(ierr); double *u = (double*) malloc(grd->num_pts*sizeof(double)); double *diff = (double*) malloc(grd->num_pts*sizeof(double)); grid_eval(grd, pb->sol, u); for (i = 0; i < grd->num_pts; i++) diff[i] = sol->state->phi[i] - u[i]; print_norm(diff, grd->num_pts); free(u); free(diff); grid_destroy(grd); free(grd); map_destroy(mp); free(mp); problem_destroy(pb); free(pb); ierr = solver_destroy(sol);CHKERRQ(ierr); free(sol); if (options.eig && rank == 0) { system("./python/plot.py"); } MPI_Finalize(); return 0; }
int so_main() { print_intro(); print_so_version(); print_svn_revision(); print_build_time(); print_gcc_version(); print_build_env(); printf("\n"); exit(0); }
static void *the_shell_thread_func(void *arg) { int ret; char clean_cmd_line[512]; cur_histotry_cmds_num = 0; shell_buf_cur_len=0; print_intro(); if (login_auth()) goto EXIT; redirect_io(fd_pty_slave); print_hint(); while (!shell_thread_should_exit) { ret=read_input(0); if (ret<0) goto EXIT; if (ret==1) { if (shell_buf_cur_len==0) goto CMD_OVER; update_histotry_cmds(shell_buf); shell_buf_cur_len=0; str_trim_all(clean_cmd_line, shell_buf); //printf_to_fd(ori_std_output, "== ret=%s\n", shell_buf); if (strlen(clean_cmd_line)==0) goto CMD_OVER; if (strcmp(clean_cmd_line,"quit")==0) goto EXIT; proccess_cmd(clean_cmd_line); printf_to_fd(1, "\n"); CMD_OVER: print_hint(); } } EXIT: shell_quit_occurred = 1; return NULL; }
void intro_interface() { if (print1_check==false) { print_intro(); } while (key!='1') { key=Keypad_getkey(); if (print2_check==false && (key=='1'||force_key=='1')) { print_modes(); } } key=NO_KEY; force_key=NO_KEY; }
int wikilib_run(void) { int sleep; long time_now; struct wl_input_event ev; int more_events = 0; unsigned long last_event_time = 0; int rc; /* * test searching code... */ article_buf_pointer = NULL; search_init(); history_list_init(); malloc_status_simple(); print_intro(); #ifndef INCLUDED_FROM_KERNEL if (!load_init_article(idx_init_article)) { display_mode = DISPLAY_MODE_ARTICLE; last_display_mode = DISPLAY_MODE_INDEX; } #endif render_string(SUBTITLE_FONT_IDX, -1, 55, MESSAGE_TYPE_A_WORD, strlen(MESSAGE_TYPE_A_WORD), 0); for (;;) { if (more_events) sleep = 0; else sleep = 1; if (!more_events && display_mode == DISPLAY_MODE_ARTICLE && render_article_with_pcf()) sleep = 0; else if (!more_events && display_mode == DISPLAY_MODE_INDEX && render_search_result_with_pcf()) sleep = 0; else if (!more_events && display_mode == DISPLAY_MODE_HISTORY && render_history_with_pcf()) sleep = 0; if (finger_move_speed != 0) { scroll_article(); sleep = 0; } #ifdef INCLUDED_FROM_KERNEL time_now = get_time_ticks(); if(display_mode == DISPLAY_MODE_INDEX) { if (press_delete_button && get_search_string_len()>0) { sleep = 0; if(time_diff(time_now, start_search_time) > seconds_to_ticks(3.5)) { if (!clear_search_string()) { search_string_changed_remove = true; search_reload_ex(SEARCH_RELOAD_NORMAL); } press_delete_button = false; } else if (time_diff(time_now, start_search_time) > seconds_to_ticks(0.5) && time_diff(time_now, last_delete_time) > seconds_to_ticks(0.25)) { if (!search_remove_char(0)) { search_string_changed_remove = true; search_reload_ex(SEARCH_RELOAD_NO_POPULATE); } last_delete_time = time_now; } } } else if (display_mode == DISPLAY_MODE_RESTRICTED) { if (press_delete_button && get_password_string_len()>0) { sleep = 0; time_now = get_time_ticks(); if(time_diff(time_now, start_search_time) > seconds_to_ticks(3.5)) { clear_password_string(); press_delete_button = false; } else if (time_diff(time_now, start_search_time) > seconds_to_ticks(0.5) && time_diff(time_now, last_delete_time) > seconds_to_ticks(0.25)) { password_remove_char(); last_delete_time = time_now; } } } #endif if (!more_events && display_mode == DISPLAY_MODE_INDEX && fetch_search_result(0, 0, 0)) { sleep = 0; } if (keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_CHECK)) // check if need to reset invert sleep = 0; if (check_invert_link()) // check if need to invert link sleep = 0; if (sleep) { if (time_diff(get_time_ticks(), last_event_time) > seconds_to_ticks(15)) rc = history_list_save(HISTORY_SAVE_POWER_OFF); else rc = history_list_save(HISTORY_SAVE_NORMAL); if (rc > 0) { #ifdef INCLUDED_FROM_KERNEL delay_us(200000); // for some reason, save may not work if no delay #endif } else if (rc < 0) sleep = 0; // waiting for last_event_time timeout to save the history } wl_input_wait(&ev, sleep); more_events = 1; switch (ev.type) { case WL_INPUT_EV_TYPE_CURSOR: handle_cursor(&ev); last_event_time = get_time_ticks(); break; case WL_INPUT_EV_TYPE_KEYBOARD: if (ev.key_event.value != 0) { b_show_scroll_bar = 0; handle_key_release(ev.key_event.keycode); } last_event_time = get_time_ticks(); break; case WL_INPUT_EV_TYPE_TOUCH: handle_touch(&ev); last_event_time = ev.touch_event.ticks; break; default: more_events = 0; break; } } /* never reached */ return 0; }
int quicksort(void) { WINDOW *win1; FILE *fp1; int max_x, max_y, start_y, start_x, starty_of_box, height_of_box = 3; int choice, random = 1, ret_val; char c; data qcsort; init_sort_info(&qcsort); /* initialise number of swaps and comparisons to 0 */ cbreak(); init_pair(2, COLOR_RED, COLOR_BLACK); fp1 = fopen("files/quicksort.txt", "r"); if(fp1 == NULL) { /* display error */ fprintf(stdout, "\vfopen: files/quicksort.txt :: %s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \v", strerror(errno)); endwin(); exit(0); } getmaxyx(stdscr, max_y, max_x); /* get the max dimensions of the screen */ print_in_middle(stdscr, 3, 0, max_x, "QUICKSORT", COLOR_PAIR(3)); start_y = max_y / 5; start_x = max_x / 4 + 4; print_intro(fp1, start_y, start_x); /* print the introduction page of Quicksort */ instruction(max_y - 2, 0, "Press <ENTER> to CONTINUE or 'p' to return to the previous menu."); c = getch(); if(c == 'p') { clear(); curs_set(TRUE); fclose(fp1); return 0; } else { (qcsort.comparisons)++; /* this is incremented as the partition function has a do...while */ get_num_elem(&qcsort); /* get the number of elements to perform sorting on */ clear(); while(random != 0) { /* this loop is required because sometimes random function generates already sorted elements */ random = num_generator(&qcsort); /* randomly generate 'elements' numbers and store in qcsort.numbers[elements] */ message(max_y); /* print "generating random numbers..." */ } clear(); print_in_middle(stdscr, 3, 0, max_x, "QUICKSORT", COLOR_PAIR(3)); instruction(max_y - 3, 0, "Press <ENTER> to START."); instruction(max_y - 2, 0, "Press 'p' to go to the Main Menu."); curs_set(FALSE); /* curs_set(TRUE) shows a dirty cursor at top-left of the box */ attron(A_BOLD); print_numbers(&qcsort, max_y, max_x); attroff(A_BOLD); win1 = NULL; /* win1 will be used for displaying the final box after each iteration */ choice = getch(); if(choice == 'p') { clear(); curs_set(TRUE); fclose(fp1); free(qcsort.numbers); return 0; } else if(choice == ENTER) { /* start the animation */ move(max_y - 3, 0); clrtoeol(); attron(A_BOLD); mvprintw(max_y - 12, 0, "RED: Current position of pivot."); mvprintw(max_y - 10, 0, "GREEN: Final position of element."); attroff(A_BOLD); instruction(max_y - 3, 0, "Press <RIGHT ARROW KEY> to proceed to the next step."); sleep(3); attron(A_BOLD); ret_val = quicksort_driver(qcsort.numbers, 0, qcsort.elements - 1, max_y, max_x, &qcsort, win1); if(ret_val == INT_MIN) { /* exit */ clear(); curs_set(TRUE); fclose(fp1); free(qcsort.numbers); return 0; } sleep(1); starty_of_box = (max_y - height_of_box) / 4 + 5; move(starty_of_box - 2, 0); /* to delete the letter 'i' which remains after the animation */ clrtoeol(); move(starty_of_box - 1, 0); /* to delete the letter 'j' which remains after the animation */ clrtoeol(); clear_boxes(starty_of_box); /* clear the boxes off the screen */ move(max_y - 19, 0); clrtobot(); attron(A_BOLD); mvprintw(max_y - 17, max_x / 4 + 15, "Yeah! The numbers are sorted!!"); mvprintw(max_y - 13, max_x / 4 + 15, "Info:"); mvprintw(max_y - 11, max_x / 4 + 15, "Number of swaps = %d", qcsort.swaps); mvprintw(max_y - 9, max_x / 4 + 15, "Number of comparisons = %d", qcsort.comparisons); } curs_set(TRUE); move(max_y - 5, 0); clrtobot(); instruction(max_y - 2, 0, "Press any key to continue.\n"); getch(); } attroff(A_BOLD); fclose(fp1); free(qcsort.numbers); return 0; }
int selectionsort(void) { WINDOW *win1, *win2, *win3; FILE *fp1; int startx_of_box, starty_of_box, width_of_box, height_of_box, max_x, max_y, start_y, start_x; int choice, i, j, iter_no = 1, inner_iter, random = 1; int min, min_index, x_box1, x_box2; char c; data ssort; init_sort_info(&ssort); /* initialise number of swaps and comparisons to 0 */ win3 = NULL; /* win3 will be used for displaying the final box after each iteration */ cbreak(); fp1 = fopen("files/selectionsort.txt", "r"); if(fp1 == NULL) { /* display error */ fprintf(stdout, "\vfopen: files/selectionsort.txt :: %s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \v", strerror(errno)); endwin(); exit(0); } getmaxyx(stdscr, max_y, max_x); /* get max coordinates of the screen */ print_in_middle(stdscr, 3, 0, max_x, "SELECTION SORT", COLOR_PAIR(3)); start_y = max_y / 5; start_x = max_x / 4 + 4; print_intro(fp1, start_y, start_x); /* print the introduction page of Selection Sort */ instruction(max_y - 2, 0, "Press <ENTER> to CONTINUE or 'p' to return to the previous menu."); c = getch(); if(c == 'p') { /* exit */ clear(); fclose(fp1); curs_set(TRUE); return 0; } else { get_num_elem(&ssort); /* get the number of elements to perform sorting on */ clear(); while(random != 0) { /* this loop is required because sometimes random function generates already sorted elements */ random = num_generator(&ssort); /* randomly generate 'elements' numbers and store in ssort.numbers[elements] */ message(max_y); /* print "generating random numbers..." */ } clear(); print_in_middle(stdscr, 3, 0, max_x, "SELECTION SORT", COLOR_PAIR(3)); inner_iter = ssort.elements; height_of_box = 3; /* height of box */ width_of_box = 4; /* width of box */ starty_of_box = (max_y - height_of_box) / 4 + 5; /* starting y coordinate of the box */ startx_of_box = max_x / 4 + 2; /* starting x coordinate of the box */ instruction(max_y - 3, 0, "Press <ENTER> to START."); instruction(max_y - 2, 0, "Press 'p' to go to the Main Menu.\n"); curs_set(FALSE); /* curs_set(TRUE) shows a dirty cursor at top-left of the box */ win1 = create_newwin(height_of_box, width_of_box, starty_of_box, startx_of_box); /* create windows */ startx_of_box += 8; win2 = create_newwin(height_of_box, width_of_box, starty_of_box, startx_of_box); attron(A_BOLD); print_numbers(&ssort, max_y, max_x); attroff(A_BOLD); choice = getch(); if(choice == 'p') { /* exit */ clear(); curs_set(TRUE); fclose(fp1); free(ssort.numbers); destroy_win(win1); destroy_win(win2); return 0; } if(choice == ENTER) { /* start the animation */ move(max_y - 3, 0); clrtoeol(); attron(A_BOLD); mvprintw(max_y - 12, 0, "GREEN: Smallest element in the current list."); mvprintw(max_y - 10, 0, "YELLOW: Final position of element."); attroff(A_BOLD); instruction(max_y - 3, 0, "Press <RIGHT ARROW KEY> to proceed to the next step."); sleep(3); attron(A_BOLD); refresh(); destroy_win(win1); x_box1 = startx_of_box; for(j = 0; j < ssort.elements - 1; j++) { sleep(1); mvprintw(max_y / 4, (max_x - 19) / 2,"Iteration number: %d", iter_no); destroy_win(win2); print_numbers(&ssort, max_y, max_x); x_box2 = x_box1 + 5; win1 = create_newwin(height_of_box, width_of_box, starty_of_box, x_box1); win2 = create_newwin(height_of_box, width_of_box, starty_of_box, x_box1 + 5); print_numbers(&ssort, max_y, max_x); min = ssort.numbers[j]; min_index = j; move(max_y - 19, 0); clrtoeol(); mvprintw(max_y - 19, max_x / 4 + 18, "Minimum element is %d.", ssort.numbers[j]); refresh(); for(i = j + 1; i < inner_iter; i++) { sleep(1); print_numbers(&ssort, max_y, max_x); destroy_win(win2); win2 = create_newwin(height_of_box, width_of_box, starty_of_box, x_box2); if(ssort.numbers[i] < min) { print_numbers(&ssort, max_y, max_x); sleep(1); min = ssort.numbers[i]; min_index = i; move(max_y - 19, 0); clrtoeol(); mvprintw(max_y - 19, max_x / 4 + 18, "New minimum element is %d.", ssort.numbers[i]); refresh(); } else { move(max_y - 19, 0); clrtoeol(); mvprintw(max_y - 19, max_x / 4 + 18, "Minimum element remains %d.", ssort.numbers[min_index]); refresh(); } ssort.comparisons++; /* increment the number of comparisons in ssort */ print_numbers(&ssort, max_y, max_x); choice = getch(); if(choice == 'p') { /* exit */ clear(); curs_set(TRUE); fclose(fp1); free(ssort.numbers); destroy_win(win1); destroy_win(win2); return 0; } x_box2 += 5; } iter_no++; /* place a box over the smallest number */ box_over_num(min_index, win3, max_y, max_x, height_of_box, width_of_box, 3); print_numbers(&ssort, max_y, max_x); sleep(1); move(max_y - 19, 0); clrtoeol(); mvprintw(max_y - 19, max_x / 4 + 18, "Now %d and %d get swapped.", ssort.numbers[min_index], ssort.numbers[j]); refresh(); sleep(2); destroy_win(win3); print_numbers(&ssort, max_y, max_x); win3 = NULL; ssort.numbers[min_index] = ssort.numbers[j]; ssort.numbers[j] = min; ssort.swaps++; /* place a box over the number, now in its final position */ box_over_num(j, win3, max_y, max_x, height_of_box, width_of_box, 4); x_box1 += 5; print_numbers(&ssort, max_y, max_x); } destroy_win(win1); destroy_win(win2); print_numbers(&ssort, max_y, max_x); sleep(1); clear_boxes(starty_of_box); /* clear the boxes from the screen */ move(max_y - 19, 0); clrtobot(); mvprintw(max_y - 17, max_x / 4 + 15, "Yeah! The numbers are sorted!!"); mvprintw(max_y - 13, max_x / 4 + 15, "Info:"); mvprintw(max_y - 11, max_x / 4 + 15, "Number of swaps = %d", ssort.swaps); mvprintw(max_y - 9, max_x / 4 + 15, "Number of comparisons = %d", ssort.comparisons); attroff(A_BOLD); } move(max_y - 4, 0); clrtobot(); curs_set(TRUE); instruction(max_y - 2, 0, "Press any key to continue.\n"); getch(); } fclose(fp1); free(ssort.numbers); return 0; }
/** ** long-term TODO: * substitute assertions with error messages (only run time errors) * look for a clean printing structure * ** maybe TODO: * record where tir occured (in the particle variable) * record how much energy is lost during the propagation in the particles * handle the lists in OpenGL in an explicit function for a better overview * polarization density: change to compute the stokes vector * ** TODO: * check multiple scattering, as some error was detected in the main loop with uninitialized rays * problem with the tracing visualization: the start of a transmitted ray isn't stored properly * -> add make trace when updating i1 */ int main(int argc, char **argv) { //testing(); getchar(); exit(EXIT_SUCCESS); FP_ERR_CLEAR; { int i; for(i = 0; i < argc; i++) fprintf(stdout, "arg[%d]: %s\n", i, argv[i]); } #if RELEASE_BUILD print_intro(); #endif init_allocations(); const uchar use_ogl = 0; uint nors, ui, res_azim, res_rad, nprtcls, res_polar_bin, res_azim_bin; double max_rad, lambda, mu_prtcl; point3 init, fin, polarisation; sphere3 screen; sphrcl_prtcl *mat_prtcls; /**< set the detection screen: */ res_polar_bin = 91; res_azim_bin = 360; bin_hit_screen *b_htscrn = alloc_bin_hit_screen(1, 4., res_polar_bin, res_azim_bin); /**< set the rays and some detection containers: */ lambda = 632.8e-6; max_rad = 3.9e-1; res_rad = 5; /* 80 */ res_azim = 10; if(res_azim < MAX_NUMBER_OF_RAYS / res_rad) nors = res_azim * res_rad; else error_msg("there are too many rays to be created - change the data type.", ERR_ARG); ray *rs = alloc_ray(nors); hit_screen *htscrn = alloc_hit_screen(nors); /**< set the particles: */ nprtcls = 3; mu_prtcl = 1.; sphrcl_prtcl *prtcls = alloc_sphrcl_prtcl(nprtcls); //set_sphrcl_prtcl(&prtcls[0],rfrct_indx_h2o(lambda,"mm"),mu_prtcl,0.,0.,0.,.4); set_sphrcl_prtcl(&prtcls[0], 1.4 + 0.i, mu_prtcl, 0., 0., 0., .4); set_sphrcl_prtcl(&prtcls[1], n_vac, mu_prtcl, 0., 1., 0., .42); set_sphrcl_prtcl(&prtcls[2], n_vac, mu_prtcl, 0., 0., 1., .41); set_sphere3(&screen, 0., 0., 0., b_htscrn[0].rad); /**< initiate the bundle of rays: */ set_point3(&polarisation, 1., 0., 0.); set_point3(&init, -1., 0., 0.); set_point3(&fin, 0., 0., 0.); gen_startrays_straight(rs, lambda, nors, res_azim, res_rad, max_rad, &init, &fin, &polarisation); /**< initiate the drawing of rays: */ glray *glrays; if(use_ogl) { glrays = alloc_glray(1, nors); copy_ray_to_glray_s(rs, glrays[0].glrs, nors); for(ui = 0; ui < nors; ui++) make_trace(&rs[ui], &glrays[0], ui); } FP_ERR_CHECK; prog_of_rays(0, INIT_PROG); #if PARALLEL_PROCESSING #if OSID == ISWIN32 & RELEASE_BUILD #warning "on windows xp 32 bit and mingw32 with gcc 4.6.2 \ there have been found deviations when using the built - in openmp 3.0. \ deviations have been detected in about 20 percent of the results at the 4th decimal place." #endif /**< parallel start ==> */ #pragma omp parallel for default(shared) lastprivate(ui) schedule(guided,2) #endif for(ui = 0; ui < nors; ui++) { intrsec isec; double min_l; uint min_l_ind = 0, n_subrs = 256, n_subhtscrn = 512, uj, i1, i2, i3, i4, j1, j2, n_move, max_subhtscrn = 1 << 15; ray first, second; memcpy(&first, &rs[ui], sizeof(ray)); /** * first run through the system. the code can be easily shortened by * beginning with the inner loop, but if the ray hits no particle, * this procedure would cost unnecessary memory allocations. */ for(uj = 0, min_l = DBL_MAX; uj < nprtcls; uj++) /**< check for the nearest intersection with a particle */ { if(intersec_lin_sph(&prtcls[uj].s, &first.v, 0, &isec)) if(first.v.l < min_l) { min_l = first.v.l; min_l_ind = uj; } } if(intersec_lin_sph(&screen, &first.v, 1, &isec)) /**< check for the intersection with the screen */ { if(first.v.l < min_l) { propagate_ray(&first); if(use_ogl) make_trace(&first, &glrays[0], ui); #pragma omp critical(reg_hit) { reg_hit(&first, &htscrn[ui], isec.cangl, FIRSTTIME_HIT_STATE); } #pragma omp critical(prog_of_rays) { prog_of_rays(1, COUNT_PROG); } #pragma omp atomic global_ray_info.count_hit++; continue; /**< if the screen was hit, proceed with the next ray */ } } else { #pragma omp critical(reg_hit) {reg_hit(&first, &htscrn[ui], 0xDEAD, EXCEPTION_STATE);} #pragma omp atomic global_ray_info.count_lost++; fprintf(stderr, "ray %u:\n", ui); error_msg("direct loss of a ray", ERR_ARG); continue; } /**< if a particle has been hit by the ray before the screen, allocate memory and start the inner loop: */ ray *subrs = alloc_ray(n_subrs); hit_screen *subhtscrn = alloc_hit_screen(n_subhtscrn); /**< handle the first intersection: */ intersec_lin_sph(&prtcls[min_l_ind].s, &first.v, 1, &isec); #pragma omp atomic prtcls[min_l_ind].hits++; propagate_ray(&first); if(set_refr_index(&first, &isec, prtcls[min_l_ind].n, prtcls[min_l_ind].mu)) { if(isec.incdnc == OBLIQUE) orthogo_ray_at_intersec(&first, &isec); i2 = handle_reflntrans(&first, &second, &isec); if(i2) memcpy(&subrs[1], &second, sizeof(ray)); first.hits++; } else { i2 = 0; propagate_ray_eps(&first); } if(use_ogl) make_trace(&first, &glrays[0], ui); memcpy(&subrs[0], &first, sizeof(ray)); i4 = i2 + 1; subrs[i4].lam = 0xDEAD; /**< now, we have at maximum 2 rays from the initial one */ for(i1 = 0, i3 = n_subrs, j1 = 0, j2 = n_subhtscrn, n_move = 0; i1 <= i2;) /**< --> start inner loop */ { /** * i1: current ray index * i2: total rays to work out minus 1 * i3: allocated rays * i4: rays to work out and the next ray to be saved by handle_reflntrans * n_move: times of moving subrs by n_subrs * j1: current hit_screen index * j2: allocated hit_screen variables */ assert(subrs[i1].lam != 0.); if(i1 == n_subrs) /**< save precious memory by overwriting the already handled rays */ { assert(i1 <= i4 && (i1 + i4) <= i3); memmove(&subrs[0], &subrs[i1], i4 * sizeof(ray)); i1 = 0; i2 -= n_subrs; i4 -= n_subrs; n_move++; } if(i1 + i4 == i3) /**< check for memory re-allocation of rays */ { subrs = realloc_ray(subrs, 0., i3, n_subrs); i3 += n_subrs; } if(j1 == j2) /**< check for memory re-allocation of hit detection */ { if(j2 > max_subhtscrn - n_subhtscrn) { #pragma omp critical(sort_detection) {sort_detection(subhtscrn, j1, &b_htscrn[0], 0);} j1 = 0; } else { subhtscrn = realloc_hit_screen(subhtscrn, j2, n_subhtscrn); j2 += n_subhtscrn; } } if(get_ray_int(&subrs[i1]) < MINI_INTENSITY) /**< check boundary condition */ { if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); reg_hit(&subrs[i1], &subhtscrn[j1], 0xDEAD, EXHAUSTED_RAY_STATE); i1++; j1++; if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); #pragma omp atomic global_ray_info.count_exhstd++; continue; } /**< check for the nearest intersection with the particles: */ for(uj = 0, min_l = DBL_MAX; uj < nprtcls; uj++) { if(intersec_lin_sph(&prtcls[uj].s, &subrs[i1].v, 0, &isec)) if(subrs[i1].v.l < min_l) { min_l = subrs[i1].v.l; min_l_ind = uj; } } /**< check for a hit on the detector: */ if(intersec_lin_sph(&screen, &subrs[i1].v, 1, &isec)) if(subrs[i1].v.l < min_l) { propagate_ray(&subrs[i1]); if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); reg_hit(&subrs[i1], &subhtscrn[j1], isec.cangl, REGULAR_HIT_STATE); i1++; j1++; if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); #pragma omp atomic global_ray_info.count_hit++; continue; } if(min_l == DBL_MAX) { if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); reg_hit(&subrs[i1], &subhtscrn[j1], 0xDEAD, EXCEPTION_STATE); i1++; j1++; if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); #pragma omp atomic global_ray_info.count_lost++; continue; } /**< set the intersection: */ intersec_lin_sph(&prtcls[min_l_ind].s, &subrs[i1].v, 1, &isec); #pragma omp atomic prtcls[min_l_ind].hits++; /**< propagate the ray to the intersection: */ propagate_ray(&subrs[i1]); /**< check if ray is traveling into another medium: */ if(set_refr_index(&subrs[i1], &isec, prtcls[min_l_ind].n, prtcls[min_l_ind].mu)) { if(isec.incdnc == OBLIQUE) orthogo_ray_at_intersec(&subrs[i1], &isec); assert(i1 + i4 < i3); assert(subrs[i4].lam == 0xDEAD); if(handle_reflntrans(&subrs[i1], &subrs[i4], &isec)) { if(get_ray_int(&subrs[i4]) < MINI_INTENSITY) /**< this is just to increment the event-counter of the particle */ { #pragma omp atomic prtcls[min_l_ind].exhstds++; } i2++; i4++; assert(subrs[i4].lam == 0.); subrs[i4].lam = 0xDEAD; } subrs[i1].hits++; } else propagate_ray_eps(&subrs[i1]); if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); if(get_ray_int(&subrs[i1]) < MINI_INTENSITY) /**< this is just to increment the event-counter of the particle */ { #pragma omp atomic prtcls[min_l_ind].exhstds++; } } /**< end inner loop, all child rays from one starting rays are worked out <-- */ #pragma omp critical(sort_detection) { sort_detection(subhtscrn, j1, &b_htscrn[0], 0); } #pragma omp critical(count_gen_update) /**< this can be substituted by atomic capture with omp 3.1 */ { global_ray_info.count_gen += (i2 + n_move * n_subrs); } #pragma omp critical(prog_of_rays) { prog_of_rays(i2 + 1 + n_move * n_subrs, PRINT_PROG); /**< +1 due to the first ray */ } free(subrs); free(subhtscrn); } /**< <== parallel end */ sort_detection(htscrn, nors, &b_htscrn[0], 1); prog_of_rays(0, CLEAR_OUT); FP_ERR_CHECK; print_bin_hit_screen("tenet / opera", &b_htscrn[0], 10, 0, INTENSITY, "testing", 0); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], E_FIELD_AMPLITUDE, 0, 0, 1, (res_polar_bin >> 1) + 1); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], MOD_E_FIELD_AMPLITUDE, 0, 0, 1, (res_polar_bin >> 1) + 1); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], INTENSITY, 0, 0, 1, (res_polar_bin >> 1) + 1); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], POLARISATION_DENSITY, 0, 0, 1, (res_polar_bin >> 1) + 1); boundingbox bbox; line3 trans_prtcls; trans_prtcls = (line3) { .o = {0., 0., 0.}, .r = {1., 1., 0.}, .l = 0.
int main(int argc, char **argv) { void (*aften_remap)(void *samples, int n, int ch, A52SampleFormat fmt, int acmod) = NULL; uint8_t *frame = NULL; FLOAT *fwav = NULL; int nr, fs, err; FILE *ifp[A52_NUM_SPEAKERS]; FILE *ofp = NULL; PcmContext pf; CommandOptions opts; AftenContext s; uint32_t samplecount, bytecount, t0, t1, percent; FLOAT kbps, qual, bw; int frame_cnt; int input_file_format; enum PcmSampleFormat read_format; /* update output every 200ms */ clock_t update_clock_span = (clock_t)(0.2f * CLOCKS_PER_SEC); clock_t current_clock; clock_t last_update_clock = clock() - update_clock_span; int ret_val = 0; int i; opts.s = &s; aften_set_defaults(&s); err = parse_commandline(argc, argv, &opts); if (err) { if (err == 1) { print_intro(stderr); print_usage(stderr); return 1; } else { print_intro(stdout); if (err == 2) { print_help(stdout); } else if (err == 3) { print_long_help(stdout); } return 0; } } if (s.verbose > 0) { print_intro(stderr); } memset(ifp, 0, A52_NUM_SPEAKERS * sizeof(FILE *)); for (i = 0; i < opts.num_input_files; i++) { if (!strncmp(opts.infile[i], "-", 2)) { #ifdef _WIN32 _setmode(_fileno(stdin), _O_BINARY); #endif ifp[i] = stdin; } else { ifp[i] = fopen(opts.infile[i], "rb"); if (!ifp[i]) { fprintf(stderr, "error opening input file: %s\n", opts.infile[i]); goto error_end; } } } #ifdef CONFIG_DOUBLE read_format = PCM_SAMPLE_FMT_DBL; #else read_format = PCM_SAMPLE_FMT_FLT; #endif // initialize pcmfile using input input_file_format = PCM_FORMAT_UNKNOWN; if (opts.raw_input) input_file_format = PCM_FORMAT_RAW; if (pcm_init(&pf, opts.num_input_files, ifp, read_format, input_file_format)) { fprintf(stderr, "invalid input file(s)\n"); goto error_end; } if (opts.read_to_eof) pcm_set_read_to_eof(&pf, 1); if (opts.raw_input) { pcm_set_source_params(&pf, opts.raw_ch, opts.raw_fmt, opts.raw_order, opts.raw_sr); } // print wav info to console if (s.verbose > 0) { fprintf(stderr, "input format: "); if (opts.num_input_files > 1) fprintf(stderr, "\n"); pcm_print(&pf, stderr); } // if acmod is given on commandline, determine lfe from number of channels if (s.acmod >= 0) { int ch = acmod_to_ch[s.acmod]; if (ch == pf.channels) { if (s.lfe < 0) { s.lfe = 0; } else { if (s.lfe != 0) { fprintf(stderr, "acmod and lfe do not match number of channels\n"); goto error_end; } } } else if (ch == (pf.channels - 1)) { if (s.lfe < 0) { s.lfe = 1; } else { if (s.lfe != 1) { fprintf(stderr, "acmod and lfe do not match number of channels\n"); goto error_end; } } } else { fprintf(stderr, "acmod does not match number of channels\n"); goto error_end; } } else { // if acmod is not given on commandline, determine from WAVE file int ch = pf.channels; if (s.lfe >= 0) { if (s.lfe == 0 && ch == 6) { fprintf(stderr, "cannot encode 6 channels w/o LFE\n"); goto error_end; } else if (s.lfe == 1 && ch == 1) { fprintf(stderr, "cannot encode LFE channel only\n"); goto error_end; } if (s.lfe) { pf.ch_mask |= 0x08; } } if (aften_wav_channels_to_acmod(ch, pf.ch_mask, &s.acmod, &s.lfe)) { fprintf(stderr, "mismatch in channels, acmod, and lfe params\n"); goto error_end; } } // set some encoding parameters using wav info s.channels = pf.channels; s.samplerate = pf.sample_rate; #ifdef CONFIG_DOUBLE s.sample_format = A52_SAMPLE_FMT_DBL; #else s.sample_format = A52_SAMPLE_FMT_FLT; #endif // open output file if (!strncmp(opts.outfile, "-", 2)) { #ifdef _WIN32 _setmode(_fileno(stdout), _O_BINARY); #endif ofp = stdout; } else { ofp = fopen(opts.outfile, "wb"); if (!ofp) { fprintf(stderr, "error opening output file: %s\n", opts.outfile); goto error_end; } } // print ac3 info to console if (s.verbose > 0) { fprintf(stderr, "output format: %d Hz %s", s.samplerate, acmod_str[s.acmod]); if (s.lfe) { fprintf(stderr, " + LFE"); } fprintf(stderr, "\n\n"); } // allocate memory for coded frame and sample buffer frame = calloc(A52_MAX_CODED_FRAME_SIZE, 1); fwav = calloc(A52_SAMPLES_PER_FRAME * s.channels, sizeof(FLOAT)); if (frame == NULL || fwav == NULL) goto error_end; samplecount = bytecount = t0 = t1 = percent = 0; qual = bw = 0.0; frame_cnt = 0; fs = 0; nr = 0; if (opts.chmap == 0) aften_remap = aften_remap_wav_to_a52; else if (opts.chmap == 2) aften_remap = aften_remap_mpeg_to_a52; // Don't pad start with zero samples, use input audio instead. if (!opts.pad_start) { int diff; nr = pcm_read_samples(&pf, fwav, 256); diff = 256 - nr; if (diff > 0) { memmove(fwav + diff * s.channels, fwav, nr); memset(fwav, 0, diff * s.channels * sizeof(FLOAT)); } if (aften_remap) aften_remap(fwav + diff, nr, s.channels, s.sample_format, s.acmod); s.initial_samples = fwav; } // initialize encoder if (aften_encode_init(&s)) { fprintf(stderr, "error initializing encoder\n"); goto error_end; } // print SIMD instructions used print_simd_in_use(stderr, &s.system.wanted_simd_instructions); // print number of threads used fprintf(stderr, "Threads: %i\n\n", s.system.n_threads); do { nr = pcm_read_samples(&pf, fwav, A52_SAMPLES_PER_FRAME); if (aften_remap) aften_remap(fwav, nr, s.channels, s.sample_format, s.acmod); fs = aften_encode_frame(&s, frame, fwav, nr); if (fs < 0) { fprintf(stderr, "Error encoding frame %d\n", frame_cnt); break; } else if (fs > 0) { if (s.verbose > 0) { samplecount += A52_SAMPLES_PER_FRAME; bytecount += fs; qual += s.status.quality; bw += s.status.bwcode; if (s.verbose == 1) { current_clock = clock(); if (current_clock - last_update_clock >= update_clock_span) { t1 = samplecount / pf.sample_rate; if (frame_cnt > 0 && (t1 > t0 || samplecount >= pf.samples)) { kbps = (bytecount * FCONST(8.0) * pf.sample_rate) / (FCONST(1000.0) * samplecount); percent = 0; if (pf.samples > 0) { percent = (uint32_t)((samplecount * FCONST(100.0)) / pf.samples); percent = CLIP(percent, 0, 100); } fprintf(stderr, "\rprogress: %3u%% | q: %4.1f | " "bw: %2.1f | bitrate: %4.1f kbps ", percent, (qual / (frame_cnt+1)), (bw / (frame_cnt+1)), kbps); } t0 = t1; last_update_clock = current_clock; } } else if (s.verbose == 2) { fprintf(stderr, "frame: %7d | q: %4d | bw: %2d | bitrate: %3d kbps\n", frame_cnt, s.status.quality, s.status.bwcode, s.status.bit_rate); } } fwrite(frame, 1, fs, ofp); frame_cnt++; } } while (nr > 0 || fs > 0 || !frame_cnt); if (s.verbose >= 1) { if (samplecount > 0) { kbps = (bytecount * FCONST(8.0) * pf.sample_rate) / (FCONST(1000.0) * samplecount); } else { kbps = 0; } frame_cnt = MAX(frame_cnt, 1); if (s.verbose == 1) { fprintf(stderr, "\rprogress: 100%% | q: %4.1f | bw: %2.1f | bitrate: %4.1f kbps\n\n", (qual / frame_cnt), (bw / frame_cnt), kbps); } else if (s.verbose == 2) { fprintf(stderr, "\n"); fprintf(stderr, "average quality: %4.1f\n", (qual / frame_cnt)); fprintf(stderr, "average bandwidth: %2.1f\n", (bw / frame_cnt)); fprintf(stderr, "average bitrate: %4.1f kbps\n\n", kbps); } } goto end; error_end: ret_val = 1; end: if (fwav) free(fwav); if (frame) free(frame); pcm_close(&pf); for (i = 0; i < opts.num_input_files; i++) { if (ifp[i]) fclose(ifp[i]); } if (ofp) fclose(ofp); if (aften_encode_close(&s)) return 1; return ret_val; }
int main(int argc, char *argv[]) { std::string ip_address = ""; int parse_ret = parse_command_line_options(argc, argv, ip_address); if(parse_ret != 1) return parse_ret; if(ip_address.empty()) { ip_address = DEFAULT_IP_ADDR; } print_intro(); modbus_t *mb; mb = modbus_new_tcp(DEFAULT_IP_ADDR, 502); if (mb == NULL) { fprintf(stderr, "Unable to allocate libmodbus context\n"); return -1; } if (modbus_connect(mb) == -1) { fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno)); modbus_free(mb); return -1; } setup_interupt(); bool write_bool = true; int write_num = 0; unsigned int count = 0; uint8_t outputs[16] = {0}; //variables for calculations bool button_pressed = false; try { while (true) { uint16_t input = 0; if(read_inputs(mb, &input) == -1) break; button_pressed = get_input_bit(input, 9); //solenoid = button xor photoeyen bool sol_out = button_pressed ^ get_input_bit(input, 2); outputs[0] = sol_out; if(write_outputs(mb, outputs) == -1) break; print_io(input, outputs); /* code for incrmenting IO count++; if(count%50==0){ outputs[write_num] = write_bool; write_num++; } if(write_num==16){ write_bool = !write_bool; write_num = 0; }*/ usleep(1*1000); //Sleep 1ms } } catch(InterruptException& e) { modbus_close(mb); modbus_free(mb); } }