/***************************************************** ** ** EphemExpert --- calcLength ** ******************************************************/ int EphemExpert::calcLength() { int i, p, ret = 0; unsigned int i1; double dummy; Calculator *calculator = CalculatorFactory().getCalculator(); planetdata.clear(); for ( i1 = 0; i1 < chartprops->getPlanetList().size(); i1++ ) { p = chartprops->getPlanetList()[i1]; if ( p == OASCENDANT || p == OMERIDIAN || p > MAX_EPHEM_OBJECTS ) continue; EphemPlanetData pdata( p ); for ( i = 0; i <= nb_days; i++ ) // calc length and retrogression { //d->setDate( i+1, month, year, -tz ); d->setDate( jd[i] ); calculator->calcPositionSpeed( d, p, pdata.len[i], dummy, pdata.speed[i], true, chartprops->isVedic() ); pdata.retro[i] = ( pdata.speed[i] < 0 ); pdata.rasi[i] = getRasi( pdata.len[i] ); pdata.nakshatra[i] = getNakshatra( pdata.len[i], N27 ); } if ( pdata.len[0] == 0 && p != OARIES ) ret++; planetdata.push_back( pdata ); } clen = true; return ret; }
std::vector<u8> DecryptVerifyCCM(const std::vector<u8>& cipher, const CCMNonce& nonce, size_t slot_id) { if (!IsNormalKeyAvailable(slot_id)) { LOG_ERROR(HW_AES, "Key slot %zu not available. Will use zero key.", slot_id); } const AESKey normal = GetNormalKey(slot_id); const std::size_t pdata_size = cipher.size() - CCM_MAC_SIZE; std::vector<u8> pdata(pdata_size); try { CCM_3DSVariant::Decryption d; d.SetKeyWithIV(normal.data(), AES_BLOCK_SIZE, nonce.data(), CCM_NONCE_SIZE); d.SpecifyDataLengths(0, pdata_size, 0); CryptoPP::AuthenticatedDecryptionFilter df( d, new CryptoPP::ArraySink(pdata.data(), pdata_size)); CryptoPP::ArraySource as(cipher.data(), cipher.size(), true, new CryptoPP::Redirector(df)); if (!df.GetLastResult()) { LOG_ERROR(HW_AES, "FAILED"); return {}; } } catch (const CryptoPP::Exception& e) { LOG_ERROR(HW_AES, "FAILED with: %s", e.what()); return {}; } return pdata; }
int main(int argc,char* argv[]) { int rc,myid,num_nodes; rc = MPI_Init(&argc,&argv); if (rc != MPI_SUCCESS) { printf ("Error starting MPI program. Terminating.\n"); MPI_Abort(MPI_COMM_WORLD, rc); } MPI_Comm_size(MPI_COMM_WORLD,&num_nodes); MPI_Comm_rank(MPI_COMM_WORLD,&myid); // Setup plasma data PlasmaData pdata(argc,argv); // Figure out how many compute devices are on this node // Set the number of OMP threads to the number of compute devices // MPI_Finalize(); }
void KServer::recv_signup(const char *accountname,const char *password) { std::string pw = makeHashString( std::string(password) ); db_proto::Player pdata( g_idpool->get(), accountname, pw.c_str()); g_dbcli->send_put_Player( uID, pdata ); m_lastFunction = FUNCTION_SIGNUP; }
void CLabel::set(const void* Str){ width((int)strlen((const char*)Str)); //deallocates the dynamic memory where the label's data has been stored delete [] (char*)pdata(); //allocates dynamic memory for that data and copies the data in the newly allocated memory allocateAndCopy((const char*)Str); }
UserDataPtr IkSolverBase::RegisterCustomFilter(int32_t priority, const IkSolverBase::IkFilterCallbackFn &filterfn) { CustomIkSolverFilterDataPtr pdata(new CustomIkSolverFilterData(priority,filterfn,shared_iksolver())); std::list<UserDataWeakPtr>::iterator it; FORIT(it, __listRegisteredFilters) { CustomIkSolverFilterDataPtr pitdata = boost::dynamic_pointer_cast<CustomIkSolverFilterData>(it->lock()); if( !!pitdata && pdata->_priority > pitdata->_priority ) { break; } }
int main(int argc,char* argv[]) { int rc,myid,num_nodes; rc = MPI_Init(&argc,&argv); if (rc != MPI_SUCCESS) { printf ("Error starting MPI program. Terminating.\n"); MPI_Abort(MPI_COMM_WORLD, rc); } MPI_Comm_size(MPI_COMM_WORLD,&num_nodes); MPI_Comm_rank(MPI_COMM_WORLD,&myid); int ndevices = 0; int nprocs = omp_get_num_procs(); nprocs = 1; int nptcls_node,nptcls_total; int nthreads = ndevices + nprocs; Normalization* mynorms = new NormIslandEM(); // Setup plasma data PlasmaData pdata(argc,argv,mynorms); pdata.nVelocity = 3; pdata.ndimensions = 2; pdata.iEM = 1; pdata.nz = 2; pdata.setup(); HoLoInterface2D* LOsolver = new HoLoInterface2D(&pdata); EWave2D_Initializer* initializer = new EWave2D_Initializer(&pdata); ImplicitPIC* simulation = new ImplicitPIC(&pdata,LOsolver,initializer); simulation->simulate(); MPI_Finalize(); }
SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const { if (!m_smallCapsFontData) { FontDescription desc = FontDescription(fontDescription); desc.setSpecifiedSize(0.70f * fontDescription.computedSize()); FontPlatformData pdata(desc, m_font.fontPtr()->GetFamily().c_str()); m_smallCapsFontData = FontCache::getCachedFontData(&pdata); } return m_smallCapsFontData; }
/*write data to fpga */ int write_fpga_data(int fd, struct fpga_msg *msg, int step) { if(fd < 0) return (-1); lseek(fd, (*msg).addr, SEEK_SET); cdebug("step %d begin ==== write %d bytes at 0x%04x:", step, (*msg).len, (unsigned short)(*msg).addr); if (write(fd, (*msg).buf, (*msg).len) == (*msg).len){ pdata((*msg).buf, (*msg).len); cdebug("\nstep %d done\n", step); } else{ cdebug(" step %d error\n", step); return (-1); } return 1; }
static wxBitmap wxBitmapFromMemoryRGBA(const unsigned char* data, u32 width, u32 height) { static const std::array<u8, 54> header = {{ 0x42, 0x4D, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, // Width 0x20, 0x00, 0x00, 0x00, // Height 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 0x00, 0x00, // Data size 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}; u32 stride = (4 * width); u32 bytes = (stride * height) + header.size(); bytes = (bytes + 3) & ~3; u32 data_length = bytes - header.size(); std::vector<u8> pdata(bytes); std::copy(header.begin(), header.end(), pdata.begin()); u8* const pixelData = &pdata[header.size()]; for (u32 y = 0; y < height; y++) std::memcpy(&pixelData[y * stride], &data[(height - y - 1) * stride], stride); std::memcpy(&pdata[18], &width, sizeof(u32)); std::memcpy(&pdata[22], &height, sizeof(u32)); std::memcpy(&pdata[34], &data_length, sizeof(u32)); wxMemoryInputStream is(pdata.data(), bytes); return wxBitmap(wxImage(is, wxBITMAP_TYPE_BMP)); }
/*Check if the fiber module is plugged */ int is_fiber_plugged(int fd, int port) { struct fpga_msg is_plugged_msg; unsigned short temp = 0; if(port<16) { is_plugged_msg.addr = FPGA_SFP_PLUGGED; } else { is_plugged_msg.addr = FPGA_SFPXFP_PLUGGED; } is_plugged_msg.len = 2; cdebug("Check the addr 0x%x\n ", is_plugged_msg.addr); lseek(fd, is_plugged_msg.addr, SEEK_SET); if (read(fd, is_plugged_msg.buf, is_plugged_msg.len) == is_plugged_msg.len) { cdebug("Check if a fiber modue inserted at Port %d\n ", port); pdata(is_plugged_msg.buf,is_plugged_msg.len); }else{ cdebug("Can not read fpga when check if fiber is plugged"); return (-1); } temp = (is_plugged_msg.buf[0] & 0xff)<<8; temp += is_plugged_msg.buf[1] & 0xff; cdebug("\ntemp is 0x%x\n",temp); if((temp>> (port<16?port:(port-16))) & 0x01 ) //if 1, then return { cdebug("\n The fiber module is not plugged\n"); return (-1); } cdebug("\nThe fiber module is inserted at port %d",port); return 1; }
/* wcmd function fills the datastructure rw */ char * wcmd (struct cmd *pcmd, struct wthio *rw) { int ndat = 0; /* length of array containing the data frame */ int err; /* return value of functions, useful for errorhandling */ int retval = 0; long snum = 0; /* current dataset number */ int command; int argcm; unsigned char data[MAXBUFF]; /* data array to store the raw dataframe and the message datagram */ char *clk; /* display time in reasonable format */ char *rbuf; /* return buffer */ syslog(LOG_DEBUG, "wcmd: called for command request: %d\n",pcmd->command); rw->wstat.ndats = 0; command = pcmd->command; argcm = pcmd->argcmd; /* first get status of weatherstation needed to fill sens.status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } pcmd->command = command; syslog(LOG_DEBUG, "wcmd : check status OK\n"); /* status weatherstation */ if ( ( rbuf = wstat(data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } /* command 0 : poll DCF time */ if (command == 0) { tzset(); /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* calculate seconds since EPOCH if DCF synchronized */ rw->DCF.time = dcftime(data, ndat); if (rw->DCF.time == -1) { rbuf = mkmsg("DCF not synchronized\n"); } else { clk = ctime(&rw->DCF.time); rbuf = mkmsg("%s", clk); } } /* command 1 : Request Dataset */ else if (command == 1) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ rw->DCF.time = dcftime(data, ndat); /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { rbuf = mkmsg("no data available (<DLE> received)\n"); } /* fill data structure sens */ else { /* get one dataset */ err = datex(data, ndat, rw); syslog(LOG_DEBUG, "wcmd : returncode datex : %d\n", err); rw->wstat.ndats = rw->wstat.ndats + 1; snum++; } /* echo sensor data */ if ( rw->wstat.ndats > 0 ) rbuf = pdata(rw); } /* command 2 : Select next dataset */ else if (command == 2) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* if DLE no data available */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { rbuf = mkmsg("no data available(<DLE> received)\n"); retval = 16; } else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { /* if ACK next dataset is available */ rbuf = mkmsg("next dataset available (<ACK> received)\n"); retval = 6; } /* exit if unknown response */ else { rbuf = mkmsg("error next dataset : \"unknown response\"\n"); retval = -1; } } /* command 3 : Activate 8 temperature sensors */ else if (command == 3) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { rbuf = mkmsg("set 9 temperature sensors (<ACK> received)\n"); } /* update status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } if ( ( wstat(data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } } /* command 4 : Activate 16 temperature sensors */ else if (command == 4) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { rbuf = mkmsg("set 16 temperature sensors(<ACK> received)\n"); } /* update status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } if ( ( wstat(data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } } /* command 5 : Request status of weatherstation */ else if ( command == 5 ) { ; /* status known, drive thru */ } /* command 6 : Set logging intervall of weatherstation */ else if (command == 6) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { rbuf = mkmsg("set logging interval to %d [min] (<ACK> received)\n", pcmd->argcmd); } /* update status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } if ( ( wstat( data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } } /* command 12 : Recursively, request dataset and select next dataset, recursive combination of command 1 and 2 */ else if ( ( command == 12) || ( command == 7) ) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ rw->DCF.time = dcftime(data, ndat); while (retval != 16) { /* write command and retrieve data */ pcmd->command = 1; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* extract dataset from raw dataframe */ /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { rbuf = mkmsg("no data available (<DLE> received)\n"); retval = 16; } /* do extraction */ else { if ( ( err = datex(data, ndat, rw)) == -1) { rbuf = mkmsg("wcmd: error extracting data frame"); return (rbuf); } rw->wstat.ndats = rw->wstat.ndats + 1; } /* write the command word to select next dataset and retrieve response*/ pcmd->command = 2; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* stop if DLE no data available, */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { /* rbuf = mkmsg( "<DLE> received :\"no data available\"!"); */ retval = 16; } /* if ACK next dataset is available */ else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_DEBUG, \ "wcmd: next dataset available (<ACK> received)!\n"); retval = 6; } /* return if unknown response */ /* no data is returned, maybe too strict? */ else { rbuf = mkmsg( "wcmd: error request next dataset : unknown response\n"); return (rbuf); } syslog(LOG_DEBUG, "wcmd: retval : %d\n", retval); } /* echo sensor data */ if ( rw->wstat.ndats > 0 ) { rbuf = pdata(rw); #if defined POSTGRES if ( command == 7 ) { if ( ( err = pg_data(rw)) == -1 ) { rbuf = mkmsg("wmcd: postgres error\n") ; return (rbuf); } } #endif } }//command 12 || command 7 else { rbuf = mkmsg("unknown command\n"); } syslog(LOG_DEBUG, "wcmd: exit OK\n"); return(rbuf); }//wcmd()
void KexiDBConnectionWidget::setData(const KexiDB::ConnectionData& data, const QString& shortcutFileName) { KexiProjectData pdata(data); setDataInternal(pdata, true /*connectionOnly*/, shortcutFileName); }
int main(int argc,char* argv[]) { PlasmaData pdata(argc,argv); gnuplot_ctrl* plot; gnuplot_ctrl* plot_anim; plot = gnuplot_init(); plot_anim = gnuplot_init(); gnuplot_setstyle(plot,"lines"); gnuplot_setstyle(plot_anim,"points"); gnuplot_cmd(plot_anim,"set term gif animate nooptimize size 1280,1280 xffffffff"); gnuplot_cmd(plot_anim,"set output \"particles.gif\""); gnuplot_cmd(plot_anim,"set xrange [-1:1]"); gnuplot_cmd(plot_anim,"set yrange [-1:1]"); float xmin = 0; float ymin = 0; float zmin = 0; float Lx = 5.0; float Ly = 5.0; float Lz = 5.0; int nx = 64; int ny = 64; int nz = 64; int nspecies = 1; const float dt = 0.01; const float dtau0 = 0.1; const int nptcls = 500; const int steps = 200; int iptcl[nptcls]; float Ey = 5.0; float Bz = 100.0; pdata.nx = nx; pdata.ny = ny; pdata.nz = nz; pdata.Lx = Lx; pdata.Ly = Ly; pdata.Lz = Lz; pdata.xmin = xmin; pdata.ymin = ymin; pdata.zmin = zmin; pdata.epsilon_a = 1.0e-4; pdata.epsilon_r = 1.0e-10; pdata.dt = dt; pdata.niter_max = 20; pdata.nSubcycle_max = 1000; pdata.Bmag_avg = 1.0; pdata.ndimensions = 3; pdata.setup(); FieldDataCPU fields; ParticleListCPU particles; HOMoments* moments; int numprocs = omp_get_num_procs(); moments = (HOMoments*)malloc(numprocs*sizeof(HOMoments)); for(int i=0;i<numprocs;i++) { moments[i] = *new HOMoments(&pdata); } float x_plot[nptcls][steps]; float y_plot[nptcls][steps]; float gx_plot[nptcls][steps]; float gy_plot[nptcls][steps]; float error_array[nptcls]; //float x_plot_a[nptcls]; //float y_plot_a[nptcls]; fields.allocate(&pdata); particles.allocate(nptcls); fields.dx = pdata.dxdi; fields.dy = pdata.dydi; fields.dz = pdata.dzdi; particles.ispecies = 0; for(int i=0;i<nptcls;i++) { iptcl[i] = i; particles.px[i] = rand()%10000/10000.0; particles.py[i] = rand()%10000/10000.0; particles.pz[i] = 0.5; particles.ix[i] = nx/2; particles.iy[i] = ny/2; particles.iz[i] = nz/2; particles.vx[i] = 0.5*(2*(rand()%10000))/10000.0 + 0.5; particles.vy[i] = 0.5*(2*(rand()%10000))/10000.0 + 0.5; particles.vz[i] = 0.0* (rand()%50000 / 50000.0f - 0.5); error_array[i] = 0; } // Setup E-field for(int i=0;i<nx;i++) { for(int j=0;j<ny;j++) { for(int k=0;k<nz;k++) { float x = i*pdata.dxdi+xmin; float y = j*pdata.dydi+ymin; float z = k*pdata.dzdi+zmin; float Ex = -1.0*x; fields.getE(i,j,k,0) = 0; fields.getE(i,j,k,1) = Ey; fields.getE(i,j,k,2) = 0; fields.getB(i,j,k,0) = 0; fields.getB(i,j,k,1) = 0; fields.getB(i,j,k,2) = Bz; // printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k, // fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2)); } } } fields.q2m[0] = 1.0; printf("Efield setup complete\n"); float time; double avg_error = 0.0; int n_error = 0; CPUTimer timer; moments->init_plot(); timer.start(); for(int i=0;i<steps;i++) { //time = dtau0*(i); //moments.set_vals(0); particles.push(&pdata,&fields,moments); printf("finished step %i\n",i); for(int j=0;j<nptcls;j++) { float px,py,gx,gy; float rl; float vx,vy,vxy,vz,vxyz; float vgx,vgy; float verror; px = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin; py = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin; vx = particles.vx[j]; vy = particles.vy[j]; vz = particles.vz[j]; vxy = sqrt(vx*vx+vy*vy); vxyz = sqrt(vxy*vxy + vz*vz); rl = vxy/Bz; gx = vy*Bz/sqrt(vx*Bz*vx*Bz + vy*Bz*vy*Bz)*rl + px; gy = -vx*Bz/sqrt(vx*Bz*vx*Bz + vy*Bz*vy*Bz)*rl + py; x_plot[j][i] = px; y_plot[j][i] = py; gx_plot[j][i] = gx; gy_plot[j][i] = gy; if(i >= 1) { vgx = (gx_plot[j][i] - gx_plot[j][0])/(dt*(i)); vgy = (gy_plot[j][i] - gy_plot[j][0])/(dt*(i)); verror = fabs(Ey/Bz - vgx)/(Ey/Bz); error_array[j] = fmax(error_array[j],verror); avg_error += verror; n_error ++; // printf("true[%i] v = %e, %e actual v = %e, %e, error = %e\n", // j,Ey/Bz,0.0f,vgx,vgy,verror); } } //if((i+1)%64 == 0) //gnuplot_resetplot(plot_anim); /* float diff_avg = 0.0; for(int j=0;j<nptcls;j++) { x_plot[j][i] = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin; y_plot[j][i] = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin; //printf("particle %i with position %f, %f\n",j,x_plot[j][i],y_plot[j][i]); // x_plot_a[j] = x_plot[j][i]; // y_plot_a[j] = y_plot[j][i]; } */ //avg_error += diff_avg / steps; //gnuplot_plot_xy(plot_anim,x_plot_a,y_plot_a,nptcls,NULL); } timer.stop(); printf("average error = %e \n",avg_error/((float)n_error)); printf("Run did %f particles per second\n",nptcls*steps/(timer.diff()*1.0e-3)); for(int j=0;j<nptcls;j++) { if(error_array[j] >= 1.0e-2) gnuplot_plot_xy(plot,x_plot[j],y_plot[j],steps,NULL); } //moments->plot(nz/2,0,HOMoments_currentx); printf("Press 'Enter' to continue\n"); getchar(); moments->close_plot(); gnuplot_close(plot); gnuplot_close(plot_anim); }
int main(int argc,char* argv[]) { PlasmaData pdata(argc,argv); FieldDataCPU fields; pdata.Lx = 1.0; pdata.Ly = 1.0; pdata.Lz = 1.0; pdata.setup(); fields.allocate(&pdata); int nx = pdata.nx; int ny = pdata.ny; int nz = pdata.nz; int nshape = 100; float shape1[nshape]; float shape2[nshape]; float shapex[nshape]; for(int i=0;i<nshape;i++) { float x = i*4.0/nshape - 2.0; shape1[i] = S1_shape(x); shape2[i] = S2_shape(x); shapex[i] = x; } gnuplot_ctrl* shape_plot = gnuplot_init(); gnuplot_plot_xy(shape_plot,shapex,shape1,nshape,"Shape 1"); gnuplot_plot_xy(shape_plot,shapex,shape2,nshape,"Shape 2"); // Setup E-field for(int i=0;i<pdata.nx;i++) { for(int j=0;j<pdata.ny;j++) { for(int k=0;k<pdata.nz;k++) { float x = i*pdata.dxdi+pdata.xmin; float y = j*pdata.dydi+pdata.ymin; float z = k*pdata.dzdi+pdata.zmin; fields.getE(i,j,k,0) = Ex_function(x,y+0.5*pdata.dydi,z+0.5*pdata.dzdi); fields.getE(i,j,k,1) = Ey_function(x+0.5*pdata.dxdi,y,z+0.5*pdata.dzdi); fields.getE(i,j,k,2) = Ez_function(x+0.5*pdata.dxdi,y+0.5*pdata.dydi,z); fields.getB(i,j,k,0) = Ex_function(x,y,z); fields.getB(i,j,k,1) = Ey_function(x,y,z); fields.getB(i,j,k,2) = Ez_function(x,y,z); //fields.getB(i,j,k,0) = 0.0; //fields.getB(i,j,k,1) = 0.0f; //fields.getB(i,j,k,2) = 0.0f; // printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k, // fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2)); } } } fields.init_plot(); fields.plot(&pdata,pdata.nz/2,0,0,0); getchar(); double Ex_total = 0; double Ey_total = 0; double Ez_total = 0; double Bx_total = 0; double By_total = 0; double Bz_total = 0; // Setup E-field for(int i=0;i<pdata.nx;i++) { for(int j=0;j<pdata.ny;j++) { for(int k=0;k<pdata.nz;k++) { float xfrac = 0.5; float yfrac = 0.5; float zfrac = 0.5; float x = (xfrac + i)*pdata.dxdi+pdata.xmin; float y = (yfrac + j)*pdata.dydi+pdata.ymin; float z = (zfrac + k)*pdata.dzdi+pdata.zmin; float Ex_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,0,FieldData_deriv_f); float Ey_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,1,FieldData_deriv_f); float Ez_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,2,FieldData_deriv_f); float Ex_real = Ex_function(x,y,z); float Ey_real = Ey_function(x,y,z); float Ez_real = Ez_function(x,y,z); float Ex_err = fabs(Ex_real - Ex_intrp)/fabs(Ex_real); float Ey_err = fabs(Ey_real - Ey_intrp)/fabs(Ey_real); float Ez_err = fabs(Ez_real - Ez_intrp)/fabs(Ez_real); float Bx_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,0,FieldData_deriv_f); float By_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,1,FieldData_deriv_f); float Bz_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,2,FieldData_deriv_f); float Bx_real = Ex_function(x,y,z); float By_real = Ey_function(x,y,z); float Bz_real = Ez_function(x,y,z); float Bx_err = fabs(Bx_real - Bx_intrp)/fabs(Bx_real); float By_err = fabs(By_real - By_intrp)/fabs(By_real); float Bz_err = fabs(Bz_real - Bz_intrp)/fabs(Bz_real); Ex_total += Ex_err; Ey_total += Ey_err; Ez_total += Ez_err; Bx_total += Bx_err; By_total += By_err; Bz_total += Bz_err; //printf("values: x: %f / %f, y: %f / %f, z: %f / %f \n",Ex_real,Ex_intrp,Ey_intrp,Ey_real,Ez_intrp,Ez_real); //printf("Errors: x = %e, y = %e, z = %e\n",Ex_err,Ey_err,Ez_err); } } } printf("Errors_avg: x = %e, y = %e, z = %e\n",Ex_total/(nx*ny*nz*1.0),Ey_total/(nx*ny*nz*1.0),Ez_total/(nx*ny*nz*1.0)); printf("Errors_avg: x = %e, y = %e, z = %e\n",Bx_total/(nx*ny*nz*1.0),By_total/(nx*ny*nz*1.0),Bz_total/(nx*ny*nz*1.0)); printf("Efield setup complete\n"); }
int main(int argc,char* argv[]) { int rc,myid,num_nodes; rc = MPI_Init(&argc,&argv); if (rc != MPI_SUCCESS) { printf ("Error starting MPI program. Terminating.\n"); MPI_Abort(MPI_COMM_WORLD, rc); } MPI_Comm_size(MPI_COMM_WORLD,&num_nodes); MPI_Comm_rank(MPI_COMM_WORLD,&myid); int ndevices = 0; int nprocs = omp_get_num_procs(); nprocs = 1; int nptcls_node,nptcls_total; int nthreads = ndevices + nprocs; srand(1209876*(5+myid)); // Setup plasma data PlasmaData pdata(argc,argv); pdata.ny = 2; pdata.nz = 2; pdata.setup(); pdata.ndimensions = 1; pdata.Bmag_avg = 0; nptcls_node = ndevices*pdata.nptcls_gpu + nprocs * pdata.nptcls_cpu; MPI_Allreduce(&nptcls_node,&nptcls_total,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); pdata.nptcls_total = nptcls_total; ParallelInfo** pinfo = (ParallelInfo**)malloc((nthreads+1)*sizeof(ParallelInfo*)); pinfo[0] = new ParallelInfo; pinfo[0] -> nthreads = nthreads; pinfo[0] -> n_nodes = num_nodes; pinfo[0] -> myid_mpi = myid; pinfo[0] -> device_type = 0; AmpereSolver* LOsolver = new AmpereSolver; Landau_Initializer* initializer = new Landau_Initializer(&pdata); ImplicitPIC* simulation = new ImplicitPIC(&pdata,LOsolver,initializer,pinfo,ndevices); simulation->simulate(); MPI_Finalize(); }
/* wcmd function fills the datastructure sens */ int wcmd (struct sensor sens[], struct cmd *pcmd, int *setno) { int i; /* for array subscription */ int ndat = 0; /* length of array containing the data frame */ int err; /* return value of functions, useful for errorhandling */ int retval = 0; /* return values for this function */ /* 0 : everythings fine */ /* 1 : no data available */ /* -1 : unknown response of weatherstation */ int snum = 0; /* number of data sets */ int command; int argcm; struct DCFstruct DCF; /* DCF status and synchronous */ struct wstatus setting; u_char data[MAXBUFF]; /* data array to store the raw dataframe and the message datagram */ char *clk; /* display time in reasonable format */ command = pcmd->command; argcm = pcmd->argcmd; /* first get status of weatherstation needed to fill sens.status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); pcmd->command = command; syslog(LOG_INFO, "wcmd : check status OK\n"); /* status weatherstation */ err = wstat(data, ndat, &DCF, sens, &setting); syslog(LOG_INFO, "wcmd : DCF.stat : %d\n", DCF.stat); syslog(LOG_INFO, "wcmd : DCF.sync : %d\n", DCF.sync); syslog(LOG_INFO, "wcmd : number sensors : %d\n", setting.numsens); syslog(LOG_INFO, "wcmd : version : %x\n", setting.version); for ( i = 0; i < MAXSENSORS; i++ ) { syslog(LOG_DEBUG, "wcmd : sens[%d].status: %d, type: %s\n", i, sens[i].status, sens[i].type); } /* command 0 : poll DCF time */ if (command == 0) { /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* calculate seconds since EPOCH if DCF synchronized */ DCF.time = dcftime(data, ndat); if (DCF.time == -1) printf("Weatherstation not synchronized\n"); else { clk = ctime(&DCF.time); printf("%s", clk); } } /* command 1 : Request Dataset */ else if (command == 1) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ DCF.time = dcftime(data, ndat); /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, "wcmd : DLE received : weather station :\"no data available\": exit!\n"); retval = 16; } /* fill data structure sens */ else { /* get one dataset */ err = getone(data, ndat, sens, snum, DCF); syslog(LOG_INFO, "wcmd : returncode getone : %d\n", err); snum++; } /* echo sensor data */ err = pdata(sens, snum); } /* command 2 : Select next dataset */ else if (command == 2) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* if DLE no data available */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, \ "wcmd : DLE received : weather station :\"no data available\"!\n"); retval = 16; } else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) /* if ACK next dataset is available */ { syslog(LOG_INFO, \ "wcmd : ACK received : weather station :\"next dataset available\": exit!\n"); retval = 6; } /* exit if unknown response */ else { syslog(LOG_EMERG, "wcmd : error request next dataset : unknown response: exit \n"); retval = -1; } } /* command 3 : Activate 8 temperature sensors */ else if (command == 3) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, "wcmd : ACK received\n"); printf("Weatherstation response : <ACK>\n"); } } /* command 4 : Activate 16 temperature sensors */ else if (command == 4) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, "wcmd : ACK received\n"); printf("Weatherstation response : <ACK>\n"); } } /* command 5 : Request status of weatherstation */ else if ( command == 5 ) { /* check status - this is done at every call of wcmd*/ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* status weatherstation */ err = wstat(data, ndat, &DCF, sens, &setting); syslog(LOG_INFO, "wcmd : DCF.stat : %d\n", DCF.stat); syslog(LOG_INFO, "wcmd : DCF.sync : %d\n", DCF.sync); syslog(LOG_INFO, "wcmd : number sensors : %d\n", setting.numsens); syslog(LOG_INFO, "wcmd : version : %x\n", setting.version); for ( i = 0; i < MAXSENSORS; i++ ) { syslog(LOG_DEBUG, "wcmd : sens[%d].status: %d, type: %s\n", i, sens[i].status, sens[i].type); } printf("Status weatherstation\n"); printf("Version : %x\n", setting.version); printf("Interval : %d\n", setting.intv); printf("Numsens : %d\n", setting.numsens); printf("DCF.stat : %d\n", DCF.stat); printf("DCF.sync : %d\n", DCF.sync); } /* command 6 : Set logging intervall of weatherstation */ else if (command == 6) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, "wcmd : ACK received\n"); printf("Weatherstation response : <ACK>\n"); } } /* command 12 : Recursively, request dataset and select next dataset, recursive combination of command 1 and 2 */ else if (command == 12) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ DCF.time = dcftime(data, ndat); while (retval != 16) { /* write command and retrieve data */ pcmd->command = 1; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, \ "wcmd : DLE received : weather station :\"no data available\"!\n"); retval = 16; } /* fill data structure sens */ else { /* get one dataset */ err = getone(data, ndat, sens, snum, DCF); syslog(LOG_INFO, "wcmd : returncode getone : %d\n", err); /* increase dataset number index */ snum++; } /* write the command word to select next dataset and retrieve response*/ pcmd->command = 2; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* if DLE no data available */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, \ "wcmd : DLE received : weather station :\"no data available\"!\n"); printf("DLE received : weather station :\"no data available\"!\n"); retval = 16; } /* if ACK next dataset is available */ else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, \ "wcmd : ACK received : weather station :\"next dataset available\"!\n"); retval = 6; } /* exit if unknown response */ else { syslog(LOG_EMERG, \ "wcmd : error request next dataset : unknown response: exit \n"); retval = -2; } syslog(LOG_INFO, "wcmd : retval : %d\n", retval); } /* echo sensor data */ err = pdata(sens, snum); } else { printf("Unknown command: exit!\n"); exit(1); } *setno = snum; syslog(LOG_INFO, "wcmd : returncode wcmd : %d, number of sets : %d\n", retval, *setno); return(retval); }
int main(int argc, char *argv[]) { int fd; int count = 0; unsigned int addr = 0; unsigned char data[32] = {0}; int ret; spi_rdwr sopt; if (argc != 2 && argc != 4) { usage(); return 0; } fd = open("/dev/spidev0.0", O_RDWR); if (fd == -1) { printf("dpll file open failed.\n"); return -1; } if (argc == 2 && argv[1][0] == 't') { selftest(fd); } else if (argc == 4 && argv[1][0] == 'r') { sopt.cs = 0; sscanf(argv[2], "%hx", &sopt.addr); sscanf(argv[3], "%hd", &sopt.len); printf("read %d bytes at 0x%04x:", sopt.len, (unsigned short)sopt.addr); if (read(fd, &sopt, 0) == sopt.len) { pdata(sopt.buff, sopt.len); printf(" done\n"); } else { printf(" error\n"); } } else if (argc == 4 && argv[1][0] == 'w') { sopt.cs = 0; sscanf(argv[2], "%hx", &sopt.addr); sopt.len = strlen(argv[3]); if (count % 2 != 0) { printf("error: unaligned byte:hex\n"); } else { int i; char *cp; unsigned char tmp; cp = argv[3]; for(i = 0; *cp; i++, cp++) { tmp = *cp - '0'; if(tmp > 9) tmp -= ('A' - '0') - 10; if(tmp > 15) tmp -= ('a' - 'A'); if(tmp > 15) { printf("Hex conversion error on %c, mark as 0.\n", *cp); tmp = 0; } if((i % 2) == 0) sopt.buff[i / 2] = (tmp << 4); else sopt.buff[i / 2] |= tmp; } sopt.len >>= 1; printf("write %d bytes at 0x%04x:", sopt.len, (unsigned short)sopt.addr); pdata(sopt.buff, sopt.len); if (write(fd, &sopt, 0) == sopt.len) printf(" done\n"); else printf(" error\n"); } }
int main(int argc,char** argv) { int rc,myid,num_nodes; system("numactl --show"); int provided; rc = MPI_Init(&argc,&argv); setvbuf( stdout, NULL, _IONBF, 0 ); if (rc != MPI_SUCCESS) { printf ("Error starting MPI program. Terminating.\n"); MPI_Abort(MPI_COMM_WORLD, rc); } system("numactl --show"); printf("made it past system\n"); MPI_Comm_size(MPI_COMM_WORLD,&num_nodes); printf("made it past com size\n"); MPI_Comm_rank(MPI_COMM_WORLD,&myid); printf("made it past com rank\n"); MPI_Barrier(MPI_COMM_WORLD); int ndevices = 0; int nprocs = 1; //nprocs = 1; int nptcls_node,nptcls_total; int nthreads = ndevices + nprocs; srand(156*(32+5*myid)); // iControlServer = 1; PlasmaData pdata(argc,argv); sseServer* ControlServer= pdata.output_ctrl->server; WebControlSystem* control= pdata.output_ctrl->control; // // Setup the input parser // InputParser* parser = new InputParser(argc,argv); // sseDataStream* stream = new sseDataStream(&pdata,4,0); // int exit_control = 0; // // // char* ROOT; // int PORTi; // parser->GetParam("SERVER_PORT_NUMBER","-p",PORTi,32000); // // std::stringstream tmp; // tmp << PORTi; // char PORTc[6]; // // sprintf(PORTc,"%s",tmp.str().c_str()); // WebControlSystem* control = new WebControlSystem(parser); // ControlServer = new sseServer(ROOT,PORTc,stream,control,&exit_control); while(!(control->CheckiRun())) { sleep(1); } MPI_Finalize(); }
int InitServer::run() { if (isNotOk()) return(NOTOK); if (services_.empty()) return(NOTOK); InitServer::pobject_ = this; ::signal(SIGINT, InitServer::handler); ::signal(SIGQUIT, InitServer::handler); ::signal(SIGTERM, InitServer::handler); SVCSIter sit = services_.begin(); SVCSIter sitend = services_.end(); registered_services_ = services_.size(); for ( ; sit != sitend; ++sit) { dbgprintf("Starting service %s:\n", sit->first.c_str()); std::string uri = sit->first; UseCntPtr<InitServer::SubServer> psubserver(sit->second); int pid = ::fork(); if (pid == 0) { // child server MustBeTrue(psubserver != NULL); exit((*psubserver)(uri)); } else if (pid > 0) { // parent -- track pid dbgprintf("Service %s started (pid=%d).\n", uri.c_str(), pid); PID2ServiceData data(1,maxstartups_,uri,psubserver); pid2services_.insert(std::pair<int, PID2ServiceData>(pid, data)); pids_.insert(pid); } else { // some type of error MustBeTrue(pid >= 0); } } for (int status; !pids_.empty(); ) { pid_t pid = ::waitpid(-1, &status, 0); if (errno == ECHILD) { pids_.clear(); return(NOTOK); } PID2SERVICESIter piter = pid2services_.find(pid); if (piter == pid2services_.end()) continue; dbgprintf("Service %s (pid=%d) died.\n", piter->second.uri_.c_str(), pid); if (piter->second.startups_ >= piter->second.maxstartups_) { dbgprintf("Service %s (pid=%d) NOT restarted (%d out of %d).\n", piter->second.uri_.c_str(), pid, piter->second.startups_, piter->second.maxstartups_); pids_.erase(pid); pid2services_.erase(pid); continue; } dbgprintf("Service %s (pid=%d) attempting to restart (%d out of %d).\n", piter->second.uri_.c_str(), pid, piter->second.startups_, piter->second.maxstartups_); // save new data for new child pid PID2ServiceData pdata(piter->second.startups_+1, piter->second.maxstartups_, piter->second.uri_, piter->second.psubserver_); // erase old data pids_.erase(pid); pid2services_.erase(pid); int childpid = ::fork(); if (childpid == 0) { // child -- restart server MustBeTrue(pdata.psubserver_ != NULL); exit((*pdata.psubserver_)(pdata.uri_)); } else if (childpid > 0) { // parent -- track pid dbgprintf("Service %s (pid=%d) restarted (%d out of %d).\n", pdata.uri_.c_str(), childpid, pdata.startups_, pdata.maxstartups_); pid2services_.insert(std::pair<int, PID2ServiceData>(childpid, pdata)); pids_.insert(childpid); } else { // some type of error MustBeTrue(childpid >= 0); } } return(OK); }
void dodata(char *buffer, IDA_DHDR *first, IDA_DHDR *last, struct counters *count, int print, int check, int sort, int group) { int status, swab; IDA_DREC drec; IDA_DHDR *head; static long prev_recno[IDA_MAXSTREAMS]; long jump; int nsamp_ok, time_ok, trig, reboot; static long tagno = BADD_TAG; int bad = FALSE; /* Fill the structure */ swab = (check & C_LASTW) ? 1 : 0; if ((status = ida_drec(ida, &drec, buffer, 0, swab)) != 0) { if (print & P_CORRUPT) pcorrupt(count, IDA_DATA, status, print); ++count->badd; ++count->corrupt; return; } head = &drec.head; if (head->dl_stream < 0 || head->dl_stream >= IDA_MAXSTREAMS) { prt_badd_hdr(print, &tagno); tag(tagno++); printf("%8ld ", count->rec); printf("illegal data logger stream code = "); printf("%hd\n", head->dl_stream); ++count->badd; return; } /* Increment relevant ARS/DAS counters */ if (head->atod == IDA_ARS) ++count->ars; if (head->atod == IDA_DAS) ++count->das; /* If this is the first instance of this stream, save the header */ if (!HAVEPREV) first[head->dl_stream] = *head; /* Print the header contents */ if (print & P_DATA) pdata(&drec, count, print); /* Check for duplicate headers, early return if so */ if ( (check & C_SAME) && ckdupdat(&PRVH, PRVR, head, count->rec, print, count) != 0 ) return; /* Print time triples */ if (print & P_TTRIP) pttrip(head, count, print); /* Count the number of triggered records */ if (head->mode != 0) { ++count->trgrec; trig = TRUE; } else { trig = FALSE; } /* Insure number of samples is reasonable and add to stream total */ if ((check & C_NSAMP) && !(nsamp_ok = ida_sampok(head))) { prt_badd_hdr(print, &tagno); tag(tagno++); printf("%8ld ", count->rec); printf("illegal nsamp =%4hd for ", head->nsamp); printf("format = "); switch (head->form) { case S_UNCOMP: printf("S_UNCOMP, "); break; case L_UNCOMP: printf("L_UNCOMP, "); break; case IGPP_COMP: printf("IGPPCOMP, "); break; default: printf("UNKNOWN!, "); break; } printf("wrdsiz = %2d, ", head->wrdsiz); printf("nbytes = %3d\n", head->nbytes); if (!bad) { bad = TRUE; ++count->badd; } } else { nsamp_ok = TRUE; } if (nsamp_ok) count->totpts[head->dl_stream] += head->nsamp; /* Report on internal time tag structure errors */ if ((check & C_BADTAG) && head->beg.error) { ++count->badtag; if (print & P_BADTAG) pbadtag(&head->beg,count,IDA_DATA,print); time_ok = FALSE; } else { time_ok = TRUE; } if ((check & C_BADTAG) && head->end.error) { ++count->badtag; if (print & P_BADTAG) pbadtag(&head->end,count,IDA_DATA,print); time_ok = FALSE; } else { time_ok = TRUE; } /* Look for time quality transitions */ if (check & C_TQUAL) cktqual(head, count, print); /* Look for external time jumps */ if ((check & C_TINC) && time_ok) ckextjmp(head,count,print); /* Check for intra-record time jumps (valid only after rev 5) */ if ((check & C_TINC) && ida->rev.value >= 5 && time_ok && nsamp_ok) { if (head->beg.sys >= head->end.sys) { prt_badd_hdr(print, &tagno); tag(tagno++); printf("%8ld ", count->rec); printf("beg sys_time "); printf("(%s) ", sys_timstr(head->beg.sys, head->beg.mult, NULL)); printf(">= end sys_time "); printf("(%s)\n", sys_timstr(head->end.sys, head->end.mult, NULL)); if (!bad) { bad = TRUE; ++count->badd; } } else { jump = cktinc(head,NULL,count->rec,-1L,sort,group,print); if (jump != 0) { ++count->ierr; if (jump <= -BIG_TIMERR) ++count->nerr; if (jump >= BIG_TIMERR) ++count->perr; } } } /* check for true time jumps */ if (check & C_TTC) chktrut(head); /* Look for DAS reboots */ if (HAVEPREV && head->beg.sys < PRVH.beg.sys) { reboot = 1; ++count->reboots; } else { reboot = 0; } /* Check for inter-record time jumps */ if ( (check & C_TINC) && time_ok && nsamp_ok && HAVEPREV && !trig && !bad && !reboot ) { jump = cktinc(head,&PRVH,count->rec,PRVR,sort,group,print); if (jump != 0) { ++count->ierr; if (jump <= -BIG_TIMERR) ++count->nerr; if (jump >= BIG_TIMERR) ++count->perr; } } /* Check for time offset errors */ if ((check & C_TOFF) && ida->rev.value >= 5 && time_ok && nsamp_ok) { if (cktoff(head, count->rec, print) != 0) ++count->oerr; } /* Look for compression/decompression errors */ if ((check & C_LASTW) && head->form == IGPP_COMP && nsamp_ok) { cklastw(&drec, count, print); } /* Save this record header and number */ savehead(&PRVH, head, &PRVR, count); }
int main(int argc,char* argv[]) { PlasmaData pdata(argc,argv); pdata.nspecies = 1; int nspecies = pdata.nspecies; int nptcls = pdata.nptcls; int steps = pdata.nsteps; int nx = pdata.nx; int ny = pdata.ny; int nz = pdata.nz; pdata.ndimensions = 3; int iptcl[nptcls]; float Ey = 2.0; float Bz = 50.0; FieldDataCPU fields; ParticleListCPU particles; ParticleListCPU particles2; HOMoments* moments; int numprocs = omp_get_num_procs(); moments = (HOMoments*)malloc(numprocs*sizeof(HOMoments)); for(int i=0;i<numprocs;i++) { moments[i] = *new HOMoments(&pdata); } fields.allocate(&pdata); particles.allocate(nptcls); particles2.allocate(nptcls); fields.dx = pdata.dxdi; fields.dy = pdata.dydi; fields.dz = pdata.dzdi; particles.ispecies = 0; for(int i=0;i<nptcls;i++) { iptcl[i] = i; particles.px[i] = rand()%10000/10000.0; particles.py[i] = rand()%10000/10000.0; particles.pz[i] = 0.5; particles.ix[i] = i%nx; particles.iy[i] = (i%(nx*ny))/nx; particles.iz[i] = 0; particles.vx[i] = 0.5*(2*(rand()%10000))/10000.0; particles.vy[i] = 0.5*(2*(rand()%10000))/10000.0; particles.vz[i] = 0.1* (rand()%50000 / 50000.0f - 0.5); particles.dt_finished[i] = 0; } particles2.copy_from(&particles); for(int i=0;i<nptcls;i++) { float px1,py1,pz1,vx1,vy1,vz1; int ix1,iy1,iz1; float px2,py2,pz2,vx2,vy2,vz2; int ix2,iy2,iz2; px1 = particles.get_fvalue(i,0); py1 = particles.get_fvalue(i,1); pz1 = particles.get_fvalue(i,2); vx1 = particles.get_fvalue(i,3); vy1 = particles.get_fvalue(i,4); vz1 = particles.get_fvalue(i,5); ix1 = particles.get_ivalue(i,0); iy1 = particles.get_ivalue(i,1); iz1 = particles.get_ivalue(i,2); px2 = particles2.get_fvalue(i,0); py2 = particles2.get_fvalue(i,1); pz2 = particles2.get_fvalue(i,2); vx2 = particles2.get_fvalue(i,3); vy2 = particles2.get_fvalue(i,4); vz2 = particles2.get_fvalue(i,5); ix2 = particles2.get_ivalue(i,0); iy2 = particles2.get_ivalue(i,1); iz2 = particles2.get_ivalue(i,2); if((px1 != px2)||(py1 != py2)||(pz1 != pz2)|| (vx1 != vx2)||(vy1 != vy2)||(vz1 != vz2)) { printf("Data Structure Values Different for particle %i!!!\n",i); printf("%f, %f, %f, %f, %f, %f\n",px1,py1,pz1,vx1,vy1,vz1); printf("%f, %f, %f, %f, %f, %f\n",px2,py2,pz2,vx2,vy2,vz2); } } // Setup E-field for(int i=0;i<nx;i++) { for(int j=0;j<ny;j++) { for(int k=0;k<nz;k++) { float x = i*pdata.dxdi+pdata.xmin; float y = j*pdata.dydi+pdata.ymin; float z = k*pdata.dzdi+pdata.zmin; float Ex = -1.0*x; fields.getE(i,j,k,0) = 0; fields.getE(i,j,k,1) = Ey; fields.getE(i,j,k,2) = 0.0; fields.getB(i,j,k,0) = 0; fields.getB(i,j,k,1) = 0; fields.getB(i,j,k,2) = Bz; // printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k, // fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2)); } } } fields.q2m[0] = 1.0; printf("Efield setup complete\n"); float time; double avg_error = 0.0; int n_error = 0; CPUTimer timer; CPUTimer timer2; moments->init_plot(); int nsteps1 = 0; int nsteps2 = 0; timer.start(); for(int i=0;i<steps;i++) { //time = dtau0*(i); //moments.set_vals(0); nsteps1 += particles.push(&pdata,&fields,moments); printf("finished step %i\n",i); } timer.stop(); timer2.start(); for(int i=0;i<steps;i++) { //time = dtau0*(i); //moments.set_vals(0); nsteps2 += particles2.push(&pdata,&fields,moments); printf("finished step %i\n",i); } timer2.stop(); printf("SoA Run did %f particle-steps per second with %i steps\n",nsteps1/(timer.diff()*1.0e-3),nsteps1); printf("AoS Run did %f particle-steps per second with %i steps\n",nsteps2/(timer2.diff()*1.0e-3),nsteps2); //moments->plot(nz/2,0,HOMoments_currentx); printf("Press 'Enter' to continue\n"); getchar(); //moments->close_plot(); //particles2.CPUfree(); }
int main(int argc,char* argv[]) { int rc,myid,num_nodes; system("numactl --show"); int provided; rc = MPI_Init_thread(&argc,&argv,MPI_THREAD_FUNNELED,&provided); if (rc != MPI_SUCCESS) { printf ("Error starting MPI program. Terminating.\n"); MPI_Abort(MPI_COMM_WORLD, rc); } MPI_Comm_size(MPI_COMM_WORLD,&num_nodes); MPI_Comm_rank(MPI_COMM_WORLD,&myid); system("numactl --show"); int ndevices = 0; int nprocs = 1; nprocs = 1; int nptcls_node,nptcls_total; int nthreads = ndevices + nprocs; srand(1209876*(5+myid)); system("echo $LD_LIBRARY_PATH"); // Setup plasma data PlasmaData pdata(argc,argv); pdata.ny = 2; pdata.nz = 2; pdata.setup(); pdata.ndimensions = 1; pdata.nVelocity = 1; pdata.iEM = 0; pdata.rdata->SimName = "IonAcousticShock"; // Coupled1D_ES* LOsolver = new Coupled1D_ES; // AmpereSolver* LOsolver = new AmpereSolver; HoLoInterface* LOsolver = new HoLoInterface(&pdata); IonAcoustic_Initializer* initializer = new IonAcoustic_Initializer(&pdata); ImplicitPIC* simulation = new ImplicitPIC(&pdata,LOsolver,initializer); simulation->simulate(); MPI_Finalize(); }
void justine::robocar::Traffic::cmd_session ( boost::asio::ip::tcp::socket client_socket ) { const int network_buffer_size = 524288; char data[network_buffer_size]; // TODO buffered write... try { for ( ;; ) { CarLexer cl; boost::system::error_code err; size_t length = client_socket.read_some ( boost::asio::buffer ( data ), err ); if ( err == boost::asio::error::eof ) { break; } else if ( err ) { throw boost::system::system_error ( err ); } std::istringstream pdata ( data ); cl.switch_streams ( &pdata ); cl.yylex(); length = 0; int resp_code = cl.get_errnumber(); int num = cl.get_num(); int id {0}; if ( cl.get_cmd() == 0 ) { for ( ;; ) { std::vector<std::shared_ptr<Car>> cars_copy; { std::lock_guard<std::mutex> lock ( cars_mutex ); cars_copy = cars; } std::stringstream ss; ss << m_time << " " << m_minutes << " " << cars_copy.size() << std::endl; /*for ( auto car:cars_copy ) { car->step(); ss << *car << " " << std::endl; }*/ //atirva for ( std::vector<std::shared_ptr<Car>>::iterator it=cars_copy.begin(); it != cars_copy.end(); ++it ) { auto car = *it; car->step(); ss << *car << " " << std::endl; } boost::asio::write ( client_socket, boost::asio::buffer ( data, length ) ); length = std::sprintf ( data, "%s", ss.str().c_str() ); boost::asio::write ( client_socket, boost::asio::buffer ( data, length ) ); std::this_thread::sleep_for ( std::chrono::milliseconds ( 200 ) ); } } else if ( cl.get_cmd() <100 ) { std::lock_guard<std::mutex> lock ( cars_mutex ); for ( int i {0}; i<cl.get_num(); ++i ) { if ( cl.get_role() =='c' ) id = addCop ( cl ); else id = addGangster ( cl ); if ( !resp_code ) length += std::sprintf ( data+length, "<OK %d %d/%d %c>", id, num, i+1, cl.get_role() ); else length += std::sprintf ( data+length, "<WARN %d %d/%d %c>", id, num, i+1, cl.get_role() ); } } // cmd 100 else if ( cl.get_cmd() == 101 ) { if ( m_smart_cars_map.find ( cl.get_id() ) != m_smart_cars_map.end() ) { std::shared_ptr<SmartCar> c = m_smart_cars_map[cl.get_id()]; if ( c->set_route ( cl.get_route() ) ) length += std::sprintf ( data+length, "<OK %d>", cl.get_id() ); else length += std::sprintf ( data+length, "<ERR bad routing vector>" ); } else length += std::sprintf ( data+length, "<ERR unknown car id>" ); } else if ( cl.get_cmd() == 1001 ) { if ( m_smart_cars_map.find ( cl.get_id() ) != m_smart_cars_map.end() ) { std::shared_ptr<SmartCar> c = m_smart_cars_map[cl.get_id()]; length += std::sprintf ( data+length, "<OK %d %u %u %u>", cl.get_id(), c->from(), c->to_node(), c->get_step() ); } else length += std::sprintf ( data+length, "<ERR unknown car id>" ); } else if ( cl.get_cmd() == 1002 ) { std::lock_guard<std::mutex> lock ( cars_mutex ); if ( m_smart_cars_map.find ( cl.get_id() ) != m_smart_cars_map.end() ) { bool hasGangsters {false}; /*for ( auto c:m_smart_cars ) { if ( c->get_type() == CarType::GANGSTER ) { length += std::sprintf ( data+length, "<OK %d %u %u %u>", cl.get_id(), c->from(), c->to_node(), c->get_step() ); if ( length > network_buffer_size - 512 ) { length += std::sprintf ( data+length, "<WARN too many gangsters to send through this implementation...>" ); break; } hasGangsters = true; } } */ //atirva for ( std::vector<std::shared_ptr<SmartCar>>::iterator it = m_smart_cars.begin(); it != m_smart_cars.end(); ++it ) { auto c = *it; if ( c->get_type() == CarType::GANGSTER ) { length += std::sprintf ( data+length, "<OK %d %u %u %u>", cl.get_id(), c->from(), c->to_node(), c->get_step() ); if ( length > network_buffer_size - 512 ) { length += std::sprintf ( data+length, "<WARN too many gangsters to send through this implementation...>" ); break; } hasGangsters = true; } } if ( !hasGangsters ) length += std::sprintf ( data+length, "<WARN there is no gangsters>" ); } else length += std::sprintf ( data+length, "<ERR unknown car id>" ); } else if ( cl.get_cmd() == 1003 ) { std::lock_guard<std::mutex> lock ( cars_mutex ); if ( m_smart_cars_map.find ( cl.get_id() ) != m_smart_cars_map.end() ) { bool hasCops {false}; /* for ( auto c:m_cop_cars ) { length += std::sprintf ( data+length, "<OK %d %u %u %u %d>", cl.get_id(), c->from(), c->to_node(), c->get_step(), c->get_num_captured_gangsters() ); if ( length > network_buffer_size - 512 ) { length += std::sprintf ( data+length, "<WARN too many cops to send through this implementation...>" ); break; } hasCops = true; }*/ //atirva for ( std::vector<std::shared_ptr<CopCar>>::iterator it = m_cop_cars.begin(); it != m_cop_cars.end(); ++it ) { auto c = *it; length += std::sprintf ( data+length, "<OK %d %u %u %u %d>", cl.get_id(), c->from(), c->to_node(), c->get_step(), c->get_num_captured_gangsters() ); if ( length > network_buffer_size - 512 ) { length += std::sprintf ( data+length, "<WARN too many cops to send through this implementation...>" ); break; } hasCops = true; } if ( !hasCops ) length += std::sprintf ( data+length, "<WARN there is no cops>" ); } else length += std::sprintf ( data+length, "<ERR unknown car id>" ); } else if ( cl.get_cmd() == 10001 ) { if ( m_smart_cars_map.find ( cl.get_id() ) != m_smart_cars_map.end() ) { std::shared_ptr<SmartCar> c = m_smart_cars_map[cl.get_id()]; if ( c->set_fromto ( cl.get_from(), cl.get_to() ) ) length += std::sprintf ( data+length, "<OK %d>", cl.get_id() ); else length += std::sprintf ( data+length, "<ERR cannot set>" ); } else length += std::sprintf ( data+length, "<ERR unknown car id>" ); } else { length += std::sprintf ( data+length, "<ERR unknown proto command>" ); } boost::asio::write ( client_socket, boost::asio::buffer ( data, length ) ); } } catch ( std::exception& e ) { std::cerr << "Ooops: " << e.what() << std::endl; } }
int TrajectoryAnalysisCommandLineRunner::run(int argc, char *argv[]) { TrajectoryAnalysisModule *module = impl_->module_; SelectionCollection selections; selections.setDebugLevel(impl_->debugLevel_); TrajectoryAnalysisSettings settings; TrajectoryAnalysisRunnerCommon common(&settings); impl_->parseOptions(&settings, &common, &selections, &argc, argv); const TopologyInformation &topology = common.topologyInformation(); module->initAnalysis(settings, topology); // Load first frame. common.initFirstFrame(); module->initAfterFirstFrame(settings, common.frame()); t_pbc pbc; t_pbc *ppbc = settings.hasPBC() ? &pbc : NULL; int nframes = 0; AnalysisDataParallelOptions dataOptions; TrajectoryAnalysisModuleDataPointer pdata( module->startFrames(dataOptions, selections)); do { common.initFrame(); t_trxframe &frame = common.frame(); if (ppbc != NULL) { set_pbc(ppbc, topology.ePBC(), frame.box); } selections.evaluate(&frame, ppbc); module->analyzeFrame(nframes, frame, ppbc, pdata.get()); module->finishFrameSerial(nframes); ++nframes; } while (common.readNextFrame()); module->finishFrames(pdata.get()); if (pdata.get() != NULL) { pdata->finish(); } pdata.reset(); if (common.hasTrajectory()) { fprintf(stderr, "Analyzed %d frames, last time %.3f\n", nframes, common.frame().time); } else { fprintf(stderr, "Analyzed topology coordinates\n"); } // Restore the maximal groups for dynamic selections. selections.evaluateFinal(nframes); module->finishAnalysis(nframes); module->writeOutput(); return 0; }
static void print_nsp(const u_char *nspp, u_int nsplen) { const struct nsphdr *nsphp = (struct nsphdr *)nspp; int dst, src, flags; flags = EXTRACT_LE_8BITS(nsphp->nh_flags); dst = EXTRACT_LE_16BITS(nsphp->nh_dst); src = EXTRACT_LE_16BITS(nsphp->nh_src); switch (flags & NSP_TYPEMASK) { case MFT_DATA: switch (flags & NSP_SUBMASK) { case MFS_BOM: case MFS_MOM: case MFS_EOM: case MFS_BOM+MFS_EOM: printf("data %d>%d ", src, dst); { struct seghdr *shp = (struct seghdr *)nspp; int ack; #ifdef PRINT_NSPDATA u_char *dp; #endif u_int data_off = sizeof(struct minseghdr); ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); data_off += sizeof(short); if (ack & SGQ_OACK) { /* ackoth field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("onak %d ", ack & SGQ_MASK); else (void)printf("oack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); data_off += sizeof(short); } } (void)printf("seg %d ", ack & SGQ_MASK); #ifdef PRINT_NSPDATA dp = &(nspp[data_off]); pdata(dp, 10); #endif } break; case MFS_ILS+MFS_INT: printf("intr "); { struct seghdr *shp = (struct seghdr *)nspp; int ack; #ifdef PRINT_NSPDATA u_char *dp; #endif u_int data_off = sizeof(struct minseghdr); ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); data_off += sizeof(short); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("nakdat %d ", ack & SGQ_MASK); else (void)printf("ackdat %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); data_off += sizeof(short); } } (void)printf("seg %d ", ack & SGQ_MASK); #ifdef PRINT_NSPDATA dp = &(nspp[data_off]); pdata(dp, 10); #endif } break; case MFS_ILS: (void)printf("link-service %d>%d ", src, dst); { struct seghdr *shp = (struct seghdr *)nspp; struct lsmsg *lsmp = (struct lsmsg *)&(nspp[sizeof(struct seghdr)]); int ack; int lsflags, fcval; ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("nakdat %d ", ack & SGQ_MASK); else (void)printf("ackdat %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); } } (void)printf("seg %d ", ack & SGQ_MASK); lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags); fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval); switch (lsflags & LSI_MASK) { case LSI_DATA: (void)printf("dat seg count %d ", fcval); switch (lsflags & LSM_MASK) { case LSM_NOCHANGE: break; case LSM_DONOTSEND: (void)printf("donotsend-data "); break; case LSM_SEND: (void)printf("send-data "); break; default: (void)printf("reserved-fcmod? %x", lsflags); break; } break; case LSI_INTR: (void)printf("intr req count %d ", fcval); break; default: (void)printf("reserved-fcval-int? %x", lsflags); break; } } break; default: (void)printf("reserved-subtype? %x %d > %d", flags, src, dst); break; } break; case MFT_ACK: switch (flags & NSP_SUBMASK) { case MFS_DACK: (void)printf("data-ack %d>%d ", src, dst); { struct ackmsg *amp = (struct ackmsg *)nspp; int ack; ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); if (ack & SGQ_OACK) { /* ackoth field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("onak %d ", ack & SGQ_MASK); else (void)printf("oack %d ", ack & SGQ_MASK); } } } break; case MFS_IACK: (void)printf("ils-ack %d>%d ", src, dst); { struct ackmsg *amp = (struct ackmsg *)nspp; int ack; ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); if (ack & SGQ_ACK) { /* acknum field */ if ((ack & SGQ_NAK) == SGQ_NAK) (void)printf("nak %d ", ack & SGQ_MASK); else (void)printf("ack %d ", ack & SGQ_MASK); ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); if (ack & SGQ_OACK) { /* ackdat field */ if ((ack & SGQ_ONAK) == SGQ_ONAK) (void)printf("nakdat %d ", ack & SGQ_MASK); else (void)printf("ackdat %d ", ack & SGQ_MASK); } } } break; case MFS_CACK: (void)printf("conn-ack %d", dst); break; default: (void)printf("reserved-acktype? %x %d > %d", flags, src, dst); break; } break; case MFT_CTL: switch (flags & NSP_SUBMASK) { case MFS_CI: case MFS_RCI: if ((flags & NSP_SUBMASK) == MFS_CI) (void)printf("conn-initiate "); else (void)printf("retrans-conn-initiate "); (void)printf("%d>%d ", src, dst); { struct cimsg *cimp = (struct cimsg *)nspp; int services, info, segsize; #ifdef PRINT_NSPDATA u_char *dp; #endif services = EXTRACT_LE_8BITS(cimp->ci_services); info = EXTRACT_LE_8BITS(cimp->ci_info); segsize = EXTRACT_LE_16BITS(cimp->ci_segsize); switch (services & COS_MASK) { case COS_NONE: break; case COS_SEGMENT: (void)printf("seg "); break; case COS_MESSAGE: (void)printf("msg "); break; case COS_CRYPTSER: (void)printf("crypt "); break; } switch (info & COI_MASK) { case COI_32: (void)printf("ver 3.2 "); break; case COI_31: (void)printf("ver 3.1 "); break; case COI_40: (void)printf("ver 4.0 "); break; case COI_41: (void)printf("ver 4.1 "); break; } (void)printf("segsize %d ", segsize); #ifdef PRINT_NSPDATA dp = &(nspp[sizeof(struct cimsg)]); pdata(dp, nsplen - sizeof(struct cimsg)); #endif } break; case MFS_CC: (void)printf("conn-confirm %d>%d ", src, dst); { struct ccmsg *ccmp = (struct ccmsg *)nspp; int services, info; u_int segsize, optlen; #ifdef PRINT_NSPDATA u_char *dp; #endif services = EXTRACT_LE_8BITS(ccmp->cc_services); info = EXTRACT_LE_8BITS(ccmp->cc_info); segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize); optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen); switch (services & COS_MASK) { case COS_NONE: break; case COS_SEGMENT: (void)printf("seg "); break; case COS_MESSAGE: (void)printf("msg "); break; case COS_CRYPTSER: (void)printf("crypt "); break; } switch (info & COI_MASK) { case COI_32: (void)printf("ver 3.2 "); break; case COI_31: (void)printf("ver 3.1 "); break; case COI_40: (void)printf("ver 4.0 "); break; case COI_41: (void)printf("ver 4.1 "); break; } (void)printf("segsize %d ", segsize); if (optlen) { (void)printf("optlen %d ", optlen); #ifdef PRINT_NSPDATA optlen = min(optlen, nsplen - sizeof(struct ccmsg)); dp = &(nspp[sizeof(struct ccmsg)]); pdata(dp, optlen); #endif } } break; case MFS_DI: (void)printf("disconn-initiate %d>%d ", src, dst); { struct dimsg *dimp = (struct dimsg *)nspp; int reason; u_int optlen; #ifdef PRINT_NSPDATA u_char *dp; #endif reason = EXTRACT_LE_16BITS(dimp->di_reason); optlen = EXTRACT_LE_8BITS(dimp->di_optlen); print_reason(reason); if (optlen) { (void)printf("optlen %d ", optlen); #ifdef PRINT_NSPDATA optlen = min(optlen, nsplen - sizeof(struct dimsg)); dp = &(nspp[sizeof(struct dimsg)]); pdata(dp, optlen); #endif } } break; case MFS_DC: (void)printf("disconn-confirm %d>%d ", src, dst); { struct dcmsg *dcmp = (struct dcmsg *)nspp; int reason; reason = EXTRACT_LE_16BITS(dcmp->dc_reason); print_reason(reason); } break; default: (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst); break; } break; default: (void)printf("reserved-type? %x %d > %d", flags, src, dst); break; } }
void selftest(int fd) { int count = 0; unsigned char data[32] = {0}; printf("ds31400 spi self test:\n"); printf("single read 0x00 ID1\n"); if (lseek(fd, 0x00, SEEK_SET) != 0x00) { printf("lseek error.\n"); return; } count = 1; printf("result:"); if (read(fd, data, (size_t)count) == count) { pdata(data, count); printf(" done.\n"); } else { printf(" error.\n"); return; } printf("burst read 0x00 ID[1:2]\n"); if (lseek(fd, 0x00, SEEK_SET) != 0x00) { printf("lseek error.\n"); return; } count = 2; printf("result:"); if (read(fd, data, (size_t)count) == count) { pdata(data, count); printf(" done.\n"); } else { printf(" error.\n"); return; } printf("single write 0x60 ICSEL = 0x01\n"); if (lseek(fd, 0x60, SEEK_SET) != 0x60) { printf("lseek error.\n"); return; } count = 1; data[0] = 0x01; printf("result:"); if (write(fd, data, (size_t)count) == count) { printf(" done.\n"); } else { printf(" error.\n"); return; } printf("single read 0x60 ICSEL\n"); if (lseek(fd, 0x60, SEEK_SET) != 0x60) { printf("lseek error.\n"); return; } count = 1; printf("result:"); if (read(fd, data, (size_t)count) == count) { pdata(data, count); printf(" done.\n"); } else { printf(" error.\n"); return; } printf("burst write 0x66 ICD[1:4] = 1a 2b 3c 4d\n"); if (lseek(fd, 0x66, SEEK_SET) != 0x66) { printf("lseek error.\n"); return; } count = 4; data[0] = 0x1a; data[1] = 0x2b; data[2] = 0x3c; data[3] = 0x4d; printf("result:"); if (write(fd, data, (size_t)count) == count) { printf(" done.\n"); } else { printf(" error.\n"); return; } printf("burst read 0x66 ICD[1:4]\n"); if (lseek(fd, 0x66, SEEK_SET) != 0x66) { printf("lseek error.\n"); return; } count = 4; printf("result:"); if (read(fd, data, (size_t)count) == count) { pdata(data, count); printf(" done.\n"); } else { printf(" error.\n"); return; } }
CLine::~CLine() { if(alloc) delete [] (char*)pdata(); }
void CLine::set(const void* Str) { if(alloc) delete [] (char*)pdata(); allocateAndCopy((const char*)Str); }
CLabel::~CLabel(){ delete[] (char*)pdata(); }