DECLARE SUB curva (s!, d!, la!, N!, col!, ang0, ang1, ang2, delan)

SCREEN 12

CLS

COLOR 15

pi = 4 * ATN(1)

s = .91679

d = 3.3936

N = 10

la1 = .5393

la2 = .6393

ang1 = 0

ang2 = 45

delan = 1

LOCATE 8, 1

PRINT "                             PROGRAM 'ELEGRA'"

PRINT

PRINT

PRINT "Elementary diffraction grating."

PRINT "Plots the instrumental function of a grating for two wavelengths"

COLOR 11: PRINT "smaller lambda  "; : COLOR 15: PRINT "and  "; : COLOR 12:

PRINT "larger lambda.": COLOR 15

PRINT "The width of each transparent slit is s. Distance between slits is d."

PRINT "Number of slits is N. Angle of incidence is ang0."

PRINT "The graph is the diffracted intensity as a function of angle from"

PRINT "ang1 to ang2, that are printed, with marks each step delan."

PRINT "It is useful to verify the grating equation, to calculate the"

PRINT "intensity of the orders, resolving power and free spectral range."

PRINT "The default values are those of Fig.3.9."

PRINT "Lengths are in microns and angles in degrees."

PRINT "To finish put any of the 5 first items = 0."

DO: LOOP WHILE INKEY$ = ""

CLS

DO

LOCATE 1, 1: PRINT "         ";

LOCATE 1, 1: PRINT "Width of each transparent slit s ="; s;

INPUT a$: IF a$ <> "" THEN s = VAL(a$)

IF s = 0 THEN END

LOCATE 2, 1: PRINT "         ";

LOCATE 2, 1: PRINT "Distance between slits d ="; d;

INPUT a$: IF a$ <> "" THEN d = VAL(a$)

IF d = 0 THEN END

LOCATE 3, 1: PRINT "         ";

LOCATE 3, 1: PRINT "Number of slits N ="; N;

INPUT a$: IF a$ <> "" THEN N = VAL(a$)

IF N = 0 THEN END

LOCATE 4, 1: PRINT "         ";

COLOR 11

LOCATE 4, 1: PRINT "smaller lambda ="; la1;

INPUT a$: IF a$ <> "" THEN la1 = VAL(a$)

IF la1 = 0 THEN END

LOCATE 5, 1: PRINT "         ";

COLOR 12

LOCATE 5, 1: PRINT "larger lambda ="; la2;

INPUT a$: IF a$ <> "" THEN la2 = VAL(a$)

IF la2 = 0 THEN END

LOCATE 6, 1: PRINT "         ";

COLOR 15

LOCATE 6, 1: PRINT "Incidence angle ang0 ="; ang0;

INPUT a$: IF a$ <> "" THEN ang0 = VAL(a$)

IF ang0 = 90 THEN ang0 = 89.999

IF ang0 = -90 THEN ang0 = -89.999

LOCATE 7, 1: PRINT "         ";

LOCATE 7, 1: PRINT "Smaller angle of the diffracted interval ang1 ="; ang1;

INPUT a$: IF a$ <> "" THEN ang1 = VAL(a$)

IF ang1 = 90 THEN ang1 = 89.999

IF ang1 = -90 THEN ang1 = -89.999

LOCATE 8, 1: PRINT "         ";

LOCATE 8, 1: PRINT "Larger angle of the diffracted interval ang2 ="; ang2;

INPUT a$: IF a$ <> "" THEN ang2 = VAL(a$)

IF ang2 = 90 THEN ang2 = 89.999

IF ang2 = -90 THEN ang2 = -89.999

LOCATE 9, 1: PRINT "         ";

LOCATE 9, 1: PRINT "Marks each "; delan; " degrees?"; : PRINT " delan = ";

INPUT a$: IF a$ <> "" THEN delan = VAL(a$)

IF delan = 0 THEN END

LOCATE 10, 1: PRINT "         ";

CLS

LOCATE 30, 1: PRINT INT(100 * ang1 + .5) / 100;

LOCATE 30, 74: PRINT INT(100 * ang2 + .5) / 100;

FOR ang = ang1 TO ang2 STEP delan

xp = 640 * (ang - ang1) / (ang2 - ang1)

LINE (xp, 0)-(xp, 479), 8

NEXT ang

LINE (639, 0)-(639, 479), 8

FOR yp = 0 TO 479 STEP 47.9

LINE (0, yp)-(639, yp), 8

NEXT yp

col = 11

la = la1

CALL curva(s, d, la, N, col, ang0, ang1, ang2, delan)

col = 12

la = la2

CALL curva(s, d, la, N, col, ang0, ang1, ang2, delan)

DO: LOOP WHILE INKEY$ = ""

LOOP

 

SUB curva (s, d, la, N, col, ang0, ang1, ang2, delan)

pi = 4 * ATN(1)

FOR ang = ang1 TO ang2 STEP (ang2 - ang1) / 640

alfa = ang * pi / 180

alfa0 = ang0 * pi / 180

alfa1 = ang1 * pi / 180

alfa2 = ang2 * pi / 180

p = SIN(alfa) - SIN(alfa0)

x = pi * s * p / la

y = pi * d * p / la

IF x = 0 THEN 1

I = (SIN(N * y) / (N * SIN(y))) ^ 2 * (SIN(x) / x) ^ 2

xp = 640 * (alfa - alfa1) / (alfa2 - alfa1)

yp = 479 * (1 - I)

1 IF ang = ang1 THEN PSET (xp, yp), col

LINE -(xp, yp), col

NEXT ang

END SUB