Page MenuHomec4science

parser.c
No OneTemporary

File Metadata

Created
Thu, Jan 16, 05:56

parser.c

/* Copyright (c) 2016 Aram_Yesildeniz All rights reserved. *
* original name hippie2 by Aram_Yesildeniz *
/*********************************************************************************
* Copyright (c) 2016 *
* modified and extended by Ali Omar abdelazim Mohammed <ali.mohammed@unibas.ch> *
* University of Basel, Switzerland *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the license (GNU LGPL) which comes with this package. *
*********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "global_data.c"
#include "parser.h"
int getIntNumber(FILE *readFile, char *pattern) {
rewind(readFile);
int bufferSize = 100;
char bufferLine[bufferSize];
while (fgets(bufferLine, bufferSize, readFile) != NULL) {
if (strstr(bufferLine, pattern)) { // go line by line and check if pattern is in line
break; // line found
}
}
// pattern not found
if (!strstr(bufferLine, pattern)) {
return -1;
}
char *linePtr = strstr(bufferLine, pattern); // set pointer to beginning of pattern, so that correct number will be read. Needed when several numbers are in one line
int number;
while (*linePtr) {
if (isdigit(*linePtr)) {
sscanf(linePtr, "%d", &number);
break;
}
linePtr++;
}
return number;
}
float getFloatNumber(FILE *readFile, char *pattern) {
rewind(readFile);
int bufferSize = 100;
char bufferLine[bufferSize];
while (fgets(bufferLine, bufferSize, readFile) != NULL) {
if (strstr(bufferLine, pattern)) { // go line by line and check if pattern is in line
break; // line found
}
}
// pattern not found
if (!strstr(bufferLine, pattern)) {
return -1;
}
char *linePtr = strstr(bufferLine, pattern); // set pointer to beginning of pattern, so that correct number will be read. Needed when several numbers are in one line
float number;
while (*linePtr) {
if (isdigit(*linePtr)) {
sscanf(linePtr, "%f", &number);
break;
}
linePtr++;
}
return number;
}
void readhosts(FILE *readFile, int num_hosts, int num_cores[]) {
rewind(readFile);
// set ptr to start of table
int lineSize = 100;
int temp,Ncores;
char line[lineSize];
while (fgets(line, lineSize, readFile) != NULL) {
if (strstr(line, "hostID\t#cores")) {
break; // found title line of table
}
}
// read table line by line and save values in arrays
int i;
for (i = 0; i < num_hosts; i++) {
fgets(line, lineSize, readFile);
sscanf(line, "%d\t%d", &temp, &Ncores);
num_cores[temp] = Ncores;
}
}
void readTable(FILE *readFile, int chunks, Chunk_t *chunkList) {
rewind(readFile);
// set ptr to start of table
int lineSize = 100;
char line[lineSize];
while (fgets(line, lineSize, readFile) != NULL) {
if (strstr(line, "chunkID\tbatchID\tjobID\t#Tasks\thostID\tcoreID\tstartTime\tendTime")) {
break; // found title line of table
}
}
// read table line by line and save values in arrays
int i;
for (i = 0; i < chunks; i++) {
fgets(line, lineSize, readFile);
sscanf(line, "%d %d %d %d %d %d %lf %lf", &chunkList[i].chunkID, &chunkList[i].batchID, &chunkList[i].jobID, &chunkList[i].num_tasks, &chunkList[i].hostID, &chunkList[i].coreID, &chunkList[i].startTime, &chunkList[i].endTime);
}
}
void readjobs(FILE *readFile, int num_jobs, int job_ID[])
{
rewind(readFile);
// set ptr to start of table
int lineSize = 100;
int temp;
char line[lineSize];
while (fgets(line, lineSize, readFile) != NULL) {
if (strstr(line, "index\tJobID")) {
break; // found title line of table
}
}
// read table line by line and save values in arrays
int i;
for (i = 0; i < num_jobs; i++) {
fgets(line, lineSize, readFile);
sscanf(line, "%d\t%d", &temp, &job_ID[i]);
}
}

Event Timeline