#!/usr/bin/gawk -f BEGIN{ IGNORECASE=1; ## make matching easier FS=OFS=","; COCOMO=1; ## COCOMO81=1, COCOMOII=2 Input=1; ## 1=sym, 2=num, 3=ln Output=3; ## 2=num, 3=ln, 4=SF Process ## if 4=SF Process, SF*S = 0.01*SF*ln(Size), let SF'behavier like multiplers OutputFile="Output.arff"; Project=0; delete StoreData; delete ProcessedData; Data=0; } {sub(/\%.*/,"")} ## skip comments /^[ \t]*$/ {next; } ## skip blank comments /@relation/{ print $0 > OutputFile; } /@attribute/ { split($0,Line,/ /); Attr=trim(tolower(Line[2])); push(Attrs,Attr); $0="@attribute " Attr " real"; print $0 >> OutputFile; } /@data/ { Data=1 } Data && NF > 2 { Project++; for(I=1;I<=NF;I++){ StoreData[Project, I]=$I; } } ##=========== embed all related functions================================== ##================================== Start================================= function readtable(file,a, i,f,line,n,tab) { while ((getline line < file) > 0) { n=split(line,f,/,/); lines++ for(i=1;i<=n;i++) f[i]=trim(f[i]); if (match(f[1],/^=/)) { tab=rhs(f[1]); for(i=1;i"/dev/stderr"; fflush("/dev/stderr"); } function dir(str) { printf "BAD! " str >"/dev/stderr"; fflush("/dev/stderr"); exit 1; } # string generation function str(n,c, x) { while ((n--) > 0) x= x c; return x; } #trim magic function trimLeft(x) { sub(/^[ \t]*/,"",x); return x; } function trimRight(x) { sub(/[ \t]*$/,"",x); return x; } function trim(x, y) { return trimRight(trimLeft(x)); } # match magic function lhs(s) { return substr(s, 1, RSTART-1) } function mid(s,x,y) { return substr(s, RSTART + x, RLENGTH - x - y) } function rhs(s) { return substr(s, RSTART+RLENGTH) } # convert a string to an array look up function s2a(str,a,sep, n,i,tmp,c) { n=split(str,tmp,sep); for(i=1;i<=n;i=i+2) { c++; a[tmp[i]]=tmp[i+1]; } return c; } ##================================== END ================================== ##=========== embed all related functions================================== END { readtable(TuningsFile,Tunings); if (COCOMO==1){ for(i=1;i<=Project;i++){ for(j=1;j<=NF-2;j++){ if(Input==1){ ProcessedData[i,j]=Tunings["em",Attrs[j],trim(StoreData[i,j])]; } else{ ProcessedData[i,j]=StoreData[i,j]; } if(Input<=2 && Output==3){ ProcessedData[i,j]=log(ProcessedData[i,j]); } } ProcessedData[i,j]=StoreData[i,j]; if(Input<=2 && Output==3){ ProcessedData[i,j]=log(ProcessedData[i,j]); } j++; ProcessedData[i,j]=StoreData[i,j]; if(Input<=2 && Output==3){ ProcessedData[i,j]=log(ProcessedData[i,j]); } } } else{ for(i=1;i<=Project;i++){ for(j=1;j<=NF-2;j++){ if(Input==1){ ProcessedData[i,j]=Tunings["CII",Attrs[j],trim(StoreData[i,j])]; } else{ ProcessedData[i,j]=StoreData[i,j]; } if(Input<=2 && (Output==3 || Output==4)){ if(j>5){ ProcessedData[i,j]=log(ProcessedData[i,j]); } } } ProcessedData[i,j]=StoreData[i,j]; if(Input<=2 && (Output==3 || Output==4)){ ProcessedData[i,j]=log(ProcessedData[i,j]); } j++; ProcessedData[i,j]=StoreData[i,j]; if(Input<=2 && (Output==3 || Output==4)){ ProcessedData[i,j]=log(ProcessedData[i,j]); } if(Output==4){ ProcessedData[i,1]=ProcessedData[i,1]/100*ProcessedData[i,(NF-1)]; ProcessedData[i,2]=ProcessedData[i,2]/100*ProcessedData[i,(NF-1)]; ProcessedData[i,3]=ProcessedData[i,3]/100*ProcessedData[i,(NF-1)]; ProcessedData[i,4]=ProcessedData[i,4]/100*ProcessedData[i,(NF-1)]; ProcessedData[i,5]=ProcessedData[i,5]/100*ProcessedData[i,(NF-1)]; } } } print "" >>OutputFile; print "@data" >>OutputFile; print "" >>OutputFile; for(i=1;i<=Project;i++){ for(j=1;j<=NF-1;j++){ printf ProcessedData[i,j] "," >>OutputFile; } print ProcessedData[i,j] >>OutputFile; } }