📄 forms.c
字号:
if((high - low) == 0) //single story house { routerroomz = 0; return(0); } if (p == 0.0) { //an incomplete line found, and so height is determined, exit function if (routerroomz > 1000) routerroomz = (routerroomz/(1000)); if (routerroomz > 100) routerroomz = (routerroomz/(100)); return(0); } routerroomz = ((routerroomz + p)/2); //average over a range of values if(a == 20) //The maximum amount of rooms have been analysed return(0); } else if(roomcoord == 1) //generate the x,y,z coordiantes of each MP in each room. //Note: the first argument is set to be the form argument { if (roomcoordtemp == 1) //only print this once for each student number roomcoordtemp = 0; if (b == 1) //an incomplete line found, thus no more rooms to analyse return(0); if(c == 2) //ground level z = perheight; else z = (perheight + routerroomz); //Now I calculate the x,y,z coordiantes for each MP, along with the dispalcement from the router. //Note: n,o -> room coordinates while l,m -> room sizes x = l + n; y = m + o; displacementx = (x - routerposx); displacementy = (y - routerposy); displacementz = (z - routerposz); dismag = sqrt(displacementx*displacementx + displacementy*displacementy + displacementz*displacementz); if (a != -1) //error checking form(level, a, 2, out, 0, dismag, b, displacementz); //level = argc x = l + n; y = o; displacementx = (x - routerposx); displacementy = (y - routerposy); displacementz = (z - routerposz); dismag = sqrt(displacementx*displacementx + displacementy*displacementy + displacementz*displacementz); if (a != -1) form(level, a, 5, out, 0, dismag, b, displacementz); x = n; y = o; displacementx = (x - routerposx); displacementy = (y - routerposy); displacementz = (z - routerposz); dismag = sqrt(displacementx*displacementx + displacementy*displacementy + displacementz*displacementz); if (a != -1) form(level, a, 7, out, 0, dismag, b, displacementz); x = n; y = m + o; displacementx = (x - routerposx); displacementy = (y - routerposy); displacementz = (z - routerposz); dismag = sqrt(displacementx*displacementx + displacementy*displacementy + displacementz*displacementz); if (a != -1) form(level, a, 10, out, 0, dismag, b, displacementz); x = (l/2) + n; y = (m/2) + o; displacementx = (x - routerposx); displacementy = (y - routerposy); displacementz = (z - routerposz); dismag = sqrt(displacementx*displacementx + displacementy*displacementy + displacementz*displacementz); if (a != -1) form(level, a, 0, out, 0, dismag, b, displacementz); if(a == 20) //The maximum amount of rooms have been analysed return(0); } else if (confidence == 1) { fgets(line, 150, in); if ((line[0] = 'E') && (line[1] == 'R') && (line[2] = 'R')) { fgets(line, 150, in); sscanf(line, "%d", &a); // read in number fprintf(out, "CONFIDENCE: %d \n", 1); return(a); } if(inc == 139) { fprintf(out, "CONFIDENCE: %d \n", one); //router found and no errors found and form is fine return(0); } } } } } return(0);}//Given the 3 dimensional coordinates in relation to the origin of both the room and the router position within the room,//the router vector can be determined.//a,b,c are the router position coordinates relative to the room //d,e,f are the room corrdinates relative the originint routerpos(float a, float b, float c, float d, float e, float f){ routerposx = (a + d); routerposy = (b + e); routerposz = (c + f); return(0);}//find the start of the objects, same for all versionsint start(FILE *in, FILE *out, char *number){ int j,i = 0; char temp[BUFSIZ]; //a temp string while(i < 155) // approx 150 lines of data in V1.7. The functuion fscanf is sometimes unpredictable and will { // not scan in a whole line in one scanf access. fscanf(in, "%s", temp); if (strcmp(temp,"Objects") == 0) //START { z++; for(j = 0; j < 2; j++) // skip over text { fscanf(in, "%s", temp); } return(0); } i++; } i = 0; return(0);}//Within objects -> locate router. Once router found, the function determines the router's coordinates using the scan() function. //The function then proceeds to extract the cordinates of the router from object line.//The function scan is called with 4th arguments set, which determines the average value of the heights.//Pass all corrdinate values into routerpos() function to determine vector from origin.int router(FILE *in, FILE *out, int argv, char *studnumber){ int count = 0, l = 0; char line[BUFSIZ], other[BUFSIZ]; int router_found = 0; float f,g,h,i,j,k; int a,b,c,d,e, roomnum; float routerx, routery, routerz; int check = 0; char confidence[15] = "CONFIDENCE: 0 \n"; char error[60] = "WLAN: -9\nAIR: -9\nPEOPLE: -9\n-9\nEND"; // for each line of objects, even though 75 lines, needs to be greater as fgets counts the commas at the end of each line as a new line. for(l = 0; l < 180; l++) { f=g=h=i=j=k=-1.0; a=b=c=d=e=-1; fgets(line, 150, in); count = (sscanf(line, "%d,%d,%d,%d,%d,%f,%f,%f,%f,%f,%f,%s", &a,&b,&c,&d,&e,&f,&g,&h,&i,&j,&k,other)); if((d == 21) && (e == 1)) //the unique number for the router { router_found = 1; //router found, and so integer set roomnum = b; routerx = f; routery = g; routerz = h; if((routerx > 100) || (routery > 100) || (routerz>100)) //no room is to be greater than 10m, thus cm were used { routerx = routerx/100; routery = routery/100; routerz = routerz/100; } if((routerx > 1000) || (routery > 1000) || (routerz>1000)) //no room is to be greater than 10m, thus cm were used { routerx = routerx/1000; routery = routery/1000; routerz = routerz/1000; } if ((f == 0.0) && (g == 0.0) && (h == 0.0)) //determine if router object was correctly filled in { router_found = 0; //router was not mapped, and so router not found fprintf(out, "%s%s", confidence, error); //coordinates are incorrect return(0); } scan(roomnum, routerx, routery, in, out, 1, 0, 0, 0); //determines the room coordinates of the router levelhouse(in); //the amount of floors in the mapped dwelling is needed scan(0, 0, 0, in, out, 0, 1, 0, 0); //determines the height of the router routerpos(routerroomx, routerroomy, routerroomz, routerx, routery,routerz); // calculates the vector of the router check = scan(0, 0, 0, in, out, 0, 0, 0, 1); //checks to determine if file has been altered and to what extent if(check == 6) //found data that want to skip over { fprintf(out, "%s", error); return(0); } kismet(argv, out, in); aircon_people(argv, out, in); scan(argv, 0, 0, in, out, 0, 0, 1, 0); //find distances from router fprintf(out, "END"); return(0); } } if (router_found == 0) fprintf(out, "%s%s", confidence, error); //router not found return(0);}//same function as above, however used for version 1.7 of the spreadsheet.int router17(FILE *in, FILE *out, int argv, char *studnumber){ int count = 0, l = 0; char line[BUFSIZ], other[BUFSIZ]; int router_found = 0; float f,g,h,i,j,k; int a,b,c,d,e, roomnum; float routerx, routery, routerz; int check = 0; char confidence[15] = "CONFIDENCE: 0 \n"; char error[60] = "WLAN: -9\nAIR: -9\nPEOPLE: -9\n-9\nEND"; for(l = 0; l < 180; l++) // for each line of objects { f=g=h=i=j=k=-1.0; a=b=c=d=e=-1; fgets(line, 150, in); count = (sscanf(line, "%d,%d,%d,%d,%d,%f,%f,%f,%f,%f,%f,%s", &a,&b,&c,&d,&e,&f,&g,&h,&i,&j,&k,other)); if((d == 22) && (e == 1)) //the unique number for the router { router_found = 1; //router found, and so integer set roomnum = b; routerx = f; routery = g; routerz = h; if((routerx > 100) || (routery > 100) || (routerz>100)) //no room is to be greater than 10m, thus cm were used { routerx = routerx/100; routery = routery/100; routerz = routerz/100; } if((routerx > 1000) || (routery > 1000) || (routerz>1000)) //no room is to be greater than 10m, thus cm were used { routerx = routerx/1000; routery = routery/1000; routerz = routerz/1000; } if ((f == 0.0) && (g == 0.0) && (h == 0.0)) //determine if router object was correctly filled in { router_found = 0; //router was not mapped, and so router not found fprintf(out, "%s%s", confidence, error); //coordinates are incorrect return(0); } scan(roomnum, routerx, routery, in, out, 1, 0, 0, 0); //determines the room coordinates of the router levelhouse(in); //the amount of floors in the mapped dwelling is needed scan(0, 0, 0, in, out,0, 1, 0, 0); //determines the height of the router routerpos(routerroomx, routerroomy, routerroomz, routerx, routery,routerz); // calculates the vector of the router check = scan(0, 0, 0, in, out, 0, 0, 0, 1); //checks to determine if file has been altered and to what extent if(check == 6) //found data that want to skip over { fprintf(out, "%s", error); return(0); } kismet(argv, out, in); aircon_people(argv, out, in); scan(argv, 0, 0, in, out, 0, 0, 1, 0); //find distances from router fprintf(out, "END"); return(0); } } if (router_found == 0) fprintf(out, "%s%s", confidence, error); //router not found return(0);}//main function intmain(int argc, char *argv[]){ FILE *fp; FILE *fw; int i, max; int version3, version4, version5, version6, version7; char vernumber[BUFSIZ], postc[BUFSIZ], studnumber[BUFSIZ]; const char *final = "analysed"; const char *csv = "form"; char temp[BUFSIZ]; //a temp string if(argc != 2) printf("Need correct arguments ./a.exe <number of csv files that are to be opened>"); else { max = atoi(argv[1]); //integer representing maximum number of csv files for(i=1 ; i<=max ; i++) //step through all forms which are in the arguments { printf("Analysing form%d ...\n", i); //the number of files that were analysed. router_found = 0; once = 0; sprintf(temp,"%s%d.csv",csv,i); fp = fopen(temp, "r"); //.csv file if ((fp) == NULL) fprintf(stderr, "Cannot open %s\n", argv[i]); sprintf(temp,"%s%d.txt",final,i); fw = fopen(temp, "w"); if ((fw) == NULL) { printf("fopen failed filename: %s\n",temp); exit(1); } else { fgets(vernumber , 100 , fp); //extract fist line of the file fscanf(fp, "%s %s", temp, studnumber); fscanf(fp, "%s %s", temp, postc); // postcode } if (vernumber[11] == '3') // the following if statement determines what version of the form was used. { version3++; start(fp, fw, studnumber); //determines where the objects start router(fp, fw, i, studnumber); //the function router is called, see above } else if (vernumber[11] == '4') { version4++; start(fp, fw, studnumber); router(fp, fw, i, studnumber); } else if (vernumber[11] == '5') { version5++; start(fp, fw, studnumber); router(fp, fw, i, studnumber); } else if (vernumber[11] == '6') { version6++; start(fp, fw, studnumber); router(fp, fw, i, studnumber); } else if (vernumber[11] == '7') { version7++; start(fp, fw, studnumber); router17(fp, fw, i, studnumber); } fclose (fp); } fclose(fw); printf("\n\n%d analaysed files\n", z); //the number of files that were analysed. }return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -