Exemple #1
0
/* Unpack the full instruction */
void unpack_instruction(struct Instruction* c)
{
	unpack_byte(c->raw0, &(c->operation[0]));
	unpack_byte(c->raw1, &(c->operation[2]));
	unpack_byte(c->raw2, &(c->operation[4]));
	unpack_byte(c->raw3, &(c->operation[6]));
	c->opcode[0] = c->operation[0];
	c->opcode[1] = c->operation[1];
}
Exemple #2
0
int
msa_recv_pkt(msa_pkt_t *pkt, int sfd)
{
    byte_t *dt = 0;
    byte_t st_u = 0;
    size_t st_sz = 0, id_sz = 0, sz_sz = 0;
    unsigned int id_u = 0, sz_u = 0;

    assert(sfd >= 0);

    st_sz = sizeof(byte_t);
    id_sz = sizeof(int);
    sz_sz = sizeof(int);
    
    dt = malloc(st_sz);
    msa_recv_all(sfd, dt, st_sz);
    st_u = unpack_byte(dt);
    pkt->st = st_u;
    free(dt); dt = 0;

    dt = malloc(id_sz);
    msa_recv_all(sfd, dt, id_sz);
    id_u = unpack_int(dt);
    pkt->id = id_u;
    free(dt); dt = 0;
    
    dt = malloc(sz_sz);
    msa_recv_all(sfd, dt, sz_sz);
    sz_u = unpack_int(dt);
    pkt->sz = sz_u;
    free(dt); dt = 0;
    
    if (sz_u != 0) {
        dt = malloc(sz_u * sizeof(char));
        msa_recv_all(sfd, dt, sz_u * sizeof(char));
        pkt->da = unpack_str(dt, sz_u * sizeof(char));
        free(dt); dt = 0;
    } else {
        pkt->da = 0;
    }

    return 0; /* do some error checking? */
}
Exemple #3
0
// the packed reference sequence is read from the PAC file, uncompressed,
// concatenated with its reverse complement, and stored into seq
void pac2seq(const char *pacFname, unsigned char** seq, bwtint_t *totalSeqLen) {
	FILE* pacFile = (FILE*) fopen(pacFname, "rb");
	if (pacFile == NULL) {
		printf("pac2seq: Cannot open PAC file %s!\n", pacFname);
		exit(1);
	}
	fseek(pacFile, -1, SEEK_END);
	// position in the file (# bytes from the beginning of file)
	bwtint_t pacFileLen = ftell(pacFile);
	if (pacFileLen < 0) {
		printf("pac2seq: Cannot determine the length of the PAC file!\n");
		exit(1);
	}
	unsigned char endByte;
	if(fread(&endByte, sizeof(unsigned char), 1, pacFile) < 1) {
		printf("pac2seq: Cannot read the PAC file!\n");
                exit(1);
	}
	bwtint_t seqLength = pacFileLen*CHARS_PER_BYTE - endByte;

	// read the packed sequence
	fseek(pacFile, 0, SEEK_SET);
	unsigned char* packedSeq = (unsigned char*) malloc(sizeof(char) * pacFileLen);
	if(fread(packedSeq, 1, pacFileLen, pacFile) < pacFileLen) {
		printf("pac2seq: Could not read the expected length of the PAC file!\n");
                exit(1);
	}
	fclose(pacFile);

	// unpack the sequence
	*seq = (unsigned char*) malloc(sizeof(char) * (2*seqLength + 1));
	unpack_byte(packedSeq, *seq, seqLength);

	// add the reverse complement
	for(bwtint_t i = 0; i < seqLength; i++) {
		(*seq)[2*seqLength-i-1] = iupacCompl[(int) (*seq)[i]];
	}
	(*totalSeqLen) = 2*seqLength;

	free(packedSeq);
}