Advertisement
LightningStalker

gridcalc.c

Oct 12th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. /*
  2.  * Computes the wavelength of incident light.  Formulas used are:
  3.  * Arctangent - atan(c / a) - thanks Cyparagon
  4.  * Diffraction grid formula - nλ = d sin(ϴ)
  5.  * Pythagorean theorem - a² + b² = c²
  6.  * The Lightning Stalker 2013
  7.  */
  8.  
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. int main (int argc, char **argv)
  14. {
  15.     float a, c, d, wl;
  16.    
  17.     if (argc == 4)
  18.     {
  19.         a = atof(argv[1]);
  20.         c = atof(argv[2]);
  21.         d = atof(argv[3]);
  22.         wl = d * sin(atan(c / a));
  23.         printf("Wavelength is %1.1fnm\n", wl);
  24.     }
  25.     else
  26.     {
  27.         puts("gridcalc is a diffraction grid wavelength calculator.\n");
  28.         puts("Usage: gridcalc a c d");
  29.         puts("a = Distance from grid to target in mm");
  30.         puts("c = Distance from center to first order spectrum line of interest in mm");
  31.         puts("d = Distance between diffraction grid elements in nm");
  32.         puts("Example: gridcalc 100 88 1000");
  33.         puts("Output should be 660.6nm");
  34.         return(1);
  35.     }
  36.    
  37.     return(0);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement