PROGRAM Lens ! Copyright 2006 Matthew Norton ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ! ! NOTE: This is in FORTRAN 90 and you will need a FORTRAN 90 complier to run this code ! -------------------------------------------------------------------------- ! ! This Program solves the thin lens equation for the object location, the ! image location, or the focal length. ! ! -------------------------------------------------------------------------- ! ! Created by Matthew S. Norton ! Created on March 23, 2006 ! Created because I was bored ! ! -------------------------------------------------------------------------- IMPLICIT NONE DOUBLE PRECISION Obj, Img, Foc CHARACTER (1) :: Response Main: DO PRINT *, "Do you want to solve for the object location (o), image location (i), or focal length (f) or enter 0 to quit?" READ *, Response SELECT CASE(Response) CASE("o") CALL OBJECT CASE("O") CALL OBJECT CASE("i") CALL IMAGE CASE("I") CALL IMAGE CASE("f") CALL FOCAL CASE("F") CALL FOCAL CASE ("0") EXIT Main CASE DEFAULT PRINT '(1X, A21, 1X, A1, 1X, A23)', "ERROR! Improper input,", Response, "please input o, i, or f" CYCLE Main END SELECT END DO Main CONTAINS SUBROUTINE Object PRINT *, "What is the image distance?" READ *, Img PRINT *, "What is the focal length?" READ *, Foc Obj = (- Foc * Img) / (Foc - Img) PRINT '(1X, A, 1X, F10.6)', "The object distance is:", Obj END SUBROUTINE Object SUBROUTINE Image PRINT *, "What is object distance?" READ *, Obj PRINT *, "What is the focal length?" READ *, Foc Img = (-Foc * Obj) / (Foc - Obj) PRINT '(1X, A, 1X, F10.6)', "The image distance is:", Img END SUBROUTINE Image SUBROUTINE Focal PRINT *, "What is the object distance?" READ *, Obj PRINT *, "What is the image distance?" READ *, Img Foc = (Img * Obj) / (Img + Obj) PRINT '(1X, A, 1X, F10.6)', "The focal length is:", Foc END SUBROUTINE Focal END PROGRAM Lens