int main(){ /*--- message ---*/ printf("*********************************\n"); printf("*** Use SGESV to solve Ax = B ***\n"); printf("*********************************\n"); printf("\n"); /*--- open files that store data ---*/ OPEN_FILE(); /*--- read data ---*/ GET_DATA(); /*--- call lapack subroutine SGESV, note: ---*/ /*--- (1) all the arguments must be pointers ---*/ /*--- (2) add an underscore to the routine name ---*/ /*--- (3) matrices must be transformed into their Fortran vector formats ---*/ SGESV_(&n, &nrhs, AT, &lda, IPIV, BT, &ldb, &info); /*--- print the solution ---*/ PRINT_SOLUTION(); /*--- close files ---*/ fclose(fptA); fclose(fptB); return 0; }
stream::inout_sptr FATArchive::open(const EntryPtr id) { // TESTED BY: fmt_grp_duke3d_open // Make sure we're not trying to open a folder as a file //assert((id->fAttr & EA_FOLDER) == 0); // We can't do this because some folder formats have their FAT and // everything stored as a "file" in the parent archive, so the subfolder // code opens this file (even though it's flagged as a folder) and then // passes the data to the Archive. // We are casting away const here, but that's because we need to maintain // access to the EntryPtr, which we may need to "change" later (to update the // offset if another file gets inserted before it, i.e. any change would not // be visible externally.) FATEntryPtr pFAT = boost::dynamic_pointer_cast<FATEntry>(id); stream::sub_sptr psSub(new stream::sub()); stream::fn_truncate fnTrunc = boost::bind(&FATArchive::resizeSubstream, this, pFAT, _1); psSub->open( this->psArchive, pFAT->iOffset + pFAT->lenHeader, pFAT->storedSize, fnTrunc ); // Add it to the list of open files, in case we need to shift the substream // around later on as files are added/removed/resized. this->openFiles.insert(OPEN_FILE( pFAT, psSub )); return psSub; }
partition load_partition_info(char *bin_data_dir, int num, char *spec, double *time){ //loads partitioning information partition p; int i, n, id; FILE *fp; char fn[STRLEN], tmp[MAXSTRLEN]; float tm; sprintf(fn, "%s%s_%06d.txt", bin_data_dir, spec, num); if(!strcmp(spec, "sys")){ OPEN_FILE(fp, fn, "rt"); fscanf(fp, "@ %e", &tm); *time = (double)tm; fgets(tmp, MAXSTRLEN, fp); //skip the remainder of the line fscanf(fp, "@ %d", &n); fgets(tmp, MAXSTRLEN, fp); //skip the remainder of the line fscanf(fp, "@ %d", &id); fclose(fp); } else if(!strcmp(spec, "tec")){ OPEN_FILE(fp, fn, "rb"); fread(time, sizeof(double), 1, fp); fread(&n, sizeof(int), 1, fp); fread(&id, sizeof(int), 1, fp); fclose(fp); } else error(FUNCTION, "unknown spec = \"%s\"", spec); p.N = n; p.nodes = calloc(n, sizeof(cpudmn)); sprintf(fn, "%sfileMap_%06d.txt", bin_data_dir, id); OPEN_FILE(fp, fn, "rt"); fgets(tmp, MAXSTRLEN, fp); //skip first line for(i = 0; i < p.N; i++){ fgets(tmp, MAXSTRLEN, fp); if(strlen(tmp) < 2) error(FUNCTION, "inconsistent structure of file %s", fn); sscanf(tmp, "%d: (%d %d %d) - (%d %d %d)", &n, &(p.nodes[i].imin), &(p.nodes[i].jmin), &(p.nodes[i].kmin), &(p.nodes[i].imax), &(p.nodes[i].jmax), &(p.nodes[i].kmax)); //printf("cpu %d: (%d %d %d) - (%d %d %d)\n", n, p.nodes[i].imin, p.nodes[i].jmin, p.nodes[i].kmin, p.nodes[i].imax, p.nodes[i].jmax, p.nodes[i].kmax); } fclose(fp); return p; }
void load_domain_info(domain *dmn, char *bin_data_dir){ //loads domain information FILE *fp; char fn[STRLEN]; sprintf(fn, "%s/domain.bin", bin_data_dir); OPEN_FILE(fp, fn, "rb"); fread(&(dmn->h1), sizeof(double), 1, fp); fread(&(dmn->h2), sizeof(double), 1, fp); fread(&(dmn->h3), sizeof(double), 1, fp); fread(&(dmn->Lx), sizeof(double), 1, fp); fread(&(dmn->Ly), sizeof(double), 1, fp); fread(&(dmn->Lz), sizeof(double), 1, fp); fread(&(dmn->tau), sizeof(double), 1, fp); fread(&(dmn->imin), sizeof(int), 1, fp); fread(&(dmn->jmin), sizeof(int), 1, fp); fread(&(dmn->kmin), sizeof(int), 1, fp); fread(&(dmn->imax), sizeof(int), 1, fp); fread(&(dmn->jmax), sizeof(int), 1, fp); fread(&(dmn->kmax), sizeof(int), 1, fp); fclose(fp); if( (dmn->imin != dmn->imax)&&(dmn->jmin != dmn->jmax)&&(dmn->kmin != dmn->kmax) ){ dmn->dim = 3; dmn->mp_2D = 0; dmn->aa_1D = 0; } else if( (dmn->imin == dmn->imax)&&(dmn->jmin != dmn->jmax)&&(dmn->kmin != dmn->kmax) ){ dmn->dim = 2; dmn->mp_2D = 2; dmn->aa_1D = 0; } else if( (dmn->imin != dmn->imax)&&(dmn->jmin == dmn->jmax)&&(dmn->kmin != dmn->kmax) ){ dmn->dim = 2; dmn->mp_2D = 3; dmn->aa_1D = 0; } else if( (dmn->imin != dmn->imax)&&(dmn->jmin != dmn->jmax)&&(dmn->kmin == dmn->kmax) ){ dmn->dim = 2; dmn->mp_2D = 1; dmn->aa_1D = 0; } else if( (dmn->imin == dmn->imax)&&(dmn->jmin == dmn->jmax)&&(dmn->kmin != dmn->kmax) ){ dmn->dim = 1; dmn->mp_2D = 0; dmn->aa_1D = 3; } else if( (dmn->imin == dmn->imax)&&(dmn->jmin != dmn->jmax)&&(dmn->kmin == dmn->kmax) ){ dmn->dim = 1; dmn->mp_2D = 0; dmn->aa_1D = 2; } else{ dmn->dim = 1; dmn->mp_2D = 0; dmn->aa_1D = 1; } }
void load_plasma(marker *m, char *bin_data_dir, int num, int cpu){ //loads the plasma from checpoint for the current cpu long int N; char fn[STRLEN]; FILE *fp; sprintf(fn, "%splasma_%06d_%03d.bin", bin_data_dir, num, cpu); OPEN_FILE(fp, fn, "rb"); fread(&N, sizeof(long int), 1, fp); fread(m, sizeof(marker), (size_t)N, fp); fclose(fp); }
abstract_fstream::abstract_fstream( const char *filename, stream_mode mode) { switch(mode) { case io::in: _data = OPEN_FILE(filename, READ_MODE); break; case io::out: _data = OPEN_FILE(filename, WRITE_MODE); break; default: throw "Invalid mode"; } if(_data == INV_FILE) { #ifdef _DEBUG printf("abstract_fstream: Can not open file '%s' for %s\n", filename, mode == io::in ? "input" : "output"); #endif throw "Can not open file"; } }
int get_checkpoints_num(char *bin_data_dir, char *suffix){ //reads the number of saved checkpoints FILE *fp; char fn[STRLEN]; int num; sprintf(fn, "%s%s.N", bin_data_dir, suffix); OPEN_FILE(fp, fn, "r"); fscanf(fp, "@ %d", &num); fclose(fp); return num; }
void open_mesh_binary_files(char *bin_data_dir, char *source_spec, char *target_spec, int num, FILE **fs, int N){ //opens the binary files containing meshed data and positions heads at the beginning of useful data char fn[STRLEN]; int cpu; #if CPU_64_BIT == 1 #define HEADER_SIZE 112 #else #define HEADER_SIZE 108 #endif for(cpu = 0; cpu < N; cpu++){ sprintf(fn, "%s%s_%s_%06d(%03d).bin", bin_data_dir, source_spec, target_spec, num, cpu); OPEN_FILE(fs[cpu], fn, "rb"); fseek(fs[cpu], HEADER_SIZE, SEEK_SET); } }
int main(){ /*--- message ---*/ printf("******************************************\n"); printf("*** Use SGEEQU to equilibrate matrix A ***\n"); printf("******************************************\n"); printf("\n"); /*--- open files that store data ---*/ OPEN_FILE(); /*--- read data ---*/ GET_DATA(); /*--- compute smallest/largest safe numbers ---*/ SMLNUM = SLAMCH(&CMACH); BIGNUM = 1.0/SMLNUM; printf("SMLNUM = %e\n", SMLNUM); printf("BIGNUM = %e\n\n", BIGNUM); /*--- call lapack subroutine SGEEQU, note: ---*/ /*--- (1) all the arguments must be pointers ---*/ /*--- (2) add an underscore to the routine name ---*/ /*--- (3) matrices must be transformed into Fortran vector format ---*/ SGEEQU_(&m, &n, AT, &lda, R, C, &rowcnd, &colcnd, &amax, &info); /*--- print the solution ---*/ PRINT_SOLUTION(); /*--- write scaled matrix if there is one ---*/ SCALED_MATRIX(); /*--- close files ---*/ fclose(fptA); return 0; }
int plot_init(FILE **plt, int hor_pic_size, domain dmn, subdomain subdmn, int mmain_plane){ //initializes .plt file int vert_pic_size = 0; OPEN_FILE(*plt, "plot.plt", "wt"); fprintf(*plt, "#gnuplot plot file\n"); if(dmn.dim == 1) vert_pic_size = hor_pic_size*0.75; if(dmn.dim == 2){ if(dmn.mp_2D == 1) vert_pic_size = (hor_pic_size*(subdmn.jmax - subdmn.jmin)*dmn.h2)/((subdmn.imax - subdmn.imin)*dmn.h1) + VERT_EXTRA; if(dmn.mp_2D == 2) vert_pic_size = (hor_pic_size*(subdmn.kmax - subdmn.kmin)*dmn.h3)/((subdmn.jmax - subdmn.jmin)*dmn.h2) + VERT_EXTRA; if(dmn.mp_2D == 3) vert_pic_size = (hor_pic_size*(subdmn.kmax - subdmn.kmin)*dmn.h3)/((subdmn.imax - subdmn.imin)*dmn.h1) + VERT_EXTRA; } if(dmn.dim == 3){ if(mmain_plane == 1) vert_pic_size = (hor_pic_size*(subdmn.jmax - subdmn.jmin)*dmn.h2)/((subdmn.imax - subdmn.imin)*dmn.h1) + VERT_EXTRA; if(mmain_plane == 2) vert_pic_size = (hor_pic_size*(subdmn.kmax - subdmn.kmin)*dmn.h3)/((subdmn.jmax - subdmn.jmin)*dmn.h2) + VERT_EXTRA; if(mmain_plane == 3) vert_pic_size = (hor_pic_size*(subdmn.kmax - subdmn.kmin)*dmn.h3)/((subdmn.imax - subdmn.imin)*dmn.h1) + VERT_EXTRA; } fprintf(*plt, "set term png large size %d,%d\n", hor_pic_size, vert_pic_size); return vert_pic_size; }
static void init_data(args_t *args) { int i; if ( args->nflt ) { if ( args->nflt > 1 && args->nflt!=args->files->nreaders ) error("Error: expected either one -i/-e option or as many as there are input files\n"); if ( args->nflt < args->files->nreaders ) { if ( !args->flt_expr[0] ) error("Error: useless use of -i/-e\n"); args->nflt = args->files->nreaders; args->flt_expr = (char**) realloc(args->flt_expr,sizeof(char*)*args->nflt); args->flt_logic = (int*) realloc(args->flt_logic,sizeof(int)*args->nflt); args->flt = (filter_t**) realloc(args->flt,sizeof(filter_t*)*args->nflt); for (i=1; i<args->nflt; i++) { args->flt_expr[i] = args->flt_expr[0]; args->flt_logic[i] = args->flt_logic[0]; args->flt[i] = filter_init(args->files->readers[i].header,args->flt_expr[i]); } args->flt[0] = filter_init(args->files->readers[0].header,args->flt_expr[0]); } else { for (i=0; i<args->files->nreaders; i++) { if ( !args->flt_expr[i] ) continue; args->flt[i] = filter_init(args->files->readers[i].header,args->flt_expr[i]); } } } if ( args->isec_op==OP_EXACT ) { if ( strlen(args->isec_exact)!=args->files->nreaders ) error("The number of files does not match the bitmask: %d vs %s\n", args->files->nreaders,args->isec_exact); for (i=0; i<args->files->nreaders; i++) if ( args->isec_exact[i]!='0' && args->isec_exact[i]!='1' ) error("Unexpected bitmask: %s\n",args->isec_exact); for (i=0; i<args->files->nreaders; i++) args->isec_exact[i] -= '0'; } // Which files to write: parse the string passed with -w char *p = args->write_files; while (p && *p) { if ( !args->write ) args->write = (int*) calloc(args->files->nreaders,sizeof(int)); if ( sscanf(p,"%d",&i)!=1 ) error("Could not parse --write %s\n", args->write_files); if ( i<0 || i>args->files->nreaders ) error("The index is out of range: %d (%s)\n", i, args->write_files); args->write[i-1] = 1; args->iwrite = i-1; args->nwrite++; while (*p && *p!=',') p++; if ( *p==',' ) p++; } if ( args->nwrite>1 && !args->prefix ) error("Expected -p when mutliple output files given: --write %s\n", args->write_files); if ( args->isec_op==OP_COMPLEMENT && args->nwrite ) { if ( args->nwrite>1 ) error("Multiple files to -w make no sense with -C\n"); if ( !args->write[0] ) error("Only -w1 makes sense with -C\n"); } if ( args->prefix ) { // Init output directory and create the readme file args->fh_log = open_file(NULL,"w","%s/README.txt", args->prefix); if ( !args->fh_log ) error("%s/README.txt: %s\n", args->prefix, strerror(errno)); fprintf(args->fh_log,"This file was produced by vcfisec.\n"); fprintf(args->fh_log,"The command line was:\tbcftools %s ", args->argv[0]); int i; for (i=1; i<args->argc; i++) fprintf(args->fh_log," %s",args->argv[i]); fprintf(args->fh_log,"\n\nUsing the following file names:\n"); const char *suffix = "vcf"; if ( args->output_type & FT_BCF ) suffix = "bcf"; else if ( args->output_type & FT_GZ ) suffix = "vcf.gz"; // Open output files and write the legend if ( args->isec_op==OP_VENN ) { args->fh_out = (htsFile**) malloc(sizeof(htsFile*)*4); args->fnames = (char**) calloc(4,sizeof(char*)); #define OPEN_FILE(i,j) { \ open_file(&args->fnames[i], NULL, "%s/%04d.%s", args->prefix, i, suffix); \ args->fh_out[i] = hts_open(args->fnames[i], hts_bcf_wmode(args->output_type)); \ if ( !args->fh_out[i] ) error("Could not open %s\n", args->fnames[i]); \ if ( args->n_threads ) hts_set_threads(args->fh_out[i], args->n_threads); \ if (args->record_cmd_line) bcf_hdr_append_version(args->files->readers[j].header,args->argc,args->argv,"bcftools_isec"); \ bcf_hdr_write(args->fh_out[i], args->files->readers[j].header); \ } if ( !args->nwrite || args->write[0] ) { OPEN_FILE(0,0); fprintf(args->fh_log,"%s\tfor records private to\t%s\n", args->fnames[0], args->files->readers[0].fname); } if ( !args->nwrite || args->write[1] ) { OPEN_FILE(1,1); fprintf(args->fh_log,"%s\tfor records private to\t%s\n", args->fnames[1], args->files->readers[1].fname); } if ( !args->nwrite || args->write[0] ) { OPEN_FILE(2,0); fprintf(args->fh_log,"%s\tfor records from %s shared by both\t%s %s\n", args->fnames[2], args->files->readers[0].fname, args->files->readers[0].fname, args->files->readers[1].fname); } if ( !args->nwrite || args->write[1] ) { OPEN_FILE(3,1); fprintf(args->fh_log,"%s\tfor records from %s shared by both\t%s %s\n", args->fnames[3], args->files->readers[1].fname, args->files->readers[0].fname, args->files->readers[1].fname); } } else { // Init one output file for each reader args->fh_out = (htsFile**) calloc(args->files->nreaders, sizeof(htsFile*)); args->fnames = (char**) calloc(args->files->nreaders, sizeof(char*)); for (i=0; i<args->files->nreaders; i++) { if ( args->write && !args->write[i] ) continue; if ( args->isec_op==OP_COMPLEMENT && i>0 ) break; OPEN_FILE(i,i); fprintf(args->fh_log,"%s\tfor stripped\t%s\n", args->fnames[i], args->files->readers[i].fname); } #undef OPEN_FILE args->fh_sites = open_file(NULL, "w", "%s/sites.txt", args->prefix); if ( !args->fh_sites ) error("%s/sites.txt: %s\n", args->prefix, strerror(errno)); } } else { if (args->output_fname) { args->fh_sites = fopen(args->output_fname, "w"); if ( args->fh_sites == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); } else args->fh_sites = pysam_stdout; } }
static void init_data(args_t *args) { // Which files to write: parse the string passed with -w char *p = args->write_files; while (p && *p) { int i; if ( !args->write ) args->write = (int*) calloc(args->files->nreaders,sizeof(int)); if ( sscanf(p,"%d",&i)!=1 ) error("Could not parse --write %s\n", args->write_files); if ( i<0 || i>args->files->nreaders ) error("The index is out of range: %d (%s)\n", i, args->write_files); args->write[i-1] = 1; args->iwrite = i-1; args->nwrite++; while (*p && *p!=',') p++; if ( *p==',' ) p++; } if ( args->nwrite>1 && !args->prefix ) error("Expected -p when mutliple output files given: --write %s\n", args->write_files); if ( args->isec_op==OP_COMPLEMENT && args->nwrite ) { if ( args->nwrite>1 ) error("Multiple files to -w make no sense with -C\n"); if ( !args->write[0] ) error("Only -w1 makes sense with -C\n"); } if ( args->prefix ) { // Init output directory and create the readme file args->fh_log = open_file(NULL,"w","%s/README.txt", args->prefix); if ( !args->fh_log ) error("%s/README.txt: %s\n", args->prefix, strerror(errno)); fprintf(args->fh_log,"This file was produced by vcfisec.\n"); fprintf(args->fh_log,"The command line was:\tbcftools %s ", args->argv[0]); int i; for (i=1; i<args->argc; i++) fprintf(args->fh_log," %s",args->argv[i]); fprintf(args->fh_log,"\n\nUsing the following file names:\n"); const char *suffix = "vcf"; if ( args->output_type & FT_BCF ) suffix = "bcf"; else if ( args->output_type & FT_GZ ) suffix = "vcf.gz"; // Open output files and write the legend if ( args->isec_op==OP_VENN ) { args->fh_out = (htsFile**) malloc(sizeof(htsFile*)*3); args->fnames = (char**) malloc(sizeof(char*)*3); #define OPEN_FILE(i,j) { \ open_file(&args->fnames[i], NULL, "%s/%04d.%s", args->prefix, i, suffix); \ args->fh_out[i] = hts_open(args->fnames[i], hts_bcf_wmode(args->output_type)); \ if ( !args->fh_out[i] ) error("Could not open %s\n", args->fnames[i]); \ bcf_hdr_append_version(args->files->readers[j].header,args->argc,args->argv,"bcftools_isec"); \ bcf_hdr_write(args->fh_out[i], args->files->readers[j].header); \ } OPEN_FILE(0,0); fprintf(args->fh_log,"%s\tfor records private to\t%s\n", args->fnames[0], args->files->readers[0].fname); OPEN_FILE(1,1); fprintf(args->fh_log,"%s\tfor records private to\t%s\n", args->fnames[1], args->files->readers[1].fname); OPEN_FILE(2,0); fprintf(args->fh_log,"%s\tfor records shared by both\t%s %s\n", args->fnames[2], args->files->readers[0].fname, args->files->readers[1].fname); } else { // Init one output file for each reader args->fh_out = (htsFile**) calloc(args->files->nreaders, sizeof(htsFile*)); args->fnames = (char**) calloc(args->files->nreaders, sizeof(char*)); for (i=0; i<args->files->nreaders; i++) { if ( args->write && !args->write[i] ) continue; if ( args->isec_op==OP_COMPLEMENT && i>0 ) break; OPEN_FILE(i,i); fprintf(args->fh_log,"%s\tfor stripped\t%s\n", args->fnames[i], args->files->readers[i].fname); } #undef OPEN_FILE args->fh_sites = open_file(NULL, "w", "%s/sites.txt", args->prefix); if ( !args->fh_sites ) error("%s/sites.txt: %s\n", args->prefix, strerror(errno)); } } else args->fh_sites = stdout; }
int main(int argn, char **argv) { /* Initialize QT application */ QApplication app(argn, argv); /* Handle signals, sent by program by * telling about them to user and * ending the execution */ LLCCEP_exec::cAttachSignalsHandler(); try { /* Windows, created by the executing program */ ::std::vector<LLCCEP_exec::window *> windows; ; /* Command-line parameters */ LLCCEP_tools::commandLineParametersParser clpp; clpp.addFlag(LLCCEP_tools::commandLineFlag{{"--help", "-h"}, "help", false}); clpp.setHelpText("LLCCEP debugger help:\n" "-h/--help | show help(this text)\n" "The single free parameter will be input " "program"); clpp.setMaxFreeParams(1); /* Parse command-line parameters */ clpp.parse(argn, argv); /* If needed to show help, show it * and end the execution */ if (clpp.getParam("help") == "1" || !clpp.getFreeParams().size()) { if (!clpp.getFreeParams().size()) ::std::cerr << "No input!" << ::std::endl; clpp.showHelp(); return 0; } /* Soft-processor */ LLCCEP_exec::softcore sc; /* Memeory manager */ LLCCEP_exec::memoryManager mm; /* Program reader */ LLCCEP::codeReader cr; ::std::FILE *in; OPEN_FILE(in, clpp.getFreeParams()[0].c_str(), "r"); /* Read program's common information */ cr.initializeInputFile(in); cr.readProgramHeader(); /* Initialize soft-processor data */ sc.setMm(&mm); sc.setCodeReader(&cr); /* Execute program */ sc.executeProgram(); /* Close input */ ::std::fclose(in); } catch (LLCCEP::runtime_exception &exc) { /* Spawn message box in case of * internal exception */ LLCCEP_exec::messageBox("Program was interrupted by an exception", exc.msg(), QMessageBox::Close, QMessageBox::Close, QMessageBox::Critical).spawn(); /* Dump to console error information */ QUITE_ERROR(yes, "Program was interrupted by an exception:\n" "%s", exc.msg()); } catch (::std::exception &exc) { /* Spawn message box in case of * internal exception */ LLCCEP_exec::messageBox("Program was interrupted by an exception", exc.what(), QMessageBox::Close, QMessageBox::Close, QMessageBox::Critical).spawn(); /* Dump to console error information and exit */ QUITE_ERROR(yes, "Program was interrupted by an exception:\n" "%s", exc.what()); } catch (::std::string &err) { /* Dump to console error information and exit */ QUITE_ERROR(yes, "%s", err.c_str()); } catch (int64_t id) { /* Dump to console error information and exit */ QUITE_ERROR(yes, "Error " int64_t_pf, id); } catch (...) { /* Dump to console error information and exit */ QUITE_ERROR(yes, "Unknown exception"); } return 0; }
void plot_fourier_transform(domain dmn, special_task st, int mmain_plane, int_array mcuts, arr2d A, int i_slice, int num, FILE *plt, int hor_pic_size, int vert_pic_size, double time){ //saves a number of cuts for fourier components into dat-files using procedures save_dat_file int i, j, flag; double kxmin = 0, kymin = 0, kxmax = 0, kymax = 0, kx, ky, kxmin_bound = 0, kxmax_bound = 0, kymin_bound = 0, kymax_bound = 0; double z = 0; char str[STRLEN]; char xlabel[16], ylabel[16], zlabel[2]; FILE *fp; #define BOUNDS_F(kxmin_, kxmax_, kymin_, kymax_, hx_, hy_, hz_, xlabel_, ylabel_, zlabel_){ \ kxmin = -1./(2*hx_); \ kxmax = 1./(2*hx_); \ kymin = -1./(2*hy_); \ kymax = 1./(2*hy_); \ if(st.enable_intervals){ \ kxmin_bound = kxmin_; \ kxmax_bound = kxmax_; \ kymin_bound = kymin_; \ kymax_bound = kymax_; \ } \ else{ \ kxmin_bound = kxmin; \ kxmax_bound = kxmax; \ kymin_bound = kymin; \ kymax_bound = kymax; \ } \ z = hz_*mcuts.data[i_slice]; \ sprintf(xlabel, "%s", xlabel_); \ sprintf(ylabel, "%s", ylabel_); \ sprintf(zlabel, "%s", zlabel_); \ } if(dmn.dim == 3){ if(mmain_plane == 1) BOUNDS_F(st.ix.min, st.ix.max, st.iy.min, st.iy.max, dmn.h1, dmn.h2, dmn.h3, "lambda k_x", "lambda k_y", "z"); if(mmain_plane == 2) BOUNDS_F(st.iy.min, st.iy.max, st.iz.min, st.iz.max, dmn.h2, dmn.h3, dmn.h1, "lambda k_y", "lambda k_z", "x"); if(mmain_plane == 3) BOUNDS_F(st.ix.min, st.ix.max, st.iz.min, st.iz.max, dmn.h1, dmn.h3, dmn.h2, "lambda k_x", "lambda k_z", "y"); } else if(dmn.dim == 2){ if(dmn.mp_2D == 1) BOUNDS_F(st.ix.min, st.ix.max, st.iy.min, st.iy.max, dmn.h1, dmn.h2, 0, "lambda k_x", "lambda k_y", ""); if(dmn.mp_2D == 2) BOUNDS_F(st.iy.min, st.iy.max, st.iz.min, st.iz.max, dmn.h2, dmn.h3, 0, "lambda k_y", "lambda k_z", ""); if(dmn.mp_2D == 3) BOUNDS_F(st.ix.min, st.ix.max, st.iz.min, st.iz.max, dmn.h1, dmn.h3, 0, "lambda k_x", "lambda k_z", ""); } else{ if(dmn.aa_1D == 1) BOUNDS_F(st.ix.min, st.ix.max, 0, 1, dmn.h1, 1, 0, "lambda k_x", "", ""); if(dmn.aa_1D == 2) BOUNDS_F(st.iy.min, st.iy.max, 0, 1, dmn.h2, 1, 0, "lambda k_y", "", ""); if(dmn.aa_1D == 3) BOUNDS_F(st.iz.min, st.iz.max, 0, 1, dmn.h3, 1, 0, "lambda k_z", "", ""); } sprintf(str, "dat/spectr_%06d(%03d).dat", num, i_slice); OPEN_FILE(fp, str, "w"); if(dmn. dim > 1){ flag = 0; for(i = 0; i < A.nx; i++){ for(j = 0; j < A.ny; j++){ kx = kxmax*(i+0.5-A.nx/2)*2/A.nx; ky = kymax*(j+0.5-A.ny/2)*2/A.ny; if(in(kx, kxmin_bound, kxmax_bound) && in(ky, kymin_bound, kymax_bound)){ if(flag == 0){ flag = 1; arr2d_set_ij(arr2d_ij(A, i, j) + VERY_SMALL_VALUE, &A, i, j); //for gnuplot } fprintf(fp, "%e %e %e\n", kx, ky, arr2d_ij(A, i, j)); } } fprintf(fp, "\n"); } } else{ for(i = 0; i < A.nx; i++){ kx = kxmax*(i+0.5-A.nx/2)*2/A.nx; if(in(kx, kxmin_bound, kxmax_bound)) fprintf(fp, "%e %e\n", kx, arr2d_ij(A, i, 0)); } } fclose(fp); fprintf(plt, "set output 'pics/spectr_%06d(%03d).png'\n", num, i_slice); if(dmn.dim == 3) fprintf(plt, "set title 'energy spectral density: cut at %s = %.2f lambdas, time = %.2f waveperiods'\n", zlabel, z, time); else fprintf(plt, "set title 'energy spectral density: time = %.2f waveperiods'\n", time); fprintf(plt, "set xlabel '%s'\n", xlabel); fprintf(plt, "set ylabel '%s'\n", ylabel); if(dmn.dim > 1){ fprintf(plt, "set term png large size %d,%d\n", hor_pic_size, (int)((hor_pic_size*kymax_bound)/kxmax_bound + VERT_EXTRA)); fprintf(plt, "set pm3d map\n"); fprintf(plt, "splot 'dat/spectr_%06d(%03d).dat' notitle\n", num, i_slice); } else{ fprintf(plt, "set term png large size %d,%d\n", hor_pic_size, (int)(hor_pic_size*0.75)); fprintf(plt, "set grid\n"); fprintf(plt, "plot 'dat/spectr_%06d(%03d).dat' w l notitle\n", num, i_slice); fprintf(plt, "unset grid\n"); } fprintf(plt, "set term png large size %d,%d\n", hor_pic_size, vert_pic_size); }
void df_plot(distrib_function_task dt, arr2d df, int hor_pic_size, int vert_pic_size, int num, double time, FILE *plt){ //saves distribution function data and updates plot file FILE *fp; char str[STRLEN], xlabel[32], ylabel[32]; int i, j, sum = 0; double x, y; sprintf(str, "dat/df_%06d.dat", num); OPEN_FILE(fp, str, "w"); if((df.nx > 1)&&(df.ny > 1)) arr2d_set_ij(arr2d_ij(df, 0, 0) + 1, &df, 0, 0); for(i = 0; i < dt.nhist1; i++){ x = dt.i1.min + (i+0.5)*(dt.i1.max-dt.i1.min)/dt.nhist1; if(dt.sum == 2){ for(j = 0; j < dt.nhist2; j++){ y = dt.i2.min + (j+0.5)*(dt.i2.max-dt.i2.min)/dt.nhist2; if(!dt.log_distr) fprintf(fp, "%e %e %.0f\n", x, y, arr2d_ij(df, i, j)); else fprintf(fp, "%e %e %e\n", x, y, log(1 + arr2d_ij(df, i, j))); } fprintf(fp, "\n"); } else{ if(!dt.log_distr) fprintf(fp, "%e %.0f\n", x, arr2d_ij(df, i, 0)); else fprintf(fp, "%e %e\n", x, log(1 + arr2d_ij(df, i, 0))); } } fclose(fp); fprintf(plt, "set term png large size %d,%d\n", hor_pic_size, (int)(hor_pic_size*0.75)); #define MKLABEL(label_) { \ if(sum == 0) sprintf(xlabel, "%s", label_); \ else sprintf(ylabel, "%s", label_); \ sum++; \ } if(dt.x) MKLABEL("x/lambda"); if(dt.y) MKLABEL("y/lambda"); if(dt.z) MKLABEL("z/lambda"); if(dt.px) MKLABEL("p_x/mc"); if(dt.py) MKLABEL("p_y/mc"); if(dt.pz) MKLABEL("p_z/mc"); if(dt.gamma) MKLABEL("particles gamma factor"); if(dt.theta_pos_x) MKLABEL("theta_pos_x"); if(dt.theta_pos_y) MKLABEL("theta_pos_y"); if(dt.theta_pos_z) MKLABEL("theta_pos_z"); if(dt.theta_mom_x) MKLABEL("theta_mom_x"); if(dt.theta_mom_y) MKLABEL("theta_mom_y"); if(dt.theta_mom_z) MKLABEL("theta_mom_z"); if(dt.phi_pos_xy) MKLABEL("phi_pos_xy"); if(dt.phi_pos_yz) MKLABEL("phi_pos_yz"); if(dt.phi_pos_xz) MKLABEL("phi_pos_xz"); if(dt.phi_mom_xy) MKLABEL("phi_mom_xy"); if(dt.phi_mom_yz) MKLABEL("phi_mom_yz"); if(dt.phi_mom_xz) MKLABEL("phi_mom_xz"); if(dt.sum == 1){ if(!dt.log_distr) sprintf(ylabel, "delta N"); else sprintf(ylabel, "ln ( 1 + delta N )"); } fprintf(plt, "set output 'pics/df_%06d.png'\n", num); sprintf(str, "q/m = %f", dt.q_div_m); fprintf(plt, "set title 'Particle %shistogram", dt.log_distr?"logarithmic ":""); if((dt.q_div_m <= MAX_Q_DIV_M)||(dt.energy_filter)) fprintf(plt, " for particles having "); fprintf(plt, "%s", (dt.q_div_m > MAX_Q_DIV_M)?"":str); sprintf(str, "gamma in [%.3e, %.3e]", dt.ef.min, dt.ef.max); fprintf(plt, "%s%s", ((dt.q_div_m <= MAX_Q_DIV_M)?" and ":""), (dt.energy_filter?str:"")); fprintf(plt, ": t = %.2f'\n", time); fprintf(plt, "set xlabel '%s'\n", xlabel); fprintf(plt, "set ylabel '%s'\n", ylabel); if(dt.sum == 2){ fprintf(plt, "set pm3d map\n"); fprintf(plt, "splot 'dat/df_%06d.dat' using 1:2:3 notitle\n", num); fprintf(plt, "unset pm3d\n"); } else{ fprintf(plt, "set grid\n"); fprintf(plt, "plot 'dat/df_%06d.dat' w l notitle\n", num); fprintf(plt, "unset grid\n"); } fprintf(plt, "set term png large size %d,%d\n", hor_pic_size, vert_pic_size); }
INPUT_INFO* parse_input(const char* file_name) { /* hf 6-31g* 0 1 N 7 0.0000000000 0.0000000000 0.0000000000 N 7 0.0000000000 0.0000000000 1.0980000000 */ int i = 0, j; FILE *f; INPUT_INFO *inputFile; char BasisFile[20] = "EMSL/"; // save the name of basis file char method[5], basisName[10]; ATOM_INFO *atomList; COORD *coord; int gCount = 0, basisCount; // initial allocate 100 basis function, 300 GTO; inputFile = calloc(sizeof(INPUT_INFO), 1); atomList = inputFile->atomList = malloc(sizeof(ATOM_INFO)*INITIAL_ATOM_COUNT); coord = inputFile->gXYZ = malloc(sizeof(COORD) * INITIAL_ATOM_COUNT); OPEN_FILE(f, file_name); // read the control parameter like Gaussian 09 fscanf(f, "%s%s", method, basisName); // Get the electronic count and multidegree of the system fscanf(f, "%d%u", &inputFile->icharge, &inputFile->imult); #if DEBUG_OUTPUT_INPUTFILE fprintf(stdout, "%s %s\n\n%d %u\n", method, basisName, inputFile->icharge, inputFile->imult); #endif // read the atom information include atom Number and coordination while (fscanf(f, "%s%d%lf%lf%lf", atomList[i].symbol, &atomList[i].n, &coord[i].x, &coord[i].y, &coord[i].z) != EOF) { // tranverse ANGS to BOHR coord[i].x *= ANGS_2_BOHR; coord[i].y *= ANGS_2_BOHR; coord[i].z *= ANGS_2_BOHR; #if DEBUG_OUTPUT_INPUTFILE fprintf(stdout, "%s %d %lf %lf %lf\n", atomList[i].symbol, atomList[i].n, coord[i].x, coord[i].y, coord[i].z); #endif // connect the coordination inputFile->atomList[i].cid = i; inputFile->atomCount++; i++; } fclose(f); // release redundant memory REALLOC(inputFile->atomList, inputFile->atomCount * sizeof(ATOM_INFO)); // ---------------------------------------------------------------- // Read Basis information from the basis function database // ---------------------------------------------------------------- inputFile->basisSet = malloc(sizeof(BASIS)* INITIAL_BASIS_COUNT); inputFile->gp = malloc(sizeof(GTO_PARTIAL)* INDEPENDENT_GTO_COUNT); inputFile->gtoSet = malloc(sizeof(GTO)* INDEPENDENT_GTO_COUNT); Get_Basis_File(basisName, BasisFile); OPEN_FILE(f, BasisFile); readbasis(f, inputFile); fclose(f); /* ---------------------------------------------------------------- * allocate memory for store P, K, gamma * ---------------------------------------------------------------- */ gCount = inputFile->gCount; basisCount = inputFile->basisCount; #if DEBUG_INPUT fprintf(stdout, "%d %d %d\n", gCount, inputFile->gtoCount, basisCount); for (i = 0; i < gCount; i++) fprintf(stdout, "%d %lf %lf\n", i, inputFile->gp[i].alpha, inputFile->gp[i].coeff); #endif inputFile->K = (double **)malloc(sizeof(double *) * gCount); inputFile->zeta = (double **)malloc(sizeof(double *) * gCount); inputFile->P = (COORD **)malloc(sizeof(COORD *) * gCount); for (i = 0; i < gCount; i ++) { MALLOC(inputFile->K[i], sizeof(double) * gCount); MALLOC(inputFile->zeta[i], sizeof(double) * gCount); MALLOC(inputFile->P[i], sizeof(COORD) * gCount); } for (i = 0; i < gCount; i++) { for (j = 0; j <= i; j++) { // compute \zeta = \alpha_1 + \alpha_2 inputFile->zeta[i][j] = inputFile->zeta[j][i] = inputFile->gp[i].alpha + inputFile->gp[j].alpha; // compute K = f(\alpha_1, \alpha_2, AB) inputFile->K[i][j] = inputFile->K[j][i] = K_OS(&inputFile->gp[i], &inputFile->gp[j], inputFile->gXYZ); // compute P Gaussian_product_center(&inputFile->gp[i], &inputFile->gp[j], inputFile->gXYZ, &inputFile->P[i][j]); inputFile->P[j][i] = inputFile->P[i][j]; #if DEBUG_ZETA_K_P fprintf(stdout, "i, j: %d %d\nzeta = %lf\tK = %lf\tP: %lf %lf %lf\n", i, j, inputFile->zeta[i][j], inputFile->K[i][j], inputFile->P[i][j].x, inputFile->P[i][j].y, inputFile->P[i][j].z); #endif } } return inputFile; }