int main(int argc, char *argv[]) { // command line grabbing try { TCLAP::CmdLine cmd("Projects the electrondensity of a CHGCAR file onto a image file.", ' ', "0.9"); //************************************** // declare values to be parsed //************************************** TCLAP::ValueArg<std::string> arg_output_filename("o","filename","Filename to print to",true,"test.png","string"); cmd.add(arg_output_filename); TCLAP::ValueArg<std::string> arg_sp("p","starting_point","Start point of cutting plane",true,"(0.5,0.5,0.5)","3d-vector"); cmd.add(arg_sp); TCLAP::ValueArg<std::string> arg_v("v","vector1","Plane Vector 1",true,"(1,0,0)","3d-vector"); cmd.add(arg_v); TCLAP::ValueArg<std::string> arg_w("w","vector2","Plane Vector 2",true,"(0,0,1)","3d-vector"); cmd.add(arg_w); TCLAP::ValueArg<unsigned int> arg_s("s","scale","Scaling in px/angstrom",true, 200,"unsigned integer"); cmd.add(arg_s); TCLAP::ValueArg<std::string> arg_input_filename("i","input","Input file (i.e. CHGCAR)",true,"CHGCAR","filename"); cmd.add(arg_input_filename); TCLAP::SwitchArg arg_negative("n","negative_values","CHGCAR can contain negative values", cmd, false); cmd.parse(argc, argv); //************************************** // parsing values //************************************** std::string input_filename = arg_input_filename.getValue(); std::string output_filename = arg_output_filename.getValue(); pcrecpp::RE re("^([0-9.-]+),([0-9.-]+),([0-9.-]+)$"); std::string sp = arg_sp.getValue(); float sp_in[3]; re.FullMatch(sp.c_str() , &sp_in[0], &sp_in[1], &sp_in[2]); Vector s(sp_in[0],sp_in[1],sp_in[2]); std::string v = arg_v.getValue(); float v_in[3]; re.FullMatch(v.c_str() , &v_in[0], &v_in[1], &v_in[2]); Vector v1(v_in[0],v_in[1],v_in[2]); std::string w = arg_w.getValue(); float w_in[3]; re.FullMatch(w.c_str() , &w_in[0], &w_in[1], &w_in[2]); Vector v2(w_in[0],w_in[1],w_in[2]); float scale = arg_s.getValue(); bool negative_values = arg_negative.getValue(); //************************************** // start running the program //************************************** std::cout << "Running EDP" << std::endl; std::cout << "Lattice v1: " << v_in[0] << "," << v_in[1] << "," << v_in[2] << std::endl; std::cout << "Lattice v2: " << w_in[0] << "," << w_in[1] << "," << w_in[2] << std::endl; std::cout << "Start point: " << sp_in[0] << "," << sp_in[1] << "," << sp_in[2] << std::endl; // read in field ScalarField sf(input_filename.c_str()); sf.read(true); // define intervals in Angstrom float interval = 20.0; float li = -interval; float hi = interval; float lj = -interval; float hj = interval; float color_interval = 5; PlaneProjector pp(&sf, -color_interval, color_interval); pp.extract(v1, v2, s, scale, li, hi, lj, hj, negative_values); pp.plot(); pp.isolines(int(color_interval + 1)*2, negative_values); pp.write(output_filename); return 0; } catch (TCLAP::ArgException &e) { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; return -1; } }
int wmain(int argc, wchar_t** argv) { _setmode(_fileno(stdout), _O_U16TEXT); _setmode(_fileno(stderr), _O_U16TEXT); #else int main(int argc, char** argv) { #endif struct Arguments args = parse_args(argc, argv); if(!args.valid) { return EXIT_FAILURE; } bool success = true; for(size_t i = 0; i < args.num_filenames; ++i) { FILE* file = open_file(args.filenames[i]); struct TempFile* temp_file = make_temp_file("newline_%.tmp"); if(file == NULL) { arg_printerr( arg_f arg_s(": ") arg_f arg_s(": ") arg_f, argv[0], args.filenames[i], arg_strerror(errno) ); if(temp_file != NULL) { fclose(temp_file->file); delete(temp_file->filename); free_temp_file(temp_file); } success = false; } else if(temp_file == NULL) { arg_printerr( arg_f arg_s(": ") arg_f arg_s(": Unable to create temporary ") arg_s("file"), argv[0], args.filenames[i] ); fclose(file); success = false; } else { bool result = trim_file( file, temp_file->file, args.newline_type, args.trailing_newline, args.strip_whitespace ); if(result) { // Need to copy the temp file to original file. It would be // faster to just rename() the temporary file to the original // file, but this won't preserve file metadata such as // permission bits or owners. ReplaceFile() does this on // Windows, but an easy solution for Unix systems doesn't seem // to exist. fseeko(file, 0, SEEK_SET); fseeko(temp_file->file, 0, SEEK_SET); uint8_t* buffer = malloc(FileBufferLen); size_t read_bytes = fread( buffer, 1, FileBufferLen, temp_file->file ); while(read_bytes) { fwrite(buffer, 1, read_bytes, file); read_bytes = fread( buffer, 1, FileBufferLen, temp_file->file ); } free(buffer); off_t file_len = ftello(file); fflush(file); ftruncate(fileno(file), file_len); } if(args.verbose) { if(result) { arg_print( arg_s("Processed ") arg_f, args.filenames[i] ); } else { arg_print( arg_s("No changes made to ") arg_f, args.filenames[i] ); } } fclose(file); fclose(temp_file->file); delete(temp_file->filename); free_temp_file(temp_file); } } free_args(&args); if(!success) { return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { FILE *fp,*fp1; lock_node read,read1; head=NULL; enum { e_get, e_clr, deaf, slp } option; if (argc == 1) { fprintf(stderr, "Usage: %s [-mutex | -sem ]\n", argv[0]); } else if (argc == 2) { sleep_time=5; if (strcmp(argv[1], "-mutex") == 0) { option = e_get; } else if (strcmp(argv[1], "-sem") == 0) { option = e_clr; } else if (strcmp(argv[1], "-all") == 0) { option = deaf; } else { fprintf(stderr, "Usage: %s [-mutex | -sem ]\n", argv[0]); return 1; } } else if (argc == 3) { sleep_time=atoi(argv[1]); if (strcmp(argv[2], "-mutex") == 0) { option = e_get; } else if (strcmp(argv[2], "-sem") == 0) { option = e_clr; } else if (strcmp(argv[2], "-all") == 0) { option = deaf; } else { fprintf(stderr, "Usage: %s [-mutex | -sem ]\n", argv[0]); return 1; } } else { fprintf(stderr, "Usage: %s [-mutex | -sem ]\n", argv[0]); return 1; } switch (option) { case e_get: system("insmod mutex_lockstat.ko"); sleep(sleep_time); system("rmmod mutex_lockstat.ko"); fp=fopen("ab.txt","r"); arg_m(fp,read); remove("ab.txt"); break; case e_clr: system("insmod sem_lockstat.ko"); sleep(sleep_time); system("rmmod sem_lockstat.ko"); fp=fopen("ab2.txt","r"); arg_s(fp,read); remove("ab2.txt"); break; case deaf: system("insmod sem_lockstat.ko"); system("insmod mutex_lockstat.ko"); sleep(sleep_time); system("rmmod mutex_lockstat.ko"); system("rmmod sem_lockstat.ko"); fp=fopen("ab.txt","r"); fp1=fopen("ab2.txt","r"); arg_d(fp,fp1,read,read1); remove("ab2.txt"); remove("ab.txt"); break; default: break; } fclose(fp); print(); return 0; }