static void handle_files(struct ts *ts, struct packet *packet) { int file_time = ALIGN_DOWN(packet->ts.tv_sec, ts->rotate_secs); // Is this file already created? if (file_time <= ts->output_startts) return; close_output_file(ts, UNLINK_OLD); format_output_filename(ts, file_time); /* * When tsdumper2 is started, try to continue writing into "current" file. * This allows the program to be killed/restarted. * * If current file does not exist, create new file with the time of the start * (not aligned to rotate_secs). */ int append = 0; if (ts->output_fd < 0) { // First file (or error). append = file_exists(ts->output_filename); if (!append) { // Create first file *NOT ALIGNED* format_output_filename(ts, packet->ts.tv_sec); } } ts->output_fd = append ? append_output_file(ts) : create_output_file(ts); }
int cmd_archive(int argc, const char **argv, const char *prefix) { const char *exec = "git-upload-archive"; const char *output = NULL; const char *remote = NULL; struct option local_opts[] = { OPT_STRING('o', "output", &output, N_("file"), N_("write the archive to this file")), OPT_STRING(0, "remote", &remote, N_("repo"), N_("retrieve the archive from remote repository <repo>")), OPT_STRING(0, "exec", &exec, N_("command"), N_("path to the remote git-upload-archive command")), OPT_END() }; argc = parse_options(argc, argv, prefix, local_opts, NULL, PARSE_OPT_KEEP_ALL); if (output) create_output_file(output); if (remote) return run_remote_archiver(argc, argv, remote, exec, output); setvbuf(stderr, NULL, _IOLBF, BUFSIZ); return write_archive(argc, argv, prefix, 1, output, 0); }
int main(int argc, char *argv[]) { // Read cmd line arguments if (!read_cmd_args(argc, argv)) { printf(XPP_HELP); return 1; } if (m_option.verbose) { printf(XPP_BANNER); } // Create output file if (m_option.output) { if (!create_output_file()) { return 2; } } // Report results. if (m_option.output) { if (m_option.verbose) { printf("done.\n"); } else { printf("XPP created %s\n", m_output_file); } } if (m_option.debug) { debug_report(); } return 0; // success }
int cmd_archive(int argc, const char **argv, const char *prefix) { const char *exec = "git-upload-archive"; const char *output = NULL; const char *remote = NULL; const char *format_option = NULL; struct option local_opts[] = { OPT_STRING('o', "output", &output, "file", "write the archive to this file"), OPT_STRING(0, "remote", &remote, "repo", "retrieve the archive from remote repository <repo>"), OPT_STRING(0, "exec", &exec, "cmd", "path to the remote git-upload-archive command"), OPT_END() }; argc = parse_options(argc, argv, prefix, local_opts, NULL, PARSE_OPT_KEEP_ALL); if (output) { create_output_file(output); format_option = format_from_name(output); } /* * We have enough room in argv[] to muck it in place, because * --output must have been given on the original command line * if we get to this point, and parse_options() must have eaten * it, i.e. we can add back one element to the array. * * We add a fake --format option at the beginning, with the * format inferred from our output filename. This way explicit * --format options can override it, and the fake option is * inserted before any "--" that might have been given. */ if (format_option) { memmove(argv + 2, argv + 1, sizeof(*argv) * argc); argv[1] = format_option; argv[++argc] = NULL; } if (remote) return run_remote_archiver(argc, argv, remote, exec); setvbuf(stderr, NULL, _IOLBF, BUFSIZ); return write_archive(argc, argv, prefix, 1); }
/* * Description: Creates the entry file if it doesn't exists * Input: 1. Output files * 2. File name without extension */ void create_extern_output_file_if_needed(compiler_output_files* output_files, char* file_name_without_extension) { if (output_files->extern_file == NULL) { output_files->extern_file = create_output_file(file_name_without_extension, EXTERN_FILE_EXT); } }
/* * Description: Executes the second transition * Input: 1. Input file handle * 2. Name of input file * 3. Code length in memory word * 4. Data length in memory word */ void second_transition_execute(FILE* pFile, char* file_name_without_extension, unsigned int previous_transition_ic, unsigned int previous_transition_dc) { compiler_output_files output_files; int line_number = 0; /* Creates transition first data */ transition_data* transition = create_transition_data(); if (transition == NULL) { return; } /* Create ob file */ output_files.ob_file = create_output_file(file_name_without_extension, CODE_FILE_EXT); if (output_files.ob_file == NULL) { return; } output_files.entry_file = NULL; output_files.extern_file = NULL; /* Write first line to ob file */ write_code_and_data_size_to_output_file(previous_transition_ic, previous_transition_dc, output_files.ob_file); /* Step 1 - Initializes IC to zero*/ transition->IC = 0; /* Reads all code lines */ while (!feof(pFile) && !transition->is_runtimer_error) { char line[MAX_LINE_LENGTH]; line_number++; /* Step 2 - Read next line*/ if (fgets(line, MAX_LINE_LENGTH + 1, pFile)) { /* This isn't an empty line or a comment */ if (!is_empty_or_comment(line)) { transition->current_line_information = create_line_info(file_name_without_extension, line_number, line); /* Process line */ if (transition->current_line_information != NULL) { second_transition_process_line(transition, &output_files); free(transition->current_line_information); } else { transition->is_runtimer_error = true; } } } } /* No error has occurred */ if (!transition->is_runtimer_error && !transition->is_compiler_error) { /* Write data initialization section into ob file */ write_data_to_output_file(output_files.ob_file); /* Close files */ if (output_files.ob_file != NULL) { fclose(output_files.ob_file); } if (output_files.extern_file != NULL) { fclose(output_files.extern_file); } if (output_files.entry_file != NULL) { fclose(output_files.entry_file); } } else { /* Close and delete file */ if (output_files.ob_file != NULL) { char* full_name = allocate_string(strlen(file_name_without_extension) + strlen(CODE_FILE_EXT)); fclose(output_files.ob_file); if (full_name != NULL) { strcpy(full_name, file_name_without_extension); strcat(full_name, CODE_FILE_EXT); remove(full_name); free(full_name); } else { print_runtime_error("Couldn't delete compilation files"); } } /* Close and delete file */ if (output_files.extern_file != NULL) { char* full_name = allocate_string(strlen(file_name_without_extension) + strlen(EXTERN_FILE_EXT)); fclose(output_files.extern_file); if (full_name != NULL) { strcpy(full_name, file_name_without_extension); strcat(full_name, EXTERN_FILE_EXT); remove(full_name); free(full_name); } else { print_runtime_error("Couldn't delete compilation files"); } } /* Close and delete file */ if (output_files.entry_file != NULL) { char* full_name = allocate_string(strlen(file_name_without_extension) + strlen(ENTRY_FILE_EXT)); fclose(output_files.entry_file); if (full_name != NULL) { strcpy(full_name, file_name_without_extension); strcat(full_name, ENTRY_FILE_EXT); remove(full_name); free(full_name); } else { print_runtime_error("Couldn't delete compilation files"); } } } }
int _tmain(int argc, _TCHAR* argv[]) { double** g; //PF firings vector int timestep; // timestep i++ = + 1 msec //PF synapces weights vector double *sigma, *vector_e;//, **eligibility_exp; double scalar_Purkinje_presynap, sigma_sum; //full time fo running int fulltime;// = 200000;//100000;//40000; //Purkinje summation window parameter double T_p = 20; //msec (while dt = 1 msec) double Liana_buf = 0; double CSpikeTime = 0; //initial Purkinje firing frequency double Purkinje = 0; //number of PF synapces on Purkinje cell int N;// = 2000;//1000; double epsilon;// = 0.000001;//0.000001;//0.0000001; int L;// = 1000;//2000; //lenght of "snake-in-a-box" //input_alpha(t): alpha-atm - static, alpha(timestep) - dynamic //double alpha_atm = 5; //read settings (N,L, alpha parameters) from file double a_amp, a_period, sigma_init; int gen_snake, alpha_mode; read_settings_file(N,L,a_amp,a_period, fulltime, gen_snake, epsilon, sigma_init, alpha_mode); //random numbers generator srand(time(NULL)); vector_e = generate_eligibility(N); //eligibility_exp = gen_elig_exp(N); sigma = generate_vect_sigma(N, sigma_init); if (gen_snake == 1)g = generate_vect_g(N,L); //slow cause of snake/////// Write snake's file else if (gen_snake == 0) g = vector_g_from_file(N,L); //quick else if (gen_snake == 2) g = generate_random_g(N,L); else {printf("wrong 'gen_snake' value"); getchar();exit(-1);} FILE* myfile1, *myfile2, *myfile3, *myfile4, *myfile5; myfile1 = create_output_file("1"); myfile2 = create_output_file("2"); myfile3 = create_output_file("3"); myfile4 = create_output_file("4"); myfile5 = create_output_file("5"); for (timestep = 0; timestep < fulltime; timestep++) { if (LianaCellFiringFunction(alpha(timestep,a_amp,a_period, alpha_mode), Purkinje, Liana_buf) == true) CSpikeTime = 0; eligibility(g, vector_e/*, eligibility_exp*/, timestep, N, L); changing_weights(sigma, vector_e, CSpikeTime, N, L, epsilon); //calculating of Purkinje output scalar_Purkinje_presynap = 0; sigma_sum = 0; for (int k = 0; k < N; k++) { scalar_Purkinje_presynap = scalar_Purkinje_presynap + sigma[k]*g[timestep%L][k]; sigma_sum = sigma_sum + sigma[k]; } //Purkinje = Purkinje*exp(-1/T_p)+scalar_Purkinje_presynap; Purkinje = Purkinje*0.5*0+scalar_Purkinje_presynap; if (timestep<200000)fprintf(myfile1, "%d %f %f %f %f %f\n", timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode)); else if (timestep<400000)fprintf(myfile2, "%d %f %f %f %f %f\n", timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode)); else if (timestep<600000)fprintf(myfile3, "%d %f %f %f %f %f\n", timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode)); else if (timestep<800000)fprintf(myfile4, "%d %f %f %f %f %f\n", timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode)); else if (timestep<1000000)fprintf(myfile5, "%d %f %f %f %f %f\n", timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode)); else {printf("\ntimestep is out of range\n"); getchar();exit(-1);} CSpikeTime++; } fclose(myfile1); for (int i = 0; i<L; i++) free(g[i]); free(g); free(vector_e); fclose(myfile1); fclose(myfile2); fclose(myfile3); fclose(myfile4); fclose(myfile5); //free(eligibility_exp[1]);free(eligibility_exp[0]);free(eligibility_exp); free(sigma); return 0; }