int sbrr_open(sbrr handle, const char *binary_report_file) {
    size_t offset;

    handle->fd = open(binary_report_file, O_RDONLY);
    if (handle->fd < 0) {
        free(handle);
        return errno;
    }

    if (fstat(handle->fd, &handle->buf) < 0) {
        free(handle);
        close(handle->fd);
        return errno;
    }

    handle->map = (char *) malloc(handle->buf.st_size);
    read(handle->fd, (void *) handle->map, handle->buf.st_size);

    handle->header = (header_t*) handle->map;
    handle->footer = (footer_t*) (handle->map + handle->buf.st_size-sizeof(footer_t));
    if (handle->header->magic != MAGIC || handle->footer->magic != MAGIC) {
        close(handle->fd);
        free(handle->map);
        free(handle);
        return -1;
    }

    offset = sizeof(header_t);

    handle->subcatchment_ids = (char **) malloc(handle->header->num_subcatchments * sizeof(char **));
    handle->node_ids = (char **) malloc(handle->header->num_nodes * sizeof(char **));
    handle->link_ids = (char **) malloc(handle->header->num_links * sizeof(char **));

    offset += read_ids(handle->subcatchment_ids, handle->map, offset, handle->header->num_subcatchments);
    offset += read_ids(handle->node_ids, handle->map, offset, handle->header->num_nodes);
    offset += read_ids(handle->link_ids, handle->map, offset, handle->header->num_links);

    handle->pollutant_types = malloc(sizeof(int)*handle->header->num_pollutants);
    for (int i = 0; i < handle->header->num_pollutants; i++) {
        int32_t *type = (int32_t*) (handle->map+offset);
        handle->pollutant_types[i] = *type;
        offset += sizeof(int32_t);
    }

    int npol = handle->header->num_pollutants;
    handle->subcatchment_result_len =  SUBCATCH_RESULTS_MAX - 1 + npol;
    handle->node_result_len = NODE_RESULTS_MAX - 1 + npol;
    handle->link_result_len = LINK_RESULTS_MAX - 1 + npol;

    handle->bytes_per_period = sizeof(double)
                               + handle->header->num_subcatchments * handle->subcatchment_result_len * sizeof(float)
                               + handle->header->num_nodes * handle->node_result_len * sizeof(float)
                               + handle->header->num_links * handle->link_result_len * sizeof(float)
                               + MAX_SYS_RESULTS * sizeof(float);

    sanity_check(handle);

    return 0;
}
Example #2
0
bool is_two_fan_board(bool verbose) {
  struct wedge_eeprom_st eeprom;
  /* Retrieve the board type from EEPROM */
  if (wedge_eeprom_parse(NULL, &eeprom) == 0) {
    /* able to parse EEPROM */
    if (verbose) {
      syslog(LOG_INFO, "board type is %s", eeprom.fbw_location);
    }
    /* only WEDGE is NOT two-fan board */
    return strncasecmp(eeprom.fbw_location, "wedge",
                       sizeof(eeprom.fbw_location));
  } else {
    int status;
    int board_id = 0;
    int rev_id = 0;
    /*
     * Could not parse EEPROM. Most likely, it is an old HW without EEPROM.
     * In this case, use board ID to distinguish if it is wedge or 6-pack.
     */
    status = read_ids(&rev_id, &board_id);
    if (verbose) {
      syslog(LOG_INFO, "rev ID %d, board id %d", rev_id, board_id);
    }
    if (status == 0 && board_id != 0xf) {
      return true;
    } else {
      return false;
    }
  }
}
Example #3
0
struct gadget_particle_t *read_gadget_particles(char *file_name)
{
    FILE *fp;
    if (!(fp = fopen(file_name, "r"))) {
        fprintf(stderr, "Cannot open %s\n", file_name);
        exit(1);
    }

    struct gadget_header_t *header = malloc(sizeof(*header));
    check_mem(header);

    int dummy;
    fread(&dummy, sizeof(dummy), 1, fp);
    fread(header, sizeof(*header), 1, fp);
    fread(&dummy, sizeof(dummy), 1, fp);

    uint32_t len = header->npart[1];

    struct gadget_particle_t *particles = malloc(sizeof(*particles) * len);
    void *buf = malloc(sizeof(float) * 3 * len);
    check_mem(buf);
    check_mem(particles);
    
    read_positions(fp, header, buf, particles);
    read_velocities(fp, header, buf, particles);
    read_ids(fp, header, buf, particles);

    free(header);
    free(buf);

    fclose(fp);

    return particles;
}
Example #4
0
main(int argc, char **argv) {
    FILE *fp;
    int i;

    progname = argv[0];	
    for (i = 1; i < argc && argv[i][0] == '-' && argv[i][1] != 0; i++)
        if (!strcmp(argv[i], "-noquote"))
            showquotes = 0;
        else
            errormsg(Error, "%s: unknown option %s\n", progname, argv[i]);
    nwindex = new_recognizer(ALPHANUM, SYMBOLS);
    if (i == argc) {
       
#line 75 "finduses.nw"
{   FILE *tmp = tmpfile();
    char *line;
    if (tmp == NULL) 
#line 155 "finduses.nw"
errormsg(Fatal, "%s: couldn't open temporary file\n", progname);
#line 78 "finduses.nw"
    while ((line = getline_noweb(stdin)) != NULL) {
        if (fputs(line, tmp) == EOF) 
#line 157 "finduses.nw"
errormsg(Fatal, "%s: error writing temporary file\n", progname);
#line 80 "finduses.nw"
        if (is_index(line, "defn")) {
            if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = 0;
            add_ident(nwindex, line+1+5+1+4+1);
        } else if (is_index(line, "localdefn")) {
            if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = 0;
            add_ident(nwindex, line+1+5+1+9+1);
        } else if (is_keyword(line, "fatal")) {
	    exit(1);
	}
    }
    rewind(tmp);
    stop_adding(nwindex);
    add_use_markers(tmp, stdout);
}
#line 46 "finduses.nw"
    } else {
       
#line 56 "finduses.nw"
for (; i < argc; i++)
    if ((fp=fopen(argv[i],"r"))==NULL)
        errormsg(Error, "%s: couldn't open file %s\n", progname, argv[i]);
    else {
        read_ids(fp);
        fclose(fp);
    }
#line 48 "finduses.nw"
       stop_adding(nwindex);
       add_use_markers(stdin, stdout);
    }
    nowebexit(NULL);
    return errorlevel;          /* slay warning */
}
Example #5
0
/*Func: read_from_stat()
 * This fucnction create stat type struct
 * Read the information from stat()
 * Check to see if there is error
 * Calling functions to read info of the file:
 * 	timestamp
 * 	user_id, group_id
 * 	mode, size, numintro
 */
void read_from_stat(file *info){
	int t=0;
	struct stat fileinfo;
	t = fstat(info->desc,&fileinfo);
	//perror("File Stat");
	if(t==-1){
		printf(CY"Error: File stat cannot be read. \nProgram is now exiting!\n"NC);
		exit(EXIT_FAILURE);
	}
	read_time(info, fileinfo);
	read_ids(info, fileinfo);
	read_mode(info, fileinfo);
	read_size(info, fileinfo);

}
int main() {

	char* refId = "rs1048659";
	char* name = "HG00372";

	// CI part

    int i,j;
    read_names();
    read_ids();
    int size_names = size_of_names();
    int size_ids = size_of_ids();

    int refId_id = find_ids_id(refId);
    int name_id = find_name_id(name);


    read_encs();
    char encC = get_char_in_enc((size_names*refId_id)+name_id);

    read_skeys();
    char skeyC = get_char_in_skeys((size_names*refId_id)+name_id);
    // SPU -> GC building part

	GarbledCircuit garbledCircuit;
	GarblingContext garblingContext;

	int inputsNb = 32;
	int wiresNb = 50000;
	int gatesNb = 50000;
	int outputsNb = 32;

	//Create a circuit.
	block labels[2 * inputsNb];
	createInputLabels(labels, inputsNb);
	InputLabels inputLabels = labels;
	createEmptyGarbledCircuit(&garbledCircuit, inputsNb, outputsNb, gatesNb,
			wiresNb, inputLabels);
	startBuilding(&garbledCircuit, &garblingContext);

	// Transform generator's input into fixed wire
	int zero = fixedZeroWire(&garbledCircuit,&garblingContext);
	int one = fixedOneWire(&garbledCircuit,&garblingContext);

	int onewire = getNextWire(&garblingContext);
	NOTGate(&garbledCircuit,&garblingContext,zero,onewire);

	int zerowire = getNextWire(&garblingContext);
	NOTGate(&garbledCircuit,&garblingContext,one,zerowire);

	int outputs[outputsNb];
	int *inp = (int *) malloc(sizeof(int) * inputsNb*2);
	countToN(inp, inputsNb);
	//countToN(outputs, inputsNb);

	int bits[inputsNb];
	int_into_ints(encC,bits);
	for (i = 0; i < inputsNb; i++) {
		if (bits[i]) {
			inp[inputsNb+i] = onewire;
		} else {
			inp[inputsNb+i] = zerowire;
		}
	}
	int tempOutput[2*outputsNb];
	XORCircuit(&garbledCircuit, &garblingContext, inputsNb*2, inp, outputs);

	block *outputbs = (block*) malloc(sizeof(block) * outputsNb);
	OutputMap outputMap = outputbs;
	finishBuilding(&garbledCircuit, &garblingContext, outputMap, outputs);
	garbleCircuit(&garbledCircuit, inputLabels, outputMap);

	// MU -> Evaluation part
	block extractedLabels[inputsNb];

	int extractedInputs[inputsNb];
	int_into_ints(skeyC,extractedInputs);

	extractLabels(extractedLabels, inputLabels, extractedInputs, inputsNb);
	block computedOutputMap[outputsNb];
	evaluate(&garbledCircuit, extractedLabels, computedOutputMap);
	int outputVals[outputsNb];
	mapOutputs(outputMap, computedOutputMap, outputVals, outputsNb);
	//TODO
	int res = ints_into_int(outputVals);
	printf("RESULT IS : %d\n",res);
	return 0;
}