      SUBROUTINE YEARTH(RS,AS,DS,AY,DY,ASUN,DSUN,FLAG,ELV)              00010000
      REAL*8    RS,AS,DS,AY,DY,ASUN,DSUN,ELV                            00020000
      INTEGER   FLAG                                                    00030000
                                                                        00040000
C Y-AXIS NO HOUKOU GA CHIKYUU NI KAKUSARETEIRUKA ?                      00050000
C SARANI,  CHIKYUU NI KAKUSARETEIRUTOKINI, Y-AXIS NO MITEIRU            00051000
C CHIKYUU GA TAIYOU NI TERASARETEIRUKA DOUKA WO ATAERU.                 00060000
C ARGUMENTS:                                                            00070000
C  RS,AS,DS (IN): CHIKYUU CHUUSIN ZAHYOU DENO EISEI NO ICHI.            00080000
C                   RS(KM), AS(DEG), DS(DEG)                            00090000
C  AY,DY    (IN): Y-AXIS NO HOUKOU (DEG).                               00100000
C  ASUN,DSUN(IN): TAIYOU NO HOUKOU (DEG).                               00110000
C  FLAG    (OUT): 0, CHIKYUU NI KAKUSARETE INAI,                        00120000
C                 1, TAIYOU NI TERASARETE INAI CHIKYUU WO MITEIRU,      00130000
C                 2, TAIYOU NI TERASARETE IRU  CHIKYUU WO MITEIRU.      00140000
C  ELV     (OUT): ELVATION ANGLE OF Y-AXIS DIR. FROM THE EARTH EDGE.(D) 00141000
                                                                        00150000
      REAL*8    RE/6378.16/,RAD/1.74532959D-2/                          00160000
      REAL*8    A,D,AE,DE,X,Z,EU(3),EI(3),C                             00170000
                                                                        00180000
      CALL EURSET(AS,DS,AY,DY,EU)                                       00190000
      CALL ROTATE(EU,AY,DY,A,D)                                         00200000
      D=-D*RAD                                                          00210000
      A=ACOS(RE/RS)                                                     00211000
      ELV=(A-D)/RAD                                                     00212002
      IF(ELV.LE.-1.0D-10) THEN                                          00213007
        C=COS(D)                                                        00214007
        Z=RE*RE-RS*RS*C*C                                               00215007
        X=RS*SIN(2*D)/2-C*SQRT(Z)                                       00221005
        IF(X/RE.LT.1.0E-10) THEN                                        00231000
          D=90.0D0                                                      00233000
         ELSE                                                           00234000
          Z=RS-X*TAN(D)                                                 00240000
          D=ATAN(Z/X)/RAD                                               00250000
        ENDIF                                                           00251000
        A=0                                                             00260000
        CALL INVSET(EU,EI)                                              00270001
        CALL ROTATE(EI,A,D,AE,DE)                                       00280000
        CALL RIKAKU(ASUN,DSUN,AE,DE,D)                                  00290000
        IF(D.GT.90) THEN                                                00300000
          FLAG=1                                                        00310004
         ELSE                                                           00320000
          FLAG=2                                                        00330004
        ENDIF                                                           00340000
       ELSE                                                             00350000
        FLAG=0                                                          00360004
      ENDIF                                                             00370000
      RETURN                                                            00380000
      END                                                               00390000
