/***************************************************************************** * \brief Simulates the use and switch between the three different pilot * connections in real time. * \parameters None * \return None *****************************************************************************/ void test_pilot_connections(void) { #if USE_DEBUG_PLOT static int iFirstTime = 1; int i, k,n; int temp; int speechIndex; int speechIndex2; bool bUseSpeech = true; // Initialize time indices if(iFirstTime) { plot_init(); iFirstTime = 0; if (bUseSpeech) { true_voice_dtmf_queue('A'); true_voice_dtmf_queue('A'); true_voice_dtmf_remove_last_added(); true_voice_dtmf_queue('7'); //true_voice_dtmf_send_queue(); } } // Send male or female speech through a channel speechIndex = 0; speechIndex2 = 0; temp=0; while(temp < TV_PLOT_LENGTH){ temp += BUFLEN_8KHZ; //Update input buffer for(i=0; i<BUFLEN_8KHZ; i++){ //mic.psTechHeadset[i] = femaleSpeech[i+speechIndex]; //mic.psTechHeadset = audioMic[1] rx.psFtn[i] = femaleSpeech[i+speechIndex]; rx.psClt2wire[i] = femaleSpeech[i+speechIndex]; rx.psLmr[i] = maleSpeech[i+speechIndex]; // Start with pilot in aircraft with switch to Clt StriC if (temp<11000){ mic.psPilotCable[i] = 0; mic.psPilotCltCable[i] = maleSpeech[i+speechIndex]; mic.psPilotHeadset[i] = 0; rx.psClt2wire[i] = femaleSpeech[i+speechIndex]; speechIndex2 = 0; } // Pilot in aircraft change switch to talk to 1st tech else if(temp<22000){ mic.psPilotCable[i] = maleSpeech[i+speechIndex2]; mic.psPilotCltCable[i] = 0; //mic.psTechHeadset = audioMic[1] mic.psPilotHeadset[i] = 0; rx.psClt2wire[i] = femaleSpeech[i+speechIndex2]; rx.psFtn[i] = femaleSpeech[i+speechIndex2]; speechIndex = 0; } // Pilot use headset jack on BS else{ true_voice_pilot_mode(1); // 0 = Pilot aircraft cable, 1 = Pilot headset mic.psPilotCable[i] = 0; mic.psPilotCltCable[i] = 0; mic.psPilotHeadset[i] = maleSpeech[i+speechIndex]; } } speechIndex+=BUFLEN_8KHZ; speechIndex2+=BUFLEN_8KHZ; if (speechIndex>=11311-BUFLEN_8KHZ){ speechIndex=0; } if (speechIndex2>=11311-BUFLEN_8KHZ){ speechIndex2=0; } if (temp == (32*30)){ true_voice_dtmf_send_queue(); } // Mixer true_voice(rx, mic, tx, ls); // Store data (see plot.c in true_voice) write_plot_data(tx.psTechToRadio, &plot1, BUFLEN_8KHZ); write_plot_data(tx.psPilotAndCltToRadio, &plot2, BUFLEN_8KHZ); write_plot_data(tx.psFtnToLine, &plot3, BUFLEN_8KHZ); write_plot_data(tx.psCltToLine, &plot4, BUFLEN_8KHZ); write_plot_data(tx.psLmrToLine, &plot5, BUFLEN_8KHZ); write_plot_data(tx.psFtnToRadio, &plot6, BUFLEN_8KHZ); write_plot_data(tx.psCltToRadio , &plot7, BUFLEN_8KHZ); write_plot_data(tx.psLmrToRadio, &plot8, BUFLEN_8KHZ); write_plot_data(ls.psTechLeft, &plot9, BUFLEN_8KHZ); write_plot_data(ls.psTechRight, &plot10, BUFLEN_8KHZ); write_plot_data(ls.psTechMono, &plot11, BUFLEN_8KHZ); write_plot_data(ls.psPilotMono, &plot12, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCable, &plot13, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCltCable, &plot14, BUFLEN_8KHZ); } // Write stored data to output file write_plot_buffer_to_file("Tx0_TechToRadio.dat", &plot1); write_plot_buffer_to_file("Tx1_PilotAndCltToRadio.dat", &plot2); write_plot_buffer_to_file("Tx2_FtnToLine.dat", &plot3); write_plot_buffer_to_file("Tx3_CltToLine.dat", &plot4); write_plot_buffer_to_file("Tx4_LmrToLine.dat", &plot5); write_plot_buffer_to_file("Tx5_FtnToRadio.dat", &plot6); write_plot_buffer_to_file("Tx6_CltToRadio.dat", &plot7); write_plot_buffer_to_file("Tx7_LmrToRadio.dat", &plot8); write_plot_buffer_to_file("Ls0_TechLeft.dat", &plot9); write_plot_buffer_to_file("Ls1_TechRight.dat", &plot10); write_plot_buffer_to_file("Ls2_TechMono.dat", &plot11); write_plot_buffer_to_file("Ls3_PilotMono.dat", &plot12); write_plot_buffer_to_file("Ls4_PilotCable.dat", &plot13); write_plot_buffer_to_file("Ls5_PilotCltCable.dat",&plot14); #endif //USE_DEBUG_PLOT }
void test_fileInput(void) { #if USE_DEBUG_PLOT long int i; plot_init(); bufferedFileHandle_t input_file_handle; bufferedFileHandle_t noise_file_handle; short resI = createBufferedFileReader("..\\..\\data\\input_startMotorPrat8k20.bin", &input_file_handle); short resN = createBufferedFileReader("..\\..\\data\\noise_startMotorPrat8k5.bin", &noise_file_handle); fseek(input_file_handle.file, sizeof(short)*8000*4, SEEK_SET); fseek(noise_file_handle.file, sizeof(short)*8000*4, SEEK_SET); true_voice_module_enable(NOISE_REDUCTION, 1); true_voice_module_enable(AGC, 0); clock_t t_start, t_stop; t_start = clock(); for(i=0; i*BUFLEN_8KHZ<TV_PLOT_LENGTH; i++){ // where all the shit is short bytesReadI = readData(mic.psPilotHeadset, sizeof(short)*BUFLEN_8KHZ, &input_file_handle); short bytesReadN = readData(mic.psMicNoise, sizeof(short)*BUFLEN_8KHZ, &noise_file_handle); int n; // for(n=0; n<BUFLEN_8KHZ; n++){ // mic.psMicNoise[n] >>= 6; // } if (bytesReadI != sizeof(short)*BUFLEN_8KHZ || bytesReadN != sizeof(short)*BUFLEN_8KHZ) break; int hej = 0; if(i==19){ hej = hej+1; } write_plot_data(mic.psPilotHeadset, &plot2, BUFLEN_8KHZ); true_voice(rx, mic, tx, ls); // Store data (see plot.c in true_voice) write_plot_data(mic.psPilotHeadset, &plot1, BUFLEN_8KHZ); /* short test; if(fProb*10 >MAX_16) test = MAX_16; else test = 10*fProb; // write_plot_data(&test, &plot2, 1); */ } t_stop = clock(); printf("algorithm took: %f s\n", (t_stop-t_start)/300E6); //Enable clock first while in debug: Run->Clock->Enable printf("which is: %f ms per loop\n", (t_stop-t_start)/300E6/i*1000); //Enable clock first while in debug: Run->Clock->Enable closeBufferedFileReader(&input_file_handle); closeBufferedFileReader(&noise_file_handle); // Write stored data to output file write_plot_buffer_to_file("micPilot.dat", &plot1); write_plot_buffer_to_file("micPilotOrg.dat", &plot2); // write_plot_buffer_to_file("voxProb.dat", &plot2); // write_plot_buffer_to_file("micNoise.dat", &plot2); // write_plot_buffer_to_file("lsPilot.dat", &plot3); #endif // USE_DEBUG_PLOT }
void test_all_lec(void) { #if USE_DEBUG_PLOT static int iFirstTime = 1; int i,j,k; int speechIndex=0; t_echo_handler clt_echo_handler; t_echo_handler ftn_echo_handler; t_echo_handler pilot_echo_handler; // Initialize time indices if(iFirstTime) { subband_init(); plot_init(); iFirstTime = 0; for(i=0; i<(N_RX + N_MIC); i++) { uiSineTimeIndex[i] = 0; } clt_echo_handler = createEchoHandler(); ftn_echo_handler = createEchoHandler(); pilot_echo_handler = createEchoHandler(); //true_voice_module_enable(AGC, 0); //true_voice_module_enable(LS_LIMITER, 0); //true_voice_module_enable(NOISE_REDUCTION, 0); //true_voice_module_enable(LEC, 0); true_voice_module_enable(LEC, 1); true_voice_clt_mode(1); } for (j=0; j<2; j++) { memset(mic.psPilotCltCable,0,sizeof(short)*BUFLEN_8KHZ); memset(mic.psPilotCable,0,sizeof(short)*BUFLEN_8KHZ); memset(mic.psTechHeadset,0,sizeof(short)*BUFLEN_8KHZ); short* pMicIn = j==0 ? mic.psPilotCltCable : mic.psPilotCable; short* pMicIn2 = mic.psTechHeadset; for(i=0; i<7; i++) { speechIndex = 0; while(speechIndex < TV_PLOT_LENGTH/(2*7)) { for (k=0; k<BUFLEN_8KHZ; k++){ if (k+speechIndex<11311 && i != 0){ pMicIn[k] = j==0 ? maleSpeech[k+speechIndex] : femaleSpeech[k+speechIndex]; pMicIn2[k] =femaleSpeech[k+speechIndex]; } else{ pMicIn[k] = 0; pMicIn2[k] = 0; } } if (i>=4) { create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true, &clt_echo_handler); create_echo(tx.psFtnToLine, &maleSpeech[speechIndex], rx.psFtn, true, &ftn_echo_handler); if (j==1) { short temp[BUFLEN_8KHZ]; memcpy(temp, mic.psPilotCable, sizeof(short)*BUFLEN_8KHZ); create_echo(ls.psPilotMonoCable, temp, mic.psPilotCable, true, &pilot_echo_handler); } } else { create_echo(tx.psCltToLine, 0, rx.psClt2wire, false, &clt_echo_handler); create_echo(tx.psFtnToLine, 0, rx.psFtn, false, &ftn_echo_handler); if (j==1) { short temp[BUFLEN_8KHZ]; memcpy(temp, mic.psPilotCable, sizeof(short)*BUFLEN_8KHZ); create_echo(ls.psPilotMonoCable, temp, mic.psPilotCable, true, &pilot_echo_handler); } } write_plot_data(rx.psFtn, &plot5, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCable, &plot7, BUFLEN_8KHZ); write_plot_data(mic.psPilotCable, &plot8, BUFLEN_8KHZ); true_voice(rx, mic, tx, ls); write_plot_data(mic.psPilotCltCable, &plot1, BUFLEN_8KHZ); write_plot_data(rx.psClt2wire, &plot2, BUFLEN_8KHZ); write_plot_data(rx.psClt, &plot3, BUFLEN_8KHZ); write_plot_data(mic.psTechHeadset, &plot4, BUFLEN_8KHZ); write_plot_data(rx.psFtn, &plot6, BUFLEN_8KHZ); write_plot_data(mic.psPilotCable, &plot9, BUFLEN_8KHZ); speechIndex=speechIndex+BUFLEN_8KHZ; } } } write_plot_buffer_to_file("lineIn.dat", &plot1); write_plot_buffer_to_file("lineOut.dat", &plot2); write_plot_buffer_to_file("lineInProcessed.dat", &plot3); write_plot_buffer_to_file("FtnIn.dat", &plot4); write_plot_buffer_to_file("FtnOut.dat", &plot5); write_plot_buffer_to_file("FtnInProcessed.dat", &plot6); write_plot_buffer_to_file("PilotIn.dat", &plot7); write_plot_buffer_to_file("PilotOut.dat", &plot8); write_plot_buffer_to_file("PilotInProcessed.dat", &plot9); #endif //USE_DEBUG_PLOT }
/***************************************************************************** * \brief Testing mixer by creating sine waves for all input channels * \parameters None * \return None *****************************************************************************/ void test_mixer(void) { #if USE_DEBUG_PLOT static int iFirstTime = 1; int i, k,n; int temp; int speechIndex; bool bUseSpeech = false; bool bUseCltCable = false; // Initialize time indices if(iFirstTime) { for(i=0; i<(N_RX + N_MIC); i++) { uiSineTimeIndex[i] = 0; } plot_init(); iFirstTime = 0; // true_voice_pilot_mode(0); // true_voice_clt_mode(1); if (bUseSpeech) { true_voice_dtmf_queue('A'); true_voice_dtmf_queue('A'); true_voice_dtmf_remove_last_added(); true_voice_dtmf_queue('7'); true_voice_dtmf_send_queue(); } } if (!bUseSpeech){ // Use sine waves while(uiSineTimeIndex[0] < TV_PLOT_LENGTH) { // Create sine wave for each channel with frequency 100 Hz, 200 Hz, 300 Hz, ... for(i=0; i<N_RX; i++) { sin_block(audioRx[i], (i+1)*100, &uiSineTimeIndex[i]); } for(i=0; i<N_MIC; i++) { if (tvSettings.bPilotConnection == AIRCRAFT_CABLE) { sin_block(audioMic[i], (i+1+N_RX)*100, &uiSineTimeIndex[i+N_RX]); if (bUseCltCable) { if ((i==(N_MIC-2))) { sin_block(audioMic[i], (i+1+N_RX)*0, &uiSineTimeIndex[i+N_RX]); } } else { if ((i==(N_MIC-1))) { sin_block(audioMic[i], (i+1+N_RX)*0, &uiSineTimeIndex[i+N_RX]); } } } else { sin_block(audioMic[i], (i+1+N_RX)*100, &uiSineTimeIndex[i+N_RX]); } } //TODO: eventually remove temporary signals for limiter testing // TEMPORARY: change signals for limiter testing // for(i=0; i<N_RX; i++) { // if(uiSineTimeIndex[0] < TV_PLOT_LENGTH*0.1) { // for (k=0; k<BUFLEN_8KHZ; k++){ // audioRx[i][k]=mult_q15(audioRx[i][k], 8000); // } // } // else if (uiSineTimeIndex[0] < (TV_PLOT_LENGTH)*0.3) { // for (k=0; k<BUFLEN_8KHZ; k++){ // audioRx[i][k]=mult_q15(audioRx[i][k], 32767); // } // } // else{ // for (k=0; k<BUFLEN_8KHZ; k++){ // audioRx[i][k]=mult_q15(audioRx[i][k], 8000); // } // } // } // if (uiSineTimeIndex[0]>400) { // true_voice_volume_speaker(1, 10); // } // if (uiSineTimeIndex[0]>500) { // true_voice_volume_speaker(2, 5); // } // Mixer true_voice(rx, mic, tx, ls); // Store data (see plot.c in true_voice) write_plot_data(tx.psTechToRadio, &plot1, BUFLEN_8KHZ); write_plot_data(tx.psPilotAndCltToRadio, &plot2, BUFLEN_8KHZ); write_plot_data(tx.psFtnToLine, &plot3, BUFLEN_8KHZ); write_plot_data(tx.psCltToLine, &plot4, BUFLEN_8KHZ); write_plot_data(tx.psLmrToLine, &plot5, BUFLEN_8KHZ); write_plot_data(tx.psFtnToRadio, &plot6, BUFLEN_8KHZ); write_plot_data(tx.psCltToRadio , &plot7, BUFLEN_8KHZ); write_plot_data(tx.psLmrToRadio, &plot8, BUFLEN_8KHZ); write_plot_data(ls.psTechLeft, &plot9, BUFLEN_8KHZ); write_plot_data(ls.psTechRight, &plot10, BUFLEN_8KHZ); write_plot_data(ls.psTechMono, &plot11, BUFLEN_8KHZ); write_plot_data(ls.psPilotMono, &plot12, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCable, &plot13, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCltCable, &plot14, BUFLEN_8KHZ); } }// end sin waves if (bUseSpeech) { // Send male or female speech through a channel speechIndex = 0; temp=0; while(temp < TV_PLOT_LENGTH){ temp += BUFLEN_8KHZ; //Update input buffer for(i=0; i<BUFLEN_8KHZ; i++){ rx.psTech1[i] = maleSpeech[i+speechIndex]; //mic.psTechHeadset = audioMic[1] rx.psPilot[i] = femaleSpeech[i+speechIndex]; rx.psLmr[i] = femaleSpeech[i+speechIndex]; } speechIndex+=BUFLEN_8KHZ; if (speechIndex>=11311-BUFLEN_8KHZ){ speechIndex=0; } // if(speechIndex == (32*35)){ // true_voice_dtmf_send_queue(); // } /* true_voice_volume_speaker(1, 0); true_voice_volume_speaker(2, 10); if (speechIndex>5000) { true_voice_volume_speaker(1, 10); true_voice_volume_speaker(2, 5); } if (speechIndex>10000) { true_voice_volume_speaker(1, 6); true_voice_volume_speaker(2, 3); } */ // Mixer // clock_t t_start, t_stop, t_overhead; // t_start = clock(); // t_stop = clock(); // t_overhead = t_stop - t_start; // t_start = clock(); true_voice(rx, mic, tx, ls); // t_stop = clock(); // printf("True Voice took: %f ms\n", (t_stop-t_start-t_overhead)/300E6*1000); //Enable clock first while in debug: Run->Clock->Enable // Store data (see plot.c in true_voice) write_plot_data(tx.psTechToRadio, &plot1, BUFLEN_8KHZ); write_plot_data(tx.psPilotAndCltToRadio,&plot2, BUFLEN_8KHZ); write_plot_data(tx.psFtnToLine, &plot3, BUFLEN_8KHZ); write_plot_data(tx.psCltToLine, &plot4, BUFLEN_8KHZ); write_plot_data(tx.psLmrToLine, &plot5, BUFLEN_8KHZ); write_plot_data(tx.psFtnToRadio, &plot6, BUFLEN_8KHZ); write_plot_data(tx.psCltToRadio , &plot7, BUFLEN_8KHZ); write_plot_data(tx.psLmrToRadio, &plot8, BUFLEN_8KHZ); write_plot_data(ls.psTechLeft, &plot9, BUFLEN_8KHZ); write_plot_data(ls.psTechRight, &plot10, BUFLEN_8KHZ); write_plot_data(ls.psTechMono, &plot11, BUFLEN_8KHZ); write_plot_data(ls.psPilotMono, &plot12, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCable, &plot13, BUFLEN_8KHZ); write_plot_data(ls.psPilotMonoCltCable, &plot14, BUFLEN_8KHZ); } }//end speech // Write stored data to output file write_plot_buffer_to_file("Tx0_TechToRadio.dat", &plot1); write_plot_buffer_to_file("Tx1_PilotAndCltToRadio.dat", &plot2); write_plot_buffer_to_file("Tx2_FtnToLine.dat", &plot3); write_plot_buffer_to_file("Tx3_CltToLine.dat", &plot4); write_plot_buffer_to_file("Tx4_LmrToLine.dat", &plot5); write_plot_buffer_to_file("Tx5_FtnToRadio.dat", &plot6); write_plot_buffer_to_file("Tx6_CltToRadio.dat", &plot7); write_plot_buffer_to_file("Tx7_LmrToRadio.dat", &plot8); write_plot_buffer_to_file("Ls0_TechLeft.dat", &plot9); write_plot_buffer_to_file("Ls1_TechRight.dat", &plot10); write_plot_buffer_to_file("Ls2_TechMono.dat", &plot11); write_plot_buffer_to_file("Ls3_PilotMono.dat", &plot12); write_plot_buffer_to_file("Ls4_PilotCable.dat", &plot13); write_plot_buffer_to_file("Ls5_PilotCltCable.dat",&plot14); write_plot_buffer_to_file("plotVar1.dat", &plotVar1); // write_plot_buffer_to_file("plotVar2.dat", &plotVar2); // write_plot_buffer_to_file("plotVar3.dat", &plotVar3); #endif // USE_DEBUG_PLOT }
int main(int argc, char **argv) { extern int plot_mag; extern int plot_inverse; int i, j; get_options(argc, argv, options, help_string); if(!psdump) { plot_mag = mag; plot_inverse = invert; plot_init(width, height, 2, term); plot_set_all(0); } srandom(seed); /* Convert angles to radians. */ angle = angle * M_PI / 180.0; vangle = vangle * M_PI / 180.0; /* Make space for the positions, velocities, and new velocities. */ xp = xmalloc(sizeof(double) * num); yp = xmalloc(sizeof(double) * num); xv = xmalloc(sizeof(double) * num); yv = xmalloc(sizeof(double) * num); xnv = xmalloc(sizeof(double) * num); ynv = xmalloc(sizeof(double) * num); /* Set to random initial conditions. */ for(i = 0; i < num; i++) { xp[i] = random() % width; yp[i] = random() % height; xv[i] = random_range(-1.0, 1.0); yv[i] = random_range(-1.0, 1.0); norm(&xv[i], &yv[i]); } /* For each time step... */ for(i = 0; i < steps; i++) { /* For each boid, compute its new heading. */ for(j = 0; j < num; j++) compute_new_heading(j); /* For each boid again... */ for(j = 0; j < num; j++) { /* Undraw the boid. */ if(!psdump) draw_boid(j, 0); /* Update the velocity and position. */ xv[j] = xnv[j]; yv[j] = ynv[j]; xp[j] += xv[j] * dt; yp[j] += yv[j] * dt; /* Wrap around the screen coordinates. */ if(xp[j] < 0) xp[j] += width; else if(xp[j] >= width) xp[j] -= width; if(yp[j] < 0) yp[j] += height; else if(yp[j] >= height - 1) yp[j] -= height; /* Redraw the boid. */ if(!psdump) draw_boid(j, 1); } } if(!psdump) plot_finish(); /* If we want a PS dump of the final configuration, do it. */ if(psdump) { plot_inverse = 0; plot_init(width, height, 2, "ps"); for(i = 0; i < num; i++) { draw_boid(i, 0); } plot_finish(); } exit(0); }
void plot_init(int width, int height, int levels, char *term) { if(!term) term = term_default; if(0) ; #ifdef PLOTX11 else if(strcmp(term, "x11") == 0) { _plot_init = x11plot_init; _plot_point = x11plot_point; _plot_line = x11plot_line; _plot_finish = x11plot_finish; } else if(strcmp(term, "X11") == 0) { _plot_init = X11plot_init; _plot_point = X11plot_point; _plot_line = X11plot_line; _plot_finish = X11plot_finish; } #endif #ifdef WIN32 else if(strcmp(term, "win") == 0) { _plot_init = winplot_init; _plot_point = winplot_point; _plot_line = winplot_line; _plot_finish = winplot_finish; } else if(strcmp(term, "Win") == 0) { _plot_init = Winplot_init; _plot_point = Winplot_point; _plot_line = Winplot_line; _plot_finish = Winplot_finish; } #endif #ifdef PLOTVGA else if(strcmp(term, "vga") == 0) { _plot_init = vgaplot_init; _plot_point = vgaplot_point; _plot_line = vgaplot_line; _plot_finish = vgaplot_finish; } #endif else if(strcmp(term, "ps") == 0) { _plot_init = psplot_init; _plot_point = psplot_point; _plot_line = psplot_line; _plot_finish = psplot_finish; } else if(strcmp(term, "pgm") == 0) { _plot_init = pgmplot_init; _plot_point = pgmplot_point; _plot_line = plot_line_internal; _plot_finish = pgmplot_finish; } else if(strcmp(term, "raw") == 0) { _plot_init = rawplot_init; _plot_point = rawplot_point; _plot_line = plot_line_internal; _plot_finish = rawplot_finish; } else if(strcmp(term, "none") == 0) { _plot_init = none_init; _plot_point = none_point; _plot_line = none_line; _plot_finish = none_finish; } else { plot_init(width, height, levels, term_default); return; } _plot_init(width, height, levels); plot_levels = levels; plot_width = width; plot_height = height; plot_xmin = 0.0; plot_xmax = width - 1; plot_ymin = height - 1; plot_ymax = 0.0; }
//================================================== // simulation //================================================== void simulate(int seed){ ran_seed(seed); int N = 18*512; double radius = 1.0; double L = sqrt(1.02*pi*radius*radius*N); int Npercell = 50; int pbc[] = {1,1}; double epsilon = 180.0; double damp_coeff = 0.3; double kickforce = 20.0; double dt = 1e-1; double t = 0.0; double R = 2*radius; double R2 = R*R; int i, j, k; int *key; int *type = (int*)malloc(sizeof(int)*N); int *neigh = (int*)malloc(sizeof(int)*N); double *rad = (double*)malloc(sizeof(double)*N); double *col = (double*)malloc(sizeof(double)*N); for (i=0; i<N; i++){ type[i] = neigh[i] = rad[i] = 0;} double *x = (double*)malloc(sizeof(double)*2*N); double *v = (double*)malloc(sizeof(double)*2*N); double *f = (double*)malloc(sizeof(double)*2*N); double *w = (double*)malloc(sizeof(double)*2*N); double *o = (double*)malloc(sizeof(double)*2*N); for (i=0; i<2*N; i++){o[i] = x[i] = v[i] = f[i] = w[i] = 0.0;} #ifdef PLOT double time_end = 1e20; #else double time_end = 1e2; #endif #ifdef PLOT plot_init(); plot_clear_screen(); key = plot_render_particles(x, rad, type, N, L,col); #endif //------------------------------------------------- // initialize for (i=0; i<N; i++){ rad[i] = radius; x[2*i+0] = L*ran_ran2(); x[2*i+1] = L*ran_ran2(); v[2*i+0] = 0.0; v[2*i+1] = 0.0; type[i] = BLACK; if (i==0) type[i] = RED; } //------------------------------------------------------- // make boxes for the neighborlist int size[2]; int size_total = 1; for (i=0; i<2; i++){ size[i] = (int)(L / (R)); size_total *= size[i]; } int *count = (int*)malloc(sizeof(int)*2*size_total); int *cells = (int*)malloc(sizeof(int)*2*size_total*Npercell); for (i=0; i<size_total; i++){ for (j=0; j<Npercell; j++) cells[i*Npercell + j] = 0; count[i] = 0; } //========================================================== // where the magic happens //========================================================== int frames = 0; #ifdef FPS struct timespec start; clock_gettime(CLOCK_REALTIME, &start); #endif int STRESS = 1; double T = 0.0; for (t=0.0; t<time_end; t+=dt){ double colmax = 0.0; int index[2]; for (i=0; i<size_total; i++) count[i] = 0; for (i=0; i<N; i++){ col[i] = 0.0; coords_to_index(&x[2*i], size, index, L); int t = index[0] + index[1]*size[0]; cells[t*Npercell+count[t]] = i; count[t]++; } int tt[2]; int tix[2]; int image[2]; double dx[2]; for (i=0; i<N; i++){ f[2*i+0] = 0.0; f[2*i+1] = 0.0; coords_to_index(&x[2*i], size, index, L); for (tt[0]=-1; tt[0]<=1; tt[0]++){ for (tt[1]=-1; tt[1]<=1; tt[1]++){ int goodcell = 1; for (j=0; j<2; j++){ tix[j] = mod_rvec(index[j]+tt[j],size[j]-1,pbc[j],&image[j]); if (pbc[j] < image[j]) goodcell=0; } if (goodcell){ int ind = tix[0] + tix[1]*size[0]; for (j=0; j<count[ind]; j++){ int n = cells[ind*Npercell+j]; double dist = 0.0; for (k=0; k<2; k++){ dx[k] = x[2*n+k] - x[2*i+k]; if (image[k]) dx[k] += L*tt[k]; dist += dx[k]*dx[k]; } //=============================================== // force calculation - hertz if (dist > 1e-10 && dist < R2){ double r0 = R; double l = sqrt(dist); double co = epsilon * (1-l/r0)*(1-l/r0) * (l<r0); for (k=0; k<2; k++){ f[2*i+k] += - dx[k] * co; if (STRESS==1) col[i] += co*co*dx[k]*dx[k];//100*co*dx[k];//sqrt(co*co*dx[k]*dx[k]); } if (STRESS==2) col[i] += dx[1] * co*co*dx[1]; if (STRESS==3) col[i] += dx[0] * co*co*dx[0]; if (STRESS==4) col[i] += dx[1] * co*co*dx[0]; } } } } } //==================================== // damping f[2*i+0] -= damp_coeff*v[2*i+0]; f[2*i+1] -= damp_coeff*v[2*i+1]; //===================================== // noise f[2*i+0] += T*(ran_ran2()-0.5); f[2*i+1] += T*(ran_ran2()-0.5); //===================================== // kick force f[2*i+0] += o[2*i+0]; o[2*i+0] = 0.0; f[2*i+1] += o[2*i+1]; o[2*i+1] = 0.0; //======================= // color norm if (col[i] > colmax) colmax = col[i]; } // now integrate the forces since we have found them for (i=0; i<N;i++){ // Newton-Stomer-Verlet if (key['h'] != 1){ v[2*i+0] += f[2*i+0] * dt; v[2*i+1] += f[2*i+1] * dt; x[2*i+0] += v[2*i+0] * dt; x[2*i+1] += v[2*i+1] * dt; } // boundary conditions for (j=0; j<2; j++){ if (pbc[j] == 1){ if (x[2*i+j] >= L-EPSILON || x[2*i+j] < 0) x[2*i+j] = mymod(x[2*i+j], L); } else { const double restoration = 1.0; if (x[2*i+j] >= L){x[2*i+j] = 2*L-x[2*i+j]; v[2*i+j] *= -restoration;} if (x[2*i+j] < 0) {x[2*i+j] = -x[2*i+j]; v[2*i+j] *= -restoration;} if (x[2*i+j] >= L-EPSILON || x[2*i+j] < 0){x[2*i+j] = mymod(x[2*i+j], L);} } } // just check for errors if (x[2*i+0] >= L || x[2*i+0] < 0.0 || x[2*i+1] >= L || x[2*i+1] < 0.0) printf("out of bounds\n"); //col[i] += v[2*i+0]*v[2*i+0] + v[2*i+1]*v[2*i+1]; if (STRESS == 1) col[i] = col[i]/8; if (STRESS == 2) col[i] = col[i]/16; if (STRESS == 3) col[i] = col[i]/16; if (STRESS == 4) col[i] = col[i]/4; if (STRESS > 1) col[i] = fabs(col[i])+0.5; } #ifdef PLOT const int FRAMESKIP = 1; if (frames % FRAMESKIP == 0){ char filename[100]; sprintf(filename, "screen_%05d.png", frames/FRAMESKIP); plot_clear_screen(); key = plot_render_particles(x, rad, type, N, L,col); #ifdef IMAGES plot_saveimage(filename); #endif } #endif frames++; if (key['1'] == 1) STRESS = 1; if (key['2'] == 1) STRESS = 2; if (key['3'] == 1) STRESS = 3; if (key['4'] == 1) STRESS = 4; if (key['q'] == 1) break; if (key['w'] == 1){ for (i=0; i<N; i++){ if (type[i] == RED) o[2*i+1] = -kickforce; } } if (key['s'] == 1){ for (i=0; i<N; i++){ if (type[i] == RED) o[2*i+1] = kickforce; } } if (key['a'] == 1){ for (i=0; i<N; i++){ if (type[i] == RED) o[2*i+0] = -kickforce; } } if (key['d'] == 1){ for (i=0; i<N; i++){ if (type[i] == RED) o[2*i+0] = kickforce; } } if (key['9'] == 1) T -= 0.01; if (key['0'] == 1) T += 0.01; if (key['8'] == 1) T = 0.0; if (key['o'] == 1) L -= 0.01; if (key['p'] == 1) L += 0.01; } // end of the magic, cleanup //---------------------------------------------- #ifdef FPS struct timespec end; clock_gettime(CLOCK_REALTIME, &end); printf("fps = %f\n", frames/(end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec)/1e9); #endif free(cells); free(count); free(x); free(v); free(f); free(w); free(o); free(neigh); free(rad); free(type); #ifdef PLOT plot_clean(); #endif }
static void gui_init(int argc, char** argv) { char buf[PATH_MAX]; OBJECT * cursors; atari_find_resource(buf, "netsurf.rsc", "./res/netsurf.rsc"); LOG(("%s ", (char*)&buf)); if (rsrc_load(buf)==0) { die("Uable to open GEM Resource file!"); } wind_get_grect(0, WF_WORKXYWH, &desk_area); create_cursor(0, POINT_HAND, NULL, &gem_cursors.hand ); create_cursor(0, TEXT_CRSR, NULL, &gem_cursors.ibeam ); create_cursor(0, THIN_CROSS, NULL, &gem_cursors.cross); create_cursor(0, BUSY_BEE, NULL, &gem_cursors.wait); create_cursor(0, ARROW, NULL, &gem_cursors.arrow); create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizeall); create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenesw); create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenwse); cursors = gemtk_obj_get_tree(CURSOR); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_APPSTART, cursors, &gem_cursors.appstarting); gem_set_cursor( &gem_cursors.appstarting ); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZEWE, cursors, &gem_cursors.sizewe); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZENS, cursors, &gem_cursors.sizens); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_NODROP, cursors, &gem_cursors.nodrop); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_DENY, cursors, &gem_cursors.deny); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_MENU, cursors, &gem_cursors.menu); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_HELP, cursors, &gem_cursors.help); LOG(("Enabling core select menu")); nsoption_set_bool(core_select_menu, true); LOG(("Loading url.db from: %s", nsoption_charp(url_file) )); if( strlen(nsoption_charp(url_file)) ) { urldb_load(nsoption_charp(url_file)); } LOG(("Loading cookies from: %s", nsoption_charp(cookie_file) )); if( strlen(nsoption_charp(cookie_file)) ) { urldb_load_cookies(nsoption_charp(cookie_file)); } if (process_cmdline(argc,argv) != true) die("unable to process command line.\n"); LOG(("Initializing NKC...")); nkc_init(); LOG(("Initializing plotters...")); plot_init(nsoption_charp(atari_font_driver)); tree_set_icon_dir(nsoption_charp(tree_icons_path)); aes_event_in.emi_m1leave = MO_LEAVE; aes_event_in.emi_m1.g_w = 1; aes_event_in.emi_m1.g_h = 1; //next_poll = clock() + (CLOCKS_PER_SEC>>3); }
void test_lec(void) { #if USE_DEBUG_PLOT static int iFirstTime = 1; int i,j; int speechIndex=0; bool bUseSpeech = true; bool bUseTrueVoice = false; // Initialize time indices if(iFirstTime) { subband_init(); plot_init(); iFirstTime = 0; for(i=0; i<(N_RX + N_MIC); i++) { uiSineTimeIndex[i] = 0; } } short* pMicIn = bUseTrueVoice ? mic.psPilotCable : tx.psCltToLine; for(j=0; j<7; j++) { speechIndex = 0; while(speechIndex < TV_PLOT_LENGTH/7) { if (bUseSpeech) { for (i=0; i<BUFLEN_8KHZ; i++){ if (i+speechIndex<11311 && j != 0){ pMicIn[i] =maleSpeech[i+speechIndex]; } else{ pMicIn[i] = 0; } } } else { sin_block(pMicIn, (0+1)*200, &uiSineTimeIndex[0]); vecmultq15xScalar(pMicIn, pMicIn, (q15)(INT16_MAX*0.99), 15 ,BUFLEN_8KHZ); } if (bUseTrueVoice) { true_voice(rx, mic, tx, ls); if (j>=4) { create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true); } else { create_echo(tx.psCltToLine, 0, rx.psClt2wire, false); } } else { if (j>=4) { create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true); } else { create_echo(tx.psCltToLine, 0, rx.psClt2wire, false); } // clock_t t_start, t_stop, t_overhead; // t_start = clock(); // t_stop = clock(); // t_overhead = t_stop - t_start; // t_start = clock(); internal_lec(rx.psClt2wire, tx.psCltToLine, rx.psClt); // t_stop = clock(); // printf("LEC took: %f ms\n", (t_stop-t_start-t_overhead)/300E6*1000); //Enable clock first while in debug: Run->Clock->Enable } write_plot_data(rx.psClt2wire, &plot1, BUFLEN_8KHZ); write_plot_data(tx.psCltToLine, &plot2, BUFLEN_8KHZ); write_plot_data(rx.psClt, &plot3, BUFLEN_8KHZ); speechIndex=speechIndex+BUFLEN_8KHZ; } } write_plot_buffer_to_file("lineIn.dat", &plot1); write_plot_buffer_to_file("lineOut.dat", &plot2); write_plot_buffer_to_file("lineInProcessed.dat", &plot3); #endif //USE_DEBUG_PLOT }
static int get_node_from_line( LIST* list,char* line , NODE* node , int* type){ char c; char* token; int flag; static long node_count = 1; if( line == NULL || node == NULL || type == NULL ) return 0; //printf("\nParsing line: %s\n",line); c = line[0]; switch(c){ case 'R': case 'r':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->resistance.name , token); /* *Read <+> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->resistance.node1 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->resistance.node1 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); if (!ht_get(list->hashtable,token,&n)) { printf("Token failed: %s \n",token); perror("Key was not found in the hash table\n The program will exit\n"); exit(0); } node->resistance.node1 = n; } } //printf("Resistance node number: %ld\n",node->resistance.node1); /* * Read <-> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->resistance.node2 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->resistance.node2 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->resistance.node2 = n; } } //node->resistance.node2 = atoi(token); /* read value node */ token = strtok(NULL," "); if( token == NULL){ return 0; } node->resistance.value = atof(token); /* NO MORE TOKENS.IF FOUND RETURN ERROR */ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_RESISTANCE_TYPE; return 1; } else{ /* tokens were found.print for debugging...*/ printf("LINE: %s , garbage token : %s\n" , line , token); return 0; } } case 'C': case 'c':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->capacity.name , token); /* read <+> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->capacity.node1 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->capacity.node1 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->capacity.node1 = n; } } // node->capacity.node1 = atoi(token); /* read <-> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->capacity.node2 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->capacity.node2 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->capacity.node2 = n; } } /* read value node */ token = strtok(NULL," "); if( token == NULL){ return 0; } node->capacity.value = atof(token); /* NO MORE TOKENS.IF FOUND RETURN ERROR */ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_CAPACITY_TYPE; return 1; } else{ /* tokens were found.print for debugging...*/ printf("LINE: %s , garbage token : %s\n" , line , token); return 0; } } case 'L': case 'l':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->inductance.name , token); /* read <+> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->inductance.node1 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->inductance.node1 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->inductance.node1 = n; } } // node->inductance.node1 = atoi(token); /* read <-> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->inductance.node2 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->inductance.node2 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->inductance.node2 = n; } } //node->inductance.node2 = atoi(token); /* read value node */ token = strtok(NULL," "); if( token == NULL){ return 0; } node->inductance.value = atof(token); /* NO MORE TOKENS.IF FOUND RETURN ERROR */ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_INDUCTANCE_TYPE; return 1; } else{ /* tokens were found.print for debugging...*/ printf("LINE: %s , garbage token: %s\n" , line , token); return 0; } } /* * VOLTAGE SOURCE */ case 'v': case 'V':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->source_v.name , token); node->source_v.is_ac = 0; /* read <+> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->source_v.node1 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->source_v.node1 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->source_v.node1 = n; } } //node->source_v.node1 = atoi(token); /* read <-> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->source_v.node2 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->source_v.node2 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->source_v.node2 = n; } } //node->source_v.node2 = atoi(token); /* read value node */ token = strtok(NULL," "); if( token == NULL){ return 0; } node->source_v.value = atof(token); /* NO MORE TOKENS.IF FOUND CHECK FOR TRANSIENT SPEC*/ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_SOURCE_V_TYPE; return 1; } else{ /*check for exponential transient spec*/ if (strcmp(token,"EXP") == 0 || strcmp(token,"exp") == 0){ token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i1 value of the exponential transient spec\n"); return 0; } /*store the i1 value*/ node->source_v.i1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i2 value of the exponential transient spec\n"); return 0; } /*store the i2 value*/ node->source_v.i2 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td1 value of the exponential transient spec\n"); return 0; } /*store the td1 value*/ node->source_v.td1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tc1 value of the exponential transient spec\n"); return 0; } /*store the tc1 value*/ node->source_v.tc1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td2 value of the exponential transient spec\n"); return 0; } /*store the td2 value*/ node->source_v.td2 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tc2 value of the exponential transient spec\n"); return 0; } /*store the tc2 value*/ node->source_v.tc2 = atof(token); *type = NODE_SOURCE_V_TYPE; node->source_v.pulse_type = PULSE_EXP; node->source_v.is_ac = 1; return 1; } /*check for SIN transient spec*/ else if(strcmp(token,"SIN") == 0 || strcmp(token,"sin") == 0){ token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i1 value of the exponential transient spec\n"); return 0; } /*store the i1 value*/ node->source_v.i1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the ia value of the exponential transient spec\n"); return 0; } /*store the ia value*/ node->source_v.ia = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the fr value of the exponential transient spec\n"); return 0; } /*store the fr value*/ node->source_v.fr = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td value of the exponential transient spec\n"); return 0; } /*store the td value*/ node->source_v.td = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the df value of the exponential transient spec\n"); return 0; } /*store the df value*/ node->source_v.df = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the ph value of the exponential transient spec\n"); return 0; } /*store the ph value*/ node->source_v.ph = atof(token); *type = NODE_SOURCE_V_TYPE; node->source_v.pulse_type = PULSE_SIN; node->source_v.is_ac = 1; return 1; } /*check for PULSE transient spec*/ else if(strcmp(token,"PULSE") == 0 || strcmp(token,"PULSE") == 0){ token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i1 value of the exponential transient spec\n"); return 0; } /*store the i1 value*/ node->source_v.i1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i2 value of the exponential transient spec\n"); return 0; } /*store the i2 value*/ node->source_v.i2 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td value of the exponential transient spec\n"); return 0; } /*store the td value*/ node->source_v.td = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tr value of the exponential transient spec\n"); return 0; } /*store the tr value*/ node->source_v.tr = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tf value of the exponential transient spec\n"); return 0; } /*store the tf value*/ node->source_v.tf = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the pw value of the exponential transient spec\n"); return 0; } /*store the pw value*/ node->source_v.pw = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the per value of the exponential transient spec\n"); return 0; } /*store the per value*/ node->source_v.per = atof(token); *type = NODE_SOURCE_V_TYPE; node->source_v.pulse_type = PULSE_PULSE; node->source_v.is_ac = 1; return 1; } else if(strcmp(token,"PWL") == 0 || strcmp(token,"pwl")){ PAIR_LIST* pair_list = create_pair_list(); if(!pair_list){ printf("Not enough memory for pair list...\n"); return 0; } token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value pairs for PWL given in netlist\n"); return 0; } while(token != NULL){ double ti,ii; /*store the ti value of the pair*/ ti = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No voltage value specified for the pair\n"); return 0; } ii = atof(token); add_to_pair_list(pair_list, ti, ii); token = strtok(NULL,"() \n"); } node->source_v.pulse_type = PULSE_PULSE; node->source_v.pair_list = pair_list; node->source_v.is_ac = 1; return 1; } } break; } /* * CURRENT SOURCE */ case 'i': case 'I':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->source_i.name , token); node->source_i.is_ac = 0; /* read <+> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->source_i.node1 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->source_i.node1 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->source_i.node1 = n; } } //node->source_i.node1 = atoi(token); /* read <-> node */ token = strtok(NULL," "); if( token == NULL){ return 0; } /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->source_i.node2 = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->source_i.node2 = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->source_i.node2 = n; } } //node->source_i.node2 = atoi(token); /* read value node */ token = strtok(NULL," "); if( token == NULL){ return 0; } node->source_i.value = atof(token); /* NO MORE TOKENS.IF FOUND RETURN ERROR */ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_SOURCE_I_TYPE; return 1; } else{ /*check for exponential transient spec*/ if (strcmp(token,"EXP") == 0 || strcmp(token,"exp") == 0){ token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i1 value of the exponential transient spec\n"); return 0; } /*store the i1 value*/ node->source_i.i1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i2 value of the exponential transient spec\n"); return 0; } /*store the i2 value*/ node->source_i.i2 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td1 value of the exponential transient spec\n"); return 0; } /*store the td1 value*/ node->source_i.td1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tc1 value of the exponential transient spec\n"); return 0; } /*store the tc1 value*/ node->source_i.tc1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td2 value of the exponential transient spec\n"); return 0; } /*store the td2 value*/ node->source_i.td2 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tc2 value of the exponential transient spec\n"); return 0; } /*store the tc2 value*/ node->source_i.tc2 = atof(token); *type = NODE_SOURCE_I_TYPE; node->source_i.pulse_type = PULSE_EXP; node->source_i.is_ac = 1; return 1; } /*check for SIN transient spec*/ else if(strcmp(token,"SIN") == 0 || strcmp(token,"sin") == 0){ token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i1 value of the exponential transient spec\n"); return 0; } /*store the i1 value*/ node->source_i.i1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the ia value of the exponential transient spec\n"); return 0; } /*store the ia value*/ node->source_i.ia = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the fr value of the exponential transient spec\n"); return 0; } /*store the fr value*/ node->source_i.fr = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td value of the exponential transient spec\n"); return 0; } /*store the td value*/ node->source_i.td = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the df value of the exponential transient spec\n"); return 0; } /*store the df value*/ node->source_i.df = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the ph value of the exponential transient spec\n"); return 0; } /*store the ph value*/ node->source_i.df = atof(token); *type = NODE_SOURCE_I_TYPE; node->source_i.pulse_type = PULSE_SIN; node->source_i.is_ac = 1; return 1; } /*check for PULSE transient spec*/ else if(strcmp(token,"PULSE") == 0 || strcmp(token,"PULSE") == 0){ token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i1 value of the exponential transient spec\n"); return 0; } /*store the i1 value*/ node->source_i.i1 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the i2 value of the exponential transient spec\n"); return 0; } /*store the i2 value*/ node->source_i.i2 = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the td value of the exponential transient spec\n"); return 0; } /*store the td value*/ node->source_i.td = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tr value of the exponential transient spec\n"); return 0; } /*store the tr value*/ node->source_i.tr = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the tf value of the exponential transient spec\n"); return 0; } /*store the tf value*/ node->source_i.tf = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the pw value of the exponential transient spec\n"); return 0; } /*store the pw value*/ node->source_i.pw = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No value specified for the per value of the exponential transient spec\n"); return 0; } /*store the per value*/ node->source_i.per = atof(token); *type = NODE_SOURCE_I_TYPE; node->source_i.pulse_type = PULSE_PULSE; node->source_i.is_ac = 1; return 1; } else if(strcmp(token,"PWL") == 0 || strcmp(token,"pwl")){ PAIR_LIST* pair_list = create_pair_list(); if(!pair_list){ printf("Not enough memory for pair list...\n"); return 0; } token = strtok(NULL,"() \n"); if(token == NULL){ printf("No time value specified for the pair\n"); return 0; } while(token != NULL){ double ti,ii; /*store the ti value of the pair*/ ti = atof(token); token = strtok(NULL,"() \n"); if(token == NULL){ printf("No voltage value specified for the pair\n"); return 0; } ii = atof(token); add_to_pair_list(pair_list, ti, ii); token = strtok(NULL,"() \n"); } node->source_i.pulse_type = PULSE_PULSE; node->source_i.pair_list = pair_list; node->source_i.is_ac = 1; return 1; } } break; } /* * MOSFET transistor */ case 'M': case 'm':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->mosfet.name , token); /* read drain */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->mosfet.drain = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->mosfet.drain = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->mosfet.drain = n; } } //node->mosfet.drain = atoi(token); /* read gate */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->mosfet.gate = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->mosfet.gate = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->mosfet.gate = n; } } //node->mosfet.gate = atoi(token); /* read source */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->mosfet.source = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->mosfet.source = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->mosfet.source = n; } } //node->mosfet.source = atoi(token); /* read body */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->mosfet.body = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->mosfet.body = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->mosfet.body = n; } } //node->mosfet.body = atoi(token); /* read length */ token = strtok(NULL," "); if( token == NULL ) return 0; node->mosfet.l = atof(token); /* read width */ token = strtok(NULL," "); if( token == NULL ) return 0; node->mosfet.w = atof(token); /* NO MORE TOKENS.IF FOUND RETURN ERROR */ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_MOSFET_TYPE; return 1; } else{ /* tokens were found.print for debugging...*/ printf("LINE: %s garbage token : %s\n" , line , token); return 0; } } /* * Bipolar junction transistor */ case 'Q': case 'q':{ /* read name */ token = strtok(line," "); if( token == NULL ){ return 0 ; } strcpy( node->bjt.name , token); /* read collector */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->bjt.collector = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->bjt.collector = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->bjt.collector = n; } } //node->bjt.collector = atoi(token); /* read base */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->bjt.base = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->bjt.base = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->bjt.base = n; } } //node->bjt.base = atoi(token); /* read emitter */ token = strtok(NULL," "); if( token == NULL ) return 0; /* check for reference node (ground) */ if( strcmp(token,"0") == 0 ){ node->bjt.emitter = 0; list->has_reference = 1; } else{ /* * this is not a reference node.Add string to * hash table */ flag = ht_insert_pair(list->hashtable, token , node_count); if( flag == 1 ){ /* successfull insertion */ node->bjt.emitter = node_count; node_count++; // get ready for the next node } else if( flag == 0 ){ /* NULL pointer or out of memory */ printf("Error at inserting pair to hash table..\n"); //free_list(list); exit(1); } else if( flag == -1 ){ int n; //printf("Node : \"%s\" already on hash table \n",token); ht_get(list->hashtable,token,&n); node->bjt.emitter = n; } } //node->bjt.emitter = atoi(token); /* more will be added later */ // // HERE // /* NO MORE TOKENS.IF FOUND RETURN ERROR */ token = strtok(NULL," \n"); if( token == NULL ){ *type = NODE_BJT_TYPE; return 1; } else{ /* tokens were found.print for debugging...*/ printf("LINE: %s garbage token : %s\n" , line , token); return 0; } } /* * DIODE */ /* * Commands */ case '.':{ char* temp = line; token = strtok(temp," "); if( !token ) return 0; /* solving method */ if( strcmp(token,".OPTIONS") == 0 || strcmp(token,".options") == 0 ){ token = strtok(NULL," \n"); //printf("Token after .options :%s\n",token); if( !token ){ printf("Error while parsing...\n"); printf("Must define an option \n"); printf("Line : %s\n", line ); return 0; } if( strcmp(token,"SPARSE") == 0 || strcmp(token,"sparse") == 0 ){ list->solving_method = METHOD_LU_SPARSE; list->sparse = 1; return 2; } //printf("TOKEN AFTER .OPTIONS :%s\n",token); else if( strcmp(token,"SPD") == 0 || strcmp(token,"spd") == 0 ){ token = strtok(NULL," \n"); if(!token){ list->solving_method = METHOD_CHOLESKY; return 2; } /*------ .OPTIONS SPD ITER----------------*/ if( strcmp(token,"ITER") == 0 || strcmp(token,"ITER") == 0){ list->solving_method = METHOD_CG; return 2; } /*------------ .OPTIONS SPD SPARSE--------------*/ else if (strcmp(token,"SPARSE") == 0 || strcmp(token,"sparse") == 0){ /* cholesky solution with sparce arrays */ list->solving_method = METHOD_CHOLESKY_SPARSE; list->sparse=1; } } else if( strcmp(token,"ITER") == 0 || strcmp(token,"iter") == 0 ){ token = strtok(NULL," \n"); if( !token ){ list->solving_method = METHOD_BICG; return 2; } /*----------- .OPTIONS ITER SPARSE ---------------*/ if( strcmp(token,"SPARSE") == 0 || strcmp(token,"sparse") == 0){ /* Bi-CG with sparce arrays */ list->solving_method = METHOD_BICG_SPARSE; list->sparse=1; } /*----------- .OPTIONS ITER SPD || ITER SPD SPARCE-------*/ else if( strcmp(token, "SPD") == 0 || strcmp(token, "spd") == 0){ token = strtok(NULL," \n"); if( !token ){ list->solving_method = METHOD_CG; return 2; } else if ( strcmp(token,"SPARSE") == 0 || strcmp(token,"sparse") == 0){ /* CG solving method with sparce arrays */ list->solving_method = METHOD_CG_SPARSE; list->sparse=1; } } } else if( strcmp(token,"ITOL") == 0 || strcmp(token,"itol") == 0){ /* tolerance */ token = strtok(NULL," \n"); if ( !token ){ printf("Error while parsing...\n"); printf("Line: %s\n",line); return 0; } if( strcmp(token,"=") == 0 ){ /* now read the tolerance value */ token = strtok(NULL," \n"); if( !token ){ printf("Error while parsing..\n"); printf("Line: %s\n",line); return 0; } else{ double val; val = atof(token); list->itol = val; return 2; } } else{ printf("Error while parsing...\n"); printf("Line: %s\n",line); return 0; } } else if(strcmp(token,"SPARCE") == 0 || strcmp(token,"sparce") == 0){ /*LU with sparce arrays*/ list->solving_method = METHOD_LU_SPARSE; list->sparse=1; } else if(strcmp(token,"METHOD=TR") == 0 || strcmp(token,"method=tr") == 0){ /*Trapezoidal Transient Method*/ list->transient_sim = METHOD_TR; } else if(strcmp(token,"METHOD=BE") == 0 || strcmp(token,"method=be") == 0){ /*Trapezoidal Transient Method*/ list->transient_sim = METHOD_BE; } else{ printf("No token after .OPTIONS \n"); return 0; } //return 2; } else if(strcmp(token,".TRAN") == 0 || strcmp(token,".tran") == 0){ /*read the time step*/ token = strtok(NULL," \n"); if( !token ){ printf("Error while parsing TRAN command, please define time step...\n"); printf("Line: %s\n",line); return 0; } list->time_step = atof( token ); /*read the finish time*/ token = strtok(NULL," \n"); if( !token ){ printf("Error while parsing TRAN command, please define finish time...\n"); printf("Line: %s\n",line); return 0; } list->fin_time = atof( token ); } else if( strcmp(token,".DC") == 0 || strcmp(token,".dc") == 0 ){ // check for .DC /* token = strtok(temp," "); if( !token ){ printf("Error while parsing...\n"); printf("Line : %s\n", line ); return 0; } */ token = strtok(NULL , " "); if( !token ){ // list->solving_method = METHOD_LU; //printf("Error while parsing...\n"); //printf("Line : %s\n", line ); return 2; } list->dc_sweep.name = strdup(token); //printf("DC: name = %s \n",list->dc_sweep.name); token = strtok(NULL , " "); if( !token ){ printf("Error while parsing...\n"); printf("Line : %s\n", line ); return 0; } list->dc_sweep.start_v = atof( token ); token = strtok(NULL , " "); if( !token ){ printf("Error while parsing...\n"); printf("Line : %s\n", line ); return 0; } list->dc_sweep.end_v = atof(token); token = strtok(NULL , " "); if( !token ){ printf("Error while parsing...\n"); printf("Line : %s\n", line ); return 0; } list->dc_sweep.inc = atof(token); // check if node already declared list->dc_sweep.node = list_search_by_name(list , list->dc_sweep.name ); if( !(list->dc_sweep.node)){ printf(".DC Error: %s element not found\n",list->dc_sweep.name); exit(1); } list->dc_sweep.oldval = list->dc_sweep.node->node.source_v.value ; } else if( strcmp(token,".PLOT") == 0 || strcmp(token,".plot") == 0 ){ int plot_num=0; //reading the PLOT command keyword plot_init(); list->plot = PLOT_ON; while(1){ //reading the source type for plotting token = strtok(NULL," (\n"); if( !token && plot_num == 0 ){ printf("Error while parsing...\n"); printf("Line : %s\n", line ); return 0; } else if(!token && plot_num>0) break; //reading the node name token = strtok(NULL,")"); printf("Going to plot results for node: %s \n", token); if( !token ){ printf("Error while parsing...\n"); printf("Line : %s\n", line ); return 0; } plot_add_node(token); plot_num++; } } } } printf("Total node count: %ld \n",node_count); printf("Hash_table nodes: %d\n",list->hashtable->num_nodes); return 2; }
/***************************************************************************** * \brief Testing mixer by creating sine waves for all input channels * \parameters None * \return None *****************************************************************************/ void test_mixer(void) { #if USE_DEBUG_PLOT static int iFirstTime = 1; int i, k,n; int temp; int speechIndex; bool bUseSpeech = true; // Initialize time indices if(iFirstTime) { for(i=0; i<(N_RX + N_MIC); i++) { uiSineTimeIndex[i] = 0; } plot_init(); iFirstTime = 0; true_voice_pilot_mode(0); true_voice_clt_mode(1); if (bUseSpeech) { true_voice_dtmf_queue('A'); true_voice_dtmf_queue('A'); true_voice_dtmf_remove_last_added(); true_voice_dtmf_queue('7'); //true_voice_dtmf_send_queue(); } } if (!bUseSpeech){ // Use sine waves while(uiSineTimeIndex[0] < TV_PLOT_LENGTH) { // Create sine wave for each channel with frequency 100 Hz, 200 Hz, 300 Hz, ... for(i=0; i<N_RX; i++) { sin_block(audioRx[i], (i+1)*100, &uiSineTimeIndex[i]); } for(i=0; i<N_MIC; i++) { sin_block(audioMic[i], (i+1+N_RX)*100, &uiSineTimeIndex[i+N_RX]); } //TODO: eventually remove temporary signals for limiter testing // TEMPORARY: change signals for limiter testing // for(i=0; i<N_RX; i++) { // if(uiSineTimeIndex[0] < TV_PLOT_LENGTH*0.1) { // for (k=0; k<BUFLEN_8KHZ; k++){ // audioRx[i][k]=mult_q15(audioRx[i][k], 8000); // } // } // else if (uiSineTimeIndex[0] < (TV_PLOT_LENGTH)*0.3) { // for (k=0; k<BUFLEN_8KHZ; k++){ // audioRx[i][k]=mult_q15(audioRx[i][k], 32767); // } // } // else{ // for (k=0; k<BUFLEN_8KHZ; k++){ // audioRx[i][k]=mult_q15(audioRx[i][k], 8000); // } // } // } // if (uiSineTimeIndex[0]>400) { // true_voice_volume_speaker(1, 10); // } // if (uiSineTimeIndex[0]>500) { // true_voice_volume_speaker(2, 5); // } // Mixer true_voice(rx, mic, tx, ls); // Store data (see plot.c in true_voice) write_plot_data(tx.psTechToRadio, &plot1, BUFLEN_8KHZ); write_plot_data(tx.psPilotToRadio, &plot2, BUFLEN_8KHZ); write_plot_data(tx.psFtnToLine, &plot3, BUFLEN_8KHZ); write_plot_data(tx.psCltToLine, &plot4, BUFLEN_8KHZ); write_plot_data(tx.psLmrToLine, &plot5, BUFLEN_8KHZ); write_plot_data(tx.psFtnToRadio, &plot6, BUFLEN_8KHZ); write_plot_data(tx.psCltToRadio , &plot7, BUFLEN_8KHZ); write_plot_data(tx.psLmrToRadio, &plot8, BUFLEN_8KHZ); write_plot_data(ls.psTechLeft, &plot9, BUFLEN_8KHZ); write_plot_data(ls.psTechRight, &plot10, BUFLEN_8KHZ); write_plot_data(ls.psTechMono, &plot11, BUFLEN_8KHZ); write_plot_data(ls.psPilotMono, &plot12, BUFLEN_8KHZ); } }// end sin waves if (bUseSpeech) { // Send male or female speech through a channel speechIndex = 0; temp=0; // while(speechIndex < TV_PLOT_LENGTH){ // speechIndex=speechIndex+BUFLEN_8KHZ; // for (i=0; i<BUFLEN_8KHZ; i++){ // // if (speechIndex<=11311-BUFLEN_8KHZ){ // //mic.psTechHeadset[i] = maleSpeech[i+speechIndex]; // rx.psLmr[i] = maleSpeech[i+speechIndex]; // } else{ // //mic.psTechHeadset[i] = 0; // rx.psLmr[i] = 0; // } // if (speechIndex<=12700-BUFLEN_8KHZ){ // mic.psTechHeadset[i] = femaleSpeech[i+speechIndex]; // } else{ // mic.psTechHeadset[i] = 0; // } // } while(temp < TV_PLOT_LENGTH){ temp += BUFLEN_8KHZ; //Update input buffer for(i=0; i<BUFLEN_8KHZ; i++){ mic.psTechHeadset[i] = maleSpeech[i+speechIndex]; //mic.psTechHeadset = audioMic[1] rx.psLmr[i] = femaleSpeech[i+speechIndex]; } speechIndex+=BUFLEN_8KHZ; if (speechIndex>=11311-BUFLEN_8KHZ){ speechIndex=0; } /* if(speechIndex == (32*35)){ true_voice_dtmf_send_queue(); } true_voice_volume_speaker(1, 0); true_voice_volume_speaker(2, 10); if (speechIndex>5000) { true_voice_volume_speaker(1, 10); true_voice_volume_speaker(2, 5); } if (speechIndex>10000) { true_voice_volume_speaker(1, 6); true_voice_volume_speaker(2, 3); } */ // Mixer true_voice(rx, mic, tx, ls); // Store data (see plot.c in true_voice) write_plot_data(tx.psTechToRadio, &plot1, BUFLEN_8KHZ); write_plot_data(tx.psPilotToRadio, &plot2, BUFLEN_8KHZ); write_plot_data(tx.psFtnToLine, &plot3, BUFLEN_8KHZ); write_plot_data(tx.psCltToLine, &plot4, BUFLEN_8KHZ); write_plot_data(tx.psLmrToLine, &plot5, BUFLEN_8KHZ); write_plot_data(tx.psFtnToRadio, &plot6, BUFLEN_8KHZ); write_plot_data(tx.psCltToRadio , &plot7, BUFLEN_8KHZ); write_plot_data(tx.psLmrToRadio, &plot8, BUFLEN_8KHZ); write_plot_data(ls.psTechLeft, &plot9, BUFLEN_8KHZ); write_plot_data(ls.psTechRight, &plot10, BUFLEN_8KHZ); write_plot_data(ls.psTechMono, &plot11, BUFLEN_8KHZ); write_plot_data(ls.psPilotMono, &plot12, BUFLEN_8KHZ); } }//end speech // Write stored data to output file write_plot_buffer_to_file("Tx0_TechToRadio.dat", &plot1); write_plot_buffer_to_file("Tx1_PilotToRadio.dat", &plot2); write_plot_buffer_to_file("Tx2_FtnToLine.dat", &plot3); write_plot_buffer_to_file("Tx3_CltToLine.dat", &plot4); write_plot_buffer_to_file("Tx4_LmrToLine.dat", &plot5); write_plot_buffer_to_file("Tx5_FtnToRadio.dat", &plot6); write_plot_buffer_to_file("Tx6_CltToRadio.dat", &plot7); write_plot_buffer_to_file("Tx7_LmrToRadio.dat", &plot8); write_plot_buffer_to_file("Ls0_TechLeft.dat", &plot9); write_plot_buffer_to_file("Ls1_TechRight.dat", &plot10); write_plot_buffer_to_file("Ls2_TechMono.dat", &plot11); write_plot_buffer_to_file("Ls3_PilotMono.dat", &plot12); write_plot_buffer_to_file("plotVar1.dat", &plotVar1); write_plot_buffer_to_file("plotVar2.dat", &plotVar2); write_plot_buffer_to_file("plotVar3.dat", &plotVar3); #endif // USE_DEBUG_PLOT }
int main(int argc, char **argv) { extern int plot_mag; extern int plot_inverse; int t, i, j; get_options(argc, argv, options, help_string); plot_inverse = invert; plot_mag = mag; plot_init(width, height, 4, term); plot_set_all(0); srandom(seed); initialize_world(); /* Make the sub sample size sane. */ if(samp <= 0) samp = MIN(width, height); /* For each time step... */ for(t = 0; t < steps; t++) { plants = herbs = carns = 0; /* For evey cell. */ for(i = 0; i < height; i++) for(j = 0; j < width; j++) { world[i][j].mark = 0; if(t % pfreq == 0) plot_point(i, j, world[i][j].type); /* Count the life forms in the subsample grid. */ if(i < samp && j < samp) { if(world[i][j].type == PLANT) plants++; else if(world[i][j].type == HERB) herbs++; else if(world[i][j].type == CARN) carns++; } } /* Do not allow extinctions, if appropriate. */ if(noext) { if(herbs == 0) { i = random_range(0, height); j = random_range(0, width); world[i][j].type = HERB; world[i][j].energy = Eh; herbs = 1; } if(carns == 0) { i = random_range(0, height); j = random_range(0, width); world[i][j].type = CARN; world[i][j].energy = Ec; carns = 1; } } if(stats) fprintf(stderr, "%d\t%d\t%d\n", plants, herbs, carns); update_plants(); update_herbs(); update_carns(); } plot_finish(); exit(0); }
/** * Initialise atari gui. */ static void gui_init(int argc, char** argv) { char buf[PATH_MAX]; OBJECT * cursors; atari_find_resource(buf, "netsurf.rsc", "./res/netsurf.rsc"); LOG("Using RSC file: %s ", (char *)&buf); if (rsrc_load(buf)==0) { char msg[1024]; snprintf(msg, 1024, "Unable to open GEM Resource file (%s)!", buf); die(msg); } wind_get_grect(0, WF_WORKXYWH, &desk_area); create_cursor(0, POINT_HAND, NULL, &gem_cursors.hand ); create_cursor(0, TEXT_CRSR, NULL, &gem_cursors.ibeam ); create_cursor(0, THIN_CROSS, NULL, &gem_cursors.cross); create_cursor(0, BUSY_BEE, NULL, &gem_cursors.wait); create_cursor(0, ARROW, NULL, &gem_cursors.arrow); create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizeall); create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenesw); create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenwse); cursors = gemtk_obj_get_tree(CURSOR); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_APPSTART, cursors, &gem_cursors.appstarting); gem_set_cursor( &gem_cursors.appstarting ); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZEWE, cursors, &gem_cursors.sizewe); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZENS, cursors, &gem_cursors.sizens); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_NODROP, cursors, &gem_cursors.nodrop); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_DENY, cursors, &gem_cursors.deny); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_MENU, cursors, &gem_cursors.menu); create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_HELP, cursors, &gem_cursors.help); LOG("Enabling core select menu"); nsoption_set_bool(core_select_menu, true); LOG("Loading url.db from: %s", nsoption_charp(url_file)); if( strlen(nsoption_charp(url_file)) ) { urldb_load(nsoption_charp(url_file)); } LOG("Loading cookies from: %s", nsoption_charp(cookie_file)); if( strlen(nsoption_charp(cookie_file)) ) { urldb_load_cookies(nsoption_charp(cookie_file)); } if (process_cmdline(argc,argv) != true) die("unable to process command line.\n"); LOG("Initializing NKC..."); nkc_init(); LOG("Initializing plotters..."); plot_init(nsoption_charp(atari_font_driver)); aes_event_in.emi_m1leave = MO_LEAVE; aes_event_in.emi_m1.g_w = 1; aes_event_in.emi_m1.g_h = 1; //next_poll = clock() + (CLOCKS_PER_SEC>>3); deskmenu_init(); menu_register( -1, theapp); if (sys_type() & (SYS_MAGIC|SYS_NAES|SYS_XAAES)) { menu_register( _AESapid, (char*)" NetSurf "); } gemtk_wm_init(); /* Initialize the specific treeview windows: */ atari_global_history_init(); atari_hotlist_init(); atari_cookie_manager_init(); /* Initialize the toolbar framework: */ toolbar_init(); }
int main (int argc, char **argv) { #ifdef MBCONTOURFILTER char program_name[] = "MBCONTOURFILTER"; char help_message[] = "MBCONTOURFILTER is a utility which creates a pen plot \ncontour map of multibeam swath bathymetry. \nThe primary purpose of this program is to serve as \npart of a real-time plotting system. The contour \nlevels and colors can be controlled \ndirectly or set implicitly using contour and color change intervals. \nContours can also be set to have ticks pointing downhill."; char usage_message[] = "mbcontourfilter -Jparameters -Rwest/east/south/north \n\t[-Acontour_int/color_int/tick_int/label_int/tick_len/label_hgt/label_spacing \n\t-Btickinfo -byr/mon/day/hour/min/sec -Ccontourfile \n\t-Dtime_tick/time_annot/date_annot/time_tick_len -Eyr/mon/day/hour/min/sec \n\t-fformat -Fred/green/blue -Idatalist -K -Llonflip -M -O -Nnplot \n\t-P -ppings -Q -Ttimegap -U -Xx-shift -Yy-shift -Zalgorithm -#copies -V -H]"; #else char program_name[] = "MBCONTOUR"; char help_message[] = "MBCONTOUR is a GMT compatible utility which creates a color postscript \ncontour map of multibeam swath bathymetry. \nComplete maps are made by using MBCONTOUR in conjunction with the \nusual GMT programs. The contour levels and colors can be controlled \ndirectly or set implicitly using contour and color change intervals. \nContours can also be set to have ticks pointing downhill."; char usage_message[] = "mbcontour -Jparameters -Rwest/east/south/north \n\t[-Acontour_int/color_int/tick_int/label_int/tick_len/label_hgt/label_spacing \n\t-Btickinfo -byr/mon/day/hour/min/sec -Ccontourfile -ccopies \n\t-Dtime_tick/time_annot/date_annot/time_tick_len \n\t-Eyr/mon/day/hour/min/sec \n\t-fformat -Fred/green/blue -Idatalist -K -Llonflip -Nnplot -O \n\t-P -ppings -U -Xx-shift -Yy-shift -Zalgorithm -V -H]"; #endif extern char *optarg; int argc_gmt = 0; char *argv_gmt[MBCONTOUR_GMT_ARG_MAX]; int errflg = 0; int c; int help = 0; int flag = 0; /* MBIO status variables */ int status = MB_SUCCESS; int verbose = 0; int error = MB_ERROR_NO_ERROR; char *message = NULL; /* MBIO read control parameters */ char read_file[MBCONTOUR_LABEL_LEN]; int read_datalist; int read_data; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; FILE *fp; int format; int pings; int lonflip; int lonflip_set = MB_NO; double bounds[4]; double mb_bounds[4]; int btime_i[7]; int etime_i[7]; double btime_d; double etime_d; double speedmin; double timegap; char file[MB_PATH_MAXLINE]; int file_in_bounds; int beams_bath; int beams_amp; int pixels_ss; void *mbio_ptr = NULL; /* mbio read values */ struct swath *swath_plot = NULL; struct ping *pingcur = NULL; int kind; int pings_read; int time_i[7]; double time_d; double navlon; double navlat; double speed; double heading; double distance; double altitude; double sonardepth; char *beamflag = NULL; double *bath = NULL; double *bathlon = NULL; double *bathlat = NULL; double *amp = NULL; double *ss = NULL; double *sslon = NULL; double *sslat = NULL; char comment[256]; int pingnumber; /* plot control variables */ int contour_algorithm; char contourfile[MB_PATH_MAXLINE]; int plot; int done; int flush; int save_new; int *npings = NULL; int nping_read; int nplot; int plot_contours; int plot_triangles; int set_contours; double cont_int; double col_int; double tick_int; double label_int; double tick_len; double label_hgt; double label_spacing; double tick_len_map; double label_hgt_map; double label_spacing_map; int plot_name; int plotted_name; int plot_track; double time_tick_int; double time_annot_int; double date_annot_int; double time_tick_len; double time_tick_len_map; double name_hgt; double name_hgt_map; int name_perp; double scale; int bathy_in_feet; int plot_pingnumber; int pingnumber_tick_int; int pingnumber_annot_int; double pingnumber_tick_len; double pingnumber_tick_len_map; /* pen variables */ int ncolor; int nlevel; double *level = NULL; int *red = NULL; int *green = NULL; int *blue = NULL; int *label = NULL; int *tick = NULL; /* inch to map scale */ double inchtolon; /* other variables */ char line[MBCONTOUR_LABEL_LEN]; char labelstr[MBCONTOUR_LABEL_LEN], tickstr[MBCONTOUR_LABEL_LEN]; int count; int setcolors; double navlon_old; double navlat_old; int i1, i2; double d1, d2, d3, d4, d5, d6, d7; int nscan; int i; /* get current mb default values */ status = mb_defaults(verbose,&format,&pings,&lonflip,bounds, btime_i,etime_i,&speedmin,&timegap); /* set default input to stdin */ strcpy (read_file, "stdin"); /* initialize some values */ format = -1; read_datalist = MB_NO; contour_algorithm = MB_CONTOUR_OLD; strcpy (contourfile,"\0"); set_contours = MB_NO; bounds[0] = 0.0; bounds[1] = 0.0; bounds[2] = 0.0; bounds[3] = 0.0; scale = 0.0; nplot = 0; cont_int = 25.; col_int = 100.; tick_int = 100.; label_int = 100.; label_hgt = 0.1; label_spacing = 0.0; tick_len = 0.05; plot_name = MB_NO; plot_track = MB_NO; time_tick_int = 0.25; time_annot_int = 1.0; date_annot_int = 4.0; time_tick_len = 0.1; name_hgt = 0.1; name_perp = MB_NO; ncolor = 4; nlevel = 0; plot_contours = MB_NO; plot_triangles = MB_NO; bathy_in_feet = MB_NO; plot_pingnumber = MB_NO; pingnumber_tick_int = 50; pingnumber_annot_int = 100; pingnumber_tick_len = 0.1; /* get GMT options into separate argv */ argv_gmt[0] = argv[0]; argc_gmt = 1; for (i=1;i<argc;i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'B': case 'F': case 'J': case 'j': case 'K': case 'k': case 'O': case 'o': case 'P': case 'R': case 'r': case 'U': case 'u': case 'V': case 'v': case 'X': case 'x': case 'Y': case 'y': case '#': if (argc_gmt < MBCONTOUR_GMT_ARG_MAX) { argv_gmt[argc_gmt] = argv[i]; argc_gmt++; break; } } } } /* deal with mb options */ while ((c = getopt(argc, argv, "VvHhA:a:B:b:C:c:D:d:E:e:F:f:G:g:I:i:J:j:KkL:l:M:m:N:n:OoPp:QqR:r:S:s:T:t:UuWwX:x:Y:y:Z:z:")) != -1) switch (c) { case 'A': case 'a': nscan = sscanf (optarg, "%lf/%lf/%lf/%lf/%lf/%lf/%lf", &d1,&d2,&d3,&d4,&d5,&d6,&d7); if (nscan >= 1) cont_int = d1; if (nscan >= 2) col_int = d2; if (nscan >= 3) tick_int = d3; if (nscan >= 4) label_int = d4; if (nscan >= 5) tick_len = d5; if (nscan >= 6) label_hgt = d6; if (nscan >= 7) label_spacing = d7; if (nscan >= 1) plot_contours = MB_YES; break; case 'b': sscanf (optarg, "%d/%d/%d/%d/%d/%d", &btime_i[0],&btime_i[1],&btime_i[2], &btime_i[3],&btime_i[4],&btime_i[5]); btime_i[6] = 0; break; case 'C': sscanf (optarg,"%s", contourfile); plot_contours = MB_YES; set_contours = MB_YES; break; case 'D': case 'd': sscanf (optarg, "%lf/%lf/%lf/%lf", &time_tick_int,&time_annot_int, &date_annot_int,&time_tick_len); plot_track = MB_YES; break; case 'E': case 'e': sscanf (optarg, "%d/%d/%d/%d/%d/%d", &etime_i[0],&etime_i[1],&etime_i[2], &etime_i[3],&etime_i[4],&etime_i[5]); etime_i[6] = 0; break; case 'f': sscanf (optarg, "%d",&format); break; case 'G': case 'g': nscan = sscanf (optarg, "%lf/%d", &name_hgt, &name_perp); plot_name = MB_YES; if (nscan < 1) name_hgt = 0.1; if (nscan < 2) name_perp = MB_NO; break; case 'H': case 'h': help++; break; case 'I': case 'i': sscanf (optarg,"%s", read_file); flag++; break; case 'J': if (optarg[0] == 'm') sscanf (&optarg[1],"%lf", &scale); flag++; break; case 'L': case 'l': sscanf (optarg,"%d", &lonflip); lonflip_set = MB_YES; flag++; break; case 'M': case 'm': nscan = sscanf (optarg, "%d/%d/%lf", &i1,&i2,&d3); if (nscan >= 1) pingnumber_tick_int = i1; if (nscan >= 2) pingnumber_annot_int = i2; if (nscan >= 3) pingnumber_tick_len = d3; if (nscan >= 1) plot_pingnumber = MB_YES; break; case 'N': case 'n': sscanf (optarg,"%d", &nplot); if (nplot < 3) nplot = 3; break; case 'p': sscanf (optarg,"%d", &pings); flag++; break; case 'Q': case 'q': plot_triangles = MB_YES; break; case 'R': case 'r': sscanf(optarg,"%lf/%lf/%lf/%lf", &bounds[0],&bounds[1], &bounds[2],&bounds[3]); break; case 'S': case 's': sscanf (optarg, "%lf", &speedmin); break; case 'T': case 't': sscanf (optarg,"%lf", &timegap); flag++; break; case 'V': case 'v': verbose++; break; case 'W': case 'w': bathy_in_feet = MB_YES; break; case 'Z': case 'z': sscanf (optarg,"%d", &contour_algorithm); flag++; break; case 'B': case 'F': case 'K': case 'O': case 'P': case 'U': case 'X': case 'x': case 'Y': case 'y': case '#': break; case '?': errflg++; } /* if error flagged then print it and exit */ if (errflg) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* set number of pings to be plotted if not set */ if (nplot == 0 && contour_algorithm == MB_CONTOUR_TRIANGLES) nplot = 5; else if (nplot == 0) nplot = 50; /* if nothing set to be plotted, plot contours and track */ if (plot_contours == MB_NO && plot_triangles == MB_NO && plot_track == MB_NO && plot_pingnumber == MB_NO) { plot_contours = MB_YES; plot_track = MB_YES; } if (plot_name == MB_YES && plot_track == MB_NO && plot_pingnumber == MB_NO) { plot_track = MB_YES; } if (plot_track == MB_NO && plot_pingnumber == MB_YES) { plot_track = MB_YES; time_tick_int = 10000000.0; time_annot_int = 10000000.0; date_annot_int = 10000000.0; } /* print starting message */ if (verbose == 1 || help) { fprintf(stderr,"\nProgram %s\n",program_name); fprintf(stderr,"MB-system Version %s\n",MB_VERSION); } /* if help desired then print it and exit */ if (help) { fprintf(stderr,"\n%s\n",help_message); fprintf(stderr,"\nusage: %s\n", usage_message); exit(error); } /* initialize plotting */ status = plot_init(verbose,argc_gmt,argv_gmt,bounds,&scale,&inchtolon,&error); /* if error flagged then print it and exit */ if (status == MB_FAILURE) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"GMT option error\n"); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s>\n",program_name); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Control Parameters:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 help: %d\n",help); fprintf(stderr,"dbg2 format: %d\n",format); fprintf(stderr,"dbg2 pings: %d\n",pings); fprintf(stderr,"dbg2 lonflip: %d\n",lonflip); fprintf(stderr,"dbg2 btime_i[0]: %d\n",btime_i[0]); fprintf(stderr,"dbg2 btime_i[1]: %d\n",btime_i[1]); fprintf(stderr,"dbg2 btime_i[2]: %d\n",btime_i[2]); fprintf(stderr,"dbg2 btime_i[3]: %d\n",btime_i[3]); fprintf(stderr,"dbg2 btime_i[4]: %d\n",btime_i[4]); fprintf(stderr,"dbg2 btime_i[5]: %d\n",btime_i[5]); fprintf(stderr,"dbg2 btime_i[6]: %d\n",btime_i[6]); fprintf(stderr,"dbg2 etime_i[0]: %d\n",etime_i[0]); fprintf(stderr,"dbg2 etime_i[1]: %d\n",etime_i[1]); fprintf(stderr,"dbg2 etime_i[2]: %d\n",etime_i[2]); fprintf(stderr,"dbg2 etime_i[3]: %d\n",etime_i[3]); fprintf(stderr,"dbg2 etime_i[4]: %d\n",etime_i[4]); fprintf(stderr,"dbg2 etime_i[5]: %d\n",etime_i[5]); fprintf(stderr,"dbg2 etime_i[6]: %d\n",etime_i[6]); fprintf(stderr,"dbg2 speedmin: %f\n",speedmin); fprintf(stderr,"dbg2 timegap: %f\n",timegap); fprintf(stderr,"dbg2 read file: %s\n",read_file); fprintf(stderr,"dbg2 bounds[0]: %f\n",bounds[0]); fprintf(stderr,"dbg2 bounds[1]: %f\n",bounds[1]); fprintf(stderr,"dbg2 bounds[2]: %f\n",bounds[2]); fprintf(stderr,"dbg2 bounds[3]: %f\n",bounds[3]); fprintf(stderr,"dbg2 contour algorithm: %d\n",contour_algorithm); fprintf(stderr,"dbg2 plot contours: %d\n",plot_contours); fprintf(stderr,"dbg2 plot triangles: %d\n",plot_triangles); fprintf(stderr,"dbg2 plot track: %d\n",plot_track); fprintf(stderr,"dbg2 plot_pingnumber: %d\n",plot_pingnumber); fprintf(stderr,"dbg2 plot name: %d\n",plot_name); fprintf(stderr,"dbg2 contour interval: %f\n",cont_int); fprintf(stderr,"dbg2 color interval: %f\n",col_int); fprintf(stderr,"dbg2 tick interval: %f\n",tick_int); fprintf(stderr,"dbg2 label interval: %f\n",label_int); fprintf(stderr,"dbg2 tick length: %f\n",tick_len); fprintf(stderr,"dbg2 label height: %f\n",label_hgt); fprintf(stderr,"dbg2 label spacing: %f\n",label_spacing); fprintf(stderr,"dbg2 number contoured: %d\n",nplot); fprintf(stderr,"dbg2 time tick int: %f\n",time_tick_int); fprintf(stderr,"dbg2 time interval: %f\n",time_annot_int); fprintf(stderr,"dbg2 date interval: %f\n",date_annot_int); fprintf(stderr,"dbg2 time tick length: %f\n",time_tick_len); fprintf(stderr,"dbg2 name height: %f\n",name_hgt); fprintf(stderr,"dbg2 pingnumber tick int: %d\n",pingnumber_tick_int); fprintf(stderr,"dbg2 pingnumber annot int: %d\n",pingnumber_annot_int); fprintf(stderr,"dbg2 pingnumber tick len: %f\n",pingnumber_tick_len); fprintf(stderr,"dbg2 bathy_in_feet: %d\n\n",bathy_in_feet); } /* if bounds not specified then quit */ if (bounds[0] >= bounds[1] || bounds[2] >= bounds[3] || bounds[2] <= -90.0 || bounds[3] >= 90.0) { fprintf(stderr,"\nRegion bounds not properly specified:\n\t%f %f %f %f\n",bounds[0],bounds[1],bounds[2],bounds[3]); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_PARAMETER; exit(error); } /* scale label and tick sizes */ label_hgt_map = inchtolon * label_hgt; label_spacing_map = inchtolon * label_spacing; tick_len_map = inchtolon * tick_len; time_tick_len_map = inchtolon * time_tick_len; name_hgt_map = inchtolon * name_hgt; pingnumber_tick_len_map = inchtolon * pingnumber_tick_len; /* read contours from file */ if (set_contours == MB_YES) { /* open contour file */ if ((fp = fopen(contourfile,"r")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open contour file: %s\n", contourfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* count lines in file */ nlevel = 0; while (fgets(line,MBCONTOUR_LABEL_LEN,fp) != NULL) nlevel++; fclose(fp); /* set number of colors equal to levels */ ncolor = nlevel; /* allocate memory */ status = mb_mallocd(verbose, __FILE__, __LINE__, nlevel*sizeof(double), (void **)&level,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, nlevel*sizeof(int), (void **)&label,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, nlevel*sizeof(int), (void **)&tick,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&red,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&green,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&blue,&error); /* reopen contour file */ if ((fp = fopen(contourfile,"r")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open contour file: %s\n", contourfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* read contour levels from file */ nlevel = 0; while (fgets(line,MBCONTOUR_LABEL_LEN,fp) != NULL) { count = sscanf(line,"%lf %s %s %d %d %d", &level[nlevel],labelstr,tickstr, &red[nlevel],&green[nlevel],&blue[nlevel]); setcolors = MB_YES; if (count >= 2 && labelstr[0] == 'a') label[nlevel] = 1; else if (count >= 2 && labelstr[0] == 'n') label[nlevel] = 0; else { label[nlevel] = 0; setcolors = MB_NO; } if (count >= 3 && tickstr[0] == 't') tick[nlevel] = 1; else if (count >= 3 && tickstr[0] == 'n') tick[nlevel] = 0; else { tick[nlevel] = 0; setcolors = MB_NO; } if (count < 6 || setcolors == MB_NO) { red[nlevel] = 0; green[nlevel] = 0; blue[nlevel] = 0; } if (count > 0) nlevel++; } fclose(fp); } /* else set default colors and use contour intervals */ else { /* set defaults */ nlevel = 0; ncolor = 4; /* allocate memory */ status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&red,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&green,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&blue,&error); /* set colors */ red[0] = 0; green[0] = 0; blue[0] = 0; /* black */ red[1] = 255; green[1] = 0; blue[1] = 0; /* red */ red[2] = 0; green[2] = 200; blue[2] = 0; /* green */ red[3] = 0; green[3] = 0; blue[3] = 255; /* blue */ } /* set colors */ set_colors(ncolor,red,green,blue); /* set bounds for multibeam reading larger than map borders */ mb_bounds[0] = bounds[0] - 0.25*(bounds[1] - bounds[0]); mb_bounds[1] = bounds[1] + 0.25*(bounds[1] - bounds[0]); mb_bounds[2] = bounds[2] - 0.25*(bounds[3] - bounds[2]); mb_bounds[3] = bounds[3] + 0.25*(bounds[3] - bounds[2]); /* set lonflip if possible */ if (lonflip_set == MB_NO) { if (mb_bounds[0] < -180.0) lonflip = -1; else if (mb_bounds[1] > 180.0) lonflip = 1; else if (lonflip == -1 && mb_bounds[1] > 0.0) lonflip = 0; else if (lonflip == 1 && mb_bounds[0] < 0.0) lonflip = 0; } /* determine whether to read one file or a list of files */ if (format < 0) read_datalist = MB_YES; /* open file list */ nping_read = 0; if (read_datalist == MB_YES) { if ((status = mb_datalist_open(verbose,&datalist, read_file,look_processed,&error)) != MB_SUCCESS) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open data list file: %s\n", read_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { strcpy(file,read_file); read_data = MB_YES; } /* loop over files in file list */ if (verbose == 1) fprintf(stderr,"\n"); while (read_data == MB_YES) { /* check for mbinfo file - get file bounds if possible */ status = mb_check_info(verbose, file, lonflip, bounds, &file_in_bounds, &error); if (status == MB_FAILURE) { file_in_bounds = MB_YES; status = MB_SUCCESS; error = MB_ERROR_NO_ERROR; } /* read if data may be in bounds */ if (file_in_bounds == MB_YES) { /* check for "fast bathymetry" or "fbt" file */ if (plot_contours == MB_YES) { mb_get_fbt(verbose, file, &format, &error); } /* else check for "fast nav" or "fnv" file */ else if (plot_track == MB_YES || plot_pingnumber == MB_YES) { mb_get_fnv(verbose, file, &format, &error); } /* call mb_read_init() */ if ((status = mb_read_init( verbose,file,format,pings,lonflip,mb_bounds, btime_i,etime_i,speedmin,timegap, &mbio_ptr,&btime_d,&etime_d, &beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message); fprintf(stderr,"\nMultibeam File <%s> not initialized for reading\n",file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* allocate memory for data arrays */ if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(char), (void **)&beamflag, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bath, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_AMPLITUDE, sizeof(double), (void **)&, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathlon, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathlat, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ss, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&sslon, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&sslat, &error); /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n",message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* initialize contour controls */ status = mb_contour_init(verbose,&swath_plot,nplot,beams_bath, contour_algorithm, plot_contours,plot_triangles, plot_track,plot_name,plot_pingnumber, cont_int,col_int,tick_int,label_int, tick_len_map,label_hgt_map,label_spacing_map, ncolor,nlevel,level,label,tick, time_tick_int,time_annot_int, date_annot_int,time_tick_len_map,name_hgt_map, pingnumber_tick_int,pingnumber_annot_int, pingnumber_tick_len_map, &error); swath_plot->beams_bath = beams_bath; /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating contour control structure:\n%s\n",message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* print message */ if (verbose >= 2) fprintf(stderr,"\n"); if (verbose >= 1) fprintf(stderr,"processing data in %s...\n",file); /* loop over reading */ npings = &swath_plot->npings; *npings = 0; done = MB_NO; plotted_name = MB_NO; while (done == MB_NO) { /* read the next ping */ status = mb_read(verbose,mbio_ptr,&kind, &pings_read,time_i,&time_d, &navlon,&navlat, &speed,&heading, &distance,&altitude,&sonardepth, &beams_bath,&beams_amp,&pixels_ss, beamflag,bath,amp,bathlon,bathlat, ss,sslon,sslat, comment,&error); /* get pingnumber */ if (status == MB_SUCCESS) { status = mb_pingnumber(verbose,mbio_ptr,&pingnumber,&error); } /* copy data to swath_plot */ if (status == MB_SUCCESS || error == MB_ERROR_TIME_GAP) { pingcur = &swath_plot->pings[*npings]; /* make sure enough memory is allocated */ if (pingcur->beams_bath_alloc < beams_bath) { status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(char), (void **)&(pingcur->beamflag),&error); status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(pingcur->bath),&error); status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(pingcur->bathlon),&error); status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(pingcur->bathlat),&error); status = mb_reallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(int), (void **)&(pingcur->bflag[0]),&error); status = mb_reallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(int), (void **)&(pingcur->bflag[1]),&error); pingcur->beams_bath_alloc = beams_bath; } /* insert the data */ for (i=0;i<7;i++) pingcur->time_i[i] = time_i[i]; pingcur->time_d = time_d; pingcur->navlon = navlon; pingcur->navlat = navlat; pingcur->heading = heading; pingcur->beams_bath = beams_bath; pingcur->pingnumber = pingnumber; for (i=0;i<beams_bath;i++) { pingcur->beamflag[i] = beamflag[i]; pingcur->bath[i] = bath[i]; pingcur->bathlon[i] = bathlon[i]; pingcur->bathlat[i] = bathlat[i]; pingcur->bflag[0][i] = 0; pingcur->bflag[1][i] = 0; } } /* null out any unused beams for formats with variable numbers of beams */ for (i=beams_bath;i<swath_plot->beams_bath;i++) beamflag[i] = MB_FLAG_NULL; /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Ping read in program <%s>\n", program_name); fprintf(stderr,"dbg2 kind: %d\n", kind); fprintf(stderr,"dbg2 npings: %d\n", *npings); fprintf(stderr,"dbg2 time: %4d %2d %2d %2d %2d %2d %6.6d\n", time_i[0],time_i[1],time_i[2], time_i[3],time_i[4],time_i[5],time_i[6]); fprintf(stderr,"dbg2 navigation: %f %f\n", navlon, navlat); fprintf(stderr,"dbg2 beams_bath: %d\n", beams_bath); fprintf(stderr,"dbg2 beams_amp: %d\n", beams_amp); fprintf(stderr,"dbg2 pixels_ss: %d\n", pixels_ss); fprintf(stderr,"dbg2 error: %d\n", error); fprintf(stderr,"dbg2 status: %d\n", status); } /* scale bathymetry if necessary */ if (error == MB_ERROR_NO_ERROR && bathy_in_feet == MB_YES) { for (i=0;i<beams_bath;i++) { bath[i] = 3.2808399 * bath[i]; } } /* update bookkeeping */ if (error == MB_ERROR_NO_ERROR) { /*if (*npings == 0 || (*npings > 0 && contour_algorithm == MB_CONTOUR_TRIANGLES) || (*npings > 0 && (navlon != navlon_old || navlat != navlat_old)))*/ { nping_read += pings_read; (*npings)++; navlon_old = navlon; navlat_old = navlat; } } /* decide whether to plot, whether to save the new ping, and if done */ plot = MB_NO; flush = MB_NO; if (*npings >= nplot) plot = MB_YES; if (*npings > 0 && (error > MB_ERROR_NO_ERROR || error == MB_ERROR_TIME_GAP || error == MB_ERROR_OUT_BOUNDS || error == MB_ERROR_OUT_TIME || error == MB_ERROR_SPEED_TOO_SMALL)) { plot = MB_YES; flush = MB_YES; } save_new = MB_NO; if (error == MB_ERROR_TIME_GAP) save_new = MB_YES; if (error > MB_ERROR_NO_ERROR) done = MB_YES; /* if enough pings read in, plot them */ if (plot == MB_YES) { /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Plotting %d pings in program <%s>\n", *npings,program_name); for (i=0;i<*npings;i++) { pingcur = &swath_plot->pings[i]; fprintf(stderr,"dbg2 %4d %4d %2d %2d %2d %2d %2d %6.6d\n", i,pingcur->time_i[0], pingcur->time_i[1], pingcur->time_i[2], pingcur->time_i[3], pingcur->time_i[4], pingcur->time_i[5], pingcur->time_i[6]); } } /* plot data */ if (plot_contours == MB_YES || plot_triangles == MB_YES) mb_contour(verbose,swath_plot,&error); /* plot nav track */ if (plot_track == MB_YES) mb_track(verbose,swath_plot,&error); /* annotate pingnumber */ if (plot_pingnumber == MB_YES) { mb_trackpingnumber(verbose,swath_plot,&error); } if (plot_name == MB_YES && plotted_name == MB_NO) { mb_trackname(verbose,name_perp,swath_plot,file,&error); plotted_name = MB_YES; } /* reorganize data */ if (flush == MB_YES && save_new == MB_YES) { status = ping_copy(verbose,0,*npings, swath_plot,&error); *npings = 1; } else if (flush == MB_YES) { *npings = 0; } else if (*npings > 1) { status = ping_copy(verbose,0,*npings-1, swath_plot,&error); *npings = 1; } } } status = mb_close(verbose,&mbio_ptr,&error); /* deallocate memory for data arrays */ status = mb_contour_deall(verbose,swath_plot,&error); } /* end if file in bounds */ /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { read_data = MB_NO; } /* end loop over files in list */ } if (read_datalist == MB_YES) mb_datalist_close(verbose,&datalist,&error); /* end plot */ plot_end(verbose,&error); /* deallocate memory for data arrays */ mb_freed(verbose,__FILE__, __LINE__, (void **)&level,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&label,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&tick,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&red,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&green,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&blue,&error); /* print ending info */ if (verbose >= 1) fprintf(stderr,"\n%d pings read and plotted\n", nping_read); /* check memory */ if (verbose >= 2) status = mb_memory_list(verbose,&error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s> completed\n", program_name); fprintf(stderr,"dbg2 Ending status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* end it all */ plot_exit(argc,argv); exit(status); }
int main(int argc, char **argv) { extern int plot_mag; extern int plot_inverse; int i, j, k; /* SSZ is the size of the buffers, while SI is the current index. */ int ssz, si; /* Variables used to calculate the time evolution of the system. */ double x, y, z; /* Buffers to store delay values of all three variables. */ double *buffer[3]; /* Pointers into the buffers that always refer to the current, * and once delayed values. */ double *delays[3][2]; /* Pointers to the pointers that refer what is to be plotted. */ double **ppx, **ppy; /* Variables used to compute auto-scaling. */ double xmin, xmax, ymin, ymax; /* Values that are to be plotted. */ double px, py, pxx = 0, pyy = 0, temp; get_options(argc, argv, options, help_string); /* Set up the pointers so that they refer to the proper values to * plot with respect to. */ assign_pointer(&ppx, delays, xp); assign_pointer(&ppy, delays, yp); if(!data) { plot_mag = mag; plot_inverse = invert; plot_init(width, height, 2, term); plot_set_all(0); } /* Initialize the buffer space. */ ssz = delta + 1; for(i = 0; i < 3; i++) buffer[i] = xmalloc(sizeof(double) * ssz); si = 0; /* Initialize the system. */ x = xx0; y = yy0; z = zz0; /* Set insane minimum and maximum guesses. */ xmin = ymin = 10e10; xmax = ymax = -10e10; /* For all points (plus the skip and delay values. */ for(i = 0; i < points + skip + ssz; i++) { /* Compute the time evolution of the system. */ euler(dt, &x, &y, &z); /* Save the state so that we can remember delayed values. */ buffer[0][si] = x; buffer[1][si] = y; buffer[2][si] = z; /* For each state value ... , and for each delay value ... */ for(j = 0; j < 3; j++) for(k = 0; k < 2; k++) /* Adjust the pointers to refer to the proper delays. */ delays[j][k] = &buffer[j][(si + ssz - k * delta) % ssz]; si = (si + 1) % ssz; if(data) { if(i >= skip + ssz) printf("%f\t%f\t%f\n", x, y, z); } else { /* Get the point that we want to plot. */ px = **ppx; py = **ppy; /* If we are still skipping points, adjust the best guesses for * the minimum and maximums. */ if(i <= skip + ssz) { xmin = (px < xmin) ? px : xmin; xmax = (px > xmax) ? px : xmax; ymin = (py < ymin) ? py : ymin; ymax = (py > ymax) ? py : ymax; } /* If this is the last point to be skipped, reset the plotting * range based on the minimum and maximums. */ if(i == skip + ssz) { temp = (xmax - xmin) * factor; xmin -= temp; xmax += temp; temp = (ymax - ymin) * factor; ymin -= temp; ymax += temp; plot_set_range(xmin, xmax, ymin, ymax); } /* Plot a line from the last point to the current point. */ if(i >= skip + ssz) plot_line(pxx, pyy, px, py, 1); /* Save the last point. */ pxx = px; pyy = py; } } if(!data) plot_finish(); exit(0); }