static int fs_cd_file(const char *filename) { struct directory d; if (is_cwd_zip()) { return fs_cd_file_zip(sf_list_tail(&fs.directories), filename); } if (strcmp(filename, "..") == 0) { if (sf_list_cnt(&fs.directories)) { sf_list_pop(&fs.directories); } return chdir(".."); } else { if (directory_init(&d, filename) != SF_OK) { return SF_ERR; } sf_list_push(&fs.directories, &d); if (!d.iszip) { return chdir(filename); } } return SF_OK; }
int fs_cd(const char *pathname) { if (pathname[0] == seperator || pathname[0] == '/') { /* absolute path */ struct directory d; sf_list_clear(&fs.directories); directory_init(&d, "/"); d.name[0] = '\0'; sf_list_push(&fs.directories, &d); chdir("/"); if (pathname[1] != '\0') { fs_cd(pathname + 1); } #ifdef __WIN32__ } else if (pathname[1] == ':') { char buf[3]; snprintf(buf, 3, "%c:", pathname[0]); sf_list_clear(&fs.directories); chdir(buf); if (pathname[2] != '\0') { fs_cd(pathname + 2); } else { fs_cd("/"); } #endif } else { /* relative path */ char buf[PATH_MAX]; char *ptr; char delim[2]; strncpy(buf, pathname, PATH_MAX); delim[0] = seperator; delim[1] = '\0'; ptr = strtok(buf, delim); while (ptr) { if (strcmp(ptr, ".") != 0) { if (fs_cd_file(ptr) != SF_OK) { break; } } ptr = strtok(NULL, delim); } } return SF_OK; }
int main(int argc, char *argv[]) { // Set directory structure directory_init(argc, argv); // Read input file main_read_input(); // Read and sort output directory for finding files within our time limits init_part_files(); // Get number of particles nparts = cgns_read_nparts(); // Initialize domain and flow arrays #ifdef DEBUG show_domain(); #endif // Create output directory create_output(); // Loop over time //double inparts = 1./nparts; //double inFiles = 1./nFiles; for (int tt = 0; tt < nFiles; tt++) { int sum = cgns_fill_parts(tt); printf("t = %lf, sum = %d\n", partFileTime[tt], sum); // write to file write_mean(tt, sum); } // Free and exit free_vars(); return EXIT_SUCCESS; }
//fill buffer, make dirs int SD_SystemInit(void) { FRESULT res; FIL fsrc; // file objects unsigned int br; memset(&sd_file_manage, 0, sizeof(sd_file_manage_t)); //初始化全局变量 memset(&gWritebuf, 0, sizeof(gWritebuf)); gWritebuf.wbuf = WriteDataBuf; f_mount(&fs, "", 0); // Register a work area to logical drive 0 /*缓存将要写的数据*/ res = f_open(&fsrc, "wdata.fsn", FA_READ | FA_OPEN_EXISTING); if (res != FR_OK) { DBG_print(DBG_ERROR, "open file err, %d", res); goto err1; } res = f_read(&fsrc, gWritebuf.wbuf, fsrc.fsize, &gWritebuf.length); if (res != FR_OK) { DBG_print(DBG_ERROR, "read file err, %d", res); goto err1; } gWritebuf.validSign = 1; res = f_close(&fsrc); if (res != FR_OK) { DBG_print(DBG_ERROR, "close file err, %d", res); goto err1; } /*创建目录结构*/ res = f_mkdir(FSN_PATH); if (res != FR_OK && res != FR_EXIST) { DBG_print(DBG_ERROR, "mkdir %s err, %d", FSN_UNLOAD_PATH, res); goto err2; } res = f_mkdir(TXT_PATH); if (res != FR_OK && res != FR_EXIST) { DBG_print(DBG_ERROR, "mkdir %s err, %d", FSN_UNLOAD_PATH, res); goto err2; } res = f_mkdir(FSN_UNLOAD_PATH); if (res != FR_OK && res != FR_EXIST) { DBG_print(DBG_ERROR, "mkdir %s err, %d", FSN_UNLOAD_PATH, res); goto err2; } res = f_mkdir(FSN_LOADED_PATH); if (res != FR_OK && res != FR_EXIST) { DBG_print(DBG_ERROR, "mkdir %s err, %d", FSN_LOADED_PATH, res); goto err2; } res = f_mkdir(TXT_UNLOAD_PATH); if (res != FR_OK && res != FR_EXIST) { DBG_print(DBG_ERROR, "mkdir %s err, %d", TXT_UNLOAD_PATH, res); goto err2; } res = f_mkdir(TXT_LOADED_PATH); if (res != FR_OK && res != FR_EXIST) { DBG_print(DBG_ERROR, "mkdir %s err, %d", TXT_LOADED_PATH, res); goto err2; } directory_init("\\FSN\\UNLOAD", "*.FSN"); // traverse_subcatalog("\\FSN\\UNLOAD", &sd_file_manage, "*"); // traverse_subcatalog("\\FSN\\UNLOAD\\20160309", &sd_file_manage, L"*.*"); return 0; err1: DBG_print(DBG_ERROR, "prepare write file buffer err"); return 1; err2: DBG_print(DBG_ERROR, "make dirs err"); return 2; }
static int serve_client_out(CLIENT *client, int sock, const char *dir, const char *hostname) { FILE *fp = NULL; FILESTATS fstats; int i, connected, file_readcnt, file_sendcnt, buflen, nbytes; const char *path; char out_dir[PATH_LEN+1]; unsigned char buf[CH_MSG_SIZE]; DIRECTORY directory; /* create incoming file path */ sprintf(out_dir, "%s/%s/%s", dir, client->hostname, CHOUSESYS_OUTLOC); if ( !directory_exists(out_dir) ) { fprintf(stderr, "%s: %s: error: non-existant out directory: %s\n", timestamp(), ProgName, out_dir); return 1; } directory_init(&directory, out_dir); directory_open(&directory); /* Set file send count to 0 */ errno = 0; file_readcnt = 0; file_sendcnt = 0; connected = TRUE; while ( (path = directory_list(&directory)) ) { /* Set file statistics to 0 */ memset(&fstats, 0, sizeof(fstats)); if ( (fstats.name = (char *)strrchr(path, '/')) == NULL ) fstats.name = path; /* no path in path */ else fstats.name++; /* skip leading '/' */ #ifdef DEBUG if ( Debug > 2 ) { PRINT_DBGLOC; fprintf(stderr, "sending %s\n", fstats.name); } #endif if ( (fp = fopen(path, "r")) == NULL ) { /* soft error */ fprintf(stderr, "%s: %s: error: couldn't open %s: %s\n", timestamp(), ProgName, basename(path), strerror(ferror(fp))); continue; } file_readcnt++; /* send current file */ while ( fstats.filesize == fstats.socksize ) { if ( (buflen = fread(buf, sizeof(*buf), sizeof(buf), fp)) == 0 ) { /* finished reading file */ break; } #ifdef DEBUG if ( Debug > 7 ) { PRINT_DBGLOC; print_sockseg(buf, buflen); } #endif fstats.filesize += buflen; fstats.socksize += send(sock, buf, buflen, 0); } if ( fstats.filesize != fstats.socksize ) { /* error */ fstats.transfered = FALSE; } else { /* finished sending file data - now send eod string */ nbytes = send(sock, client->eod.hex_buf, client->eod.hex_buflen, 0); if ( nbytes != client->eod.hex_buflen ) { /* error */ fprintf(stderr, "%s: %s: warning: send end-of-data to %s failed\n", timestamp(), ProgName, hostname); fstats.transfered = FALSE; } else { fstats.transfered = TRUE; #ifdef DEBUG if ( Debug > 3 ) { PRINT_DBGLOC; print_sockseg(client->eod.hex_buf, client->eod.hex_buflen); } #endif } } /* finished with current file */ fclose(fp); /* log statistics for this file */ if ( fstats.transfered ) { file_sendcnt++; fprintf(stderr, "%s: %s: info: ", timestamp(), ProgName); fprintf(stderr, "send \"%s (%d bytes)\" succeeded to %s\n", fstats.name, fstats.filesize, hostname); } else { fprintf(stderr, "%s: %s: error: ", timestamp(), ProgName); fprintf(stderr, "send \"%s (%d bytes) failed to %s: ", fstats.name, fstats.filesize, hostname); fprintf(stderr, "%d/%d bytes read/sent\n", fstats.filesize, fstats.socksize); } } /* while ( (path = directory_list(&directory)) ) */ /* close the directory */ directory_close(&directory); /* The port number must be converted first to host byte * order before printing. On most hosts, this is not * necessary, but the ntohs() call is included here so * that this program could easily be ported to a host * that does require it. */ fprintf(stderr, "%s: %s: info: completed %s: %d of %d files sent\n", timestamp(), ProgName, hostname, file_readcnt, file_sendcnt); return 0; } /* serve_client_out() */
int main(int argc, char *argv[]) { // Set directory structure directory_init(argc, argv); printf("Initializing...\n"); fflush(stdout); // Read input file main_read_input(); // Read and sort output directory for finding files within our time limits init_files(); // Initialize domain and flow arrays domain_init(); // Create output directory create_output(); get_sigfigs(); // Pull initial time step tt = 0; cgns_fill(); // Find min and max and set up bins minmax(&min_vf, &max_vf, volume_fraction); minmax(&min_wp, &max_wp, part_w); minmax(&min_ke, &max_ke, part_ke); bin_init(min_vf, max_vf, &dBin_vf, &binStart_vf, &binEnd_vf); bin_init(min_wp, max_wp, &dBin_wp, &binStart_wp, &binEnd_wp); bin_init(min_ke, max_ke, &dBin_ke, &binStart_ke, &binEnd_ke); #ifdef DEBUG printf(" Bin Start (vf) = %lf\n", binStart_vf); printf(" Min (vf) = %lf\n", min_vf); printf(" dBin (vf) = %lf\n", dBin_vf); printf(" Max (vf) = %lf\n", max_vf); printf(" Bin End (vf) = %lf\n", binEnd_vf); #endif printf(" Bin Start (ke) = %lf\n", binStart_ke); printf(" Min (ke) = %lf\n", min_ke); printf(" dBin (ke) = %lf\n", dBin_ke); printf(" Max (ke) = %lf\n", max_ke); printf(" Bin End (ke) = %lf\n", binEnd_ke); // normalization for means double norm = 1./(dom.Gcc.s3 * nFiles); // Loop over time and bin printf("Looping...\n"); fflush(stdout); int ind, ind_vf, ind_wp; for (tt = 0; tt < nFiles; tt++) { printf(" Timestep = %d of %d\n", tt+1, nFiles); fflush(stdout); // Fill data from cgns file cgns_fill(); // Loop over space for (int cc = 0; cc < dom.Gcc.s3; cc++) { /* Volume Fraction */ mean_vf += norm*volume_fraction[cc]; // calculate index ind = (volume_fraction[cc] - binStart_vf)/dBin_vf; // if ind < 0, make it zero // if ind > nBins + 1, make it nBins +1 ind = ind*(ind >= 0); ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1)); histogram_vf[ind]++; ind_vf = ind; /* Part Wp */ mean_wp += norm*part_w[cc]; ind = (part_w[cc] - binStart_wp)/dBin_wp; ind = ind*(ind >= 0); ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1)); histogram_wp[ind]++; ind_wp = ind; /* Bivariate */ bihistogram_vf_wp[ind_wp + (nBins + 2)*ind_vf]++; /* Kinetic Energy */ mean_ke += norm*part_ke[cc]; ind = (part_ke[cc] - binStart_ke)/dBin_ke; ind = ind*(ind >= 0); ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1)); histogram_ke[ind]++; } // keep track of min max mean std for ALL files? // have bin padding as an input parameter? } // write to file write_field(); // Free and exit printf("Done!\n"); free_vars(); return EXIT_SUCCESS; }