/*************************************
*                                    *
*    外枠システム  simlkou.c         *
*  （厚生年金被保険者数）            *
*                                    *
*************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "set.h"
#include "cntl.h"
#include "file_open.h"


void simlkou(void) {

  double  TMP ;
  double  TMQ ;
  double  TMR ;
  int     ii  ;


  for ( nendo=ROUDYR+1; nendo<=KE+1; nendo++ ) {
    for ( ii=1; ii<=6; ii++ ) {
      kounenteki_c[ii][nendo-STARTY] = kounenteki_c[ii][nendo-1-STARTY] ;
    }
  }
  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( ii=1; ii<=6; ii++ ) {
      kounenteki_m[ii][nendo-STARTY]
       = ( kounenteki_c[ii][nendo-STARTY] + kounenteki_c[ii][nendo+1-STARTY] ) / 2.0 ;
    }
  }


  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( sei=1; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {

          koyouj_c[3][nendo-STARTY][sei][nenrei] = koyouj_c[1][nendo-STARTY][sei][nenrei] ;
          koyouj_m[3][nendo-STARTY][sei][nenrei] = koyouj_m[1][nendo-STARTY][sei][nenrei] ;

          for ( seido=1; seido<=3; seido++ ) {
            koyouj_c[3][nendo-STARTY][sei][nenrei]
              -= ( kyosai[seido][nendo-1-STARTY][sei][nenrei]
                    + kyosai[seido][nendo-STARTY][sei][nenrei] ) / 2.0 ;
            koyouj_m[3][nendo-STARTY][sei][nenrei] -= kyosai[seido][nendo-STARTY][sei][nenrei] ;
          }

          if ( nendo <= 2001 ) {
            if ( koyouj_m[1][nendo-STARTY][2][nenrei] > 0.0 ) {
              kyosai[7][nendo-STARTY][3][nenrei] = kyosai[7][nendo-STARTY][2][nenrei]
                * koyouj_m[1][nendo-STARTY][3][nenrei] / koyouj_m[1][nendo-STARTY][2][nenrei] ;
              kyosai[7][nendo-STARTY][4][nenrei] = kyosai[7][nendo-STARTY][2][nenrei]
                * koyouj_m[1][nendo-STARTY][4][nenrei] / koyouj_m[1][nendo-STARTY][2][nenrei] ;
            }
            koyouj_c[3][nendo-STARTY][sei][nenrei]
              -= ( kyosai[7][nendo-1-STARTY][sei][nenrei]
                    + kyosai[7][nendo-STARTY][sei][nenrei] ) / 2.0 ;
            koyouj_m[3][nendo-STARTY][sei][nenrei] -= kyosai[7][nendo-STARTY][sei][nenrei] ;
          }

      }
    }
  }



  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
        TMP = 0.0; TMQ = 0.0;
        TMP = koyouj_c[3][nendo-STARTY][3][nenrei] * kounenteki_c[1][nendo-STARTY] 
            + koyouj_c[2][nendo-STARTY][3][nenrei] * kounenteki_c[2][nendo-STARTY] ; 
        TMQ = koyouj_c[3][nendo-STARTY][4][nenrei] * kounenteki_c[1][nendo-STARTY] 
            + koyouj_c[2][nendo-STARTY][4][nenrei] * kounenteki_c[2][nendo-STARTY] ; 
        if ( TMP + TMQ > 0.0 ) {
          kouyuhaigr_c[nendo-STARTY][nenrei] = TMP / ( TMP + TMQ ) ;
        }
        else {
          kouyuhaigr_c[nendo-STARTY][nenrei] = yuhaigr_c[nendo-STARTY][nenrei] ;
        }
        TMP = 0.0; TMQ = 0.0;
        TMP = koyouj_m[3][nendo-STARTY][3][nenrei] * kounenteki_m[1][nendo-STARTY] 
            + koyouj_m[2][nendo-STARTY][3][nenrei] * kounenteki_m[2][nendo-STARTY] ; 
        TMQ = koyouj_m[3][nendo-STARTY][4][nenrei] * kounenteki_m[1][nendo-STARTY] 
            + koyouj_m[2][nendo-STARTY][4][nenrei] * kounenteki_m[2][nendo-STARTY] ; 
        if ( TMP + TMQ > 0.0 ) {
          kouyuhaigr_m[nendo-STARTY][nenrei] = TMP / ( TMP + TMQ ) ;
        }
        else {
          kouyuhaigr_m[nendo-STARTY][nenrei] = yuhaigr_m[nendo-STARTY][nenrei] ;
        }
    }
  }


  for ( nendo=STARTY+1; nendo<=KIJUN ; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {

          TMR = kouyuhaigr_m[nendo-STARTY][nenrei] ; 
          qkou12syu[nendo-STARTY][3][nenrei] = qkou12syu[nendo-STARTY][2][nenrei] * TMR ;
          qkou12syu[nendo-STARTY][4][nenrei] = qkou12syu[nendo-STARTY][2][nenrei] * ( 1.0 - TMR );
          for ( ii=4; ii<=6; ii++ ) { 
            kyosai[ii][nendo-STARTY][3][nenrei] = kyosai[ii][nendo-STARTY][2][nenrei] * TMR ;
            kyosai[ii][nendo-STARTY][4][nenrei] = kyosai[ii][nendo-STARTY][2][nenrei] * ( 1.0 - TMR );
          }
          kikin[nendo-STARTY][3][nenrei] = kikin[nendo-STARTY][2][nenrei] * TMR ;
          kikin[nendo-STARTY][4][nenrei] = kikin[nendo-STARTY][2][nenrei] * ( 1.0 - TMR ) ;
          if ( nendo>= 2002 ) {  
            kyosai[7][nendo-STARTY][3][nenrei] = kyosai[7][nendo-STARTY][2][nenrei] * TMR ;
            kyosai[7][nendo-STARTY][4][nenrei] = kyosai[7][nendo-STARTY][2][nenrei] * ( 1.0 - TMR );
          }
          if (( nenrei>=20 ) && ( nenrei<=59 )) {
            if ( qkou12syu[nendo-STARTY][1][nenrei] > 0.0 ) {
              TMP = qkou12syu3[nendo-STARTY][2][nenrei] ;
              kou3syu3[nendo-STARTY][2][nenrei] = TMP * kou3syu[nendo-STARTY][1][nenrei]
                / ( qkou12syu[nendo-STARTY][1][nenrei] + kou3syu[nendo-STARTY][1][nenrei] ) ;
              qkou12syu3[nendo-STARTY][2][nenrei] = TMP * qkou12syu[nendo-STARTY][1][nenrei]
                / ( qkou12syu[nendo-STARTY][1][nenrei] + kou3syu[nendo-STARTY][1][nenrei] ) ;
            }
            qkou12syu3[nendo-STARTY][0][nenrei]
             = qkou12syu3[nendo-STARTY][1][nenrei] + qkou12syu3[nendo-STARTY][2][nenrei] ;
            kou3syu3[nendo-STARTY][0][nenrei] = kou3syu3[nendo-STARTY][2][nenrei] ;
          }
          qkou12syu3[nendo-STARTY][3][nenrei] = qkou12syu3[nendo-STARTY][2][nenrei] ;
          qkou12syu3[nendo-STARTY][4][nenrei] = 0.0 ;
          kou3syu3[nendo-STARTY][3][nenrei] = kou3syu3[nendo-STARTY][2][nenrei] ;
          kou3syu3[nendo-STARTY][4][nenrei] = 0.0 ;
          for ( ii=1; ii<=7; ii++ ) { 
            kyosai3[ii][nendo-STARTY][3][nenrei] = kyosai3[ii][nendo-STARTY][2][nenrei] ;
            kyosai3[ii][nendo-STARTY][4][nenrei] = 0.0 ;
          }

      for ( sei=0; sei<=4; sei++ ) {

          kou12syu[nendo-STARTY][sei][nenrei] = qkou12syu[nendo-STARTY][sei][nenrei] ;
          kou12syu3[nendo-STARTY][sei][nenrei] = qkou12syu3[nendo-STARTY][sei][nenrei] ;
          for ( seido=4; seido<=6; seido++ ) { 
              kou12syu[nendo-STARTY][sei][nenrei] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
              kou12syu3[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
          if ( nendo >= 2002 ) { 
              kou12syu[nendo-STARTY][sei][nenrei] += kyosai[7][nendo-STARTY][sei][nenrei] ;
              kou12syu3[nendo-STARTY][sei][nenrei] += kyosai3[7][nendo-STARTY][sei][nenrei] ;
          }
          kounen[nendo-STARTY][sei][nenrei]
           = kou12syu[nendo-STARTY][sei][nenrei] + kou3syu[nendo-STARTY][sei][nenrei] ;
          qkounen[nendo-STARTY][sei][nenrei]
           = qkou12syu[nendo-STARTY][sei][nenrei] + kou3syu[nendo-STARTY][sei][nenrei] ;
          kounen3[nendo-STARTY][sei][nenrei] 
           = kou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] ;
          qkounen3[nendo-STARTY][sei][nenrei]
           = qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] ;

          if ( nenrei <= 69 ) { 
              nigou[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
          }
          sangou[nendo-STARTY][sei][nenrei] = kounen3[nendo-STARTY][sei][nenrei]  ;
          for ( seido=1; seido<=3; seido++ ) {  
              nigou[nendo-STARTY][sei][nenrei] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
              sangou[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
          if ( nendo <= 2001 ) { 
              nigou[nendo-STARTY][sei][nenrei] += kyosai[7][nendo-STARTY][sei][nenrei] ;
              sangou[nendo-STARTY][sei][nenrei] += kyosai3[7][nendo-STARTY][sei][nenrei] ;
          }

          if ( kounen[nendo-STARTY][sei][nenrei] > 0 ) {
              rk_sen[nendo-STARTY][sei][nenrei]
                = kou3syu[nendo-STARTY][sei][nenrei] / kounen[nendo-STARTY][sei][nenrei] ; 
          }
          if ( kou12syu[nendo-STARTY][sei][nenrei] > 0 ) {
              rk_kikin[nendo-STARTY][sei][nenrei]
                = kikin[nendo-STARTY][sei][nenrei] / kou12syu[nendo-STARTY][sei][nenrei] ; 
          }

      }
    }
  }


  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {

      for ( sei=1; sei<=2; sei++ ) {
          if ( nendo<=KIJUN ) {
            TMP = 0.0; 
            TMP = koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
                + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY] ;
            if ( TMP > 0.0 ) {
              kounen_cho[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] / TMP ;
            }
            else {
              kounen_cho[nendo-STARTY][sei][nenrei] = 0.0 ;
            }
          }
          else {
            if ( nenrei <= 69 ) { 
              kounen_cho[nendo-STARTY][sei][nenrei] = kounen_cho[nendo-1-STARTY][sei][nenrei] ;
            }
            else if ( nenrei <= 75 ) { 
              kounen_cho[nendo-STARTY][sei][nenrei] = kounen_cho[nendo-1-STARTY][sei][nenrei] ;
              if ( ( kounen_cho[nendo-1-STARTY][sei][nenrei-1] > 0.0 ) &&
                     ( kounen_cho[nendo-1-STARTY][sei][nenrei-1] < kounen_cho[nendo-1-STARTY][sei][nenrei] ) ){
                kounen_cho[nendo-STARTY][sei][nenrei] = kounen_cho[nendo-1-STARTY][sei][nenrei-1] ;
              }
            }
            else if ( ( nenrei <= 79 ) && ( nenrei - nendo + KIJUN <= 75 ) ) {
              kounen_cho[nendo-STARTY][sei][nenrei] = kounen_cho[nendo-1-STARTY][sei][nenrei-1] ;
              if ( ( kounen_cho[nendo-1-STARTY][sei][nenrei] > 0.0 ) &&
                     ( kounen_cho[nendo-1-STARTY][sei][nenrei] < kounen_cho[nendo-1-STARTY][sei][nenrei-1] ) ){
                kounen_cho[nendo-STARTY][sei][nenrei] = kounen_cho[nendo-1-STARTY][sei][nenrei] ;
              }
            }
          }
      }
      kounen_cho[nendo-STARTY][3][nenrei] = kounen_cho[nendo-STARTY][2][nenrei] ;
      kounen_cho[nendo-STARTY][4][nenrei] = kounen_cho[nendo-STARTY][2][nenrei] ;
    }
  }


  for ( nendo=KIJUN+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {

      for ( sei=1; sei<=4; sei++ ) {

        kounen[nendo-STARTY][sei][nenrei] 
          = ( koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
               + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY] )
            * kounen_cho[nendo-STARTY][sei][nenrei] ;

        if ( ( nenrei>=70 ) && ( sei<=2 ) ) {
          if ( kounen[nendo-STARTY][sei][nenrei] > kounen[nendo-1-STARTY][sei][nenrei-1] * 0.98 )  { 
            kounen[nendo-STARTY][sei][nenrei] = kounen[nendo-1-STARTY][sei][nenrei-1] * 0.98 ; 
            kounen_cho[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] 
                / ( koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
                    + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY] ) ;
            if ( sei==2 ) { 
              kounen_cho[nendo-STARTY][3][nenrei] = kounen_cho[nendo-STARTY][2][nenrei] ;
              kounen_cho[nendo-STARTY][4][nenrei] = kounen_cho[nendo-STARTY][2][nenrei] ;
            }
          }
        }

        if ( nenrei<=69 ) {
          koyouj_m[7][nendo-STARTY][sei][nenrei]
            = koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY]
                * kounen_cho[nendo-STARTY][sei][nenrei] ;
          koyouj_m[8][nendo-STARTY][sei][nenrei]
            = koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY]
                * kounen_cho[nendo-STARTY][sei][nenrei] ;
        }

      }
      kounen[nendo-STARTY][0][nenrei]
        = kounen[nendo-STARTY][1][nenrei] + kounen[nendo-STARTY][2][nenrei] ;
      koyouj_m[7][nendo-STARTY][0][nenrei]
        = koyouj_m[7][nendo-STARTY][1][nenrei] + koyouj_m[7][nendo-STARTY][2][nenrei] ;
      koyouj_m[8][nendo-STARTY][0][nenrei]
        = koyouj_m[8][nendo-STARTY][1][nenrei] + koyouj_m[8][nendo-STARTY][2][nenrei] ;
    }
  }


  if ( KIJUN > 2007 ) {
    for ( nendo=2007; nendo<=KIJUN-1; nendo++ ) {
      for ( nenrei=70; nenrei<=79; nenrei++ ) {

        if ( nenrei - nendo + 2007 <= 70 ) { 

          for ( sei=1; sei<=4; sei++ ) {

            TMP = 0.0;
            TMP = koyouj_m[3][KIJUN-STARTY][sei][nenrei] * kounenteki_m[1][KIJUN-STARTY] 
                  + koyouj_m[2][KIJUN-STARTY][sei][nenrei] * kounenteki_m[2][KIJUN-STARTY] ;
            if ( ( TMP > 0.0 ) && ( qkounen[nendo-STARTY][sei][nenrei] <= 0.0 ) ) {
                kounen[nendo-STARTY][sei][nenrei] 
                  = kounen[KIJUN-STARTY][sei][nenrei] 
                    * ( koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
                        + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY] )
                    / TMP ;
                 qkou12syu[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                kou12syu[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                qkounen[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                kounen[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
            }

          }
          kounen[nendo-STARTY][2][nenrei]
            = kounen[nendo-STARTY][3][nenrei] + kounen[nendo-STARTY][4][nenrei] ;
          qkou12syu[nendo-STARTY][2][nenrei] = kounen[nendo-STARTY][2][nenrei] ;
          kou12syu[nendo-STARTY][2][nenrei] = kounen[nendo-STARTY][2][nenrei] ;
          qkounen[nendo-STARTY][2][nenrei] = kounen[nendo-STARTY][2][nenrei] ;
          kounen[nendo-STARTY][2][nenrei] = kounen[nendo-STARTY][2][nenrei] ;
          kounen[nendo-STARTY][0][nenrei]
            = kounen[nendo-STARTY][1][nenrei] + kounen[nendo-STARTY][2][nenrei] ;
          qkou12syu[nendo-STARTY][0][nenrei] = kounen[nendo-STARTY][0][nenrei] ;
          kou12syu[nendo-STARTY][0][nenrei] = kounen[nendo-STARTY][0][nenrei] ;
          qkounen[nendo-STARTY][0][nenrei] = kounen[nendo-STARTY][0][nenrei] ;
          kounen[nendo-STARTY][0][nenrei] = kounen[nendo-STARTY][0][nenrei] ;

        }
      }
    }
  }



  for ( nendo=KIJUN+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {

      if ( nenrei<=34 ) {
        rk_sen[nendo-STARTY][1][nenrei] = rk_sen[nendo-1-STARTY][1][nenrei] ;
      }
      else if ( ( nenrei - nendo + KIJUN <= 35 ) && ( nenrei <= 79 ) ) {
        rk_sen[nendo-STARTY][1][nenrei]
          = 1.0 / 5.0 * ( rk_sen[KIJUN-STARTY][1][30] + rk_sen[KIJUN-STARTY][1][31]
                           + rk_sen[KIJUN-STARTY][1][32] + rk_sen[KIJUN-STARTY][1][33]
                           + rk_sen[KIJUN-STARTY][1][34] ) ;
      }
      else if ( nenrei<=79 ) {
        rk_sen[nendo-STARTY][1][nenrei] = rk_sen[nendo-1-STARTY][1][nenrei-1] ;
      }
      else {
        rk_sen[nendo-STARTY][1][nenrei] = 0.0 ;
      }
      for ( sei=2; sei<=4; sei++ ) {
        rk_sen[nendo-STARTY][sei][nenrei] = 0.0 ;
      }

    }
  }


  for ( nendo=KIJUN+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        kou3syu[nendo-STARTY][sei][nenrei]
          = kounen[nendo-STARTY][sei][nenrei] * rk_sen[nendo-STARTY][sei][nenrei] ;
        kou12syu[nendo-STARTY][sei][nenrei]
          = kounen[nendo-STARTY][sei][nenrei] - kou3syu[nendo-STARTY][sei][nenrei] ;
      }
      kou3syu[nendo-STARTY][0][nenrei]
        = kou3syu[nendo-STARTY][1][nenrei] + kou3syu[nendo-STARTY][2][nenrei] ;
      kou12syu[nendo-STARTY][0][nenrei]
        = kou12syu[nendo-STARTY][1][nenrei] + kou12syu[nendo-STARTY][2][nenrei] ;
    }
  }


  for ( nendo=KIJUN+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {

        rk_kikin[nendo-STARTY][sei][nenrei] = rk_kikin[KIJUN-STARTY][sei][nenrei] ;
        kikin[nendo-STARTY][sei][nenrei]
          = kou12syu[nendo-STARTY][sei][nenrei] * rk_kikin[nendo-STARTY][sei][nenrei] ;

      }
      kikin[nendo-STARTY][0][nenrei]
        = kikin[nendo-STARTY][1][nenrei] + kikin[nendo-STARTY][2][nenrei] ;

    }
  }



  for ( nendo=STARTY+1; nendo<=KIJUN; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        TMP = 0.0; TMQ = 0.0;
        TMP = koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] ;
        TMQ = koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY] ;
        if ( TMP + TMQ > 0.0 ) {
          if ( nendo>=2002 ) { 
            koyouj_m[7][nendo-STARTY][sei][nenrei]
              = kounen[nendo-STARTY][sei][nenrei] * TMP / ( TMP + TMQ ) ;
            koyouj_m[8][nendo-STARTY][sei][nenrei]
              = kounen[nendo-STARTY][sei][nenrei] * TMQ / ( TMP + TMQ ) ;
          }
          else { 
            koyouj_m[7][nendo-STARTY][sei][nenrei]
              = ( kounen[nendo-STARTY][sei][nenrei] + kyosai[7][nendo-STARTY][sei][nenrei] )
                  * TMP / ( TMP + TMQ ) ;
            koyouj_m[8][nendo-STARTY][sei][nenrei]
              = ( kounen[nendo-STARTY][sei][nenrei] + kyosai[7][nendo-STARTY][sei][nenrei] )
                  * TMQ / ( TMP + TMQ ) ;
          }
        }
        else {
          koyouj_m[7][nendo-STARTY][sei][nenrei] = 0.0 ;
          koyouj_m[8][nendo-STARTY][sei][nenrei] = 0.0 ;
        }
      }
      koyouj_m[7][nendo-STARTY][2][nenrei]
        = koyouj_m[7][nendo-STARTY][3][nenrei] + koyouj_m[7][nendo-STARTY][4][nenrei] ;
      koyouj_m[8][nendo-STARTY][2][nenrei]
        = koyouj_m[8][nendo-STARTY][3][nenrei] + koyouj_m[8][nendo-STARTY][4][nenrei] ;
      koyouj_m[7][nendo-STARTY][0][nenrei]
        = koyouj_m[7][nendo-STARTY][1][nenrei] + koyouj_m[7][nendo-STARTY][2][nenrei] ;
      koyouj_m[8][nendo-STARTY][0][nenrei]
        = koyouj_m[8][nendo-STARTY][1][nenrei] + koyouj_m[8][nendo-STARTY][2][nenrei] ;
    }
  }


  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    TMP = 0.0; TMQ = 0.0;
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {

        for ( seido=1; seido<=3; seido++ ) {
          koyouj_m[7][nendo-STARTY][sei][nenrei] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
        }
        koyouj_m[9][nendo-STARTY][sei][nenrei] 
          = koyouj_m[7][nendo-STARTY][sei][nenrei] + koyouj_m[8][nendo-STARTY][sei][nenrei] ;
        soroudh_m[7][nendo-STARTY][sei][nenrei]
          = koyouj_m[7][nendo-STARTY][sei][nenrei] * heikinh_m[1][nendo-STARTY] ; 
        soroudh_m[8][nendo-STARTY][sei][nenrei]
          = koyouj_m[8][nendo-STARTY][sei][nenrei] * heikinh_m[8][nendo-STARTY] ; 
        soroudh_m[9][nendo-STARTY][sei][nenrei]
          = soroudh_m[7][nendo-STARTY][sei][nenrei] + soroudh_m[8][nendo-STARTY][sei][nenrei] ;

        if ( sei==0 ) {
          TMP += koyouj_m[9][nendo-STARTY][0][nenrei] ;
          TMQ += soroudh_m[9][nendo-STARTY][0][nenrei] ;
        }

      }
    }
    heikinh_m[9][nendo-STARTY] = TMQ / TMP ;

  }


  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    TMP = 0.0; TMQ = 0.0;
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {

        koyouj_c[7][nendo-STARTY][sei][nenrei] 
          = ( koyouj_m[7][nendo-1-STARTY][sei][nenrei] + koyouj_m[7][nendo-STARTY][sei][nenrei] ) / 2.0 ;
        koyouj_c[8][nendo-STARTY][sei][nenrei] 
          = ( koyouj_m[8][nendo-1-STARTY][sei][nenrei] + koyouj_m[8][nendo-STARTY][sei][nenrei] ) / 2.0 ;
        koyouj_c[9][nendo-STARTY][sei][nenrei] 
          = ( koyouj_m[9][nendo-1-STARTY][sei][nenrei] + koyouj_m[9][nendo-STARTY][sei][nenrei] ) / 2.0 ;

        soroudh_c[7][nendo-STARTY][sei][nenrei]
          = koyouj_c[7][nendo-STARTY][sei][nenrei] * heikinh_c[1][nendo-STARTY] ; 
        soroudh_c[8][nendo-STARTY][sei][nenrei]
          = koyouj_c[8][nendo-STARTY][sei][nenrei] * heikinh_c[8][nendo-STARTY] ; 
        soroudh_c[9][nendo-STARTY][sei][nenrei]
          = soroudh_c[7][nendo-STARTY][sei][nenrei] + soroudh_c[8][nendo-STARTY][sei][nenrei] ;

        if ( sei==0 ) {
          TMP += koyouj_c[9][nendo-STARTY][0][nenrei] ;
          TMQ += soroudh_c[9][nendo-STARTY][0][nenrei] ;
        }

      }
    }

    heikinh_c[9][nendo-STARTY] = TMQ / TMP ;

  }


  for ( nendo=KIJUN+1; nendo<=KE; nendo++ ) {
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {

        if (( nenrei<=69 ) && ( nendo>=2002 )) {
          nigou[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
        }
        else if (( nenrei<=69 ) && ( nendo<=2001 )) {
          nigou[nendo-STARTY][sei][nenrei]
            = kounen[nendo-STARTY][sei][nenrei] + kyosai[7][nendo-STARTY][sei][nenrei] ;
        }
        else {
          nigou[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        for ( seido=1; seido<=3; seido++ ) {
          nigou[nendo-STARTY][sei][nenrei] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
        }

      }
    }
  }



}

