# awk script # # the begin command is executed BEFORE anything else is done BEGIN {FS=" "; "date" | getline date; print date } # ------------------------ File reading sequence {N=N+1} {if(N==1) {printf "Input file [ %12s ]\n",FILENAME ; print "#----------------------Input---------------------#"}} {if($1=="Weight") {mass=$2/386.04;print$0}} {if($1=="Spring") {kspring=$3;print$0}} {if($1=="Damping") {dratio=$3;print$0}} {if($1=="X0") {x0=$2;print$0}} {if($1=="V0") {v0=$2;print$0}} {if($1=="F0") {f0=$2;print$0}} {if($1=="alpha") {alpha=$2;print$0}} # # ------------------------Start of calculation sequence END { #natlfreq will be in Hz {natlfreq=sqrt(kspring/mass)/2/3.14159} {dmpdnatlfreq=natlfreq*sqrt(1-dratio^2)} {freqratio=alpha/natlfreq} {statdefl=f0/kspring} {scratch1=(1-freqratio^2)^2} {scratch2=(2*dratio*freqratio)^2} {scratch3=sqrt(scratch1+scratch2)} {displ=statdefl/scratch3} # # response plot calculations.......... # x[ ] is the varying frequency ratio # y[ ] is the response # frequency step are refined near resonance # scratches are throw-away calcs # {x[1]=0.;scratch4=(1-x[1]^2)^2;scratch5=(2*dratio*x[1])^2;scratch6=sqrt(scratch4+scratch5);y[1]=statdefl/scratch6} # {for(jk=2;jk<=10;jk++) {x[jk]=x[jk-1]+.10;scratch4=(1-x[jk]^2)^2;scratch5=(2*dratio*x[jk])^2; scratch6=sqrt(scratch4+scratch5);y[jk]=statdefl/scratch6}} {for(jk=11;jk<=14;jk++) {x[jk]=x[jk-1]+.05;scratch4=(1-x[jk]^2)^2;scratch5=(2*dratio*x[jk])^2; scratch6=sqrt(scratch4+scratch5);y[jk]=statdefl/scratch6}} {for(jk=15;jk<=23;jk++) {x[jk]=x[jk-1]+.10;scratch4=(1-x[jk]^2)^2;scratch5=(2*dratio*x[jk])^2; scratch6=sqrt(scratch4+scratch5);y[jk]=statdefl/scratch6}} # # crude plotting routine (max stars = 20): {for(jk=1;jk<=23;jk++) {if(y[jk]>ymax) {ymax=y[jk]}}} {for(jk=1;jk<=23;jk++) {yratio[jk]=int(20*y[jk]/ymax)}} {for(jk=1;jk<=23;jk++) {km=0;scratch=""; while(km<=yratio[jk]) {scratch=scratch "#";km=km+1}; ystars[jk]=scratch}} # # start printing output {print "#---------------------------------Output--------------------------------------#"} {print" "} {printf("%s %-8.2f %-s\n","Undamped natural frequency =",natlfreq,"Hz")} {printf("%s %-8.2f %-s\n","Damped natural frequency =",dmpdnatlfreq,"Hz")} {printf("%s %-8.3f\n","Applied frequency ratio=",alpha/natlfreq)} {printf("%s %-8.4f %-s\n","Amplitude at specified frequency =",displ,"inches")} {printf("%s %-8.4f %-s\n","Applied F0 / k =",statdefl,"inches")} {print" "} {print"Response Plot: "} {printf("%-8s %-8s %-10s\n","FR","Hz","Ampl")} {for(jk=1;jk<=23;jk++) {printf("%-8.2f %-8.2f %-10.4f %s\n",x[jk],x[jk]*natlfreq,y[jk],ystars[jk])}} # {print "#-----------------------------End of File---------------------------------------#"} }