void loop () { int mod = ++thing >> 8; writeRow(0, thing & 1, thing & 2, thing & 4, thing & 8); writeRow(1, thing & 16, thing & 32, thing & 64, thing & 128); writeRow(2, mod & 1, mod & 2, mod & 4, mod & 8); writeRow(4, mod & 16, mod & 32, mod & 64, mod & 128); }
void iconTitleInit (void) { // initialize video mode videoSetMode(MODE_4_2D); // initialize VRAM banks vramSetPrimaryBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_LCD, VRAM_D_LCD); // initialize bg2 as a rotation background and bg3 as a bmp background // http://mtheall.com/vram.html#T2=3&RNT2=96&MB2=3&TB2=0&S2=2&T3=6&MB3=1&S3=1 bg2 = bgInit(2, BgType_Rotation, BgSize_R_512x512, 3, 0); bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 1, 0); // initialize rotate, scale, and scroll bgSetRotateScale(bg3, 0, 1<<8, 1<<8); bgSetScroll(bg3, 0, 0); bgSetRotateScale(bg2, 0, 8*(1<<8)/6, 1<<8); bgSetScroll(bg2, -TITLE_POS_X, -TITLE_POS_Y); // clear bg2's map: 512x512 pixels is 64x64 tiles is 4KB dmaFillHalfWords(0, bgGetMapPtr(bg2), 4096); // load compressed font into bg2's tile data decompress(font6x8Tiles, bgGetGfxPtr(bg2), LZ77Vram); // load compressed bitmap into bg3 decompress(hbmenu_bannerBitmap, bgGetGfxPtr(bg3), LZ77Vram); // load font palette dmaCopy(font6x8Pal, BG_PALETTE, font6x8PalLen); // apply the bg changes bgUpdate(); // initialize OAM oamInit(&oamMain, SpriteMapping_1D_128, false); sprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_16Color); dmaFillHalfWords(0, sprite, sizeof(banner.icon)); oamSet(&oamMain, 0, ICON_POS_X, ICON_POS_Y, 0, 0, SpriteSize_32x32, SpriteColorFormat_16Color, sprite, -1, 0, 0, 0, 0, 0); // oam can only be updated during vblank swiWaitForVBlank(); oamUpdate(&oamMain); // everything's ready :) writeRow (0,"...initializing..."); writeRow (1,"===>>> HBMenu+ <<<==="); writeRow (2,"(this text should disappear..."); writeRow (3,"...otherwise, trouble!)"); }
void PrettyCompactBlockOutputStream::write(const Block & block) { UInt64 max_rows = format_settings.pretty.max_rows; if (total_rows >= max_rows) { total_rows += block.rows(); return; } size_t rows = block.rows(); WidthsPerColumn widths; Widths max_widths; Widths name_widths; calculateWidths(block, widths, max_widths, name_widths, format_settings); writeHeader(block, max_widths, name_widths); for (size_t i = 0; i < rows && total_rows + i < max_rows; ++i) writeRow(i, block, widths, max_widths); writeBottom(max_widths); total_rows += rows; }
SEXP hitandrun_simplexSample(SEXP _n, SEXP _sort, SEXP _niter) { int const n = asInteger(_n); int const sort = asLogical(_sort); int const niter = asInteger(_niter); // allocate output matrix SEXP _result = PROTECT(allocMatrix(REALSXP, niter, n)); Matrix result = { REAL(_result), niter, n }; // state variables double x[n + 1]; GetRNGstate(); // enable use of RNGs for (int i = 0; i < niter; ++i) { x[0] = 0.0; x[n] = 1.0; for (int j = 1; j < n; ++j) { x[j] = unif_rand(); } qsort(x + 1, n - 1, sizeof(double), hitandrun_doubleAsc); for (int j = 0; j < n; ++j) { x[j] = x[j + 1] - x[j]; } if (sort) { qsort(x, n, sizeof(double), hitandrun_doubleDesc); } writeRow(&result, i, x); } PutRNGstate(); UNPROTECT(1); return _result; }
void FormDlgRuleSnippet::slotBtnSave() { if (validateData()) { writeRow(); accept(); } }
SEXP hitandrun_har(SEXP _x0, SEXP _constr, SEXP _rhs, SEXP _niter, SEXP _thin) { // get problem dimensions int const niter = asInteger(_niter); int const thin = asInteger(_thin); int const n = length(_x0); int const m = length(_rhs); int const inc1 = 1; // needed for BLAS // convert input vectors / matrices _x0 = PROTECT(coerceVector(_x0, REALSXP)); _constr = PROTECT(coerceVector(_constr, REALSXP)); _rhs = PROTECT(coerceVector(_rhs, REALSXP)); double *x0 = REAL(_x0); double *rhs = REAL(_rhs); Matrix constr = { REAL(_constr), m, n }; // check the starting point if (!hitandrun_hit(&constr, rhs, x0, 0.0)) { UNPROTECT(3); error("The starting point must be inside the region"); } // allocate output matrix SEXP _result = PROTECT(allocMatrix(REALSXP, niter / thin, n)); Matrix result = { REAL(_result), niter / thin, n }; // state variables double x[n]; memcpy(x, x0, n * sizeof(double)); double d[n]; double l[2]; GetRNGstate(); // enable use of RNGs for (int i = 0; i < niter; ++i) { hitandrun_randDir(d, n); // generate random direction d hitandrun_bound(&constr, rhs, x, d, l); // calculate bounds l if (!R_FINITE(l[0]) || !R_FINITE(l[1])) { UNPROTECT(4); error("Bounding function gave NA bounds [%f, %f]", l[0], l[1]); } if (l[0] == l[1]) { // FIXME: is this an error? UNPROTECT(4); error("Bounding function gave empty interval"); } double v = l[0] + unif_rand() * (l[1] - l[0]); F77_CALL(daxpy)(&n, &v, d, &inc1, x, &inc1); // x := vd + x if ((i + 1) % thin == 0) { // write result writeRow(&result, i / thin, x); } } PutRNGstate(); // propagate RNG state back to R (or somewhere) UNPROTECT(4); return _result; }
SEXP hitandrun_bbReject(SEXP _lb, SEXP _ub, SEXP _constr, SEXP _rhs, SEXP _niter) { // get problem dimensions int const niter = asInteger(_niter); int const n = length(_lb); int const m = length(_rhs); // convert input vectors / matrices _lb = PROTECT(coerceVector(_lb, REALSXP)); _ub = PROTECT(coerceVector(_ub, REALSXP)); _constr = PROTECT(coerceVector(_constr, REALSXP)); _rhs = PROTECT(coerceVector(_rhs, REALSXP)); double *lb = REAL(_lb); double *ub = REAL(_ub); Matrix constr = { REAL(_constr), m, n }; double *rhs = REAL(_rhs); // allocate output matrix SEXP _result = PROTECT(allocMatrix(REALSXP, niter, n)); Matrix result = { REAL(_result), niter, n }; double reject = 0.0; // internal state variables double d[n]; // pre-calculated differences for (int j = 0; j < n; ++j) { d[j] = ub[j] - lb[j]; } double x[n]; GetRNGstate(); // enable use of RNGs for (int i = 0; i < niter; ++i) { int wasHit = 0; int miss = 0; while (!wasHit) { for (int j = 0; j < n; ++j) { x[j] = lb[j] + d[j] * unif_rand(); } if (hitandrun_hit(&constr, rhs, x, 0.0)) { wasHit = 1; writeRow(&result, i, x); } else { ++miss; } } reject += (double)miss / niter; } PutRNGstate(); // return samples and rejection rate as a list SEXP ans = PROTECT(allocVector(VECSXP, 2)); SET_VECTOR_ELT(ans, 0, _result); SET_VECTOR_ELT(ans, 1, ScalarReal(reject)); UNPROTECT(6); return ans; }
GeneByGeneReportIO::~GeneByGeneReportIO(){ const QList<QString>& keys = mergedTable.keys(); foreach(const QString& key, keys){ QList<QString> toWrite; toWrite.append(key); toWrite.append(mergedTable.take(key)); toWrite.append(GeneByGeneCompareResult::IDENTICAL_NO); writeRow(toWrite); }
void TableFormat::writeWholeTable( std::ostream& out, const std::string& header, const Array<std::string>& columnNames, const Array<TableColumn>& columns ) const { /* compute the total width */ int pgWidth = 0; for (Array<TableColumn>::size_type i=0; i<columnNames.size(); i++) { int cw = defaultColumnWidth(); if (columnWidths_.size() != 0) cw = columnWidths_[i]; pgWidth += cw; } setPageWidth(std::max(pageWidth_, pgWidth)); /* write the header */ out << thickline() << std::endl; out << std::endl; int numBlanks = (pageWidth_ - header.length())/2; out << blanks(numBlanks) << header << std::endl; out << std::endl; /* write the column titles */ for (Array<std::string>::size_type i=0; i<columnNames.size(); i++) { int cw = defaultColumnWidth(); if (columnWidths_.size() != 0) cw = columnWidths_[i]; out << std::left << std::setw(cw) << columnNames[i]; } out << std::endl; /* ensure that all columns have the same number of rows */ int numRows = columns[0].numRows(); for (Array<TableColumn>::size_type i=1; i<columns.size(); i++) { TEUCHOS_ASSERT_EQUALITY(columns[i].numRows(), numRows); } /* write the table data */ for (int i=0; i<numRows; i++) { if (i % lineInterval_ == 0) out << std::left << thinline() << std::endl; writeRow(out, i, columns); } /* write the footer */ out << thickline() << std::endl; }
void TableFormat::writeRow( std::ostream& out, int rowIndex, const Array<TableColumn>& columns ) const { Array<RCP<TableEntry> > entries(columns.size()); for (Array<TableColumn>::size_type i=0; i<columns.size(); i++) { entries[i] = columns[i].entry(rowIndex); } writeRow(out, entries); }
void PrettyCompactMonoBlockOutputStream::writeSuffix() { if (blocks.empty()) return; Widths_t max_widths; Widths_t name_widths; for (size_t i = 0; i < blocks.size(); ++i) calculateWidths(blocks[i], max_widths, name_widths); writeHeader(blocks.front(), max_widths, name_widths); size_t row_count = 0; for (size_t block_id = 0; block_id < blocks.size() && row_count < max_rows; ++block_id) { const Block & block = blocks[block_id]; size_t rows = block.rows(); for (size_t i = 0; i < rows && row_count < max_rows; ++i) { writeRow(i, block, max_widths, name_widths); ++row_count; } } writeBottom(max_widths); if (total_rows >= max_rows) { writeCString(" Showed first ", ostr); writeIntText(max_rows, ostr); writeCString(".\n", ostr); } total_rows = 0; if (totals) { writeCString("\nTotals:\n", ostr); PrettyCompactBlockOutputStream::write(totals); } if (extremes) { writeCString("\nExtremes:\n", ostr); PrettyCompactBlockOutputStream::write(extremes); } }
/** * Execution path for NormalisedPolygon Rebinning * @param inputWS : Workspace to be rebinned * @param vertexes : TableWorkspace for debugging purposes * @param dumpVertexes : determines whether vertexes will be written to for * debugging purposes or not * @param outputDimensions : used for the column headings for Dump Vertexes */ MatrixWorkspace_sptr ReflectometryTransform::executeNormPoly( MatrixWorkspace_const_sptr inputWS, boost::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes, bool dumpVertexes, std::string outputDimensions) const { MatrixWorkspace_sptr temp = WorkspaceFactory::Instance().create( "RebinnedOutput", m_d1NumBins, m_d0NumBins, m_d0NumBins); RebinnedOutput_sptr outWS = boost::static_pointer_cast<RebinnedOutput>(temp); const double widthD0 = (m_d0Max - m_d0Min) / double(m_d0NumBins); const double widthD1 = (m_d1Max - m_d1Min) / double(m_d1NumBins); std::vector<double> xBinsVec; std::vector<double> zBinsVec; VectorHelper::createAxisFromRebinParams({m_d1Min, widthD1, m_d1Max}, zBinsVec); VectorHelper::createAxisFromRebinParams({m_d0Min, widthD0, m_d0Max}, xBinsVec); // Put the correct bin boundaries into the workspace auto verticalAxis = new BinEdgeAxis(zBinsVec); outWS->replaceAxis(1, verticalAxis); for (size_t i = 0; i < zBinsVec.size() - 1; ++i) outWS->setX(i, xBinsVec); verticalAxis->title() = m_d1Label; // Prepare the required theta values DetectorAngularCache cache = initAngularCaches(inputWS.get()); m_theta = cache.thetas; m_thetaWidths = cache.thetaWidths; const size_t nHistos = inputWS->getNumberHistograms(); const size_t nBins = inputWS->blocksize(); // Holds the spectrum-detector mapping std::vector<specnum_t> specNumberMapping; std::vector<detid_t> detIDMapping; // Create a table for the output if we want to debug vertex positioning addColumnHeadings(vertexes, outputDimensions); for (size_t i = 0; i < nHistos; ++i) { IDetector_const_sptr detector = inputWS->getDetector(i); if (!detector || detector->isMasked() || detector->isMonitor()) { continue; } // Compute polygon points const double theta = m_theta[i]; const double thetaWidth = m_thetaWidths[i]; const double thetaHalfWidth = 0.5 * thetaWidth; const double thetaLower = theta - thetaHalfWidth; const double thetaUpper = theta + thetaHalfWidth; const MantidVec &X = inputWS->readX(i); const MantidVec &Y = inputWS->readY(i); const MantidVec &E = inputWS->readE(i); for (size_t j = 0; j < nBins; ++j) { const double lamLower = X[j]; const double lamUpper = X[j + 1]; const double signal = Y[j]; const double error = E[j]; auto inputQ = m_calculator->createQuad(lamUpper, lamLower, thetaUpper, thetaLower); FractionalRebinning::rebinToFractionalOutput(inputQ, inputWS, i, j, outWS, zBinsVec); // Find which qy bin this point lies in const auto qIndex = std::upper_bound(zBinsVec.begin(), zBinsVec.end(), inputQ[0].Y()) - zBinsVec.begin(); if (qIndex != 0 && qIndex < static_cast<int>(zBinsVec.size())) { // Add this spectra-detector pair to the mapping specNumberMapping.push_back( outWS->getSpectrum(qIndex - 1).getSpectrumNo()); detIDMapping.push_back(detector->getID()); } // Debugging if (dumpVertexes) { writeRow(vertexes, inputQ[0], i, j, signal, error); writeRow(vertexes, inputQ[1], i, j, signal, error); writeRow(vertexes, inputQ[2], i, j, signal, error); writeRow(vertexes, inputQ[3], i, j, signal, error); } } } outWS->finalize(); FractionalRebinning::normaliseOutput(outWS, inputWS); // Set the output spectrum-detector mapping SpectrumDetectorMapping outputDetectorMap(specNumberMapping, detIDMapping); outWS->updateSpectraUsing(outputDetectorMap); outWS->getAxis(0)->title() = m_d0Label; outWS->setYUnit(""); outWS->setYUnitLabel("Intensity"); return outWS; }
static Image* readGif ( GifFileType *gf ) { Image* firstImg = 0; Image* img = 0; int i, extCode, width, height, row, cmapSize; int trans = -1, nFrames = 0, delay = 0; GifRecordType rec; GifByteType *ext; ColorMapObject *cmap; GifColorType *clrs; GifPixelType *rowBuf = (GifPixelType*) AWT_MALLOC( gf->SWidth * sizeof( GifPixelType) ); do { CHECK( DGifGetRecordType( gf, &rec)); switch ( rec ) { case IMAGE_DESC_RECORD_TYPE: CHECK( DGifGetImageDesc( gf)); width = gf->Image.Width; height = gf->Image.Height; cmap = (gf->Image.ColorMap) ? gf->Image.ColorMap : gf->SColorMap; clrs = cmap->Colors; cmapSize = cmap->ColorCount; /* * create our image objects and keep track of frames */ if ( !firstImg ) { /* this is the first (maybe only) frame */ firstImg = img = createImage( width, height); } else { /* this is a subsequent gif-movie frame, link it in */ img->next = createImage( width, height); img = img->next; } /* * The trans index might have been cached by a preceeding extension record. Now * that we have the Image object, it's time to store it in img and to create the * mask */ if ( trans != -1 ) { img->trans = trans; createXMaskImage( X, img); trans = -1; } /* * Some browsers seem to assume minimal values, and some animations * seem to rely on this. But there's no safe guess, so we * skip it completely */ /* if ( delay == 0 ) delay = 1000; else if ( delay < 100 ) delay = 100; */ img->latency = delay; img->left = gf->Image.Left; img->top = gf->Image.Top; img->frame = nFrames; nFrames++; createXImage( X, img); /* * start reading in the image data */ if ( gf->Image.Interlace ) { /* Need to perform 4 passes on the images: */ for ( i = 0; i < 4; i++ ) { for (row = iOffset[i]; row < height; row += iJumps[i]) { memset( rowBuf, gf->SBackGroundColor, width); CHECK( DGifGetLine( gf, rowBuf, width)); writeRow( img, rowBuf, clrs, row); } } } else { for ( row = 0; row < height; row++) { memset( rowBuf, gf->SBackGroundColor, width); CHECK( DGifGetLine(gf, rowBuf, width)); writeRow( img, rowBuf, clrs, row); } } break; case EXTENSION_RECORD_TYPE: CHECK( DGifGetExtension( gf, &extCode, &ext)); if ( extCode == 0xf9 ) { /* graphics extension */ /* * extension record with transparency spec are preceeding description records * (which create new Images), so just cache the transp index, here */ if ( ext[1] & 1 ) { /* transparent index following */ trans = ext[4]; } delay = ((ext[3] << 8) | ext[2]) * 10; /* delay in 1/100 secs */ } else if ( extCode == 0xff ) { /* application extension block */ } while ( ext != NULL ) { CHECK( DGifGetExtensionNext( gf, &ext)); } break; case TERMINATE_RECORD_TYPE: break; default: /* Should be traps by DGifGetRecordType. */ break; } } while ( rec != TERMINATE_RECORD_TYPE ); if ( firstImg && (img != firstImg) ){ img->next = firstImg; /* link it together (as a ring) */ } return firstImg; }
void iconTitleUpdate (int isdir, const char* name) { writeRow (0,name); writeRow (1,""); writeRow (2,""); writeRow (3,""); if (isdir) { // text writeRow (2,"[directory]"); // icon clearIcon(); } else if(strlen(name) >= 5 && strcasecmp(name + strlen(name) - 5, ".argv") == 0) { // look through the argv file for the corresponding nds file FILE *fp; char *line = NULL, *p = NULL; size_t size = 0; ssize_t rc; // open the argv file fp = fopen(name,"rb"); if(fp == NULL) { writeRow(2, "(can't open file!)"); clearIcon(); fclose(fp); return; } // read each line while((rc = __getline(&line, &size, fp)) > 0) { // remove comments if((p = strchr(line, '#')) != NULL) *p = 0; // skip leading whitespace for(p = line; *p && isspace((int)*p); ++p) ; if(*p) break; } // done with the file at this point fclose(fp); if(p && *p) { // we found an argument struct stat st; // truncate everything after first argument strtok(p, "\n\r\t "); if(strlen(p) < 4 || strcasecmp(p + strlen(p) - 4, ".nds") != 0) { // this is not an nds file! writeRow(2, "(invalid argv file!)"); clearIcon(); } else { // let's see if this is a file or directory rc = stat(p, &st); if(rc != 0) { // stat failed writeRow(2, "(can't find argument!)"); clearIcon(); } else if(S_ISDIR(st.st_mode)) { // this is a directory! writeRow(2, "(invalid argv file!)"); clearIcon(); } else { iconTitleUpdate(false, p); } } } else { writeRow(2, "(no argument!)"); clearIcon(); } // clean up the allocated line free(line); } else { // this is an nds file! FILE *fp; unsigned int Icon_title_offset; int ret; // open file for reading info fp=fopen (name,"rb"); if (fp==NULL) { // text writeRow (2,"(can't open file!)"); // icon clearIcon(); fclose (fp); return; } ret=fseek (fp, offsetof(tNDSHeader, bannerOffset), SEEK_SET); if (ret==0) ret=fread (&Icon_title_offset, sizeof(int), 1, fp); // read if seek succeed else ret=0; // if seek fails set to !=1 if (ret!=1) { // text writeRow (2,"(can't read file!)"); // icon clearIcon(); fclose (fp); return; } if (Icon_title_offset==0) { // text writeRow (2,"(no title/icon)"); // icon clearIcon(); fclose (fp); return; } ret=fseek (fp,Icon_title_offset,SEEK_SET); if (ret==0) ret=fread (&banner, sizeof(banner), 1, fp); // read if seek succeed else ret=0; // if seek fails set to !=1 if (ret!=1) { // text writeRow (2,"(can't read icon/title!)"); // icon clearIcon(); fclose (fp); return; } // close file! fclose (fp); // turn unicode into ascii (kind of) // and convert 0x0A into 0x00 int i; char *p = (char*)banner.titles[0]; for (i = 0; i < sizeof(banner.titles[0]); i = i+2) { if ((p[i] == 0x0A) || (p[i] == 0xFF)) p[i/2] = 0; else p[i/2] = p[i]; } // text for(i = 0; i < 3; ++i) { writeRow (i+1, p); p += strlen(p)+1; } // icon DC_FlushAll(); dmaCopy(banner.icon, sprite, sizeof(banner.icon)); dmaCopy(banner.palette, SPRITE_PALETTE, sizeof(banner.palette)); } }