Source Code

These source-code files were from the printout at the MIT Museum, with many thanks to Deborah Douglas, the Museum's Curator of Science and Technology, for releasing it to us. The printout was digitally photographed by Paul Fjeld. A team of volunteers transcribed the source code manually from these images or, where appropriate, modified already-transcribed but similar source Luminary 131 (Apollo 13) source code to agree with the images from the printout. Note that the page images presented online are of reduced quality, and that higher-quality images are available. Report any conversion errors or legibility problems in page images to info@sandroid.org. Notations on the program listing read, in part:

	GAP:  ASSEMBLE REVISION 001 OF AGC PROGRAM LMY99 BY NASA 2021112-061
	20'35 OCT. 28,1968
Note that the date is the date of the printout, not the date of the program revision.

048312,000002:                                                                                                  ## Copyright:   Public domain.
048313,000003:                                                                                                  ## Filename:    LATITUDE_LONGITUDE_SUBROUTINES.agc
048314,000004:                                                                                                  ## Purpose:     Part of the source code for Luminary 1A build 099.
048315,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
048316,000006:                                                                                                  ##              Apollo Guidance Computer (AGC), for Apollo 11.
048317,000007:                                                                                                  ##
048318,000008:                                                                                                  ## Assembler:   yaYUL
048319,000009:                                                                                                  ## Contact:     Jim Lawton <jim DOT lawton AT gmail DOT com>
048320,000010:                                                                                                  ## Website:     www.ibiblio.org/apollo.
048321,000011:                                                                                                  ## Pages:       1133-1139
048322,000012:                                                                                                  ## Mod history: 2009-05-28 JL   Updated from page images.
048323,000013:                                                                                                  ##              2011-01-06 JL   Fixed interpretive indentation.
048324,000014:                                                                                                  ##              2016-12-17 RSB  Proofed text comments with octopus/ProoferComments
048325,000015:                                                                                                  ##                              and corrected the errors found.
048326,000016:                                                                                                  ##              2017-03-15 RSB  Comment-text fixes identified in 5-way
048327,000017:                                                                                                  ##                              side-by-side diff of Luminary 69/99/116/131/210.
048328,000018: 
048329,000019:                                                                                                  ## This source code has been transcribed or otherwise adapted from digitized
048330,000020:                                                                                                  ## images of a hardcopy from the MIT Museum.  The digitization was performed
048331,000021:                                                                                                  ## by Paul Fjeld, and arranged for by Deborah Douglas of the Museum.  Many
048332,000022:                                                                                                  ## thanks to both.  The images (with suitable reduction in storage size and
048333,000023:                                                                                                  ## consequent reduction in image quality as well) are available online at
048334,000024:                                                                                                  ## www.ibiblio.org/apollo.  If for some reason you find that the images are
048335,000025:                                                                                                  ## illegible, contact me at info@sandroid.org about getting access to the
048336,000026:                                                                                                  ## (much) higher-quality images which Paul actually created.
048337,000027:                                                                                                  ##
048338,000028:                                                                                                  ## Notations on the hardcopy document read, in part:
048339,000029:                                                                                                  ##
048340,000030:                                                                                                  ##    Assemble revision 001 of AGC program LMY99 by NASA 2021112-061
048341,000031:                                                                                                  ##    16:27 JULY 14, 1969
048342,000032: 

Page 1133

048344,000034:                                                                                                  #  SUBROUTINE TO CONVERT RAD VECTOR AT GIVEN TIME TO LAT,LONG AND ALT
048345,000035: 
048346,000036:                                                                                                  #  CALLING SEQUENCE
048347,000037:                                                                                                  #        L-1     CALL
048348,000038:                                                                                                  #        L               LAT-LONG
048349,000039: 
048350,000040:                                                                                                  #  SUBROUTINES USED
048351,000041:                                                                                                  #        R-TO-RP, ARCTAN, SETGAMMA, SETRE
048352,000042: 
048353,000043:                                                                                                  #  ERASABLE INIT. REQ.
048354,000044:                                                                                                  #        AXO, -AYO, AZO, TEPHEM (SET AT LAUNCH TIME)
048355,000045:                                                                                                  #        ALPHAV = POSITION VECTOR METERS B-29
048356,000046:                                                                                                  #        MPAC -- TIME (CSECS B-28)
048357,000047:                                                                                                  #        ERADFLAG =1, TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
048358,000048:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
048359,000049: 
048360,000050:                                                                                                  #  OUTPUT
048361,000051:                                                                                                  #        LATITUDE IN LAT         (REVS. B-0)
048362,000052:                                                                                                  #        LONGITUDE IN LONG       (REVS. B-0)
048363,000053:                                                                                                  #        ALTITUDE IN ALT         METERS B-29
048364,000054: 
048365,000055: 30,3775                                           BANK     30                                    
048366,000056: 13,2000                                           SETLOC   LATLONG                               
048367,000057: 13,2000                                           BANK                                           
048368,000058: 
048369,000059: 13,2351                                           COUNT*   $$/LT-LG                              
048370,000060: 13,2351  E4,1431                                  EBANK=   ALPHAV                                
048371,000061: 13,2351           40220        LAT-LONG           STQ      SETPD                                 
048372,000062: 13,2352           03674                                    INCORPEX                              
048373,000063: 13,2353           00001                                    0D                                    
048374,000064: 13,2354           24007                           STOVL    6D                                    #  SAVE TIME IN 6-7D FOR R-TO-RP
048375,000065: 13,2355           02032                                    ALPHAV                                
048376,000066: 13,2356           51406                           PUSH     ABVAL                                 #  0-5D= R FOR R-TO-RP
048377,000067: 13,2357           16070                           STODL    ALPHAM                                #  ABS. VALUE OF R FOR ALT FORMULA BELOW
048378,000068: 13,2360           24007                                    ZEROVEC                               #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
048379,000069: 13,2361           71414                           BOFF     COS                                   #  USE COS(0) TO GET NON-ZERO IN MPAC
048380,000070: 13,2362           01743                                    LUNAFLAG                              #  0=EARTH, 1=MOON
048381,000071: 13,2363           26364                                    CALLRTRP                              
048382,000072: 13,2364           77624        CALLRTRP           CALL                                           
048383,000073: 13,2365           51670                                    R-TO-RP                               #  RP VECTOR CONVERTED FROM R B-29
048384,000074: 13,2366           77656                           UNIT                                           #  UNIT RP B-1
048385,000075: 13,2367           36032                           STCALL   ALPHAV                                #  U2= 1/2 SINL FOR SETRE SUBR BELOW
048386,000076: 13,2370           26550                                    SETGAMMA                              #        SET GAMMA=B2/A2 FOR EARTH, =1 FOR MOON
048387,000077: 13,2371           77624                           CALL                                           #        SCALED B-1
048388,000078: 13,2372           26560                                    SETRE                                 #  CALC RE METERS B-29
048389,000079: 13,2373           63545                           DLOAD    DSQ                                   
048390,000080: 13,2374           02032                                    ALPHAV                                
048391,000081: 13,2375           63525                           PDDL     DSQ                                   
048392,000082: 13,2376           02034                                    ALPHAV     +2                         
048393,000083: 13,2377           75415                           DAD      SQRT                                  

Page 1134

048395,000085: 13,2400           76405                           DMP      SL1R                                  
048396,000086: 13,2401           00011                                    GAMRP                                 
048397,000087: 13,2402           14021                           STODL    COSTH                                 #  COS(LAT) B-1
048398,000088: 13,2403           02036                                    ALPHAV     +4                         
048399,000089: 13,2404           34023                           STCALL   SINTH                                 #  SIN(LAT) B-1
048400,000090: 13,2405           26510                                    ARCTAN                                
048401,000091: 13,2406           15121                           STODL    LAT                                   #  LAT B0
048402,000092: 13,2407           02032                                    ALPHAV                                
048403,000093: 13,2410           14021                           STODL    COSTH                                 #  COS(LONG) B-1
048404,000094: 13,2411           02034                                    ALPHAV     +2                         
048405,000095: 13,2412           34023                           STCALL   SINTH                                 #  SIN(LONG) B-1
048406,000096: 13,2413           26510                                    ARCTAN                                
048407,000097: 13,2414           15123                           STODL    LONG                                  #  LONG. REVS B-0 IN RANGE -1/2 TO 1/2
048408,000098: 13,2415           02070                                    ALPHAM                                
048409,000099: 13,2416           77625                           DSU                                            #  ALT= R-RE METERS B-29
048410,000100: 13,2417           03673                                    ERADM                                 
048411,000101: 13,2420           35125                           STCALL   ALT                                   #  EXIT WITH ALT METERS B-29
048412,000102: 13,2421           03674                                    INCORPEX                              

Page 1135

048414,000104:                                                                                                  #  SUBROUTINE TO CONVERT LAT,LONG,ALT AT GIVEN TIME TO RADIUS VECTOR
048415,000105: 
048416,000106:                                                                                                  #  CALLING SEQUENCE
048417,000107:                                                                                                  #        L-1     CALL
048418,000108:                                                                                                  #        L               LALOTORV
048419,000109: 
048420,000110:                                                                                                  #  SUBROUTINES USED
048421,000111:                                                                                                  #        SETGAMMA, SETRE, RP-TO-R
048422,000112: 
048423,000113:                                                                                                  #  ERASABLE INIT. REQ.
048424,000114:                                                                                                  #        AXO, AYO, AZO, TEPHEM SET AT LAUNCH TIME
048425,000115:                                                                                                  #        LAT -- LATITUDE         (REVS B0)
048426,000116:                                                                                                  #        LONG -- LONGITUDE       (REVS B0)
048427,000117:                                                                                                  #        ALT -- ALTITUDE         (METERS) B-29
048428,000118:                                                                                                  #        MPAC -- TIME            (CSECS B-28)
048429,000119:                                                                                                  #        ERADFLAG =1 TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
048430,000120:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
048431,000121: 
048432,000122:                                                                                                  #  OUTPUT
048433,000123:                                                                                                  #        R-VECTOR IN ALPHAV      (METERS B-29)
048434,000124: 
048435,000125: 13,2422           40220        LALOTORV           STQ      SETPD                                 #  LAT,LONG,ALT TO R VECTOR
048436,000126: 13,2423           03674                                    INCORPEX                              
048437,000127: 13,2424           00001                                    0D                                    
048438,000128: 13,2425           34007                           STCALL   6D                                    #  6-7D= TIME FOR RP-TO-R
048439,000129: 13,2426           26550                                    SETGAMMA                              #  GAMMA=B2/A2 FOR EARTH, 1 FOR MOON B-1
048440,000130: 13,2427           73545                           DLOAD    SIN                                   #                COS(LONG)COS(LAT) IN MPAC
048441,000131: 13,2430           01121                                    LAT                                   #      UNIT RP = SIN(LONG)COS(LAT)    2-3D
048442,000132: 13,2431           65275                           DMPR     PDDL                                  #  PD 2          GAMMA*SIN(LAT)       0-1D
048443,000133: 13,2432           00011                                    GAMRP                                 
048444,000134: 13,2433           01121                                    LAT                                   #         0-1D = GAMMA*SIN(LAT) B-2
048445,000135: 13,2434           65346                           COS      PDDL                                  #  PD4    2-3D = COS(LAT) B-1 TEMPORARILY
048446,000136: 13,2435           01123                                    LONG                                  
048447,000137: 13,2436           57356                           SIN      DMPR                                  #  PD 2
048448,000138: 13,2437           71525                           PDDL     COS                                   #  PD 4   2-3D = SIN(LONG)COS(LAT) B-2
048449,000139: 13,2440           01121                                    LAT                                   
048450,000140: 13,2441           71525                           PDDL     COS                                   #  PD 6   4-5D = COS(LAT) B-1 TEMPORARILY
048451,000141: 13,2442           01123                                    LONG                                  
048452,000142: 13,2443           55475                           DMPR     VDEF                                  #  PD 4   MPAC = COS(LONG)COS(LAT) B-2
048453,000143: 13,2444           41456                           UNIT     PUSH                                  #  0-5D= UNIT RP FOR RP-TO-R SUBR.
048454,000144: 13,2445           36032                           STCALL   ALPHAV                                #  ALPHAV +4= SINL FOR SETRE SUBR.
048455,000145: 13,2446           26560                                    SETRE                                 #  RE METERS B-29
048456,000146: 13,2447           43145                           DLOAD    BOFF                                  #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
048457,000147: 13,2450           24007                                    ZEROVEC                               
048458,000148: 13,2451           01743                                    LUNAFLAG                              
048459,000149: 13,2452           26454                                    CALLRPRT                              
048460,000150: 13,2453           77746                           COS                                            #  USE COS(0) TO GET NON-ZERO IN MPAC
048461,000151: 13,2454           77624        CALLRPRT           CALL                                           
048462,000152: 13,2455           55716                                    RP-TO-R                               #  EXIT WITH UNIT R VECTOR IN MPAC
048463,000153: 13,2456           16032                           STODL    ALPHAV                                
048464,000154: 13,2457           03673                                    ERADM                                 

Page 1136

048466,000156: 13,2460           74215                           DAD      VXSC                                  #  (RE + ALT)(UNIT R) METERS B-30
048467,000157: 13,2461           01125                                    ALT                                   
048468,000158: 13,2462           02032                                    ALPHAV                                
048469,000159: 13,2463           77772                           VSL1                                           #  R METERS B-29
048470,000160: 13,2464           36032                           STCALL   ALPHAV                                #  EXIT WITH R IN METERS B-29
048471,000161: 13,2465           03674                                    INCORPEX                              
048472,000162: 
048473,000163:                                                                                                  #  SUBROUTINE TO COMPUTE EARTH RADIUS
048474,000164: 
048475,000165:                                                                                                  #  INPUT
048476,000166:                                                                                                  #        1/2 SIN LAT IN ALPHAV +4
048477,000167: 
048478,000168:                                                                                                  #  OUTPUT
048479,000169:                                                                                                  #        EARTH RADIUS IN ERADM AND MPAC (METERS B-29)
048480,000170: 
048481,000171: 13,2466           63545        GETERAD            DLOAD    DSQ                                   
048482,000172: 13,2467           02036                                    ALPHAV     +4                         #  SIN**2(L)
048483,000173: 13,2470           44352                           SL1      BDSU                                  
048484,000174: 13,2471           24005                                    DP1/2                                 #  COS**2(L)
048485,000175: 13,2472           44275                           DMPR     BDSU                                  
048486,000176: 13,2473           26507                                    EE                                    
048487,000177: 13,2474           24005                                    DP1/2                                 
048488,000178: 13,2475           75465                           BDDV     SQRT                                  
048489,000179: 13,2476           26503                                    B2XSC                                 
048490,000180: 13,2477           77622                           SR4R                                           
048491,000181: 13,2500           03673                           STORE    ERADM                                 
048492,000182: 13,2501           77616                           RVQ                                            
048493,000183: 
048494,000184:                                                                                                  #  THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166, B=6356784 METERS
048495,000185:                                                                                                  #  B2XSC = B**2 SCALED B-51
048496,000186:                                                                                                  #  B2/A2 = B**2/A**2 SCALED B-1
048497,000187:                                                                                                  #  EE = (1-B**2/A**2) SCALED B-0
048498,000188: 
048499,000189: 13,2502           00446 00305  B2XSC              2DEC     .0179450689                            #  B**2 SCALED B-51
048500,000190: 13,2504  12,2004               DP1/2              =        XUNIT                                 
048501,000191: 13,2504           17711 05254  B2/A2              2DEC     .9933064884 B-1                        #  GAMMA= B**2/A**2 B-1
048502,000192: 13,2506           00155 25250  EE                 2DEC     6.6935116  E-3                        #  (1-B**2/A**2) B-0
048503,000193: 

Page 1137

048505,000195:                                                                                                  #  ARCTAN SUBROUTINE
048506,000196: 
048507,000197:                                                                                                  #  CALLING SEQUENCE
048508,000198:                                                                                                  #        SIN THETA IN SINTH B-1
048509,000199:                                                                                                  #        COS THETA IN COSTH B-1
048510,000200:                                                                                                  #        CALL ARCTAN
048511,000201: 
048512,000202:                                                                                                  #  OUTPUT
048513,000203:                                                                                                  #        ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
048514,000204: 
048515,000205: 13,2510           77600        ARCTAN             BOV                                            
048516,000206: 13,2511           26512                                    CLROVFLW                              
048517,000207: 13,2512           63545        CLROVFLW           DLOAD    DSQ                                   
048518,000208: 13,2513           00023                                    SINTH                                 
048519,000209: 13,2514           63525                           PDDL     DSQ                                   
048520,000210: 13,2515           00021                                    COSTH                                 
048521,000211: 13,2516           77615                           DAD                                            
048522,000212: 13,2517           75454                           BZE      SQRT                                  
048523,000213: 13,2520           26536                                    ARCTANXX                              #  ATAN=0/0  SET THETA=0
048524,000214: 13,2521           40065                           BDDV     BOV                                   
048525,000215: 13,2522           00023                                    SINTH                                 
048526,000216: 13,2523           26543                                    ATAN=90                               
048527,000217: 13,2524           67542                           SR1      ASIN                                  
048528,000218: 13,2525           00025                           STORE    THETA                                 
048529,000219: 13,2526           50125                           PDDL     BMN                                   
048530,000220: 13,2527           00021                                    COSTH                                 
048531,000221: 13,2530           26532                                    NEGCOS                                
048532,000222: 13,2531           43545                           DLOAD    RVQ                                   
048533,000223: 13,2532           57545        NEGCOS             DLOAD    DCOMP                                 
048534,000224: 13,2533           43244                           BPL      DAD                                   
048535,000225: 13,2534           26540                                    NEGOUT                                
048536,000226: 13,2535           24005                                    DP1/2                                 
048537,000227: 13,2536           00025        ARCTANXX           STORE    THETA                                 
048538,000228: 13,2537           77616                           RVQ                                            
048539,000229: 
048540,000230: 13,2540           52025        NEGOUT             DSU      GOTO                                  
048541,000231: 13,2541           24005                                    DP1/2                                 
048542,000232: 13,2542           26536                                    ARCTANXX                              
048543,000233: 13,2543           75345        ATAN=90            DLOAD    SIGN                                  
048544,000234: 13,2544           11037                                    LODP1/4                               
048545,000235: 13,2545           00023                                    SINTH                                 
048546,000236: 13,2546           00025                           STORE    THETA                                 
048547,000237: 13,2547           77616                           RVQ                                            
048548,000238: 
048549,000239: 13,2550  12,2006               2DZERO             =        DPZERO                                
048550,000240: 

Page 1138

048552,000242:                                                                                                  #  ..... SETGAMMA SUBROUTINE .....
048553,000243:                                                                                                  #  SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
048554,000244: 
048555,000245:                                                                                                  #  GAMMA = B**2/A**2 FOR EARTH (B-1)
048556,000246:                                                                                                  #  GAMMA = 1 FOR MOON (B-1)
048557,000247: 
048558,000248:                                                                                                  #  CALLING SEQUENCE
048559,000249:                                                                                                  #        L       CALL
048560,000250:                                                                                                  #        L+1             SETGAMMA
048561,000251: 
048562,000252:                                                                                                  #  INPUT
048563,000253:                                                                                                  #        LUNAFLAG=0 FOR EARTH, =1 FOR MOON
048564,000254: 
048565,000255:                                                                                                  #  OUTPUT
048566,000256:                                                                                                  #        GAMMA IN GAMRP (B-1)
048567,000257: 
048568,000258: 13,2550           43145        SETGAMMA           DLOAD    BOFF                                  #  BRANCH FOR EARTH
048569,000259: 13,2551           26505                                    B2/A2                                 #  EARTH GAMMA
048570,000260: 13,2552           01743                                    LUNAFLAG                              
048571,000261: 13,2553           26556                                    SETGMEX                               
048572,000262: 13,2554           77735                           SLOAD                                          
048573,000263: 13,2555           24005                                    1B1                                   #  MOON GAMMA
048574,000264: 13,2556           00011        SETGMEX            STORE    GAMRP                                 
048575,000265: 13,2557           77616                           RVQ                                            
048576,000266: 13,2560                        GAMRP              =        8D                                    
048577,000267: 

Page 1139

048579,000269:                                                                                                  #  ..... SETRE SUBROUTINE .....
048580,000270:                                                                                                  #  SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
048581,000271: 
048582,000272:                                                                                                  #        RE = RM FOR MOON
048583,000273:                                                                                                  #        RE = RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
048584,000274: 
048585,000275:                                                                                                  #  CALLING SEQUENCE
048586,000276:                                                                                                  #        L       CALL
048587,000277:                                                                                                  #        L+1             SETRE
048588,000278: 
048589,000279:                                                                                                  #  SUBROUTINES USED
048590,000280:                                                                                                  #        GETERAD
048591,000281: 
048592,000282:                                                                                                  #  INPUT
048593,000283:                                                                                                  #        ERADFLAG = 0 FOR FIXED RE, 1 FOR COMPUTED RE
048594,000284:                                                                                                  #        ALPHAV +4 = 1/2 SINL IF GETERAD IS CALLED
048595,000285:                                                                                                  #        LUNAFLAG = 0 FOR EARTH, =1 FOR MOON
048596,000286: 
048597,000287:                                                                                                  #  OUTPUT
048598,000288:                                                                                                  #        ERADM = 504RM FOR MOON (METERS B-29)
048599,000289:                                                                                                  #        ERADM = ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
048600,000290: 
048601,000291: 13,2560           71220        SETRE              STQ      DLOAD                                 
048602,000292: 13,2561           00051                                    SETREX                                
048603,000293: 13,2562           10003                                    504RM                                 
048604,000294: 13,2563           71214                           BON      DLOAD                                 #  BRANCH FOR MOON
048605,000295: 13,2564           01703                                    LUNAFLAG                              
048606,000296: 13,2565           26575                                    TSTRLSRM                              
048607,000297: 13,2566           10001                                    ERAD                                  
048608,000298: 13,2567           45014                           BOFF     CALL                                  #  ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED
048609,000299: 13,2570           00742                                    ERADFLAG                              
048610,000300: 13,2571           26573                                    SETRXX                                
048611,000301: 13,2572           26466                                    GETERAD                               
048612,000302: 13,2573           37673        SETRXX             STCALL   ERADM                                 #  EXIT WITH RE OR RM METERS B-29
048613,000303: 13,2574           00051                                    SETREX                                
048614,000304: 13,2575           77214        TSTRLSRM           BON      VLOAD                                 #  ERADFLAG=0, SET R0=RLS
048615,000305: 13,2576           00702                                    ERADFLAG                              #          =1      R0=RM
048616,000306: 13,2577           26573                                    SETRXX                                
048617,000307: 13,2600           02023                                    RLS                                   
048618,000308: 13,2601           64446                           ABVAL    SR2R                                  #  SCALE FROM B-27 TO B-29
048619,000309: 13,2602           77650                           GOTO                                           
048620,000310: 13,2603           26573                                    SETRXX                                
048621,000311: 13,2604  0000051               SETREX             =        S2                                    
048622,000312: 
048623,000313: 

End of include-file LATITUDE_LONGITUDE_SUBROUTINES.agc.  Parent file is MAIN.agc