- *dict = xbt_dict_new_homogeneous(free);
- *rng = RngStream_CreateStream("Randgen1");
- unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876541};
- RngStream_SetSeed(*rng, seed);
-
- xbt_dict_t mydict = *dict;
- mydict = *dict;
- FILE* fpInput = fopen(inputfile, "r");
- if (fpInput == NULL)
- printf("Error while opening the inputfile");
-
- fseek(fpInput, 0, 0);
-
- char line[MAX_LINE_INJ];
- char *key;
- int i;
- xbt_hist_t* data;
-
- if (fgets(line, MAX_LINE_INJ, fpInput) == NULL)
- printf("Error input file is empty!");//Skipping first row
-
-
- while (fgets(line, MAX_LINE_INJ, fpInput) != NULL)
- {
- key = strtok(line, " \t");
-
- data = xbt_dict_get_or_null(mydict, key);
- if (data)
- printf("Error, data with that block_id already exists!");
-
- data = (xbt_hist_t *) xbt_new(xbt_hist_t, 1);
- data->block_id = key;
- data->mean = atof(strtok(NULL, " \t"));
- data->n = atoi(strtok(NULL, " \t"));
- data->breaks = (double*) malloc(sizeof(double) * data->n);
- data->percentage = (double*) malloc(sizeof(double) * (data->n - 1));
-
- for (i = 0; i < data->n; i++)
- data->breaks[i] = atof(strtok(NULL, " \t"));
- for (i = 0; i < (data->n - 1); i++)
- {
- data->percentage[i] = atof(strtok(NULL, " \t"));
- }
-
- xbt_dict_set(mydict, key, data, NULL);
- }
+ *dict = xbt_dict_new_homogeneous(free);
+ *rng = RngStream_CreateStream("Randgen1");
+ unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876541};
+ RngStream_SetSeed(*rng, seed);
+
+ xbt_dict_t mydict = *dict;
+ FILE* fpInput = fopen(inputfile, "r");
+ if (fpInput == NULL) {
+ printf("Error while opening the inputfile");
+ return;
+ }
+
+ fseek(fpInput, 0, 0);
+
+ char line[MAX_LINE_INJ];
+ char* key;
+
+ if (fgets(line, MAX_LINE_INJ, fpInput) == NULL) {
+ printf("Error input file is empty!"); // Skipping first row
+ fclose(fpInput);
+ return;
+ }
+
+ while (fgets(line, MAX_LINE_INJ, fpInput) != NULL) {
+ char *saveptr = NULL; /* for strtok_r() */
+ key = strtok_r(line, "\t", &saveptr);
+
+ xbt_hist_t* data = xbt_dict_get_or_null(mydict, key);
+ if (data)
+ printf("Error, data with that block_id already exists!");
+
+ data = (xbt_hist_t*)xbt_new(xbt_hist_t, 1);
+ data->block_id = key;
+ data->counts = atoi(strtok_r(NULL, "\t", &saveptr));
+ data->mean = atof(strtok_r(NULL, "\t", &saveptr));
+ data->n = atoi(strtok_r(NULL, "\t", &saveptr));
+ data->breaks = (double*)malloc(sizeof(double) * data->n);
+ data->percentage = (double*)malloc(sizeof(double) * (data->n - 1));
+
+ for (int i = 0; i < data->n; i++)
+ data->breaks[i] = atof(strtok_r(NULL, "\t", &saveptr));
+ for (int i = 0; i < (data->n - 1); i++) {
+ data->percentage[i] = atof(strtok_r(NULL, "\t", &saveptr));
+ }
+
+ xbt_dict_set(mydict, key, data, NULL);
+ }
+ fclose(fpInput);