--- ray/src/cv/lampcolor.c 1991/09/05 15:36:34 1.4 +++ ray/src/cv/lampcolor.c 1991/09/12 13:36:43 1.6 @@ -182,13 +182,20 @@ compute() /* compute lamp radiance */ } -getd(dp) /* get a positive double from stdin */ +getd(name, dp, help) /* get a positive double from stdin */ +char *name; double *dp; +char *help; { char buf[32]; - +again: + printf("%s [%g]: ", name, *dp); if (gets(buf) == NULL) return(0); + if (buf[0] == '?') { + puts(help); + goto again; + } if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.') return(0); *dp = atof(buf); @@ -198,53 +205,46 @@ double *dp; getpolygon() /* get projected area for a polygon */ { - printf("Polygon area? "); - if (!getd(&projarea)) - return(0); - projarea *= unit2meter*unit2meter; - projarea *= PI; + static double area = 1.0; + + getd("Polygon area", &area, + "Enter the total radiating area of the polygon."); + projarea = PI*unit2meter*unit2meter * area; return(1); } getsphere() /* get projected area for a sphere */ { - double radius; + static double radius = 1.0; - printf("Sphere radius? "); - if (!getd(&radius)) - return(0); - radius *= unit2meter; - projarea = 4.*PI*PI*radius*radius; + getd("Sphere radius", &radius, + "Enter the distance from the sphere's center to its surface."); + projarea = 4.*PI*PI*unit2meter*unit2meter * radius*radius; return(1); } getcylinder() /* get projected area for a cylinder */ { - double length, radius; + static double length = 1.0, radius = 0.1; - printf("Cylinder length? "); - if (!getd(&length)) - return(0); - length *= unit2meter; - printf("Cylinder radius? "); - if (!getd(&radius)) - return(0); - radius *= unit2meter; - projarea = PI*PI*2.*PI*radius*length; + getd("Cylinder length", &length, + "Enter the length of the cylinder."); + getd("Cylinder radius", &radius, + "Enter the distance from the cylinder's axis to its surface."); + projarea = PI*PI*2.*PI*unit2meter*unit2meter * radius*length; return(1); } getring() /* get projected area for a ring */ { - double radius; + static double radius = 1.0; - printf("Disk radius? "); - if (!getd(&radius)) - return(0); - radius *= unit2meter; - projarea = PI*PI*radius*radius; + getd("Disk radius", &radius, +"Enter the distance from the ring's center to its outer edge.\n\ +The inner radius must be zero."); + projarea = PI*PI*unit2meter*unit2meter * radius*radius; return(1); }