bool JobShopData::initialize() { try { initializeT(); initializeA(); initializeP(); } catch (...) { return false; } return true; }
int main(int argc, char *argv[]){ //verify that the correct number of arguments were passed assert(argc==5 || argc==4); double h = 0.005; //step size parameter to be passed into rk double t = 0; //thermal paramaters file FILE *tpfp; //power trace file FILE *ptfp; //output file FILE *ofp; //initialize ambient temperature and resistance ambientTemp = 300; //check to see if an argument was passed for ambient temp if(argc==5){ //if it was, set ambientTemp to it sscanf(argv[3], "%lf", &ambientTemp); //if there was, the output file is argument 4 ofp = fopen(argv[4], "w");} //open the files tpfp = fopen(argv[1], "rb"); ptfp = fopen(argv[2], "rb"); //if there wasn't an ambient temp argument, output file is argument 3 if(ofp==NULL){ofp = fopen(argv[3], "w");} //make sure the files are there assert(tpfp != NULL); assert(ptfp != NULL); assert(ofp != NULL); //number of rows in each input file int thermalParamLength=row_count(tpfp); //verify that the thermal parameter file is the correct length assert(thermalParamLength==6); powerTraceLength=row_count(ptfp); //read the files into pointer arrays for thermal param and power trace thermalParam = fileArray(tpfp, thermalParamLength, 4); powerTrace = fileArray(ptfp, powerTraceLength, 5); int i; int j; //verify that none of the thermal parameters less than or equal to zero, which isn't possible for(i=0; i<thermalParamLength; i++){ for(j=0; j<4; j++){assert(thermalParam[i][j]>0);} } //T holds the temperatures. cores 0-3 are T[0]-T[3], T[4] is ambient double *T; T = initializeT(); double* aP = (double *) malloc(4*sizeof(double)); //age pointer... for(i=0; i<4; i++){aP[i] = 1;} double* age; //step through updating the temperature //counts how many timesteps are taken in each entry of powerTrace int counter; //placeholder variable for t (used in output) double t_temp; for(j=0; j<(powerTraceLength); j++){ counter=0; while(t<(powerTrace[j][0]-h/2)){ T = rk(&calculatedTdt, h, t, T, 5); //verify that none of the temperatures are below ambient (this can't happen) for(i=0; i<4; i++){assert(T[i]>=T[4]);} aP = ageRate(t, T); age = rk(&ageRate, h, t, aP, 4); //verify that none of the effective ages are less than 1 for(i=0; i<4; i++){assert(age[i]>=1);} counter++; t+=h; } //file output stuff fprintf(ofp, "%lf ", t); for(i=0; i<4; i++){ fprintf(ofp, "%lf ", T[i]); fprintf(ofp, "%lf ", age[i]); } fprintf(ofp, "\r\n"); } }