/*************************************
*                                    *
*    外枠システム  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 ( nenrei=15; nenrei<=100; nenrei++ ) {
        TMP = 0.0; TMQ = 0.0;
        TMP = koyouj_c[1][nendo-STARTY][3][nenrei] * kounenteki_c[1][nendo-STARTY] 
            + koyouj_c[2][nendo-STARTY][3][nenrei] * kounenteki_c[2][nendo-STARTY] 
            + koyouj_c[3][nendo-STARTY][3][nenrei] * kounenteki_c[3][nendo-STARTY] 
            + koyouj_c[4][nendo-STARTY][3][nenrei] * kounenteki_c[4][nendo-STARTY] 
            + koyouj_c[5][nendo-STARTY][3][nenrei] * kounenteki_c[5][nendo-STARTY]
            + koyouj_c[6][nendo-STARTY][3][nenrei] * kounenteki_c[6][nendo-STARTY] ;
        TMQ = koyouj_c[1][nendo-STARTY][4][nenrei] * kounenteki_c[1][nendo-STARTY] 
            + koyouj_c[2][nendo-STARTY][4][nenrei] * kounenteki_c[2][nendo-STARTY] 
            + koyouj_c[3][nendo-STARTY][4][nenrei] * kounenteki_c[3][nendo-STARTY] 
            + koyouj_c[4][nendo-STARTY][4][nenrei] * kounenteki_c[4][nendo-STARTY] 
            + koyouj_c[5][nendo-STARTY][4][nenrei] * kounenteki_c[5][nendo-STARTY]
            + koyouj_c[6][nendo-STARTY][4][nenrei] * kounenteki_c[6][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[1][nendo-STARTY][3][nenrei] * kounenteki_m[1][nendo-STARTY] 
            + koyouj_m[2][nendo-STARTY][3][nenrei] * kounenteki_m[2][nendo-STARTY] 
            + koyouj_m[3][nendo-STARTY][3][nenrei] * kounenteki_m[3][nendo-STARTY] 
            + koyouj_m[4][nendo-STARTY][3][nenrei] * kounenteki_m[4][nendo-STARTY] 
            + koyouj_m[5][nendo-STARTY][3][nenrei] * kounenteki_m[5][nendo-STARTY]
            + koyouj_m[6][nendo-STARTY][3][nenrei] * kounenteki_m[6][nendo-STARTY] ;
        TMQ = koyouj_m[1][nendo-STARTY][4][nenrei] * kounenteki_m[1][nendo-STARTY] 
            + koyouj_m[2][nendo-STARTY][4][nenrei] * kounenteki_m[2][nendo-STARTY] 
            + koyouj_m[3][nendo-STARTY][4][nenrei] * kounenteki_m[3][nendo-STARTY] 
            + koyouj_m[4][nendo-STARTY][4][nenrei] * kounenteki_m[4][nendo-STARTY] 
            + koyouj_m[5][nendo-STARTY][4][nenrei] * kounenteki_m[5][nendo-STARTY]
            + koyouj_m[6][nendo-STARTY][4][nenrei] * kounenteki_m[6][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<=KIJUNMAP ; 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 );
          }
          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] ; 
          }
      }
    }
  }
  for ( nendo=KIJUNMAP+1; nendo<=KE; nendo++ ) {
    for ( sei=0; sei<=2; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
      	 partnin[nendo-STARTY][sei][nenrei][0][0] =  partnin[KIJUNMAP-STARTY][sei][nenrei][0][0] * (koyouj_m[4][nendo-STARTY][sei][nenrei]+koyouj_m[5][nendo-STARTY][sei][nenrei])
      	  											/ (koyouj_m[4][KIJUNMAP-STARTY][sei][nenrei]+koyouj_m[5][KIJUNMAP-STARTY][sei][nenrei]);  
      }
    }
  }
  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
        TMP = 0.0; TMQ = 0.0;TMR = 0.0;
        TMP = koyouj_m[4][nendo-STARTY][3][nenrei]+koyouj_m[5][nendo-STARTY][3][nenrei]; 
        TMQ = koyouj_m[4][nendo-STARTY][4][nenrei]+koyouj_m[5][nendo-STARTY][4][nenrei]; 
        if ( TMP + TMQ > 0.0 ) {
          partyuhaigr_m[nendo-STARTY][nenrei] = TMP / ( TMP + TMQ ) ;
        }
        else {
          partyuhaigr_m[nendo-STARTY][nenrei] = kouyuhaigr_m[nendo-STARTY][nenrei] ;
        }
        TMR = partyuhaigr_m[nendo-STARTY][nenrei];
        partnin[nendo-STARTY][3][nenrei][0][0] =  partnin[nendo-STARTY][2][nenrei][0][0] * TMR ;
        partnin[nendo-STARTY][4][nenrei][0][0] =  partnin[nendo-STARTY][2][nenrei][0][0] * ( 1.0 - TMR );
        partnin[nendo-STARTY][2][nenrei][0][0] =  partnin[nendo-STARTY][3][nenrei][0][0] + partnin[nendo-STARTY][4][nenrei][0][0];
        partnin[nendo-STARTY][0][nenrei][0][0] =  partnin[nendo-STARTY][1][nenrei][0][0] + partnin[nendo-STARTY][2][nenrei][0][0];
        
    }
  }




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

      for ( sei=1; sei<=2; sei++ ) {
          if ( nendo<=KIJUNMAP ) {
            TMP = 0.0; 
            TMP = koyouj_m[1][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
                + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY]
                + koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[3][nendo-STARTY] 
                + koyouj_m[4][nendo-STARTY][sei][nenrei] * kounenteki_m[4][nendo-STARTY]
                + koyouj_m[5][nendo-STARTY][sei][nenrei] * kounenteki_m[5][nendo-STARTY] 
                + koyouj_m[6][nendo-STARTY][sei][nenrei] * kounenteki_m[6][nendo-STARTY]   ;
            if ( TMP > 0.0 ) {
              kounen_cho[nendo-STARTY][sei][nenrei] = (kounen[nendo-STARTY][sei][nenrei]+partnin[nendo-STARTY][sei][nenrei][0][0]
              	+kyosai[1][nendo-STARTY][sei][nenrei]+kyosai[2][nendo-STARTY][sei][nenrei]+kyosai[3][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 {
              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] ;
              }
            }
          }
      }
      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=KIJUNMAP+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {

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

        kounen[nendo-STARTY][sei][nenrei] 
          = ( koyouj_m[1][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
               + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY]
               + koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[3][nendo-STARTY]
               + koyouj_m[4][nendo-STARTY][sei][nenrei] * kounenteki_m[4][nendo-STARTY]
               + koyouj_m[5][nendo-STARTY][sei][nenrei] * kounenteki_m[5][nendo-STARTY]
               + koyouj_m[6][nendo-STARTY][sei][nenrei] * kounenteki_m[6][nendo-STARTY] )
            * kounen_cho[nendo-STARTY][sei][nenrei] -partnin[nendo-STARTY][sei][nenrei][0][0]
            -kyosai[1][nendo-STARTY][sei][nenrei]-kyosai[2][nendo-STARTY][sei][nenrei]-kyosai[3][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[1][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] 
                    + koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY]
                    + koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[3][nendo-STARTY]
                    + koyouj_m[4][nendo-STARTY][sei][nenrei] * kounenteki_m[4][nendo-STARTY]
                    + koyouj_m[5][nendo-STARTY][sei][nenrei] * kounenteki_m[5][nendo-STARTY]
                    + koyouj_m[6][nendo-STARTY][sei][nenrei] * kounenteki_m[6][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[8][nendo-STARTY][sei][nenrei]
            = koyouj_m[1][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY]
                * kounen_cho[nendo-STARTY][sei][nenrei] ;
          koyouj_m[9][nendo-STARTY][sei][nenrei]
            = koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY]
                * kounen_cho[nendo-STARTY][sei][nenrei] ;
          koyouj_m[10][nendo-STARTY][sei][nenrei]
            = (koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[3][nendo-STARTY]+koyouj_m[4][nendo-STARTY][sei][nenrei] * kounenteki_m[4][nendo-STARTY]
           + koyouj_m[5][nendo-STARTY][sei][nenrei] * kounenteki_m[5][nendo-STARTY]+koyouj_m[6][nendo-STARTY][sei][nenrei] * kounenteki_m[6][nendo-STARTY])
                * kounen_cho[nendo-STARTY][sei][nenrei] ;
          koyouj_m[7][nendo-STARTY][sei][nenrei]
          	= koyouj_m[8][nendo-STARTY][sei][nenrei]+koyouj_m[9][nendo-STARTY][sei][nenrei]+koyouj_m[10][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] ;
      koyouj_m[9][nendo-STARTY][0][nenrei]
        = koyouj_m[9][nendo-STARTY][1][nenrei] + koyouj_m[9][nendo-STARTY][2][nenrei] ;
      koyouj_m[10][nendo-STARTY][0][nenrei]
        = koyouj_m[10][nendo-STARTY][1][nenrei] + koyouj_m[10][nendo-STARTY][2][nenrei] ;
    }
  }



  for ( nendo=KIJUNMAP+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 + KIJUNMAP <= 35 ) && ( nenrei <= 79 ) ) {
        rk_sen[nendo-STARTY][1][nenrei]
          = 1.0 / 5.0 * ( rk_sen[KIJUNMAP-STARTY][1][30] + rk_sen[KIJUNMAP-STARTY][1][31]
                           + rk_sen[KIJUNMAP-STARTY][1][32] + rk_sen[KIJUNMAP-STARTY][1][33]
                           + rk_sen[KIJUNMAP-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=KIJUNMAP+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=STARTY+1; nendo<=KIJUNMAP; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=0; sei<=4; sei++ ) {
		kikin[nendo-STARTY][sei][nenrei] = 0.0;
	  }
	}
   }



  for ( nendo=STARTY+1; nendo<=KIJUNMAP; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        TMP = 0.0; TMQ = 0.0;TMR = 0.0;
        TMP = koyouj_m[1][nendo-STARTY][sei][nenrei] * kounenteki_m[1][nendo-STARTY] ;
        TMQ = koyouj_m[2][nendo-STARTY][sei][nenrei] * kounenteki_m[2][nendo-STARTY] ;
        TMR = koyouj_m[3][nendo-STARTY][sei][nenrei] * kounenteki_m[3][nendo-STARTY]+koyouj_m[4][nendo-STARTY][sei][nenrei] * kounenteki_m[4][nendo-STARTY]
        	+koyouj_m[5][nendo-STARTY][sei][nenrei] * kounenteki_m[5][nendo-STARTY]+koyouj_m[6][nendo-STARTY][sei][nenrei] * kounenteki_m[6][nendo-STARTY] ;
        if ( TMP + TMQ + TMR> 0.0 ) {
          if ( nendo>=2002 ) { 
            koyouj_m[8][nendo-STARTY][sei][nenrei]
              = kounen[nendo-STARTY][sei][nenrei] * TMP / ( TMP + TMQ + TMR ) +kyosai[1][nendo-STARTY][sei][nenrei]+kyosai[2][nendo-STARTY][sei][nenrei]+kyosai[3][nendo-STARTY][sei][nenrei];
            koyouj_m[9][nendo-STARTY][sei][nenrei]
              = kounen[nendo-STARTY][sei][nenrei] * TMQ / ( TMP + TMQ + TMR ) ;
            koyouj_m[10][nendo-STARTY][sei][nenrei]
              = kounen[nendo-STARTY][sei][nenrei] * TMR / ( TMP + TMQ + TMR ) +partnin[nendo-STARTY][sei][nenrei][0][0];
            koyouj_m[7][nendo-STARTY][sei][nenrei] = koyouj_m[8][nendo-STARTY][sei][nenrei]+koyouj_m[9][nendo-STARTY][sei][nenrei]+koyouj_m[10][nendo-STARTY][sei][nenrei];
          }
          else { 
            koyouj_m[8][nendo-STARTY][sei][nenrei]
              = ( kounen[nendo-STARTY][sei][nenrei] + kyosai[7][nendo-STARTY][sei][nenrei] )
                  * TMP / ( TMP + TMQ + TMR ) +kyosai[1][nendo-STARTY][sei][nenrei]+kyosai[2][nendo-STARTY][sei][nenrei]+kyosai[3][nendo-STARTY][sei][nenrei];
            koyouj_m[9][nendo-STARTY][sei][nenrei]
              = ( kounen[nendo-STARTY][sei][nenrei] + kyosai[7][nendo-STARTY][sei][nenrei] )
                  * TMQ / ( TMP + TMQ + TMR ) ;
            koyouj_m[10][nendo-STARTY][sei][nenrei]
              = ( kounen[nendo-STARTY][sei][nenrei] + kyosai[7][nendo-STARTY][sei][nenrei] )
                  * TMR / ( TMP + TMQ + TMR ) +partnin[nendo-STARTY][sei][nenrei][0][0];
            koyouj_m[7][nendo-STARTY][sei][nenrei] = koyouj_m[8][nendo-STARTY][sei][nenrei]+koyouj_m[9][nendo-STARTY][sei][nenrei]+koyouj_m[10][nendo-STARTY][sei][nenrei];
          }
        }
        else {
          koyouj_m[7][nendo-STARTY][sei][nenrei] = 0.0 ;
          koyouj_m[8][nendo-STARTY][sei][nenrei] = 0.0 ;
          koyouj_m[9][nendo-STARTY][sei][nenrei] = 0.0 ;
          koyouj_m[10][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[9][nendo-STARTY][2][nenrei]
        = koyouj_m[9][nendo-STARTY][3][nenrei] + koyouj_m[9][nendo-STARTY][4][nenrei] ;
      koyouj_m[10][nendo-STARTY][2][nenrei]
        = koyouj_m[10][nendo-STARTY][3][nenrei] + koyouj_m[10][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] ;
      koyouj_m[9][nendo-STARTY][0][nenrei]
        = koyouj_m[9][nendo-STARTY][1][nenrei] + koyouj_m[9][nendo-STARTY][2][nenrei] ;
      koyouj_m[10][nendo-STARTY][0][nenrei]
        = koyouj_m[10][nendo-STARTY][1][nenrei] + koyouj_m[10][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++ ) {

        soroudh_m[6][nendo-STARTY][sei][nenrei]
          = koyouj_m[8][nendo-STARTY][sei][nenrei] * heikinh_m[1][nendo-STARTY] ; 
        soroudh_m[7][nendo-STARTY][sei][nenrei]
          = koyouj_m[9][nendo-STARTY][sei][nenrei] * heikinh_m[2][nendo-STARTY] ; 
        soroudh_m[8][nendo-STARTY][sei][nenrei]
          = koyouj_m[10][nendo-STARTY][sei][nenrei] * heikinh_m[8][nendo-STARTY] ; 
        soroudh_m[9][nendo-STARTY][sei][nenrei]
          = soroudh_m[6][nendo-STARTY][sei][nenrei] + soroudh_m[7][nendo-STARTY][sei][nenrei]+ soroudh_m[8][nendo-STARTY][sei][nenrei] ;
        if ( sei==0 ) {
       	 if( nenrei<=69 ) {
          TMP += koyouj_m[7][nendo-STARTY][0][nenrei] ;
          TMQ += soroudh_m[9][nendo-STARTY][0][nenrei] ;
         }
        }

      }
    }
    heikinh_m[10][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[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 ;
		koyouj_c[10][nendo-STARTY][sei][nenrei] 
          = ( koyouj_m[10][nendo-1-STARTY][sei][nenrei] + koyouj_m[10][nendo-STARTY][sei][nenrei] ) / 2.0 ;
        koyouj_c[7][nendo-STARTY][sei][nenrei]=koyouj_c[8][nendo-STARTY][sei][nenrei]+koyouj_c[9][nendo-STARTY][sei][nenrei]+koyouj_c[10][nendo-STARTY][sei][nenrei];
        soroudh_c[6][nendo-STARTY][sei][nenrei]
          = koyouj_c[8][nendo-STARTY][sei][nenrei] * heikinh_c[1][nendo-STARTY] ; 
        soroudh_c[7][nendo-STARTY][sei][nenrei]
          = koyouj_c[9][nendo-STARTY][sei][nenrei] * heikinh_c[2][nendo-STARTY] ; 
        soroudh_c[8][nendo-STARTY][sei][nenrei]
          = koyouj_c[10][nendo-STARTY][sei][nenrei] * heikinh_c[8][nendo-STARTY] ; 
        soroudh_c[9][nendo-STARTY][sei][nenrei]
          = soroudh_c[6][nendo-STARTY][sei][nenrei] + soroudh_c[7][nendo-STARTY][sei][nenrei]+ soroudh_c[8][nendo-STARTY][sei][nenrei] ;

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

      }
    }
    heikinh_c[10][nendo-STARTY] = TMQ / TMP ;

  }


  for ( nendo=KIJUNMAP+1; nendo<=KE; nendo++ ) {
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
	   if(HIHO74 == 70){
        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] ;
        }
	   }
	   else {
        if (( nenrei<=69 ) && ( nendo>=2002 )&& ( nendo<HIHO74YR )) {
          nigou[nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
        }
		else if(( nenrei<=HIHO74 ) && ( nendo>=HIHO74YR )){
          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] ;
        }
	   }
	   
      }
    }
  }
  
  

}

