/*************************************
*                                    *
*    外枠システム  simlroud.c        *
*  （労働力人口〜雇用者推計）        *
*                                    *
*************************************/

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


void simlroud(void) {

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


  for ( nendo=ROUDYR+1; nendo<=KE+1; nendo++ ) {
    for ( sei=1; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
        roudr_c[nendo-STARTY][sei][nenrei] = roudr_c[nendo-1-STARTY][sei][nenrei] ;
        roudr_a_c[nendo-STARTY][sei][nenrei] = roudr_a_c[nendo-1-STARTY][sei][nenrei] ;
        syuwari_c[nendo-STARTY][sei][nenrei] = syuwari_c[nendo-1-STARTY][sei][nenrei] ;
        syuwari_a_c[nendo-STARTY][sei][nenrei] = syuwari_a_c[nendo-1-STARTY][sei][nenrei] ;
        syugyor_c[nendo-STARTY][sei][nenrei] = syugyor_c[nendo-1-STARTY][sei][nenrei] ;
        syugyor_a_c[nendo-STARTY][sei][nenrei] = syugyor_a_c[nendo-1-STARTY][sei][nenrei] ;
      }
    }
  }

  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        roudj_c[nendo-STARTY][sei][nenrei]
          = jinko_c[nendo-STARTY][sei][nenrei] * roudr_c[nendo-STARTY][sei][nenrei] ;
        syugyoj_c[nendo-STARTY][sei][nenrei]
          = roudj_c[nendo-STARTY][sei][nenrei] * syuwari_c[nendo-STARTY][sei][nenrei] ;
      }
      roudj_c[nendo-STARTY][2][nenrei]
        = roudj_c[nendo-STARTY][3][nenrei] + roudj_c[nendo-STARTY][4][nenrei] ;
      syugyoj_c[nendo-STARTY][2][nenrei]
        = syugyoj_c[nendo-STARTY][3][nenrei] + syugyoj_c[nendo-STARTY][4][nenrei] ;
      roudj_c[nendo-STARTY][0][nenrei]
        = roudj_c[nendo-STARTY][1][nenrei] + roudj_c[nendo-STARTY][2][nenrei] ;
      syugyoj_c[nendo-STARTY][0][nenrei]
        = syugyoj_c[nendo-STARTY][1][nenrei] + syugyoj_c[nendo-STARTY][2][nenrei] ;
    }
  }

    for ( sei=1; sei<=4; sei++ ) {
      for ( nenrei=16; nenrei<=100; nenrei++ ) {
        koyour_cho_c[KIJUN+1-STARTY][sei][nenrei] 
         = 1.0 / 5.0 * ( koyour_c[KIJUN-STARTY][sei][nenrei] / koyour_c[KIJUN-1-STARTY][sei][nenrei-1] 
              + koyour_c[KIJUN-1-STARTY][sei][nenrei] / koyour_c[KIJUN-2-STARTY][sei][nenrei-1] 
              + koyour_c[KIJUN-2-STARTY][sei][nenrei] / koyour_c[KIJUN-3-STARTY][sei][nenrei-1] 
              + koyour_c[KIJUN-3-STARTY][sei][nenrei] / koyour_c[KIJUN-4-STARTY][sei][nenrei-1] 
              + koyour_c[KIJUN-4-STARTY][sei][nenrei] / koyour_c[KIJUN-5-STARTY][sei][nenrei-1] ) ;
      }
    }
    for ( nendo=KIJUN+2; nendo<=KE+1; nendo++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        for ( nenrei=16; nenrei<=100; nenrei++ ) {
          if ( koyour_cho_c[KIJUN+1-STARTY][sei][nenrei] > 1.0 ) {
            koyour_cho_c[nendo-STARTY][sei][nenrei]
              = 1.0 + max( 0, ( koyour_cho_c[KIJUN+1-STARTY][sei][nenrei] - 1.0 )
                               * ( 5.0 - nendo + KIJUN + 1.0 ) / 5.0 ) ;
          }
          else {
            koyour_cho_c[nendo-STARTY][sei][nenrei] = koyour_cho_c[KIJUN+1-STARTY][sei][nenrei] ;
          }
        }
      }
    }

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

          if (( nenrei<=22 ) || ( nenrei-nendo+KIJUN <= 14 )) {
            koyour_c[nendo-STARTY][sei][nenrei] = koyour_c[nendo-1-STARTY][sei][nenrei] ;
          }
          else {
            koyour_c[nendo-STARTY][sei][nenrei]
              = koyour_c[nendo-1-STARTY][sei][nenrei-1] * koyour_cho_c[nendo-STARTY][sei][nenrei] ;
          }
          koyour_a_c[nendo-STARTY][sei][nenrei] = koyour_c[nendo-STARTY][sei][nenrei] ; 
        }
      }
    }

      for ( nendo=KIJUN+1; nendo<=KE+1; nendo++ ) {
        for ( nenrei=60; nenrei<=100; nenrei++ ) {
              if ( syugyor_c[nendo-STARTY][1][nenrei] > syugyor_a_c[nendo-STARTY][1][nenrei] ) {
                koyour_c[nendo-STARTY][1][nenrei]
                  = ( koyour_a_c[nendo-STARTY][1][nenrei] * syugyor_a_c[nendo-STARTY][1][nenrei]
                      + syugyor_c[nendo-STARTY][1][nenrei] - syugyor_a_c[nendo-STARTY][1][nenrei] )
                    / syugyor_c[nendo-STARTY][1][nenrei] ;
              }
        }
      }

  for ( nendo=STARTY+1; nendo<=KE+1; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        koyouj_c[0][nendo-STARTY][sei][nenrei]
          = syugyoj_c[nendo-STARTY][sei][nenrei] * koyour_c[nendo-STARTY][sei][nenrei] ;
      }
      koyouj_c[0][nendo-STARTY][2][nenrei]
        = koyouj_c[0][nendo-STARTY][3][nenrei] + koyouj_c[0][nendo-STARTY][4][nenrei] ;
      koyouj_c[0][nendo-STARTY][0][nenrei]
        = koyouj_c[0][nendo-STARTY][1][nenrei] + koyouj_c[0][nendo-STARTY][2][nenrei] ;
    }
  }


    for ( nendo=ROUDYR+1; nendo<=KE+1; nendo++ ) {
      tankor_all_c[2][nendo-STARTY] = tankor_all_c[2][nendo-1-STARTY] ;
      tankor_all_c[4][nendo-STARTY] = tankor_all_c[4][nendo-1-STARTY] ;
      tankor_all_c[5][nendo-STARTY] = tankor_all_c[5][nendo-1-STARTY] ;
      tankor_all_c[6][nendo-STARTY] = tankor_all_c[6][nendo-1-STARTY] ;
    }
    for ( nendo=KIJUN+1; nendo<=KE+1; nendo++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=100; nenrei++ ) {
          tankor_c[2][nendo-STARTY][sei][nenrei] = tankor_c[2][nendo-1-STARTY][sei][nenrei] ;
          tankor_c[3][nendo-STARTY][sei][nenrei] = tankor_c[3][nendo-1-STARTY][sei][nenrei] ;
        }
      }
    }

    for ( nendo=KIJUN-1; nendo<=KE+1; nendo++ ) {
      TMP = 0.0; TMQ = 0.0; TMR = 0.0;
      if ( nendo<=ROUDYR ) {
        for ( nenrei=15; nenrei<=79; nenrei++ ) {
          TMP += koyouj_c[0][nendo-STARTY][1][nenrei] * tankor_c[3][nendo-STARTY][1][nenrei] 
               + koyouj_c[0][nendo-STARTY][3][nenrei] * tankor_c[3][nendo-STARTY][3][nenrei]
               + koyouj_c[0][nendo-STARTY][4][nenrei] * tankor_c[3][nendo-STARTY][4][nenrei] ;
          TMQ += koyouj_c[0][nendo-STARTY][1][nenrei] 
               + koyouj_c[0][nendo-STARTY][3][nenrei]
               + koyouj_c[0][nendo-STARTY][4][nenrei] ;
        }
        if ( TMQ > 0.0 ) {
          TMR = TMP / TMQ ;
          tankor_cho_c[nendo-STARTY] = tankor_all_c[2][nendo-STARTY] / TMR ;  
        }
        else {
          tankor_cho_c[nendo-STARTY] = 0.0 ;
        }
      }
      else { 
        tankor_cho_c[nendo-STARTY] = tankor_cho_c[nendo-1-STARTY] ;  
      }
      for ( sei=1; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=100; nenrei++ ) {
          tankor_c[2][nendo-STARTY][sei][nenrei]
           = tankor_c[3][nendo-STARTY][sei][nenrei] * tankor_cho_c[nendo-STARTY] ;
          if ( tankor_c[2][nendo-STARTY][sei][nenrei] > 1.0 ) {
            tankor_c[2][nendo-STARTY][sei][nenrei] = 1.0 ;
          }
          tankor_c[1][nendo-STARTY][sei][nenrei] = 1.0 - tankor_c[2][nendo-STARTY][sei][nenrei] ;
        }
      }
    }

    for ( nendo=STARTY+1; nendo<=KE+1; nendo++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
          koyouj_c[1][nendo-STARTY][sei][nenrei]
           = koyouj_c[0][nendo-STARTY][sei][nenrei] * tankor_c[1][nendo-STARTY][sei][nenrei] ;
          koyouj_c[2][nendo-STARTY][sei][nenrei]
           = koyouj_c[0][nendo-STARTY][sei][nenrei] * tankor_c[2][nendo-STARTY][sei][nenrei] ;
          koyouj_c[4][nendo-STARTY][sei][nenrei]
           = koyouj_c[2][nendo-STARTY][sei][nenrei] * tankor_all_c[4][nendo-STARTY] ;
          koyouj_c[5][nendo-STARTY][sei][nenrei]
           = koyouj_c[2][nendo-STARTY][sei][nenrei] * tankor_all_c[5][nendo-STARTY] ;
          koyouj_c[6][nendo-STARTY][sei][nenrei]
           = koyouj_c[2][nendo-STARTY][sei][nenrei] * tankor_all_c[6][nendo-STARTY] ;
        }
        koyouj_c[1][nendo-STARTY][2][nenrei]
         = koyouj_c[1][nendo-STARTY][3][nenrei] + koyouj_c[1][nendo-STARTY][4][nenrei] ;
        koyouj_c[2][nendo-STARTY][2][nenrei]
         = koyouj_c[2][nendo-STARTY][3][nenrei] + koyouj_c[2][nendo-STARTY][4][nenrei] ;
        koyouj_c[4][nendo-STARTY][2][nenrei]
         = koyouj_c[4][nendo-STARTY][3][nenrei] + koyouj_c[4][nendo-STARTY][4][nenrei] ;
        koyouj_c[5][nendo-STARTY][2][nenrei]
         = koyouj_c[5][nendo-STARTY][3][nenrei] + koyouj_c[5][nendo-STARTY][4][nenrei] ;
        koyouj_c[6][nendo-STARTY][2][nenrei]
         = koyouj_c[6][nendo-STARTY][3][nenrei] + koyouj_c[6][nendo-STARTY][4][nenrei] ;
        koyouj_c[1][nendo-STARTY][0][nenrei]
         = koyouj_c[1][nendo-STARTY][1][nenrei] + koyouj_c[1][nendo-STARTY][2][nenrei] ;
        koyouj_c[2][nendo-STARTY][0][nenrei]
         = koyouj_c[2][nendo-STARTY][1][nenrei] + koyouj_c[2][nendo-STARTY][2][nenrei] ;
        koyouj_c[4][nendo-STARTY][0][nenrei]
         = koyouj_c[4][nendo-STARTY][1][nenrei] + koyouj_c[4][nendo-STARTY][2][nenrei] ;
        koyouj_c[5][nendo-STARTY][0][nenrei]
         = koyouj_c[5][nendo-STARTY][1][nenrei] + koyouj_c[5][nendo-STARTY][2][nenrei] ;
        koyouj_c[6][nendo-STARTY][0][nenrei]
         = koyouj_c[5][nendo-STARTY][1][nenrei] + koyouj_c[6][nendo-STARTY][2][nenrei] ;
      }
    }


  for ( nendo=STARTY+1; nendo<=KE+1; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=0; sei<=4; sei++ ) {
        jieigyoj_c[nendo-STARTY][sei][nenrei]
         = syugyoj_c[nendo-STARTY][sei][nenrei] - koyouj_c[0][nendo-STARTY][sei][nenrei] ;
      }
    }
  }

    for ( nendo=ROUDYR+1; nendo<=KE+1; nendo++ ) {
      for ( ii=1; ii<=9; ii++ ) {
        heikinh_c[ii][nendo-STARTY] = heikinh_c[ii][nendo-1-STARTY] ;
      }
    }

    for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
          soroudh_c[1][nendo-STARTY][sei][nenrei]
           = koyouj_c[1][nendo-STARTY][sei][nenrei] * heikinh_c[1][nendo-STARTY] ;
          soroudh_c[2][nendo-STARTY][sei][nenrei]
           = koyouj_c[2][nendo-STARTY][sei][nenrei] * heikinh_c[2][nendo-STARTY] ;
          soroudh_c[3][nendo-STARTY][sei][nenrei]
           = jieigyoj_c[nendo-STARTY][sei][nenrei] * heikinh_c[3][nendo-STARTY] ;
          soroudh_c[0][nendo-STARTY][sei][nenrei]
           = soroudh_c[1][nendo-STARTY][sei][nenrei] + soroudh_c[2][nendo-STARTY][sei][nenrei]
              + soroudh_c[3][nendo-STARTY][sei][nenrei] ;
        }
        for ( ii=0; ii<=3; ii++ ) {
          soroudh_c[ii][nendo-STARTY][2][nenrei]
            = soroudh_c[ii][nendo-STARTY][3][nenrei] + soroudh_c[ii][nendo-STARTY][4][nenrei] ;
          soroudh_c[ii][nendo-STARTY][0][nenrei]
            = soroudh_c[ii][nendo-STARTY][1][nenrei] + soroudh_c[ii][nendo-STARTY][2][nenrei] ;
        }
      }
    }


  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    if ( roudr_m[nendo-STARTY][1][30] <= 0.0 ) { 
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
          roudr_m[nendo-STARTY][sei][nenrei]
            = ( roudr_c[nendo-STARTY][sei][nenrei] + roudr_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
          if ( roudr_m[nendo-STARTY][sei][nenrei] > 1.0 ) { roudr_m[nendo-STARTY][sei][nenrei] = 1.0; }
          if ( roudr_m[nendo-STARTY][sei][nenrei] < 0.0 ) { roudr_m[nendo-STARTY][sei][nenrei] = 0.0; }
          roudr_a_m[nendo-STARTY][sei][nenrei]
            = ( roudr_a_c[nendo-STARTY][sei][nenrei] + roudr_a_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
          if ( roudr_a_m[nendo-STARTY][sei][nenrei] > 1.0 ) { roudr_a_m[nendo-STARTY][sei][nenrei] = 1.0; }
          if ( roudr_a_m[nendo-STARTY][sei][nenrei] < 0.0 ) { roudr_a_m[nendo-STARTY][sei][nenrei] = 0.0; }
          syuwari_m[nendo-STARTY][sei][nenrei] 
            = ( syuwari_c[nendo-STARTY][sei][nenrei] + syuwari_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
          if ( syuwari_m[nendo-STARTY][sei][nenrei] > 1.0 ) { syuwari_m[nendo-STARTY][sei][nenrei] = 1.0; }
          if ( syuwari_m[nendo-STARTY][sei][nenrei] < 0.0 ) { syuwari_m[nendo-STARTY][sei][nenrei] = 0.0; }
          syuwari_a_m[nendo-STARTY][sei][nenrei] 
            = ( syuwari_a_c[nendo-STARTY][sei][nenrei] + syuwari_a_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
          if ( syuwari_a_m[nendo-STARTY][sei][nenrei] > 1.0 ) { syuwari_a_m[nendo-STARTY][sei][nenrei] = 1.0; }
          if ( syuwari_a_m[nendo-STARTY][sei][nenrei] < 0.0 ) { syuwari_a_m[nendo-STARTY][sei][nenrei] = 0.0; }
          syugyor_m[nendo-STARTY][sei][nenrei]
            = ( syugyor_c[nendo-STARTY][sei][nenrei] + syugyor_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
          if ( syugyor_m[nendo-STARTY][sei][nenrei] > 1.0 ) { syugyor_m[nendo-STARTY][sei][nenrei] = 1.0; }
          if ( syugyor_m[nendo-STARTY][sei][nenrei] < 0.0 ) { syugyor_m[nendo-STARTY][sei][nenrei] = 0.0; }
          syugyor_a_m[nendo-STARTY][sei][nenrei]
            = ( syugyor_a_c[nendo-STARTY][sei][nenrei] + syugyor_a_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
          if ( syugyor_a_m[nendo-STARTY][sei][nenrei] > 1.0 ) { syugyor_a_m[nendo-STARTY][sei][nenrei] = 1.0; }
          if ( syugyor_a_m[nendo-STARTY][sei][nenrei] < 0.0 ) { syugyor_a_m[nendo-STARTY][sei][nenrei] = 0.0; }
        }
      }
    }
  }

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

        koyour_m[nendo-STARTY][sei][nenrei]
          = ( koyour_c[nendo-STARTY][sei][nenrei] + koyour_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
        if ( koyour_m[nendo-STARTY][sei][nenrei] > 1.0 ) { koyour_m[nendo-STARTY][sei][nenrei] = 1.0; }
        if ( koyour_m[nendo-STARTY][sei][nenrei] < 0.0 ) { koyour_m[nendo-STARTY][sei][nenrei] = 0.0; }
        koyour_a_m[nendo-STARTY][sei][nenrei]
          = ( koyour_a_c[nendo-STARTY][sei][nenrei] + koyour_a_c[nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
        if ( koyour_a_m[nendo-STARTY][sei][nenrei] > 1.0 ) { koyour_a_m[nendo-STARTY][sei][nenrei] = 1.0; }
        if ( koyour_a_m[nendo-STARTY][sei][nenrei] < 0.0 ) { koyour_a_m[nendo-STARTY][sei][nenrei] = 0.0; }
        tankor_m[2][nendo-STARTY][sei][nenrei]
          = ( tankor_c[2][nendo-STARTY][sei][nenrei] + tankor_c[2][nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
        if ( tankor_m[2][nendo-STARTY][sei][nenrei] > 1.0 ) { tankor_m[2][nendo-STARTY][sei][nenrei] = 1.0; }
        if ( tankor_m[2][nendo-STARTY][sei][nenrei] < 0.0 ) { tankor_m[2][nendo-STARTY][sei][nenrei] = 0.0; }
        tankor_m[3][nendo-STARTY][sei][nenrei]
          = ( tankor_c[3][nendo-STARTY][sei][nenrei] + tankor_c[3][nendo+1-STARTY][sei][nenrei] ) / 2.0 ;
        if ( tankor_m[3][nendo-STARTY][sei][nenrei] > 1.0 ) { tankor_m[3][nendo-STARTY][sei][nenrei] = 1.0; }
        if ( tankor_m[3][nendo-STARTY][sei][nenrei] < 0.0 ) { tankor_m[3][nendo-STARTY][sei][nenrei] = 0.0; }
        tankor_m[1][nendo-STARTY][sei][nenrei] = 1.0 - tankor_m[3][nendo-STARTY][sei][nenrei] ;

        if ( nendo>= KIJUN+1 ) {
          if (( sei== 1) && ( nenrei >= 60 )) {
            if ( syugyor_m[nendo-STARTY][sei][nenrei] > syugyor_a_m[nendo-STARTY][sei][nenrei] ) {
              koyour_m[nendo-STARTY][sei][nenrei]
                = ( koyour_a_m[nendo-STARTY][sei][nenrei] * syugyor_a_m[nendo-STARTY][sei][nenrei]
                    + syugyor_m[nendo-STARTY][sei][nenrei] - syugyor_a_m[nendo-STARTY][sei][nenrei] )
                  / syugyor_m[nendo-STARTY][sei][nenrei] ;
            }
          }
        }

      }
    }
  }




  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        roudj_m[nendo-STARTY][sei][nenrei]
          = jinko_m[nendo-STARTY][sei][nenrei] * roudr_m[nendo-STARTY][sei][nenrei] ;
        syugyoj_m[nendo-STARTY][sei][nenrei]
          = roudj_m[nendo-STARTY][sei][nenrei] * syuwari_m[nendo-STARTY][sei][nenrei] ;
        koyouj_m[0][nendo-STARTY][sei][nenrei]
          = syugyoj_m[nendo-STARTY][sei][nenrei] * koyour_m[nendo-STARTY][sei][nenrei] ;
      }
      roudj_m[nendo-STARTY][2][nenrei]
        = roudj_m[nendo-STARTY][3][nenrei] + roudj_m[nendo-STARTY][4][nenrei] ;
      syugyoj_m[nendo-STARTY][2][nenrei]
        = syugyoj_m[nendo-STARTY][3][nenrei] + syugyoj_m[nendo-STARTY][4][nenrei] ;
      koyouj_m[0][nendo-STARTY][2][nenrei]
        = koyouj_m[0][nendo-STARTY][3][nenrei] + koyouj_m[0][nendo-STARTY][4][nenrei] ;
      roudj_m[nendo-STARTY][0][nenrei]
        = roudj_m[nendo-STARTY][1][nenrei] + roudj_m[nendo-STARTY][2][nenrei] ;
      syugyoj_m[nendo-STARTY][0][nenrei]
        = syugyoj_m[nendo-STARTY][1][nenrei] + syugyoj_m[nendo-STARTY][2][nenrei] ;
      koyouj_m[0][nendo-STARTY][0][nenrei]
        = koyouj_m[0][nendo-STARTY][1][nenrei] + koyouj_m[0][nendo-STARTY][2][nenrei] ;
    }
  }


    for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
      tankor_all_m[2][nendo-STARTY]
        = ( tankor_all_c[2][nendo-STARTY] + tankor_all_c[2][nendo+1-STARTY] ) / 2.0 ;
      tankor_all_m[4][nendo-STARTY]
        = ( tankor_all_c[4][nendo-STARTY] + tankor_all_c[4][nendo+1-STARTY] ) / 2.0 ;
      tankor_all_m[5][nendo-STARTY]
        = ( tankor_all_c[5][nendo-STARTY] + tankor_all_c[5][nendo+1-STARTY] ) / 2.0 ;
      tankor_all_m[6][nendo-STARTY]
        = ( tankor_all_c[6][nendo-STARTY] + tankor_all_c[6][nendo+1-STARTY] ) / 2.0 ;
    }

    for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
      TMP = 0.0; TMQ = 0.0; TMR = 0.0;
      if ( nendo<=ROUDYR ) {
        for ( nenrei=15; nenrei<=79; nenrei++ ) {
          TMP += koyouj_m[0][nendo-STARTY][1][nenrei] * tankor_m[3][nendo-STARTY][1][nenrei] 
               + koyouj_m[0][nendo-STARTY][3][nenrei] * tankor_m[3][nendo-STARTY][3][nenrei] 
               + koyouj_m[0][nendo-STARTY][4][nenrei] * tankor_m[3][nendo-STARTY][4][nenrei] ;
          TMQ += koyouj_m[0][nendo-STARTY][1][nenrei] 
               + koyouj_m[0][nendo-STARTY][3][nenrei] 
               + koyouj_m[0][nendo-STARTY][4][nenrei] ;
        }
        TMR = TMP / TMQ ;
        tankor_cho_m[nendo-STARTY] = tankor_all_m[2][nendo-STARTY] / TMR ;  
      }
      else { 
        tankor_cho_m[nendo-STARTY] = tankor_cho_m[nendo-1-STARTY] ;  
      }
      for ( sei=1; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=100; nenrei++ ) {
          tankor_m[2][nendo-STARTY][sei][nenrei]
           = tankor_m[3][nendo-STARTY][sei][nenrei] * tankor_cho_m[nendo-STARTY] ;
          if ( tankor_m[2][nendo-STARTY][sei][nenrei] > 1.0 ) { tankor_m[2][nendo-STARTY][sei][nenrei] = 1.0; }
          if ( tankor_m[2][nendo-STARTY][sei][nenrei] < 0.0 ) { tankor_m[2][nendo-STARTY][sei][nenrei] = 0.0; }
          tankor_m[1][nendo-STARTY][sei][nenrei] = 1.0 - tankor_m[2][nendo-STARTY][sei][nenrei] ;
        }
      }
    }

    for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
          koyouj_m[1][nendo-STARTY][sei][nenrei]
           = koyouj_m[0][nendo-STARTY][sei][nenrei] * tankor_m[1][nendo-STARTY][sei][nenrei] ;
          koyouj_m[2][nendo-STARTY][sei][nenrei]
           = koyouj_m[0][nendo-STARTY][sei][nenrei] * tankor_m[2][nendo-STARTY][sei][nenrei] ;
          koyouj_m[4][nendo-STARTY][sei][nenrei]
           = koyouj_m[2][nendo-STARTY][sei][nenrei] * tankor_all_m[4][nendo-STARTY] ;
          koyouj_m[5][nendo-STARTY][sei][nenrei]
           = koyouj_m[2][nendo-STARTY][sei][nenrei] * tankor_all_m[5][nendo-STARTY] ;
          koyouj_m[6][nendo-STARTY][sei][nenrei]
           = koyouj_m[2][nendo-STARTY][sei][nenrei] * tankor_all_m[6][nendo-STARTY] ;
        }
        koyouj_m[1][nendo-STARTY][2][nenrei]
         = koyouj_m[1][nendo-STARTY][3][nenrei] + koyouj_m[1][nendo-STARTY][4][nenrei] ;
        koyouj_m[2][nendo-STARTY][2][nenrei]
         = koyouj_m[2][nendo-STARTY][3][nenrei] + koyouj_m[2][nendo-STARTY][4][nenrei] ;
        koyouj_m[4][nendo-STARTY][2][nenrei]
         = koyouj_m[4][nendo-STARTY][3][nenrei] + koyouj_m[4][nendo-STARTY][4][nenrei] ;
        koyouj_m[5][nendo-STARTY][2][nenrei]
         = koyouj_m[5][nendo-STARTY][3][nenrei] + koyouj_m[5][nendo-STARTY][4][nenrei] ;
        koyouj_m[6][nendo-STARTY][2][nenrei]
         = koyouj_m[6][nendo-STARTY][3][nenrei] + koyouj_m[6][nendo-STARTY][4][nenrei] ;
        koyouj_m[1][nendo-STARTY][0][nenrei]
         = koyouj_m[1][nendo-STARTY][1][nenrei] + koyouj_m[1][nendo-STARTY][2][nenrei] ;
        koyouj_m[2][nendo-STARTY][0][nenrei]
         = koyouj_m[2][nendo-STARTY][1][nenrei] + koyouj_m[2][nendo-STARTY][2][nenrei] ;
        koyouj_m[4][nendo-STARTY][0][nenrei]
         = koyouj_m[4][nendo-STARTY][1][nenrei] + koyouj_m[4][nendo-STARTY][2][nenrei] ;
        koyouj_m[5][nendo-STARTY][0][nenrei]
         = koyouj_m[5][nendo-STARTY][1][nenrei] + koyouj_m[5][nendo-STARTY][2][nenrei] ;
        koyouj_m[6][nendo-STARTY][0][nenrei]
         = koyouj_m[6][nendo-STARTY][1][nenrei] + koyouj_m[6][nendo-STARTY][2][nenrei] ;
      }
    }


  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=15; nenrei<=100; nenrei++ ) {
      for ( sei=0; sei<=4; sei++ ) {
        jieigyoj_m[nendo-STARTY][sei][nenrei]
         = syugyoj_m[nendo-STARTY][sei][nenrei] - koyouj_m[0][nendo-STARTY][sei][nenrei] ;
      }
    }
  }

    for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
      for ( ii=1; ii<=9; ii++ ) {
        heikinh_m[ii][nendo-STARTY]
          = ( heikinh_c[ii][nendo-STARTY] + heikinh_c[ii][nendo+1-STARTY] ) / 2.0 ;
      }
    }

    for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
      for ( nenrei=15; nenrei<=100; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
          soroudh_m[1][nendo-STARTY][sei][nenrei]
           = koyouj_m[1][nendo-STARTY][sei][nenrei] * heikinh_m[1][nendo-STARTY] ;
          soroudh_m[2][nendo-STARTY][sei][nenrei]
           = koyouj_m[2][nendo-STARTY][sei][nenrei] * heikinh_m[2][nendo-STARTY] ;
          soroudh_m[3][nendo-STARTY][sei][nenrei]
           = jieigyoj_m[nendo-STARTY][sei][nenrei] * heikinh_m[3][nendo-STARTY] ;
          soroudh_m[0][nendo-STARTY][sei][nenrei]
           = soroudh_m[1][nendo-STARTY][sei][nenrei] + soroudh_m[2][nendo-STARTY][sei][nenrei]
              + soroudh_m[3][nendo-STARTY][sei][nenrei] ;
        }
        for ( ii=0; ii<=3; ii++ ) {
          soroudh_m[ii][nendo-STARTY][2][nenrei]
            = soroudh_m[ii][nendo-STARTY][3][nenrei] + soroudh_m[ii][nendo-STARTY][4][nenrei] ;
          soroudh_m[ii][nendo-STARTY][0][nenrei]
            = soroudh_m[ii][nendo-STARTY][1][nenrei] + soroudh_m[ii][nendo-STARTY][2][nenrei] ;
        }
      }
    }

}

