int main(int argc, char *argv[]) { int i, n_steps, grid[lbmodel.n_dim], vol; double rho, gamma, kappa; double start, finish, elapsed, mups; if (argc!=3) { fprintf(stderr, "Usage: ./run <kappa> <nsteps>\n"); return -1; } lis_initialize(&argc, &argv); n_steps = atoi(argv[2]); grid[0] = 100; grid[1] = 20; vol = grid[0]*grid[1]; rho = 1.0; gamma = 0.0; kappa = atof(argv[1]); write_eos(); char filename[1024]; sprintf(filename, "profile_k%.03f.dat", kappa); lb_init(grid,rho,gamma,kappa); lb_mass_mom(0); fprintf(stdout, "Running %d iterations\n", n_steps); fflush(stdout); start = (double) clock(); for (i=0; i<n_steps; ++i) { lb_update(lbf); lb_mass_mom(i+1); write_profile(filename, 0); } finish = (double) clock(); elapsed = (finish-start)/CLOCKS_PER_SEC; mups = vol*n_steps/elapsed/1e6; fprintf(stdout, "Elapsed time: %.3f s (%.3e MUPS)\n", elapsed, mups); fflush(stdout); write_profile(filename, 0); lb_finalize(); lis_finalize(); return EXIT_SUCCESS; }
bool Profile::create_default_profile() { int i; if(!cfg) return(false); for(i=0;cfg[i].name;i++) { switch(cfg[i].type) { case cfgINT: sscanf(cfg[i].defval,"%i",(int*)cfg[i].var); break; case cfgSTR: snprintf((char*)cfg[i].var,MAX_VALUE_SIZE,"%s",cfg[i].defval); break; case cfgFLOAT: sscanf(cfg[i].defval,"%f",(float*)cfg[i].var); break; case cfgNULL: break; } } return write_profile("default"); }
static void write_uncompressed_header(VP9_COMP *cpi, struct vpx_write_bit_buffer *wb) { VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; vpx_wb_write_literal(wb, VP9_FRAME_MARKER, 2); write_profile(cm->profile, wb); vpx_wb_write_bit(wb, 0); // show_existing_frame vpx_wb_write_bit(wb, cm->frame_type); vpx_wb_write_bit(wb, cm->show_frame); vpx_wb_write_bit(wb, cm->error_resilient_mode); if (cm->frame_type == KEY_FRAME) { write_sync_code(wb); write_bitdepth_colorspace_sampling(cm, wb); write_frame_size(cm, wb); } else { // In spatial svc if it's not error_resilient_mode then we need to code all // visible frames as invisible. But we need to keep the show_frame flag so // that the publisher could know whether it is supposed to be visible. // So we will code the show_frame flag as it is. Then code the intra_only // bit here. This will make the bitstream incompatible. In the player we // will change to show_frame flag to 0, then add an one byte frame with // show_existing_frame flag which tells the decoder which frame we want to // show. if (!cm->show_frame) vpx_wb_write_bit(wb, cm->intra_only); if (!cm->error_resilient_mode) vpx_wb_write_literal(wb, cm->reset_frame_context, 2); if (cm->intra_only) { write_sync_code(wb); // Note for profile 0, 420 8bpp is assumed. if (cm->profile > PROFILE_0) { write_bitdepth_colorspace_sampling(cm, wb); } vpx_wb_write_literal(wb, get_refresh_mask(cpi), REF_FRAMES); write_frame_size(cm, wb); } else { MV_REFERENCE_FRAME ref_frame; vpx_wb_write_literal(wb, get_refresh_mask(cpi), REF_FRAMES); for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { assert(get_ref_frame_map_idx(cpi, ref_frame) != INVALID_IDX); vpx_wb_write_literal(wb, get_ref_frame_map_idx(cpi, ref_frame), REF_FRAMES_LOG2); vpx_wb_write_bit(wb, cm->ref_frame_sign_bias[ref_frame]); } write_frame_size_with_refs(cpi, wb); vpx_wb_write_bit(wb, cm->allow_high_precision_mv); fix_interp_filter(cm, cpi->td.counts); write_interp_filter(cm->interp_filter, wb); } } if (!cm->error_resilient_mode) { vpx_wb_write_bit(wb, cm->refresh_frame_context); vpx_wb_write_bit(wb, cm->frame_parallel_decoding_mode); } vpx_wb_write_literal(wb, cm->frame_context_idx, FRAME_CONTEXTS_LOG2); encode_loopfilter(&cm->lf, wb); encode_quantization(cm, wb); encode_segmentation(cm, xd, wb); write_tile_info(cm, wb); }
// After finish trainning, generate a profile void generateProfile(){ updateParametersTable(); write_profile(); }
int main(int argc, char* argv[]) { if (argc<2) { cout << "Usage: ./compute_profile dir" << endl; exit(1); } // directory setup string BASE_DIR = "/fs/nara-scratch/qwang37/brain_data/"+string(argv[1]); string partial_profile; string d2s, d2; // io streams on the final mean_conn_profile file ifstream in; ofstream out; //clock clock_t begin_t0; // read the dimensions int dim_profile, num_records; in.open("/fs/nara-scratch/qwang37/brain_data/scripts/dims"); in >> dim_profile; in >> num_records; in >> dimlow(); // initialize hash table string keyfile = "/fs/nara-scratch/qwang37/brain_data/scripts/keyfile"; // initialize the coarse map cout << "initializing coarse map" << endl; string coarsefile = "/fs/nara-scratch/qwang37/brain_data/scripts/coarse_map_file"; init_coarse(dim_profile, coarsefile); // compute conn_profile of subjects in a single data chunk cout << "Computing conn profile of data: " << argv[1] << endl; mkdir( (BASE_DIR + "/processed").c_str(), S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH ); d2s = exec("ls " + BASE_DIR + " -l | egrep '^d' | awk '$9~/^S/ {print $9}'"); stringstream d2s_in(d2s); d2s_in >> d2; while(d2s_in.good()) { // stringstream::goodbit is set to false when any of eofbit, failbit, or badbit is set string totaldir = BASE_DIR + '/' + d2; string connfile = totaldir + "/track_aal_90_0/fdt_matrix3.dot"; string coordfile = totaldir + "/track_aal_90_0/coords_pruned"; string coordfile_local2std = totaldir + "/track_aal_90_0/coords_standard"; string coordfile_std2local = totaldir + "/track_aal_90_0/coords_standard_in_diff"; // clear conn profile init_profile(dim_profile, num_records, keyfile, conn_profile()); // do something cout << "Processing " + totaldir << endl; begin_t0 = clock(); append_conn(connfile, coordfile, coordfile_local2std, coordfile_std2local); cout << "completed in " << float(clock()-begin_t0)/CLOCKS_PER_SEC << " seconds" << endl; // write partial_profile = BASE_DIR + '/' + d2 + "/partial_profile_std2local"; cout << "writing to disk...\n"; begin_t0 = clock(); write_profile(partial_profile); cout << "completed in " << float( (clock()-begin_t0)/CLOCKS_PER_SEC ) << " seconds" << endl; // move rename( (BASE_DIR + '/' + d2).c_str(), (BASE_DIR + "/processed/" + d2).c_str() ); d2s_in >> d2; } }
int main(int argc, char *argv[]) { int opt=0, verb=0; int max_harm = 64, max_lag=0; int causal_filter = 0; while ((opt=getopt(argc,argv,"hvH:L:C"))!=-1) { switch (opt) { case 'v': verb++; break; case 'H': max_harm = atoi(optarg); break; case 'L': max_lag = atoi(optarg); break; case 'C': causal_filter = 1; break; case 'h': usage(); exit(0); break; } } if (optind==argc) { usage(); exit(1); } int i, rv; /* Open file */ fitsfile *f; int status; fits_open_file(&f, argv[optind], READONLY, &status); fits_error_check_fatal(); /* Get basic dims */ struct cyclic_work w; cyclic_load_params(f, &w, &status); fits_error_check_fatal(); if (verb) { printf("Read nphase=%d npol=%d nchan=%d\n", w.nphase, w.npol, w.nchan); fflush(stdout); } int orig_npol = w.npol; w.npol = 1; /* Init FFTs */ fftwf_init_threads(); fftwf_plan_with_nthreads(4); if (verb) { printf("Planning FFTs\n"); fflush(stdout); } #define WF "/home/pdemores/share/cyclic_wisdom.dat" FILE *wf = fopen(WF,"r"); if (wf!=NULL) { fftwf_import_wisdom_from_file(wf); fclose(wf); } rv = cyclic_init_ffts(&w); if (rv) { fprintf(stderr, "Error planning ffts (rv=%d)\n", rv); exit(1); } wf = fopen(WF,"w"); if (wf!=NULL) { fftwf_export_wisdom_to_file(wf); fclose(wf); } /* Alloc some stuff */ struct periodic_spectrum raw; struct cyclic_spectrum cs, cs_neg; struct filter_time ht, ht_new; struct filter_freq hf, hf_new; struct filter_freq *hf_shift_pos, *hf_shift_neg; hf_shift_pos = (struct filter_freq *)malloc( sizeof(struct filter_freq)*w.nharm); hf_shift_neg = (struct filter_freq *)malloc( sizeof(struct filter_freq)*w.nharm); struct profile_phase pp, pp_new; struct profile_harm ph, ph_new; raw.nphase = pp.nphase = pp_new.nphase = w.nphase; raw.nchan = cs.nchan = hf.nchan = hf_new.nchan = w.nchan; cs.nharm = ph.nharm = ph_new.nharm = w.nharm; ht.nlag = ht_new.nlag = w.nlag; for (i=0; i<w.nharm; i++) { hf_shift_pos[i].nchan = w.nchan; } for (i=0; i<w.nharm; i++) { hf_shift_neg[i].nchan = w.nchan; } raw.npol = orig_npol; cs.npol = 1; cs_neg.nchan = cs.nchan; cs_neg.nharm = cs.nharm; cs_neg.npol = cs.npol; cyclic_alloc_ps(&raw); cyclic_alloc_cs(&cs); cyclic_alloc_cs(&cs_neg); filter_alloc_time(&ht); filter_alloc_time(&ht_new); filter_alloc_freq(&hf); filter_alloc_freq(&hf_new); for (i=0; i<w.nharm; i++) { filter_alloc_freq(&hf_shift_pos[i]); filter_alloc_freq(&hf_shift_neg[i]); } profile_alloc_phase(&pp); profile_alloc_phase(&pp_new); profile_alloc_harm(&ph); profile_alloc_harm(&ph_new); /* Check bounds */ if (max_harm > w.nharm) { max_harm = w.nharm; } if (max_lag > w.nlag/2) { max_lag = w.nlag/2; } if (verb) { printf("Using max of %d harmonics and %d lags\n", max_harm, max_lag); } /* Run procedure on subint 0 */ int isub = 1; /* Load data */ cyclic_load_ps(f, &raw, isub, &status); fits_error_check_fatal(); /* Add polns w/o calibration */ cyclic_pscrunch_ps(&raw, 1.0, 1.0); /* Initialize H, profile guesses */ cyclic_fscrunch_ps(&pp, &raw); profile_phase2harm(&pp, &ph, &w); ht.data[0] = 1.0; for (i=1; i<ht.nlag; i++) { ht.data[i] = 0.0; } filter_profile_norm(&ht, &ph, max_harm); profile_harm2phase(&ph, &pp, &w); /* convert to CS, produce shifted version */ cyclic_ps2cs(&raw, &cs, &w); cyclic_ps2cs(&raw, &cs_neg, &w); cyclic_shift_cs(&cs, +1, &w); cyclic_shift_cs(&cs_neg, -1, &w); /* TODO output initial profile */ /* Remove old files */ #define FILT "filters.dat" #define TFILT "tfilters.dat" #define PROF "profs.dat" #define FPROF "fprofs.dat" unlink(FILT); unlink(TFILT); unlink(PROF); unlink(FPROF); FILE *it = fopen("iter.dat", "w"); /* iterate */ int nit=0; double mse=0.0, last_mse=0.0; signal(SIGINT, cc); do { if (verb) { printf("iter %d\n", nit); fflush(stdout); } /* Make freq domain filter */ filter_time2freq(&ht, &hf, &w); write_filter(TFILT, &ht); write_filter_freq(FILT, &hf); /* Make shifted filter array */ filter_shift(hf_shift_pos, &ht, w.nharm, raw.ref_freq/(raw.bw*1e6), &w); filter_shift(hf_shift_neg, &ht, w.nharm, -1.0*raw.ref_freq/(raw.bw*1e6), &w); mse = cyclic_mse(&cs, &cs_neg, &ph, hf_shift_pos, hf_shift_neg, max_harm); /* Update filter, prof */ cyclic_update_filter(&hf_new, &cs, &cs_neg, &ph, hf_shift_pos, hf_shift_neg, max_harm); cyclic_update_profile(&ph_new, &cs, &cs_neg, hf_shift_pos, hf_shift_neg); /* Back to time domain filter */ filter_freq2time(&hf_new, &ht_new, &w); /* Fix filter normalization */ for (i=0; i<ht_new.nlag; i++) ht_new.data[i] /= (float)ht_new.nlag; /* Zero out negative lags */ if (causal_filter) { for (i=ht_new.nlag/2; i<ht_new.nlag; i++) ht_new.data[i] = 0.0; } /* Zero out large lags */ if (max_lag>0) { for (i=max_lag; i<ht_new.nlag-max_lag; i++) ht_new.data[i] = 0.0; } /* Kill nyquist point?? */ ht_new.data[ht_new.nlag/2] = 0.0; /* Normalize prof and filter */ filter_profile_norm(&ht_new, &ph_new, max_harm); /* TODO some kind of convergence test */ double prof_diff = profile_ms_difference(&ph, &ph_new, max_harm); double filt_diff = filter_ms_difference(&ht, &ht_new); /* TODO zero out high harmonics ?? */ /* Step halfway to new versions, except first time */ if (nit==0) { for (i=0; i<w.nharm; i++) ph.data[i] = ph_new.data[i]; for (i=0; i<w.nlag; i++) ht.data[i] = ht_new.data[i]; } else { //double fac = (mse<last_mse) ? 1.0 : 0.5*sqrt(mse/last_mse); double fac=0.25; for (i=0; i<w.nharm; i++) ph.data[i] = (1.0-fac)*ph.data[i] + fac*ph_new.data[i]; for (i=0; i<w.nlag; i++) ht.data[i] = (1.0-fac)*ht.data[i] + fac*ht_new.data[i]; } /* Back to phase domain profile */ ph.data[0] = 0.0; profile_harm2phase(&ph, &pp_new, &w); /* Write out current profiles */ write_profile(PROF, &pp_new); write_fprofile(FPROF, &ph); /* Print convergence params */ if (verb) { fprintf(it,"%.3e %.3e %.8e %.8e\n", prof_diff, filt_diff, mse, mse - last_mse); } last_mse = mse; /* Update iter count */ nit++; } while (run); fclose(it); exit(0); }
/* gsview menu commands */ int gsview_command(int command) { switch (command) { case IDM_NEXTHOME: case IDM_NEXT: case IDM_NEXTSKIP: case IDM_REDISPLAY: case IDM_PREVHOME: case IDM_PREVSKIP: case IDM_PREV: case IDM_GOBACK: case IDM_GOFWD: case IDM_MAGPLUS: case IDM_MAGMINUS: case IDM_FITWIN: case IDM_ZOOM: case IDM_FULLSCREEN: /* These don't close the full screen window */ break; default: gsview_fullscreen_end(); } switch (command) { case IDM_FULLSCREEN: gsview_fullscreen(); return 0; case IDM_OPEN: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_display(); return 0; case IDM_LASTFILE1: case IDM_LASTFILE2: case IDM_LASTFILE3: case IDM_LASTFILE4: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } make_cwd(last_files[command-IDM_LASTFILE1]); gsview_displayfile(last_files[command-IDM_LASTFILE1]); return 0; case IDM_CLOSE: /* doesn't unload DLL */ /* close file */ if (gsdll.open && (gsdll.state != GS_UNINIT)) { PSFILE *tpsfile; if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } tpsfile = (PSFILE *)malloc(sizeof(PSFILE)); if (tpsfile == NULL) return 0; memset((char *)tpsfile, 0, sizeof(PSFILE)); pending.psfile = tpsfile; pending.now = TRUE; if (psfile.name[0] && psfile.dsc==(CDSC *)NULL) pending.abort = TRUE; } else { /* DLL isn't loaded */ if (psfile.file) dfclose(); /* just to make sure */ psfile_free(&psfile); post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_CLOSE_DONE: if (selectname[0] != '\0') { /* pending IDM_SELECT */ PSFILE *tpsfile; tpsfile = gsview_openfile(selectname); if (tpsfile) { psfile = *tpsfile; free(tpsfile); } selectname[0] = '\0'; post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_NEXTHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_NEXT: if (not_open()) return 0; gs_page_skip(1); return 0; case IDM_NEXTSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(page_skip); return 0; case IDM_REDISPLAY: if (dfchanged()) { PSFILE *tpsfile; if (dfchanged() < 0) { gs_addmess("File has been deleted\n"); gsview_command(IDM_CLOSE); pending.unload = TRUE; pending.now = FALSE; return 0; } if (pending.psfile) tpsfile = pending.psfile; /* new file, old file deleted */ else tpsfile = gsview_openfile(psfile.name); if (tpsfile) { tpsfile->pagenum = psfile.pagenum; request_mutex(); pending.psfile = tpsfile; if ( gsdll.hmodule && (psfile.dsc==(CDSC *)NULL) && (gsdll.state != GS_IDLE) ) /* don't know where we are so close and reopen */ pending.abort = TRUE; pending.now = TRUE; release_mutex(); } } if (not_open()) return 0; if (psfile.dsc==(CDSC *)NULL) { /* don't know where we are so close and reopen */ if (gsdll.state != GS_IDLE) { if (!pending.psfile) { pending.psfile = (PSFILE *)malloc(sizeof(PSFILE)); if (pending.psfile) *pending.psfile = psfile; } pending.psfile->pagenum = pending.pagenum = 1; pending.abort = TRUE; pending.now = TRUE; } } else { pending.pagenum = -1; /* default page number is current page */ if (psfile.dsc->page_order == CDSC_SPECIAL) pending.pagenum = 1; /* restart */ } gsview_unzoom(); pending.now = TRUE; return 0; case IDM_PREVHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_PREV: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-1); return 0; case IDM_PREVSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-page_skip); return 0; case IDM_GOTO: if (not_dsc()) return 0; if (order_is_special()) return 0; if (psfile.dsc->page_count == 0) { gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER); return 0; } nHelpTopic = IDS_TOPICGOTO; { int pagenum; pagenum = psfile.pagenum; if (get_page(&pagenum, FALSE, FALSE)) { gsview_goto_page(pagenum); } } return 0; case IDM_GOBACK: if (not_dsc()) return 0; if (order_is_special()) return 0; history_back(); return 0; case IDM_GOFWD: if (not_open()) return 0; if (psfile.dsc == (CDSC *)NULL) gsview_command(IDM_NEXT); else history_forward(); return 0; case IDM_INFO: show_info(); return 0; case IDM_SELECT: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_select(); return 0; #ifndef VIEWONLY case IDM_PRINT: case IDM_PRINTTOFILE: case IDM_CONVERTFILE: if (psfile.name[0] == '\0') gsview_select(); if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (dfreopen() != 0) return 0; if (command == IDM_PRINTTOFILE) option.print_to_file = TRUE; if (psfile.name[0] != '\0') gsview_print(command == IDM_CONVERTFILE); dfclose(); return 0; case IDM_SPOOL: gsview_spool((char *)NULL, (char *)NULL); return 0; case IDM_SAVEAS: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_saveas(); return 0; case IDM_EXTRACT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (order_is_special()) return 0; if (psfile.name[0] != '\0') gsview_extract(); return 0; case IDM_PSTOEDIT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); (void)order_is_special(); /* warn, but allow it anyway */ if (dfreopen() != 0) return 0; if (psfile.name[0] != '\0') gsview_pstoedit(); dfclose(); return 0; case IDM_TEXTEXTRACT: if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_text_extract(); return 0; case IDM_TEXTEXTRACT_SLOW: gsview_text_extract_slow(); return 0; case IDM_TEXTFIND: gsview_text_find(); return 0; case IDM_TEXTFINDNEXT: gsview_text_findnext(); return 0; case IDM_COPYCLIP: copy_clipboard(); return 0; case IDM_PASTETO: paste_to_file(); return 0; case IDM_CONVERT: clip_convert(); return 0; case IDM_MEASURE: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } measure_show(); return 0; #endif /* !VIEWONLY */ case IDM_GSMESS: gs_showmess(); /* show messages from Ghostscript */ return 0; case IDM_EXIT: if (print_count) { /* Still busy printing. Warn user. */ TCHAR buf[MAXSTR]; load_string(IDS_BUSYPRINTING, buf, sizeof(buf)/sizeof(TCHAR)-1); if (message_box(buf, MB_OKCANCEL) != IDOK) return 0; } post_img_message(WM_CLOSE, 0); return 0; case IDM_CFG: /* Easy configure */ config_wizard(TRUE); return 0; case IDM_GSCOMMAND: /* Advanced configure */ if (install_gsdll() && gsdll.open) pending.unload = TRUE; return 0; case IDM_UNITPT: case IDM_UNITMM: case IDM_UNITINCH: gsview_unit(command); return 0; case IDM_UNITFINE: option.unitfine = !option.unitfine; check_menu_item(IDM_UNITMENU, IDM_UNITFINE, option.unitfine); return 0; case IDM_LANGMENU+1: case IDM_LANGMENU+2: case IDM_LANGMENU+3: case IDM_LANGMENU+4: case IDM_LANGMENU+5: case IDM_LANGMENU+6: case IDM_LANGMENU+7: case IDM_LANGMENU+8: case IDM_LANGMENU+9: case IDM_LANGMENU+10: case IDM_LANGMENU+11: case IDM_LANGMENU+12: case IDM_LANGMENU+13: case IDM_LANGMENU+14: case IDM_LANGMENU+15: case IDM_LANGMENU+16: case IDM_LANGMENU+17: case IDM_LANGMENU+18: case IDM_LANGMENU+19: gsview_language(command); return 0; case IDM_SAFER: option.safer = !option.safer; check_menu_item(IDM_OPTIONMENU, IDM_SAFER, option.safer); return 0; case IDM_SAVEDIR: option.save_dir = !option.save_dir; check_menu_item(IDM_OPTIONMENU, IDM_SAVEDIR, option.save_dir); return 0; case IDM_BUTTONSHOW: option.button_show = !option.button_show; check_menu_item(IDM_OPTIONMENU, IDM_BUTTONSHOW, option.button_show); show_buttons(); return 0; case IDM_FITPAGE: option.fit_page = !option.fit_page; check_menu_item(IDM_OPTIONMENU, IDM_FITPAGE, option.fit_page); /* should cause WM_SIZE message to be sent */ return 0; case IDM_PSTOTEXTDIS: case IDM_PSTOTEXTNORM: case IDM_PSTOTEXTCORK: check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, FALSE); option.pstotext = command - IDM_PSTOTEXTMENU - 1; check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, TRUE); return 0; case IDM_AUTOREDISPLAY: option.redisplay = !option.redisplay; check_menu_item(IDM_OPTIONMENU, IDM_AUTOREDISPLAY, option.redisplay); return 0; case IDM_EPSFCLIP: option.epsf_clip = !option.epsf_clip; check_menu_item(IDM_OPTIONMENU, IDM_EPSFCLIP, option.epsf_clip); gs_resize(); return 0; case IDM_EPSFWARN: option.epsf_warn = !option.epsf_warn; check_menu_item(IDM_OPTIONMENU, IDM_EPSFWARN, option.epsf_warn); return 0; case IDM_IGNOREDSC: option.ignore_dsc = !option.ignore_dsc; check_menu_item(IDM_OPTIONMENU, IDM_IGNOREDSC, option.ignore_dsc); if (psfile.name[0]) { if (option.redisplay) gsview_displayfile(psfile.name); else gsview_selectfile(psfile.name); } return 0; case IDM_SHOWBBOX: option.show_bbox = !option.show_bbox; check_menu_item(IDM_OPTIONMENU, IDM_SHOWBBOX, option.show_bbox); #ifdef UNIX gtk_widget_draw(img, NULL); #else #ifdef _Windows PostMessage(hwndimg, WM_GSSYNC, 0, 0L); #else if (!WinInvalidateRect(hwnd_bmp, (PRECTL)NULL, TRUE)) error_message("error invalidating rect"); if (!WinUpdateWindow(hwnd_bmp)) error_message("error updating window"); #endif #endif return 0; #ifndef VIEWONLY case IDM_PSTOEPS: if (not_open()) return 0; if (psfile.name[0] != '\0') { if (dfreopen() != 0) return 0; ps_to_eps(); dfclose(); } return 0; case IDM_MAKEEPSI: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_interchange(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPST4: case IDM_MAKEEPST6U: case IDM_MAKEEPST6P: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_tiff(command, FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSW: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_metafile(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSU: if (dfreopen() != 0) return 0; make_eps_user(); dfclose(); return 0; case IDM_EXTRACTPS: case IDM_EXTRACTPRE: if (dfreopen() != 0) return 0; extract_doseps(command); dfclose(); return 0; #endif case IDM_SETTINGS: write_profile(); return 0; case IDM_SAVESETTINGS: option.settings = !option.settings; check_menu_item(IDM_OPTIONMENU, IDM_SAVESETTINGS, option.settings); { char buf[MAXSTR]; PROFILE *prf = profile_open(szIniFile); sprintf(buf, "%d", (int)option.settings); profile_write_string(prf, INISECTION, "SaveSettings", buf); profile_close(prf); } return 0; case IDM_SOUNDS: change_sounds(); return 0; case IDM_AUTOORIENT: case IDM_PORTRAIT: case IDM_LANDSCAPE: case IDM_UPSIDEDOWN: case IDM_SEASCAPE: case IDM_SWAPLANDSCAPE: gsview_orientation(command); return 0; case IDM_DSC_OFF: case IDM_DSC_ERROR: case IDM_DSC_WARN: case IDM_DSC_INFO: check_menu_item(IDM_DSCMENU, option.dsc_warn, FALSE); option.dsc_warn = command; check_menu_item(IDM_DSCMENU, option.dsc_warn, TRUE); return 0; case IDM_ZOOM: /* called indirectly from Right Mouse Button */ if (not_dsc()) { zoom = FALSE; return 0; } if (order_is_special()) { zoom = FALSE; return 0; } if (! ((gsdll.state == GS_PAGE) || (gsdll.state == GS_IDLE)) ) { zoom = FALSE; gserror(IDS_NOZOOM, NULL, MB_ICONEXCLAMATION, SOUND_ERROR); return 0; } gs_resize(); pending.pagenum = -1; /* default page number is current page */ pending.now = TRUE; return 0; case IDM_MAGPLUS: gs_magnify((float)1.2); return 0; case IDM_MAGMINUS: gs_magnify((float)0.8333); return 0; case IDM_FITWIN: /* fit media to size of current window */ gsview_fitwin(); return 0; case IDM_DISPLAYSETTINGS: display_settings(); return 0; case IDM_MEDIAROTATE: option.media_rotate = !option.media_rotate; check_menu_item(IDM_MEDIAMENU, IDM_MEDIAROTATE, option.media_rotate); zoom = FALSE; gs_resize(); return 0; case IDM_11x17: case IDM_A3: case IDM_A4: case IDM_A5: case IDM_B4: case IDM_B5: case IDM_LEDGER: case IDM_LEGAL: case IDM_LETTER: case IDM_NOTE: case IDM_USERSIZE: case IDM_USERSIZE1: case IDM_USERSIZE2: case IDM_USERSIZE3: case IDM_USERSIZE4: case IDM_USERSIZE5: case IDM_USERSIZE6: case IDM_USERSIZE7: case IDM_USERSIZE8: case IDM_USERSIZE9: case IDM_USERSIZE10: case IDM_USERSIZE11: case IDM_USERSIZE12: case IDM_USERSIZE13: if (command == IDM_USERSIZE) if (!gsview_usersize()) return 0; gsview_media(command); return 0; case IDM_HELPCONTENT: #ifdef UNIX nHelpTopic = IDS_TOPICROOT; get_help(); #else #ifdef _Windows #ifdef USE_HTMLHELP nHelpTopic = IDS_TOPICROOT; get_help(); #else WinHelp(hwndimg,szHelpName,HELP_CONTENTS,(DWORD)NULL); #endif #else WinSendMsg(hwnd_help, HM_HELP_CONTENTS, 0L, 0L); #endif #endif return 0; case IDM_HELPSEARCH: #ifdef UNIX gs_addmess("IDM_HELPSEARCH: not implemented\n"); #else #ifdef _Windows #ifdef USE_HTMLHELP HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_INDEX, (DWORD)TEXT("")); gs_addmessf("HtmlHelp: %s HH_DISPLAY_INDEX\n", szHelpName); #else WinHelp(hwndimg,szHelpName,HELP_PARTIALKEY,(DWORD)""); #endif #else WinSendMsg(hwnd_help, HM_HELP_INDEX, 0L, 0L); #endif #endif return 0; case IDM_HELPKEYS: nHelpTopic = IDS_TOPICKEYS; get_help(); return 0; case IDM_ABOUT: show_about(); return 0; case IDM_REGISTER: registration_nag(); return 0; } return 0; }