{$N+} program Atwood; uses crt,graph,dos; const maxpts = 100; type file_name = string[50]; data = array [0..maxpts] of real; readings = array[0..maxpts] of longint; Var s1, s2 : string; ans,ch : char; inf, outf : text; on, off : readings; time, vel : data; count : longint; ntot,state,state1,state2,invertnum : integer; graphdriver,graphmode,midx,midy : integer; nx,ny,h,i,j,k,l,maxspins :integer; stop :boolean; con1, con2, sumtime, maxxx, maxxy : real; minx,maxx,miny,maxy, scalet,scalev : real; { for plots } timeconst,radius,height,gap : real; { initializing } a,sumxx,b,sumxy,sumx,sumy,del,delx,dely,temp1,temp2,temp3 : real; hour, minute, sec, sec100 : word; hour1, minute1, sec1, sec1001 : word; ti,tf, newcon2, newcon3, xcount, scon :real; run, runc, check : boolean; code : integer; v1c,v2c,xa,denom,circum : real; procedure takedat; begin writeln('The computer is recording ',ntot,' data points'); writeln; writeln('DO NOT PRESS ANY KEYS OR DATA COLLECTION WILL BE ALTERED !!'); writeln; writeln('After the ', ntot,' times are recorded the data will be '); writeln('printed to the screen'); writeln; writeln('If nothing is happening, the computer will automatically'); writeln(' stop recording the data after 15 seconds'); writeln; runc:=true; gettime(hour,minute,sec,sec100); for i := 1 to ntot do begin count := 0; run := true; while (run and runc) do begin count := count + 1; if port[$201]=240 then run:=false; if count>9000000 then runc:=false; end; off[i] := count; count:=0; run:=true; while (run and runc) do begin count := count + 1; if port[$201]=224 then run:=false; if count>9000000 then runc:=false; end; on[i] := count; end; gettime(hour1,minute1,sec1,sec1001); xcount:=0.0; for i:=1 to ntot do begin xcount:=xcount+off[i]+on[i]; end; ti:=hour*3600.0+minute*60.0+sec+sec100/100.0; tf:=hour1*3600.0+minute1*60.0+sec1+sec1001/100.0; newcon2:=xcount/(tf-ti); writeln (ntot ,' Data points have been taken.'); writeln; for i := 1 to ntot do begin if on[i]=0 then on[i]:=1; vel[i] := con1/on[i]; end; for i:=1 to ntot do begin sumtime:=0.0; for j:=1 to i do sumtime:=sumtime + off[j] + on[j]; time[i]:=sumtime-on[i]/2.0; time[i]:=time[i]/con2; end; writeln('Data point Time(sec) Velocity(cm/sec)'); for i:=1 to ntot do writeln(' ',i,' ',time[i]:16:4,' ',vel[i]:16:4); writeln; if (not runc) then begin writeln('The data is probably bad !!!!!'); writeln('The photogate might not be working properly'); writeln('Test the photogate by pressing t'); end; end; {takedat} procedure calbrat; begin writeln; writeln('This is the calibration mode to change the time and/or'); writeln('velocity calibration constants'); writeln; writeln('Enter the number 1, then make the tab block the photogate'); writeln('5 times.'); writeln; readln(i); count:=0; gettime(hour,minute,sec,sec100); runc:=true; for i := 1 to 5 do begin count := 0; run := true; while (run and runc) do begin count := count + 1; if port[$201]=240 then run:=false; if count>9000000 then runc:=false; end; off[i] := count; count:=0; run:=true; while (run and runc) do begin count := count + 1; if port[$201]=224 then run:=false; if count>9000000 then runc:=false; end; on[i] := count; end; gettime(hour1,minute1,sec1,sec1001); xcount:=0.0; for i:=1 to 5 do begin xcount:=xcount+off[i]+on[i]; end; ti:=hour*3600.0+minute*60.0+sec+sec100/100.0; tf:=hour1*3600.0+minute1*60.0+sec1+sec1001/100.0; newcon3:=xcount/(tf-ti); writeln('Old calibration constant ',con2:15:2); writeln('New calibration constant ',newcon3:15:2); writeln; writeln('Type in the calibration constant to be saved'); writeln('(type -1 is you do not want to change the constant'); readln(scon); if (scon>0) then con2:=scon; writeln; writeln('Enter the factor that you want the acceleration to'); writeln('increase by:'); readln(scon); con1:=con1*scon; writeln('Current circumference distance: ',circum); writeln('Type in the new circumference distance'); readln(circum); assign(outf,'c:\calib\cat.dat'); rewrite(outf); writeln(outf,con1); writeln(outf,con2); writeln(outf,circum); close(outf); writeln; writeln('The calibration is complete, type m to get the menu'); end; procedure writetofile; begin writeln ('Enter the filename:'); readln (s1); assign(outf,s1); rewrite(outf); count := 0; for i := 1 to ntot do writeln (outf,i,' ',time[i],' ', vel[i]); close(outf); writeln('The data has been written: ',ntot,' data points'); end; {writetofile } procedure read_file; begin writeln ('Which file do you want to read?'); readln (s1); assign(inf,s1); reset(inf); i:=-1; while not EOF(inf) do begin i:=i+1; read(inf,j,time[i+1],vel[i+1]); end; ntot:=i; writeln('The data are: '); for i:=1 to ntot do writeln(i,' ',time[i]:16:4,' ',vel[i]:16:4); close(inf); end; procedure datview; begin clrscr; writeln; writeln; writeln('The current data are:'); writeln; writeln('Data point Time(sec) Velocity(cm/sec)'); for i:=1 to ntot do writeln(i,' ',time[i]:16:4,' ',vel[i]:16:4); writeln; writeln('press m to return to the menu'); end; procedure rawview; begin clrscr; writeln; writeln; writeln('The raw data are:'); writeln; for i:=1 to ntot do begin writeln('unblocked counts: ', off[i]); writeln(' blocked counts: ', on[i]); end; writeln; writeln(' Press m to return to the menu'); end; procedure velplot; begin scalet := 1; scalev := 1; maxxx := 0; maxxy := 0; for i := 1 to ntot do begin if time[i] > maxxx then maxxx := time[i]; if vel[i] > maxxy then maxxy := vel[i]; end; graphdriver:=detect; initgraph(graphdriver,graphmode,''); maxx:=getmaxx; maxy:=getmaxy; setcolor(15); line(40,0,40,trunc(maxy-200)); line(40,trunc(maxy-200),trunc(maxx-40),trunc(maxy-200)); scalet:=(maxx-80)/maxxx; delx:=maxxx/(maxx-80); scalev:=(maxy-210)/maxxy; dely:=maxxy/(maxy-210); setcolor(14); for i:=1 to ntot do begin nx:=trunc(40+time[i]*scalet); ny:=trunc(maxy-200-scalev*vel[i]); circle(nx,ny,4); end; sumx := 0.0; sumxx := 0.0; sumy := 0.0; sumxy := 0.0; for i := 1 to ntot do begin sumx := sumx + time[i]; sumxx := sumxx + time[i]*time[i]; sumy := sumy + vel[i]; sumxy := sumxy + time[i]*vel[i]; end; del := ntot*sumxx - sumx*sumx; { DEL } a := (sumxx*sumy-sumx*sumxy)/del; b := (ntot*sumxy-sumx*sumy)/del; for i:=1 to trunc(maxx-80) do begin nx:=trunc(40+i*delx*scalet); ny:=trunc(maxy-200-scalev*(b*i*delx+a)); putpixel(nx,ny,10); end; v1c:=a+b*time[1]; v2c:=a+b*time[4]; denom:=v2c*v2c-v1c*v1c; if (denom=0) then denom:=1.0; xa:=2.0*circum*b/denom; setcolor(15); str(b:16:4,s1); outtextxy(40, trunc(maxy-180),'The slope is ' + s1 + ' cm/sec^2'); str(a:16:4,s1); outtextxy(40, trunc(maxy-170),'The intercept is ' + s1 + ' cm/sec'); str(xa:8:4,s1); str(xa*b:10:4,s2); outtextxy(5,trunc(maxy-150),'Constant acceleration calibration check:'); outtextxy(5,trunc(maxy-140),'scale factor = '+s1+' corrected acceleration = '+s2+' cm/sec^2'); for i:=1 to ntot do begin str(time[i]:16:4,s1); str(vel[i]:16:4,s2); outtextxy(40,trunc(maxy+10*i-130),s1 + ' ' + s2); end; end; procedure setpoints; begin writeln('Input the number of times the photogate will be blocked'); writeln('when the holder falls to the ground'); readln(s1); ntot:=4; val(s1,ntot,code); if (ntot<4) then begin writeln('You put in an invalid integer'); writeln('ntot will be set to 4'); ntot:=4; end; if (ntot>12) then begin writeln('You put in an invalid integer'); writeln('ntot will be set to 12'); ntot:=12; end; writeln('press m to get to main menu'); end; procedure testgate; begin writeln('Begin the test'); for i:=1 to 20 do begin if (port[$201]=224) then writeln('Un-blocked'); if (port[$201]=240) then writeln('Blocked'); delay(10000); end; writeln('The test is over'); writeln('type t to repeat the test, m to see the menu'); end; procedure menu; begin clrscr; writeln(ntot,' data points will be taken'); writeln ('What would you like to do? '); writeln; writeln ('*****************************'); writeln ('* Set the number of data points taken: n *'); writeln ('* take data: d *'); writeln ('* plot v vs t: g *'); writeln; writeln ('* View the data: v *'); writeln ('* View the raw data from computer r *'); writeln ('* To see the menu: m *'); writeln ('* Test the photogate: t *'); writeln ('* Quit: q *'); writeln ('*****************************'); end; begin {main} clrscr; writeln; writeln; writeln; writeln(' Atwood Machine Program'); writeln; writeln; writeln(' by Rich Aguayo (Cal Poly Pomona Physics graduate 91)'); writeln; writeln(' Joe Kobayashi (Cal Poly Pomona Physics graduate 99'); writeln; writeln(' and Mark Harnetiaux (Cal Poly Pomona Physics Technician'); writeln; writeln; writeln(' press enter to get menu'); ntot:=4; for i:=1 to 100 do begin time[i]:=i; vel[i]:=i; end; readln; menu; { con1:=740000.0; con2:=660000.0; } assign(inf,'c:\calib\cat.dat'); reset(inf); readln(inf,con1); readln(inf,con2); readln(inf,circum); close(inf); stop:=false; repeat if keypressed then begin case readkey of 'n','N' : begin closegraph; setpoints; end; 'd','D' : begin closegraph; takedat; end; { 'w' : begin closegraph; writetofile; end; 'r' : begin; closegraph; read_file; end; } 'g','G' : begin closegraph; velplot; end; 'v','V' : begin closegraph; datview; end; 'r','R' : begin closegraph; rawview; end; 't','T' : begin closegraph; testgate; end; 'm','M' : begin closegraph; menu; end; 'Z' : begin closegraph; calbrat; end; 'q', 'Q' : begin closegraph; stop:=true; end; end; {case} end;{if} until stop; clrscr; end.