Ejemplo n.º 1
1
upm_result_t mma7361_update(const mma7361_context dev)
{
  assert(dev != NULL);

  float sample;

  if (dev->aio_x)
    {
      if ((sample = (float)mraa_aio_read(dev->aio_x)) < 0.0)
        {
          printf("%s: mraa_aio_read(x) failed.\n", __FUNCTION__);
          return UPM_ERROR_OPERATION_FAILED;
        }

      dev->normalized_x = sample / dev->a_res;
      dev->volts_x = dev->normalized_x * dev->a_ref;
      dev->accel_x = MAP(dev->volts_x, 0.0, MMA_OUTPUT_AREF,
                         -dev->g_range, dev->g_range);
    }

  if (dev->aio_y)
    {
      if ((sample = (float)mraa_aio_read(dev->aio_y)) < 0.0)
        {
          printf("%s: mraa_aio_read(y) failed.\n", __FUNCTION__);
          return UPM_ERROR_OPERATION_FAILED;
        }

      dev->normalized_y = sample / dev->a_res;
      dev->volts_y = dev->normalized_y * dev->a_ref;
      dev->accel_y = MAP(dev->volts_y, 0.0, MMA_OUTPUT_AREF,
                         -dev->g_range, dev->g_range);
    }

  if (dev->aio_z)
    {
      if ((sample = (float)mraa_aio_read(dev->aio_z)) < 0.0)
        {
          printf("%s: mraa_aio_read(z) failed.\n", __FUNCTION__);
          return UPM_ERROR_OPERATION_FAILED;
        }

      dev->normalized_z = sample / dev->a_res;
      dev->volts_z = dev->normalized_z * dev->a_ref;
      dev->accel_z = MAP(dev->volts_z, 0.0, MMA_OUTPUT_AREF,
                         -dev->g_range, dev->g_range);
    }

  return UPM_SUCCESS;
}
Ejemplo n.º 2
0
struct map *
or_map(struct map *mp1, struct map *mp2)
{
#ifdef MAP_DEBUG
    if (Mflag) {
	printf("Oring maps");
	print_map(mp1);
	printf(" and");
	print_map(mp2);
    }
#endif
    if (POSMAP(mp1))
	if (POSMAP(mp2))
	    mp1 = (struct map *)or_bitmap((struct bitmap *) mp1,
		(struct bitmap *) mp2);
	else
	    mp1 = NOT_MAP(bic_bitmap(MAP(mp2), (struct bitmap *) mp1));
    else if (POSMAP(mp2))
	mp1 = NOT_MAP(bic_bitmap(MAP(mp1), (struct bitmap *) mp2));
    else
	mp1 = NOT_MAP(and_bitmap(MAP(mp1), MAP(mp2)));
#ifdef MAP_DEBUG
    if (Mflag) {
	printf(" ->");
	print_map(mp1);
	printf("\n");
    }
#endif
    return mp1;
}
Ejemplo n.º 3
0
static int show_oidmap(struct seq_file *m, void *unused)
{
	struct super_block *sb = m->private;
	struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
	struct reiserfs_super_block *rs = sb_info->s_rs;
	unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
	unsigned long total_used = 0;
	int i;

	for (i = 0; i < mapsize; ++i) {
		__u32 right;

		right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
		seq_printf(m, "%s: [ %x .. %x )\n",
			   (i & 1) ? "free" : "used", MAP(i), right);
		if (!(i & 1)) {
			total_used += right - MAP(i);
		}
	}
#if defined( REISERFS_USE_OIDMAPF )
	if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
		loff_t size = file_inode(sb_info->oidmap.mapf)->i_size;
		total_used += size / sizeof(reiserfs_oidinterval_d_t);
	}
#endif
	seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
		   mapsize,
		   mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
	return 0;
}
Ejemplo n.º 4
0
void IllCondDetector::EigenLap(EigenSp const &K)
{
	// Convert Eigen library storage into LAPACK storage

	N_ = K.cols();
	A_ = (double*)calloc(N_ * N_, sizeof(double));

	for (int i = 0; i < N_; i++)
	{
		for (int j = 0; j < N_; j++)
		{
			A_[MAP(i, j, N_)] = K.coeff(i, j);
		}
	}
	
	// 1-norm computing
	std::vector<double> tmp;
	for (int i = 0; i < N_; i++)
	{
		double sum = 0;
		for (int j = 0; j < N_; j++)
		{
			sum += A_[MAP(i, j, N_)];
		}
		tmp.push_back(sum);
	}
	auto max = std::max_element(tmp.begin(), tmp.end());
	Anorm_ = *max;
}
Ejemplo n.º 5
0
int
dceslicecompose(DCEslice* s1, DCEslice* s2, DCEslice* result)
{
    int err = NC_NOERR;
    size_t lastx = 0;
    DCEslice sr; /* For back compatability so s1 and result can be same object */
#ifdef DEBUG1
slicedump("compose: s1",s1);
slicedump("compose: s2",s2);
#endif
    sr.node.sort = CES_SLICE;
    sr.stride    = s1->stride * s2->stride;
    sr.first     = MAP(s1,s2->first);
    if(sr.first > s1->last)
	return NC_EINVALCOORDS;
    lastx        = MAP(s1,s2->last);
    sr.last      = XMIN(s1->last,lastx);
    sr.length    = (sr.last + 1) - sr.first;
    sr.declsize = XMAX(s1->declsize,s2->declsize); /* use max declsize */
    /* fill in other fields */
    sr.count = (sr.length + (sr.stride - 1))/sr.stride;
    *result = sr;
#ifdef DEBUG1
slicedump("compose: result",result);
#endif
    return err;
}
Ejemplo n.º 6
0
void SortRoutineGraphic::drawBackground()
{
	fill(pDarkGray);
	rect(fFrame.x, fFrame.y, fFrame.width, fFrame.height);

	fill(255);

		stroke(pWhite);
		strokeWeight(0.5);

		if (fAnimate) {
			// do a step in the sorter
			if (!fSorter->step()) {
				reset();
			}
		}

		// Draw the array of values scaled to fit the window
		for (int idx = 0; idx < nElems; idx++) {
			double mappedX = (int)MAP(idx, 0, nElems - 1, fFrame.x, fFrame.x + fFrame.width - 1);
			double mappedY = (int)MAP(fSorter->fElements[idx], 0, MAX_VALUE, fFrame.y + fFrame.height - 1, fFrame.y);

			point(mappedX, mappedY);

			if (fShowLines) {
				line(fFrame.x, fFrame.y + fFrame.height - 1, mappedX, mappedY);
			}
		
	}

	drawForeground();
}
Ejemplo n.º 7
0
void
NV10EXAComposite(PixmapPtr pix_dst,
		 int srcX, int srcY,
		 int maskX, int maskY,
		 int dstX, int dstY,
		 int width, int height)
{
	ScrnInfoPtr pScrn = xf86Screens[pix_dst->drawable.pScreen->myNum];
	NVPtr pNv = NVPTR(pScrn);
	struct nouveau_channel *chan = pNv->chan;
	struct nouveau_grobj *celsius = pNv->Nv3D;
	PicturePtr mask = pNv->pmpict,
		src = pNv->pspict;
	PictVector dstq[4] = QUAD(dstX, dstY, width, height),
		maskq[4] = QUAD(maskX, maskY, width, height),
		srcq[4] = QUAD(srcX, srcY, width, height);

	MAP(transform_vertex, src->transform, srcq);
	if (mask)
		MAP(transform_vertex, mask->transform, maskq);

	WAIT_RING (chan, 64);
	BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BEGIN_END, 1);
	OUT_RING  (chan, NV10TCL_VERTEX_BEGIN_END_QUADS);

	MAP(emit_vertex, pNv, dstq, srcq, mask ? maskq : NULL);

	BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BEGIN_END, 1);
	OUT_RING  (chan, NV10TCL_VERTEX_BEGIN_END_STOP);
}
Ejemplo n.º 8
0
void town_adjust(int *dungeon_hgt, int *dungeon_wid)
{
	bool small_town = ((p_ptr->stage < KHAZAD_DUM_TOWN) && !MAP(DUNGEON) &&
					   !MAP(FANILLA));
	
	(*dungeon_hgt) /= 3;
	(*dungeon_wid) /= (small_town ? 6 : 3);
}
Ejemplo n.º 9
0
struct map *
add_map(struct map *parm, int node)
{
    struct bitmap *map;
    int bit;
    int x, page;

#ifdef MAP_DEBUG
    if (Aflag) {
	printf("add_map: adding %d to [", node);
	print_map(parm);
	printf(" ] ");
    }
#endif
    bit = NUMBERTOBIT(node);
    x = NUMBERTOINDEX(node);
    page = NUMBERTOPAGE(node);

    bit = 1L << bit;;

    for (map = MAP(parm); map; map = map->m_next)
	if (map->m_page == page)
	    break;
    if (!map) {
	map = (struct bitmap *)malloc(sizeof *map);
	if (!map) {
#ifdef PRINT_MAP_ERROR
	    printf("No memory!\n");
#endif
	    free_map((struct map *)map);
	    return 0;
	}
	map->m_page = page;
	memset( map->m_data, 0, sizeof map->m_data);
	if (NEGMAP(parm)) {
	    int i;
	    for (i = 0; i < MDATA; ++i)
		map->m_data[i] = ~0;
	}
	map->m_next = MAP(parm);
	if (POSMAP(parm))
	    parm = (struct map *)map;
	else
	    parm = NOT_MAP(map);
    }
    if (POSMAP(parm))
	map->m_data[x] |= bit;
    else
	map->m_data[x] &= ~bit;
#ifdef MAP_DEBUG
    if (Aflag) {
	printf(" ->");
	print_map(parm);
	printf("\n");
    }
#endif
    return (struct map *)parm;
}
Ejemplo n.º 10
0
int main(int argc, char const **argv) {
	int fd;
	mcp3424 j2;
	mcp3424 j3;
	unsigned int iteration = 0;
	int i;

	int channels[4] = {
		MCP3424_CHANNEL_1,
		MCP3424_CHANNEL_2,
		MCP3424_CHANNEL_3,
		MCP3424_CHANNEL_4
	};
	unsigned int res[8];
	float v[8];

	fd = open("/dev/i2c-1", O_RDWR);
	if (fd == -1) {
		printf("error: open: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}

	mcp3424_init(&j2, fd, 0x68, MCP3424_RESOLUTION_14);
	mcp3424_set_conversion_mode(&j2, MCP3424_CONVERSION_MODE_CONTINUOUS);
	mcp3424_init(&j3, fd, 0x69, MCP3424_RESOLUTION_14);
	mcp3424_set_conversion_mode(&j3, MCP3424_CONVERSION_MODE_CONTINUOUS);

	while (1) {
		for (i = 0; i < 4; i++) {
			res[i] = mcp3424_get_raw(&j2, channels[i]);
			if (j2.err) {
				printf("error: mcp3424_get_raw: %s\n", j2.errstr);
				close(fd);
				exit(EXIT_FAILURE);
			}
			v[i] = MAP(res[i], RAW_MIN, RAW_MAX_14, V_MIN, V_MAX);
		}
		for (i = 0; i < 4; i++) {
			res[i + 4] = mcp3424_get_raw(&j3, channels[i]);
			if (j3.err) {
				printf("error: mcp3424_get_raw: %s\n", j3.errstr);
				close(fd);
				exit(EXIT_FAILURE);
			}
			v[i + 4] = MAP(res[i + 4], RAW_MIN, RAW_MAX_14, V_MIN, V_MAX);
		}

		printf("iteration: %u\n", iteration++);
		for (i = 0; i < 8; i++) {
			printf("res[%d] = %u, v[%d] = %0.2f\n", i, res[i], i, v[i]);
		}
		printf("\n");
	}

	close(fd);

	return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
static driver_id_t driver_id(ripncode_t *r)
{
    struct {
        const char  *name;
        driver_id_t  id;
    } drivers[] = {
#define MAP(_name, _id) { #_name, DRIVER_##_id }
        MAP(device , DEVICE ),
        MAP(linux  , LINUX  ),
        MAP(aix    , AIX    ),
        MAP(bsdi   , BSDI   ),
        MAP(netbsd , NETBSD ),
        MAP(solaris, SOLARIS),
        MAP(cdrdao , CDRDAO ),
        MAP(bincue , BINCUE ),
        MAP(nrg    , NRG    ),
#undef MAP
        { NULL, -1 }
    }, *d;

    if (r->driver == NULL)
        r->driver = "device";

    for (d = drivers; d->name != NULL; d++)
        if (!strcmp(d->name, r->driver))
            return d->id;

    return DRIVER_UNKNOWN;
}
Ejemplo n.º 12
0
int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
			     int count, int *eof, void *data )
{
	struct super_block *sb;
	struct reiserfs_sb_info *sb_info;
	struct reiserfs_super_block *rs;
	int i;
	unsigned int mapsize;
	unsigned long total_used;
	int len = 0;
	int exact;
    
	sb = procinfo_prologue( ( kdev_t ) ( long ) data );
	if( sb == NULL )
		return -ENOENT;
	sb_info = &sb->u.reiserfs_sb;
	rs = sb_info -> s_rs;
	mapsize = le16_to_cpu( rs -> s_oid_cursize );
	total_used = 0;

	for( i = 0 ; i < mapsize ; ++i ) {
		__u32 right;

		right = ( i == mapsize - 1 ) ? MAX_KEY_OBJECTID : MAP( i + 1 );
		len += sprintf( &buffer[ len ], "%s: [ %x .. %x )\n",
				( i & 1 ) ? "free" : "used", MAP( i ), right );
		if( ! ( i & 1 ) ) {
			total_used += right - MAP( i );
		}
		if( len > PAGE_SIZE - 100 ) {
			len += sprintf( &buffer[ len ], "... and more\n" );
			break;
		}
	}
#if defined( REISERFS_USE_OIDMAPF )
	if( sb_info -> oidmap.use_file && ( sb_info -> oidmap.mapf != NULL ) ) {
		loff_t size;

		size = sb_info -> oidmap.mapf -> f_dentry -> d_inode -> i_size;
		total_used += size / sizeof( reiserfs_oidinterval_d_t );
		exact = 1;
	} else
#endif
	{
		exact = ( i == mapsize );
	}
	len += sprintf( &buffer[ len ], "total: \t%i [%i/%i] used: %lu [%s]\n", 
			i, 
			mapsize, le16_to_cpu( rs -> s_oid_maxsize ),
			total_used, exact ? "exact" : "estimation" );

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}
Ejemplo n.º 13
0
void drawDataPoints(const int col)
{
	for (int row = 0; row < rowCount; row++){
		if (isValid(row, col)) {
			float value = getFloat(row, col);
			double x = MAP(data[row].year, yearMin, yearMax, plotX1, plotX2);
			double y = MAP(value, dataMin, dataMax, plotY2, plotY1);
			point(x, y);
		}
	}
}
Ejemplo n.º 14
0
int RemoveShitNums(int* map, const int n, const int width, const int height){
	int num = 0;
	for(int y = 0; y < height; y++){
		for(int x = 0; x < width; x++){
			if(MAP(map, x, y) >= n+1){
				MAP(map, x, y) = 0;
				num++;
			}
		}
	}
	return num;
}
Ejemplo n.º 15
0
static void LIBUSB_CALL
dump_iface_list_stream_cb(struct libusb_transfer *transfer)
{
    enum libusb_error   err;
    uhd_iface          *iface;

    assert(transfer != NULL);

    iface = (uhd_iface *)transfer->user_data;
    assert(uhd_iface_valid(iface));

    /* Clear interface "has transfer submitted" flag */
    iface->submitted = false;

    switch (transfer->status)
    {
        case LIBUSB_TRANSFER_COMPLETED:
            /* Dump the result */
            if (!stream_paused)
            {
                dump(iface, "STREAM",
                     transfer->buffer, transfer->actual_length);
                if (stream_feedback)
                    fputc('.', stderr);
            }
            /* Resubmit the transfer */
            err = libusb_submit_transfer(transfer);
            if (err != LIBUSB_SUCCESS)
                LIBUSB_IFACE_FAILURE(iface, "resubmit a transfer");
            else
            {
                /* Set interface "has transfer submitted" flag */
                iface->submitted = true;
            }
            break;

#define MAP(_name, _desc) \
    case LIBUSB_TRANSFER_##_name: \
        IFACE_ERROR(iface, _desc);  \
        break

        MAP(ERROR,      "Interrupt transfer failed");
        MAP(TIMED_OUT,  "Interrupt transfer timed out");
        MAP(STALL,      "Interrupt transfer halted (endpoint stalled)");
        MAP(NO_DEVICE,  "Device was disconnected");
        MAP(OVERFLOW,   "Interrupt transfer overflowed "
                        "(device sent more data than requested)");
#undef MAP

        case LIBUSB_TRANSFER_CANCELLED:
            break;
    }
}
Ejemplo n.º 16
0
static int __init rockchip_cpu_axi_init(void)
{
	struct device_node *np, *gp, *cp;
	void __iomem *base;

	np = of_find_compatible_node(NULL, NULL, "rockchip,cpu_axi_bus");
	if (!np)
		return -ENODEV;

#define MAP(base) if (!base) base = of_iomap(cp, 0); if (!base) continue;

	gp = of_get_child_by_name(np, "qos");
	if (gp) {
		for_each_child_of_node(gp, cp) {
			u32 priority[2], mode, bandwidth, saturation, extcontrol;
			base = NULL;
#ifdef DEBUG
			{
				struct resource r;
				of_address_to_resource(cp, 0, &r);
				pr_debug("qos: %s [%x ~ %x]\n", cp->name, r.start, r.end);
			}
#endif
			if (!of_property_read_u32_array(cp, "rockchip,priority", priority, ARRAY_SIZE(priority))) {
				MAP(base);
				CPU_AXI_SET_QOS_PRIORITY(priority[0], priority[1], base);
				pr_debug("qos: %s priority %x %x\n", cp->name, priority[0], priority[1]);
			}
			if (!of_property_read_u32(cp, "rockchip,mode", &mode)) {
				MAP(base);
				CPU_AXI_SET_QOS_MODE(mode, base);
				pr_debug("qos: %s mode %x\n", cp->name, mode);
			}
			if (!of_property_read_u32(cp, "rockchip,bandwidth", &bandwidth)) {
				MAP(base);
				CPU_AXI_SET_QOS_BANDWIDTH(bandwidth, base);
				pr_debug("qos: %s bandwidth %x\n", cp->name, bandwidth);
			}
			if (!of_property_read_u32(cp, "rockchip,saturation", &saturation)) {
				MAP(base);
				CPU_AXI_SET_QOS_SATURATION(saturation, base);
				pr_debug("qos: %s saturation %x\n", cp->name, saturation);
			}
			if (!of_property_read_u32(cp, "rockchip,extcontrol", &extcontrol)) {
				MAP(base);
				CPU_AXI_SET_QOS_EXTCONTROL(extcontrol, base);
				pr_debug("qos: %s extcontrol %x\n", cp->name, extcontrol);
			}
			if (base)
				iounmap(base);
		}
	};
Ejemplo n.º 17
0
  template <typename Iter> void serialize_str(const std::string& s, Iter oi) {
    *oi++ = '"';
    for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
      switch (*i) {
#define MAP(val, sym) case val: copy(sym, oi); break
    MAP('"', "\\\"");
    MAP('\\', "\\\\");
    MAP('/', "\\/");
    MAP('\b', "\\b");
    MAP('\f', "\\f");
    MAP('\n', "\\n");
    MAP('\r', "\\r");
    MAP('\t', "\\t");
#undef MAP
      default:
    if (static_cast<unsigned char>(*i) < 0x20 || *i == 0x7f) {
      char buf[7];
      SNPRINTF(buf, sizeof(buf), "\\u%04x", *i & 0xff);
      copy(buf, buf + 6, oi);
      } else {
      *oi++ = *i;
    }
    break;
      }
    }
    *oi++ = '"';
  }
Ejemplo n.º 18
0
struct map *
copy_map(struct map *parm)
{
    struct bitmap *result, **mpp, *map;
#ifdef MAP_DEBUG
    if (Mflag) {
	printf("copymap:");
	print_map(parm);
	printf("\n");
    }
#endif
    map = MAP(parm);
    for (mpp = &result; (*mpp = 0), map; map = map->m_next) {
	*mpp = (struct bitmap *)malloc(sizeof **mpp);
	if (!*mpp) {
#ifdef MAP_DEBUG
	    if (Mflag)
		printf("copy_map: out of memory\n");
#endif
	    free_map((struct map *)result);
	    result = 0;
	    break;
	}
	**mpp = *map;
	mpp = &(*mpp)->m_next;
    }
    if (NEGMAP(parm))
	return NOT_MAP(result);
    else
	return (struct map *)result;
}
Ejemplo n.º 19
0
/******************************************************************************

	Function:	DrawMapRect()

	Action:		Draws a portion of the map

	Params:		rect, in LOG (screen) coords.

	Returns:

	Comments:	Must convert to and from DEV (map) coords.  The map contains
						the mapping mode.

******************************************************************************/
void CWorldMap::DrawMapRect( CDC *pDC, CRect *prect )
{
	// CDC						dcMem;
	// CBitmap				*pbmOld;
	// BITMAP				bm;
	MAP_ELEMENT		*pMap;
	CRect					rDev;
	CRect					rLog;
	INT						nX, nY;

	LogRectToDevRect( &rDev, prect );
	// DevRectToLargestLogRect( &rLog, &rDev );

	for( nY = rDev.bottom; nY <= rDev.top; nY++ )
	{
		for( nX = rDev.left; nX <= rDev.right; nX++ )
		{
			rLog = GetLogRectFromMap( nX, nY );

			pMap = MAP( nX, nY );
			m_pBackImgList->Draw( pDC, pMap->nBackground,
														CPoint( rLog.left, rLog.top ),
														ILD_NORMAL );
		}
	}
}
Ejemplo n.º 20
0
Archivo: tf.c Proyecto: NetSys/sts
static const struct port_map_elem *
rule_get (const struct tf *tf, uint32_t port)
{
  const struct port_map *m = MAP (tf);
  struct port_map_elem tmp = {port};
  return bsearch (&tmp, m->elems, m->n, sizeof tmp, map_cmp);
}
Ejemplo n.º 21
0
int RemoveShit(int* map, const int shitNumber, const int shitSize, const int width, const int height){
	int num = 0;
	for(int y = 0; y < height; y++){
		for(int x = 0; x < width; x++){
			if(MAP(map, x, y) == shitNumber+1){
				MAP(map, x, y) = 0;
				num++;

				if(shitSize == num){
					return num;
				}
			}
		}
	}
	return 0;
}
Ejemplo n.º 22
0
/* Return a string representation of a VAEntrypoint */
const char *stringOfVAEntrypoint(VAEntrypoint entrypoint)
{
    switch (entrypoint) {
#define MAP(entrypoint) \
        STRCASEP(VAEntrypoint, entrypoint)
        MAP(VLD);
        MAP(IZZ);
        MAP(IDCT);
        MAP(MoComp);
        MAP(Deblocking);
#undef MAP
    default:
        break;
    }
    return "<unknown>";
}
Ejemplo n.º 23
0
void drawVolumeLabels()
{
	char numbuff[256];

	fill(0);
	textSize(10);
	textAlign(TX_RIGHT, TX_CENTER);

	stroke((uint8_t)128);
	strokeWeight(1);

	for (float v = dataMin; v <= dataMax; v += volumeIntervalMinor) {		
		if (int(v) % volumeIntervalMinor == 0) {
			float y = MAP(v, dataMin, dataMax, plotY2, plotY1);
			if (int(v) % volumeInterval == 0)
			{
				if (v == dataMin) {
					textAlign(TX_RIGHT);
				}
				else if (v == dataMax) {
					textAlign(TX_RIGHT, TX_TOP);
				}
				else {
					textAlign(TX_RIGHT, TX_CENTER);
				}

				sprintf_s(numbuff, "%d", (int)floor(v));
				text(numbuff, plotX1 - 10, y);
				line(plotX1 - 4, y, plotX1, y);		// draw a major tick
			}

			line(plotX1 - 2, y, plotX1, y);			// draw a minor tick
		}
	}
}
void variant_file::output_as_plink(const parameters &params)
{
	// Output as PLINK formatted PED/MAP files.
	if (meta_data.has_genotypes == false)
		LOG.error("Require Genotypes in VCF file in order to output as PLINK.");

	LOG.printLOG("Writing PLINK PED and MAP files ... \n");
	string ped_file = params.output_prefix + ".ped";
	string map_file = params.output_prefix + ".map";
	int fd = -1;

	vector<ofstream *> tmp_files(meta_data.N_indv);
	vector<string> tmp_filenames(meta_data.N_indv);
	for (unsigned int ui=0; ui<meta_data.N_indv; ui++)
	{
		if (include_indv[ui] == false)
			continue;

		string new_tmp = params.temp_dir+"/vcftools.XXXXXX";
		char tmpname[new_tmp.size()];
		strcpy(tmpname, new_tmp.c_str());

		fd = mkstemp(tmpname);
		if (fd == -1)
			LOG.error(" Could not open temporary file.\n", 12);
		::close(fd);

		ofstream *tmp_file = new ofstream(tmpname);
		if (!tmp_file->good())
			LOG.error("\n\nCould not open temporary file.\n\n"
					"Most likely this is because the system is not allowing me to open enough temporary files.\n"
					"Try using ulimit -n <int> to increase the number of allowed open files.\n"
					"Alternatively, try the --plink-tped command.", 12);
		(*tmp_file) << meta_data.indv[ui] << "\t" << meta_data.indv[ui] << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0;
		tmp_files[ui] = tmp_file;
		tmp_filenames[ui] = tmpname;
	}

	ofstream MAP(map_file.c_str());
	if (!MAP.is_open()) LOG.error("Could not open output file: " + map_file, 12);
	int POS;
	string ID, CHROM, CHROM2;
	map<string, string> CHROM_to_PLINK;

	if (params.chrom_map_file != "")
	{
		ifstream chrom_map(params.chrom_map_file.c_str());
		if (!chrom_map.is_open())
			LOG.error("Could not open chromosome mapping file: " + params.chrom_map_file);
		string chr, plink;
		unsigned int N_chrom_entries=0;
		while (!chrom_map.eof())
		{
			chrom_map >> chr >> plink;
			CHROM_to_PLINK[chr] = plink;
			N_chrom_entries++;
		}
		chrom_map.close();
		LOG.printLOG("\tRead " + output_log::int2str(N_chrom_entries) + " chromosome mapping file entries.\n");
	}
Ejemplo n.º 25
0
//糞(ズク)をマップからとりのぞく関数
void RemoveAllShit(int* map, const int width, const int height){
	for(int y = 0; y < height; y++){
		for(int x = 0; x < width; x++){
			MAP(map, x, y) = 0;
		}
	}
}
Ejemplo n.º 26
0
int
count_map(struct map *parm)
{
    int nf;
    struct bitmap *map;
    int i, j;

    nf = 0;
    for (map = MAP(parm); map; map = map->m_next) {
	for (i = 0; i < MDATA; ++i) {
	    if (!map->m_data[i])
		;
	    else if (!~map->m_data[i])
		nf += (1 << LSHIFT);
	    else
		for (j = 0; j < (1L << LSHIFT); ++j)
		    if (map->m_data[i] & (1L << j))
			++nf;
	}
    }
    if (NEGMAP(parm))
	nf = ~nf;		/* note 1's complement */
#ifdef MAP_DEBUG
    if (Mflag) {
	printf("countmap:");
	print_map(parm);
	printf(" -> %d\n", nf);
    }
#endif
    return nf;
}
Ejemplo n.º 27
0
static obj_ptr _map_delete(obj_ptr arg1, obj_ptr arg2, obj_ptr env)
{
    if (NMAPP(arg1))
        return MKERROR(MKSTRING("Expected a map in map-delete"), arg1);

    return MKBOOL(map_delete(&MAP(arg1), arg2));
}
Ejemplo n.º 28
0
static obj_ptr _map_size(obj_ptr arg, obj_ptr env)
{
    if (NMAPP(arg))
        return MKERROR(MKSTRING("Expected a map in map-clear"), arg);

    return MKINT(map_size(&MAP(arg)));
}
Ejemplo n.º 29
0
static obj_ptr _map_find(obj_ptr args, obj_ptr env)
{
    int     ct = _length(args);
    obj_ptr map, key, res;

    if (ct < 2 || ct > 3)
        return MKERROR_STRING(MKSTRING("Syntax: (map-find map key [default])"));

    map = CAR(args);
    if (NMAPP(map))
        return MKERROR(MKSTRING("Expected a map in first arg to map-find"), map);


    key = CADR(args);

    res = map_find(&MAP(map), key);
    if (!res)
    {
        if (ct == 3)
            return CADDR(args);
        else
            return MKERROR(MKSTRING("Key not found."), key);
    }

    return res;
}
Ejemplo n.º 30
0
static obj_ptr _map_clear(obj_ptr arg, obj_ptr env)
{
    if (NMAPP(arg))
        return MKERROR(MKSTRING("Expected a map in map-clear"), arg);

    map_clear(&MAP(arg));
    return NIL;
}