int main(int argc, char const *argv[]) { float x0 = -1.; float x_max = 10.; float dx = 0.05; size_t x_size; float* x_all = create_range(x0, x_max, dx, &x_size); float t0 = 0.; float t_max = 10.; float dt = 0.02; int plot_count = 10; int plot_every = (int) t_max / dt / plot_count; char *tag = "pure_1D"; char *dir = "pure_1D"; mkdir(dir); float* phi = create_empty_array(x_size); init_phi_1D(phi, x_all, x_size); float mu = dt * M / (dx * dx); float t = t0; int i = 0; while (t < t_max) { if (i % plot_every == 0) { output_data(x_all, phi, x_size, t, dir, tag); } i++; t += dt; update_phi(x_all, phi, x_size, t, mu, eps2, u_iso); } }
static void* convert_UnicodetoANSI (const ustring::awareness_t* dest, const ustring::awareness_t* src, const void* p, void* result) { // convert from 16-bit to 8-bit characters const int len= src->length(p); const int hopefully_enough_slack= 100; // A known problem. Sometimes WideCharToMultiByte can require a larger // buffer when working than it does when finished. How big is unknown. // It appears to only be a problem when composite characters are near the // end of the input. const int destsize= Unicode_converted_length (dest, src, p); result= dest->create (destsize, result); //create or re-allocate as needed // prepare output area fastbuf<char, 1024> output_data (destsize+hopefully_enough_slack); // do the actual converting int srcpos= 0; // position of this gulp int destpos= 0; while (srcpos < len) { //still stuff left to process // read input data int srccount= len-srcpos; // number of input bytes to process in one gulp const wchar_t* input_data= static_cast<const wchar_t*>(src->read_data(p,srcpos,srccount)); //note: call to read_data will reduce value of srccount if it can't get it all at once. srcpos += srccount; // convert this gulp int putlen= ratwin::WideCharToMultiByte (input_data, srccount, output_data, output_data.elcount()); if (putlen == 0) { win_exception X ("Classics", FNAME, __LINE__); X += L"error calling WideCharToMultiByte\n"; throw X; } dest->write_data (result, destpos, putlen, output_data); destpos += putlen; } return result; }
static void* convert_ANSItoUnicode (const ustring::awareness_t* dest, const ustring::awareness_t* src, const void* p, void* result) { // convert from 8-bit to 16-bit characters const int len= src->length(p); //total number of BYTES to be converted const int destsize= ANSI_converted_length (dest, src, p); result= dest->create (destsize, result); //create or re-allocate as needed // prepare output area fastbuf<wchar_t, 1024> output_data (destsize); // do the actual converting int srcpos= 0; // position of this gulp int destpos= 0; while (srcpos < len) { //still stuff left to process // read input data int srccount= len-srcpos; // number of input bytes to process in one gulp const char* input_data= static_cast<const char*>(src->read_data(p,srcpos,srccount)); //note: call to read_data will reduce value of srccount if it can't get it all at once. srcpos += srccount; // convert this gulp int putlen= ratwin::MultiByteToWideChar (input_data, srccount, output_data, destsize); if (putlen == 0) { win_exception X ("Classics", FNAME, __LINE__); X += L"error calling MultiByteToWideChar\n"; throw X; } dest->write_data (result, destpos, putlen, output_data); destpos += putlen; } return result; }
__interrupt void ISR_Timer_B_CCR0 (void) { // Feststellen welche Werte im timestruct der aktuellen Zeit // geaendert werden muessen if (now.s==10) { // eine Sekunde ist vergangen now.s=0; now.ss++; // im Sekundentakt Uhrzeit und Werte des SHT11 ausgeben output_data(); if (now.ss==60) { // eine Minute ist vergangen now.ss=0; now.mm++; if (now.mm==60) { // eine Stunde ist vergangen now.mm=0; now.hh++; if(now.hh==24) { // ein Tag ist vergangen now.hh=0; } } } } else { // eine Zentelsekunde ist Vergangen now.s++; } // Interruptflag entfernen um eine Wiederholung der ISR, wegen // gesetzem Interruptflag, zu verhindern TBCCTL0 &= ~CCIFG; }
static int use_temper1(struct usb_dev_handle *handle) { int r, do_read = TRUE; char data[8]; char busport[100] = {}; r = handle_bus_port(handle, busport); if (strlen(opts.only_device) > 0) { do_read = (strcmp(busport, opts.only_device) == 0); } if (do_read) { bzero(data, 8); r = read_temper1(handle, data, 8); if (r != 0) { if (decode_raw_data(data) != 0) { output_data(busport, data); } else { if (opts.verbose) fprintf(stderr, "Read returned 0 value (r = %i)\n", r); r = -1; } } else { if (opts.verbose) fprintf(stderr, "use_temper1: read_temper1 returned (r = %i)\n", r); } } return r; }
int get_lifetime(int argc, char **argv) { int ret; uint32_t timestamp; uint8_t nonce[TOKEN_NONCE_LENGTH]; uint8_t mac[TOKEN_MAC_LENGTH]; ret = tee_token_lifetimedata_get(×tamp, nonce, mac); if (ret != 0) { raise_error("tee_token_lifetimedata_get call failed, return=0x%x", ret); return ret; } output_data((uint8_t *)×tamp, sizeof(timestamp)); output_data(nonce, sizeof(nonce)); output_data(mac, sizeof(mac)); return ret; }
/* * flowstat * * Check for changes to flow control */ void flowstat(void) { if (his_state_is_will(TELOPT_LFLOW)) { if (tty_flowmode() != flowmode) { flowmode = tty_flowmode(); output_data("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); } if (tty_restartany() != restartany) { restartany = tty_restartany(); output_data("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, restartany ? LFLOW_RESTART_ANY : LFLOW_RESTART_XON, IAC, SE); } } }
int main(int argc, const char *argv[]) { // Allocate flList printf("-------- Allocating (list - length 4)\n"); flList *list = flList_alloc(4); output_data(list); // Populate flList printf("-------- Populating\n"); int i = 100; flList_set(list, 0, &i); flList_set(list, 1, &(int){ 200 });
int get_part_id (int argc, char **argv) { int ret; uint8_t partid_buf[TOKEN_PSID_LENGTH]; ret = tee_partid_get(partid_buf); if (ret != 0) raise_error("tee_partid_get() call failed, return=0x%x", ret); else output_data(partid_buf, sizeof(partid_buf)); return ret; }
void process_image(const void *p, int size) { byte *jpg = NULL; unsigned int jpgSize = 0; jpg = mjpeg2jpeg((const byte*)p, size, &jpgSize); if ( jpg == NULL ) errno_exit("mjpeg2jpeg"); fprintf(stderr, "process_image %d\n", jpgSize); output_data(jpg, jpgSize); free(jpg); }
int get_ssn(int argc, char **argv) { int ret; uint8_t data[ssn_item.size]; ret = tee_token_item_read(SERIAL_NUMBER_DATAGROUP, ssn_item.subgroup_id, ssn_item.item_id, 0, data, ssn_item.size, 0); if (ret != 0) raise_error("tee_token_item_read() call failed, return=0x%x", ret); else output_data(data, ssn_item.size); return ret; }
void send_wont(int option, int init) { if (init) { if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) || my_want_state_is_wont(option)) return; set_my_want_state_wont(option); will_wont_resp[option]++; } output_data((const char *)wont, option); DIAG(TD_OPTIONS, printoption("td: send wont", option)); }
void send_dont(int option, int init) { if (init) { if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) || his_want_state_is_wont(option)) return; set_his_want_state_wont(option); do_dont_resp[option]++; } output_data((const char *)dont, option); DIAG(TD_OPTIONS, printoption("td: send dont", option)); }
ImageRawData image_fireflies_filter ( ImageRawData * image_array, size_t array_num ) { size_t width = image_array[ 0 ].GetImageWidth(); size_t height = image_array[ 0 ].GetImageHeight(); ImageRawData average_data( width, height ); ImageRawData output_data( width, height ); // for (int i = 0; i < width; i++) // { // for (int j = 0; j < height; j++) // { // for (int k = 0; k < array_num; k++) // average_data.rawData[ i ][ j ] += // image_array[ k ].rawData[ i ][ j ] / array_num; // } // } // // double * weight; // // weight = static_cast<double * >( malloc ( sizeof ( double ) * array_num ) ); // for (int i = 0; i < width; i++) // { // for (int j = 0; j < height; j++) // { // double total = 0; // for (int k = 0; k < array_num; k++) // { // weight[ i ] = ( average_data.rawData[ i ][ j ] - image_array[ k ].rawData[ i ][ j ] ).Length (); // total += weight[ i ]; // } // // for (int k = 0; k < array_num; k++) // { // weight[ i ] /= total; // // output_data.rawData[ i ][ j ] += // // image_array[ k ].rawData[ i ][ j ] * weight[ i ]; // output_data.rawData[ i ][ j ] += // image_array[ k ].rawData[ i ][ j ].Length() > average_data.rawData[ i ][ j ].Length() // ? average_data.rawData[ i ][ j ] // : image_array[ k ].rawData[ i ][ j ]; // } // } // } return output_data; }
void ttloop() { DIAG(TD_REPORT, output_data("td: ttloop\r\n")); if (nfrontp - nbackp > 0) { netflush(); } ncc = read(net, netibuf, sizeof netibuf); if (ncc < 0) { syslog(LOG_INFO, "ttloop: read: %m"); exit(1); } else if (ncc == 0) { syslog(LOG_INFO, "ttloop: peer died: %m"); exit(1); } DIAG(TD_REPORT, output_data("td: ttloop read %d chars\r\n", ncc)); netip = netibuf; telrcv(); /* state machine */ if (ncc > 0) { pfrontp = pbackp = ptyobuf; telrcv(); } } /* end of ttloop */
void ReLULayer::forward(std::vector<Tensor> &input, std::vector<Tensor> &output) { Tensor input_data(input[0]); Tensor output_data(output[0]); float* input_data_ptr = input_data.get_data().get(); float* output_data_ptr = output_data.get_data().get(); int N_in = input_data.get_N(); int C_in = input_data.get_C(); int H_in = input_data.get_H(); int W_in = input_data.get_W(); int data_size = N_in * C_in * H_in * W_in; for(int index = 0; index < data_size; ++index) { output_data_ptr[index] = input_data_ptr[index] > 0 ? input_data_ptr[index] : 0; } }
int read_token(int argc, char **argv) { uint8_t *buf; int ret, datagroup_id; struct tee_token_info info; if (argc != 2) { raise_error("datagroup_id argument is missing"); return EXIT_FAILURE; } datagroup_id = parse_datagroup_id(argv[1]); if (datagroup_id == -1) return EXIT_FAILURE; bzero(&info, sizeof(info)); ret = tee_token_info_get(datagroup_id, &info, 0); if (ret != 0) { raise_error("tee_token_info_get() call failed, return=0x%x", ret); return ret; } if (info.lifetime.token_size == 0) { raise_error("Failed, token has been provided with the old format..."); return EXIT_FAILURE; } buf = (uint8_t *)malloc(info.lifetime.token_size * sizeof(uint32_t)); if (buf == NULL) { raise_error("Failed to alloc the buffer to retrieve the token data, error=%s", strerror(ENOMEM)); return EXIT_FAILURE; } ret = tee_token_read(datagroup_id, buf, info.lifetime.token_size * sizeof(uint32_t), 0); if (ret != 0) raise_error("tee_token_read() call failed, return=0x%x", ret); else output_data(buf, info.lifetime.token_size * sizeof(uint32_t)); free(buf); return EXIT_SUCCESS; }
int generate_shared_ecc(int argc, char **argv) { int ret; size_t pub_key_size; uint8_t *pub_key = NULL; ret = tee_token_gen_shared_ecc(&pub_key_size, &pub_key); if (ret != 0) raise_error("tee_token_gen_shared_ecc() call failed, return=0x%x", ret); else { output_data(pub_key, pub_key_size); free(pub_key); } return ret; }
int send_cryptid_request(void *data, size_t size) { int ret; size_t response_size; uint8_t *response; ret = tee_token_cryptid_request(size, data, &response_size, &response); if (ret != 0) raise_error("tee_token_cryptid_request() call failed, return=0x%x", ret); else { output_data(response, response_size); free(response); } return ret; }
void NerveTool::execute_data( StringList& data , FILE *sout ) { ClassList<Nerve> nn; // parse for( int k = 0; k < data.count(); k++ ) { String so = data.get( k ); if( so.isEmpty() ) continue; String s = so; int res = execute_line( s , sout , nn ); if( res != 0 ) fprintf( sout , "invalid string (%d): error=%s, full=%s\n" , res , ( const char * )s , ( const char * )so ); } // output output_data( sout , nn ); }
void ptyflush(void) { int n; if ((n = pfrontp - pbackp) > 0) { DIAG(TD_REPORT | TD_PTYDATA, output_data("td: ptyflush %d chars\r\n", n)); DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); n = write(pty, pbackp, n); } if (n < 0) { if (errno == EWOULDBLOCK || errno == EINTR) return; cleanup(0); } pbackp += n; if (pbackp == pfrontp) pbackp = pfrontp = ptyobuf; }
static enum ht_traverse_action clean_iterator(void *key, void *value, void *dataptr) { struct {time_t current; struct hashtable *ht; bool force;} *data = dataptr; struct ip_port_pair *pair = (struct ip_port_pair*)key; // If I haven't recieved data from a connection for 60 // seconds, I consider it's closed. if(data->current - pair->timestamp > 60 || data->force) { if(data->ht == sending_pairs) { FILE *f = fopen("history.txt", "a"); if(f == NULL) { perror("fopen"); } else { struct rtp_connect_data *rtpdata = (struct rtp_connect_data*)value; if(verbose) { printf("FINISH an rtp connection: ["); dump_ip_port_pair(pair, (print_func)fprintf, stdout); printf("]\n"); } if(rtpdata->inited) { int i; // The packets cached in the buffer should be counted here. for(i=0; i<RECIEVED_MESSAGE_COUNT; i++) { add_up_data_at_pos(rtpdata, i); } rtpdata->packet_count += RECIEVED_MESSAGE_COUNT; output_data(f, rtpdata); } fclose(f); } free(value); } free(key); return REMOVE_ITEM; } return NO_ACTION; }
int wxbencode_test::OnRun() { wxFileInputStream input_file(wxT("original.torrent")); wxFileOutputStream output_file(wxT("test_binary.torrent")); wxDataInputStream input_data(input_file); wxDataOutputStream output_data(output_file); wxTextOutputStream output_text(output_file); wxLogMessage(wxT("decoding torrent file")); wx_bdecode(input_file, input_data, e, 0); wxLogMessage(wxT("done decoding")); //wx_entry_print(e,0); wxLogMessage(wxT("encoding torrent file")); wx_bencode(output_data, output_text, e); wxLogMessage(wxT("done encoding")); return 0; }
static void prv_notify_callback(uint16_t clientID, lwm2m_uri_t * uriP, int count, lwm2m_media_type_t format, uint8_t * data, int dataLength, void * userData) { fprintf(stdout, "\r\nNotify from client #%d /%d", clientID, uriP->objectId); if (LWM2M_URI_IS_SET_INSTANCE(uriP)) fprintf(stdout, "/%d", uriP->instanceId); else if (LWM2M_URI_IS_SET_RESOURCE(uriP)) fprintf(stdout, "/"); if (LWM2M_URI_IS_SET_RESOURCE(uriP)) fprintf(stdout, "/%d", uriP->resourceId); fprintf(stdout, " number %d\r\n", count); output_data(stdout, format, data, dataLength, 1); fprintf(stdout, "\r\n> "); fflush(stdout); }
/* * The will/wont/do/dont state machines are based on Dave Borman's * Telnet option processing state machine. * * These correspond to the following states: * my_state = the last negotiated state * want_state = what I want the state to go to * want_resp = how many requests I have sent * All state defaults are negative, and resp defaults to 0. * * When initiating a request to change state to new_state: * * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) { * do nothing; * } else { * want_state = new_state; * send new_state; * want_resp++; * } * * When receiving new_state: * * if (want_resp) { * want_resp--; * if (want_resp && (new_state == my_state)) * want_resp--; * } * if ((want_resp == 0) && (new_state != want_state)) { * if (ok_to_switch_to new_state) * want_state = new_state; * else * want_resp++; * send want_state; * } * my_state = new_state; * * Note that new_state is implied in these functions by the function itself. * will and do imply positive new_state, wont and dont imply negative. * * Finally, there is one catch. If we send a negative response to a * positive request, my_state will be the positive while want_state will * remain negative. my_state will revert to negative when the negative * acknowlegment arrives from the peer. Thus, my_state generally tells * us not only the last negotiated state, but also tells us what the peer * wants to be doing as well. It is important to understand this difference * as we may wish to be processing data streams based on our desired state * (want_state) or based on what the peer thinks the state is (my_state). * * This all works fine because if the peer sends a positive request, the data * that we receive prior to negative acknowlegment will probably be affected * by the positive state, and we can process it as such (if we can; if we * can't then it really doesn't matter). If it is that important, then the * peer probably should be buffering until this option state negotiation * is complete. * */ void send_do(int option, int init) { if (init) { if ((do_dont_resp[option] == 0 && his_state_is_will(option)) || his_want_state_is_will(option)) return; /* * Special case for TELOPT_TM: We send a DO, but pretend * that we sent a DONT, so that we can send more DOs if * we want to. */ if (option == TELOPT_TM) set_his_want_state_wont(option); else set_his_want_state_will(option); do_dont_resp[option]++; } output_data((const char *)doopt, option); DIAG(TD_OPTIONS, printoption("td: send do", option)); }
static const Sparse<elt_t> do_kron(const Sparse<elt_t> &s2, const Sparse<elt_t> &s1) { index rows1 = s1.rows(); index cols1 = s1.columns(); index rows2 = s2.rows(); index cols2 = s2.columns(); index number_nonzero = s1.length() * s2.length(); index total_rows = rows1 * rows2; index total_cols = cols1 * cols2; if (number_nonzero == 0) return Sparse<elt_t>(total_rows, total_cols); Tensor<elt_t> output_data(number_nonzero); Indices output_column(number_nonzero); Indices output_row_start(total_rows+1); Indices output_dims(igen << total_rows << total_cols); typename Tensor<elt_t>::iterator out_data = output_data.begin(); typename Indices::iterator out_column = output_column.begin(); typename Indices::iterator out_begin = out_column; typename Indices::iterator out_row_start = output_row_start.begin(); // C([i,j],[k,l]) = s1(i,k) s2(j,l) *(out_row_start++) = 0; for (index l = 0; l < rows2; l++) { for (index k = 0; k < rows1; k++) { for (index j = s2.priv_row_start()[l]; j < s2.priv_row_start()[l+1]; j++) { for (index i = s1.priv_row_start()[k]; i < s1.priv_row_start()[k+1]; i++) { *(out_data++) = s1.priv_data()[i] * s2.priv_data()[j]; *(out_column++) = s1.priv_column()[i] + cols1 * s2.priv_column()[j]; } } *(out_row_start++) = out_column - out_begin; } } return Sparse<elt_t>(output_dims, output_row_start, output_column, output_data); }
void main(int argc, char **argv) { struct timeval start_t, end_t; struct timezone tzdummy; complex A[512*512], B[512*512], C[512*512]; /* Initialize Data*/ initialize_data(f1_name, A); initialize_data(f2_name, B); gettimeofday(&start_t, &tzdummy); /* 2D FFT on A */ execute_fft(A, 1); transpose(A); execute_fft(A, 1); /* 2D FFT on B */ execute_fft(B, 1); transpose(B); execute_fft(B, 1); /* Multiplication Step */ execute_mm(A, B, C); /* 2D FFT on C */ execute_fft(C, -1); transpose(C); execute_fft(C, -1); gettimeofday(&end_t, &tzdummy); output_data(f_out, C); printf("\nElapsed time = %g s\n", (double)((unsigned int)end_t.tv_usec - (unsigned int)start_t.tv_usec) / 1000000.0); printf("--------------------------------------------\n"); }
int main (int argc, char *argv[]) { error_t aprc; aprc = argp_parse(&argp, argc, argv, 0, NULL, NULL); if (aprc) { fprintf(stderr, "argp_parse failed: %s\n", strerror(aprc)); return 1; } bp_tx_init(&tx); if (!opt_blank) read_data(); apply_mutations(); output_data(); if (opt_strict_free) bp_tx_free(&tx); return 0; }
/* main program code */ int main(int argc, char** argv) { /* Verify input arguments */ if(argc!=4) show_help(); load_file(argv[3]); f=atoi(argv[1]); Dt=atof(argv[2]); printf("Frequency: %d\n",f); printf("Delta Time: %f\n",Dt); printf("Number of samples: %d\n",n); /* create matrices */ C = (double*)malloc(sizeof(double)*n*n); SF = (double*)malloc(sizeof(double)*n); CV = (double*)malloc(sizeof(double)*n); create_coefficient_matrix(); solve_matrix(); compute_frequencies(); compute_approximation(); compute_dm(); output_data(); }
static void prv_result_callback(uint16_t clientID, lwm2m_uri_t * uriP, int status, lwm2m_media_type_t format, uint8_t * data, int dataLength, void * userData) { fprintf(stdout, "\r\nClient #%d /%d", clientID, uriP->objectId); if (LWM2M_URI_IS_SET_INSTANCE(uriP)) fprintf(stdout, "/%d", uriP->instanceId); else if (LWM2M_URI_IS_SET_RESOURCE(uriP)) fprintf(stdout, "/"); if (LWM2M_URI_IS_SET_RESOURCE(uriP)) fprintf(stdout, "/%d", uriP->resourceId); fprintf(stdout, " : "); print_status(stdout, status); fprintf(stdout, "\r\n"); output_data(stdout, format, data, dataLength, 1); fprintf(stdout, "\r\n> "); fflush(stdout); }