/*************************************
*                                    *
*    外枠システム  cutout.c          *
*  （カット率ファイルの作成、出力）  *
*                                    *
*************************************/

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

void cutout(void) 
{

/*  変数定義  */
char    filename[250]    ; 
int     XEND    ;  
int     CNENDO  ;  
double  JYUMYO  ;  
double  kouteki[ENDY-STARTY+1][2]        ; 
double  kouteki_cent[ENDY-STARTY+1][2]   ; 
double  cutritu1[ENDY-STARTY+1]       ; 
double  cutritu1_cent[ENDY-STARTY+1]  ; 
double  cutritu2[ENDY-STARTY+1]       ; 
double  cutritu2_cent[ENDY-STARTY+1]  ; 
double  cutritu3[ENDY-STARTY+1]       ; 
double  cutritu3_cent[ENDY-STARTY+1]  ; 
double  TMP[ENDY-STARTY+1][4] ; 
double  TMQ[ENDY-STARTY+1][4] ; 
int     TMPEND ;
int     TMQEND ;


/*  ファイル名セットと開く  */
    sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-m.csv", BANGO, BANGO) ;
    if ((fp_cutout = fopen(filename, "w")) == NULL) {
         fprintf(stderr, "出力cutファイルを開けません!\n");
         exit (2); /* 終了 */
    }


  CNENDO = 2005   ;
  JYUMYO = 0.997  ;

/*  ゼロ設定  */
  for ( nendo=STARTY; nendo<=ENDY; nendo++ ) {
    cutritu1[nendo-STARTY] = 0.0 ;
    cutritu1_cent[nendo-STARTY] = 0.0 ;
    cutritu2[nendo-STARTY] = 0.0 ;
    cutritu2_cent[nendo-STARTY] = 0.0 ;
    cutritu3[nendo-STARTY] = 0.0 ;
    cutritu3_cent[nendo-STARTY] = 0.0 ;
    kouteki[nendo-STARTY][0] = 0.0;
    kouteki[nendo-STARTY][1] = 0.0;
  }


  for ( nendo=STARTY; nendo<=ENDY; nendo++ ) {
    if ( ( nendo==PARTJJ ) || ( nendo>=1996 ) ) {
      XEND = xend[8][nendo-STARTY] ; 
      if ( nendo==PARTJJ ) { XEND = xend[8][PARTYR1-1-STARTY]; }
      if ( nendo==PARTKK ) { XEND = xend[8][PARTYR2-1-STARTY]; }
      if ( XEND < 60 ) {  XEND = 60; }
      kouteki[nendo-STARTY][0] = 0.0 ;
      for ( sei=1; sei<=2; sei++ ) {
        for ( nenrei=15; nenrei<=110; nenrei++ ) {
          if ( nenrei<70 ) {
            if ( nendo == PARTJJ ) { 
              kouteki[PARTJJ-STARTY][0]
                += qkounen[PARTYR1-1-STARTY][sei][nenrei] + (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
            }
            else if ( nendo == PARTKK ) { 
              kouteki[PARTKK-STARTY][0]
                += qkounen[PARTYR2-1-STARTY][sei][nenrei] + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
            }
            else if  ( nendo < 2016 ) { 
              kouteki[nendo-STARTY][0] += qkounen[nendo-STARTY][sei][nenrei]  ;
            }
            else if  ( nendo >= 2016 ) { 
              kouteki[nendo-STARTY][0] += qkounen[nendo-STARTY][sei][nenrei] + partnin[nendo-STARTY][sei][nenrei][0][0] ;
            }
          }
          for ( seido=1; seido<=7; seido++ ) {
            if ( nendo == PARTJJ ) { 
              kouteki[PARTJJ-STARTY][0] += kyosai[seido][PARTYR1-1-STARTY][sei][nenrei] ;
            }
            else if ( nendo == PARTKK ) { 
              kouteki[PARTKK-STARTY][0] += kyosai[seido][PARTYR2-1-STARTY][sei][nenrei] ;
            }
            else  {
              kouteki[nendo-STARTY][0] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
            }
          }
          if (( nenrei>=20 ) && ( nenrei<XEND )) {
            if ( nendo == PARTJJ ) { 
	            kouteki[nendo-STARTY][0] += qkounen3[PARTJJ-STARTY][sei][nenrei] ;
            	for ( seido=1; seido<=7; seido++ ) {
              		kouteki[nendo-STARTY][0] += kyosai3[seido][PARTJJ-STARTY][sei][nenrei] ;
            	}
            }
            else if ( nendo == PARTKK ) { 
	            kouteki[nendo-STARTY][0] += qkounen3[PARTKK-STARTY][sei][nenrei] ;
            	for ( seido=1; seido<=7; seido++ ) {
              		kouteki[nendo-STARTY][0] += kyosai3[seido][PARTKK-STARTY][sei][nenrei] ;
            	}
            }
            else  { 
             	kouteki[nendo-STARTY][0] += qkounen3[nendo-STARTY][sei][nenrei] ;
            	for ( seido=1; seido<=7; seido++ ) {
              		kouteki[nendo-STARTY][0] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
            	}
            }
          }
          if (( nenrei>=20 ) && ( nenrei<XEND )) {
            if ( nendo == PARTJJ ) { 
            	kouteki[nendo-STARTY][0] += ichigouip[PARTJJ-STARTY][sei][nenrei] ;
          	}
          	else if ( nendo == PARTKK ) { 
            	kouteki[nendo-STARTY][0] += ichigouip[PARTKK-STARTY][sei][nenrei] ;
          	}
          	else {
          		kouteki[nendo-STARTY][0] += ichigouip[nendo-STARTY][sei][nenrei] ;
          	}
          }
          if (( nenrei>=20 ) && ( nenrei<70 )) {
           if ( nendo == PARTJJ ) { 
            	kouteki[nendo-STARTY][0] += ichigouni[PARTJJ-STARTY][sei][nenrei] ;
           }
           else if ( nendo == PARTKK ) { 
            	kouteki[nendo-STARTY][0] += ichigouni[PARTKK-STARTY][sei][nenrei] ;
           }
           else  {
          		kouteki[nendo-STARTY][0] += ichigouni[nendo-STARTY][sei][nenrei] ;
           }
          }
        }
      }
    }
  }

   
   for ( nendo=STARTY; nendo<=ENDY; nendo++ ) {
    if ( ( nendo==PARTJJ ) || ( nendo>=1996 ) ) {
      XEND = xend[8][nendo-STARTY] ; 
      if ( nendo==PARTJJ ) { XEND = xend[8][PARTYR1-1-STARTY]; }
      if ( nendo==PARTKK ) { XEND = xend[8][PARTYR2-1-STARTY]; }
      if ( XEND < 60 ) {  XEND = 60; }
      kouteki[nendo-STARTY][1] = 0.0 ;
      for ( sei=1; sei<=2; sei++ ) {
        for ( nenrei=15; nenrei<=110; nenrei++ ) {
		  if ( HIHO74==70){
		   if ( nenrei < 70 ){ 
			if ( nendo == PARTJJ ) { 
              kouteki[PARTJJ-STARTY][1]
                += qkounen[PARTYR1-1-STARTY][sei][nenrei] + (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
            }
            else if ( nendo == PARTKK ) {
              kouteki[PARTKK-STARTY][1]
                += qkounen[PARTYR2-1-STARTY][sei][nenrei] + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
            }
            else if  ( nendo < 2016 ) { 
              kouteki[nendo-STARTY][1] += qkounen[nendo-STARTY][sei][nenrei]  ;
            }
            else if  ( nendo >= 2016 ) { 
              kouteki[nendo-STARTY][1] += qkounen[nendo-STARTY][sei][nenrei] + partnin[nendo-STARTY][sei][nenrei][0][0] ;
            }
		   }
		  }
          else {
		   if ( nenrei < HIHO74+1 ) {
            if ( nendo == PARTJJ ) { 
              kouteki[PARTJJ-STARTY][1]
                += qkounen[PARTYR1-1-STARTY][sei][nenrei] + (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
            }
            else if ( nendo == PARTKK ) { 
              kouteki[PARTKK-STARTY][1]
                += qkounen[PARTYR2-1-STARTY][sei][nenrei] + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
            }
            else if  ( nendo < 2016 ) { 
              kouteki[nendo-STARTY][1] += qkounen[nendo-STARTY][sei][nenrei]  ;
            }
            else if  ( nendo >= 2016 ) { 
              kouteki[nendo-STARTY][1] += qkounen[nendo-STARTY][sei][nenrei] + partnin[nendo-STARTY][sei][nenrei][0][0] ;
            }
           }
		  }
          for ( seido=1; seido<=7; seido++ ) {
            if ( nendo == PARTJJ ) { 
              kouteki[PARTJJ-STARTY][1] += kyosai[seido][PARTYR1-1-STARTY][sei][nenrei] ;
            }
            else if ( nendo == PARTKK ) { 
              kouteki[PARTKK-STARTY][1] += kyosai[seido][PARTYR2-1-STARTY][sei][nenrei] ;
            }
            else  { 
              kouteki[nendo-STARTY][1] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
            }
          }
          if (( nenrei>=20 ) && ( nenrei<XEND )) {
            if ( nendo == PARTJJ ) { 
	            kouteki[nendo-STARTY][1] += qkounen3[PARTJJ-STARTY][sei][nenrei] ;
            	for ( seido=1; seido<=7; seido++ ) {
              		kouteki[nendo-STARTY][1] += kyosai3[seido][PARTJJ-STARTY][sei][nenrei] ;
            	}
            }
            else if ( nendo == PARTKK ) { 
	            kouteki[nendo-STARTY][1] += qkounen3[PARTKK-STARTY][sei][nenrei] ;
            	for ( seido=1; seido<=7; seido++ ) {
              		kouteki[nendo-STARTY][1] += kyosai3[seido][PARTKK-STARTY][sei][nenrei] ;
            	}
            }
            else  { 
             	kouteki[nendo-STARTY][1] += qkounen3[nendo-STARTY][sei][nenrei] ;
            	for ( seido=1; seido<=7; seido++ ) {
              		kouteki[nendo-STARTY][1] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
            	}
            }
          }
          if (( nenrei>=20 ) && ( nenrei<XEND )) {
            if ( nendo == PARTJJ ) { 
            	kouteki[nendo-STARTY][1] += ichigouip[PARTJJ-STARTY][sei][nenrei] ;
          	}
          	else if ( nendo == PARTKK ) { 
            	kouteki[nendo-STARTY][1] += ichigouip[PARTKK-STARTY][sei][nenrei] ;
          	}
          	else {
          		kouteki[nendo-STARTY][1] += ichigouip[nendo-STARTY][sei][nenrei] ;
          	}
          }
          if (( nenrei>=20 ) && ( nenrei<70 )) {
           if ( nendo == PARTJJ ) { 
            	kouteki[nendo-STARTY][1] += ichigouni[PARTJJ-STARTY][sei][nenrei] ;
           }
           else if ( nendo == PARTKK ) { 
            	kouteki[nendo-STARTY][1] += ichigouni[PARTKK-STARTY][sei][nenrei] ;
           }
           else  {
          		kouteki[nendo-STARTY][1] += ichigouni[nendo-STARTY][sei][nenrei] ;
           }
          }
        }
      }
    }
   }

  for ( nendo=STARTY+1; nendo<=ENDY; nendo++ ) {
  	if ( nendo == PARTYR1 ) {
        kouteki_cent[nendo-STARTY][0]
          = ( kouteki[PARTJJ-STARTY][0] + kouteki[nendo-STARTY][0] ) / 2.0 ; 
    }
    else if ( nendo == PARTYR2 ) {
        kouteki_cent[nendo-STARTY][0]
          = ( kouteki[PARTKK-STARTY][0] + kouteki[nendo-STARTY][0] ) / 2.0 ; 
    }
    else {
    	kouteki_cent[nendo-STARTY][0]
      	= ( kouteki[nendo-1-STARTY][0] + kouteki[nendo-STARTY][0] ) / 2.0 ;
    }
  }
  for ( nendo=STARTY+1; nendo<=ENDY; nendo++ ) {
  	if ( nendo == PARTYR1 ) {
        kouteki_cent[nendo-STARTY][1]
          = ( kouteki[PARTJJ-STARTY][1] + kouteki[nendo-STARTY][1] ) / 2.0 ; 
    }
    else if ( nendo == PARTYR2 ) {
        kouteki_cent[nendo-STARTY][1]
          = ( kouteki[PARTKK-STARTY][1] + kouteki[nendo-STARTY][1] ) / 2.0 ; 
    }
    else {
    	kouteki_cent[nendo-STARTY][1]
      	= ( kouteki[nendo-1-STARTY][1] + kouteki[nendo-STARTY][1] ) / 2.0 ;
    }
  }


  for ( nendo=CNENDO; nendo<=KE; nendo++ ) {
    if ( nendo-5 >= STARTY ) {

      if ( kouteki[nendo-5-STARTY][0] > 0.0 ) {
        TMP[nendo-STARTY][1] = 0.0 ;  TMQ[nendo-STARTY][1] = 0.0 ;
        TMPEND = xend[8][nendo-5-STARTY] ; 
        TMQEND = xend[8][nendo-2-STARTY] ;
        if ( TMPEND < 60 ) {  TMPEND = 60; }
        if ( TMQEND < 60 ) {  TMQEND = 60; }
        if ( ( MODE >= 4 ) && ( MODE45 == 1 ) ) { 
            if ( TMQEND > 60 ) { 
                for ( nenrei=60; nenrei<=TMQEND-1; nenrei++ ) {
                    TMP[nendo-STARTY][1] +=  ichigouip[nendo-5-STARTY][1][nenrei]
                                          + ichigouip[nendo-5-STARTY][2][nenrei]
                                          + sangou[nendo-5-STARTY][0][nenrei]  ;
                    TMQ[nendo-STARTY][1] +=  ichigouip[nendo-2-STARTY][1][nenrei]
                                          + ichigouip[nendo-2-STARTY][2][nenrei]
                                          + sangou[nendo-2-STARTY][0][nenrei]  ;
                }
            }
        }

        /* ここでカット率計算 年度末*/
       if ( HIHO74 == 74 ){
        if( HIHO74CHO == 1 ){
         if ( nendo < HIHO74YR+5 ){
        	cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][0] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][0] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;

      	 }
      	 else {
      		cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][1] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][1] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;

      	 }
        }
        else if(HIHO74CHO == 0 ){
        	if ( nendo < HIHO74YR+2 ){
        		cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][0] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][0] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;
          	}
          	else if( nendo < HIHO74YR+5 ){
          		cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][1] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][0] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;
          	}
          	else {
          		cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][1] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][1] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;
          	}
        }
		else if(HIHO74CHO == 2 ){
		       	cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][0] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][0] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;
        }
       }
       else {
       	cutritu1[nendo-STARTY] = pow( ( kouteki[nendo-2-STARTY][0] - TMQ[nendo-STARTY][1] )
          	                       / ( kouteki[nendo-5-STARTY][0] - TMP[nendo-STARTY][1] ) , 1.0 / 3.0 ) * JYUMYO ;
       }
      }

      if ( kouteki_cent[nendo-5-STARTY][0] > 0.0 ) {
        TMP[nendo-STARTY][2] = 0.0 ;  TMQ[nendo-STARTY][2] = 0.0 ;
        TMPEND = xend[8][nendo-6-STARTY] ; 
        TMQEND = xend[8][nendo-2-STARTY] ;
        if ( TMPEND < 60 ) {  TMPEND = 60; }
        if ( TMQEND < 60 ) {  TMQEND = 60; }
        if ( ( MODE >= 4 ) && ( MODE45 == 1 ) ) { 
            if ( TMQEND > 60 ) {
                for ( nenrei=60; nenrei<=TMQEND-1; nenrei++ ) {
                    TMP[nendo-STARTY][2] += ( ichigouip[nendo-6-STARTY][1][nenrei] + ichigouip[nendo-6-STARTY][2][nenrei]
                           + ichigouip[nendo-5-STARTY][1][nenrei] + ichigouip[nendo-5-STARTY][2][nenrei]
                           + sangou[nendo-6-STARTY][0][nenrei] + sangou[nendo-5-STARTY][0][nenrei] ) / 2.0 ;
                    TMQ[nendo-STARTY][2] += ( ichigouip[nendo-3-STARTY][1][nenrei] + ichigouip[nendo-3-STARTY][2][nenrei]
                           + ichigouip[nendo-2-STARTY][1][nenrei] + ichigouip[nendo-2-STARTY][2][nenrei]
                           + sangou[nendo-3-STARTY][0][nenrei] + sangou[nendo-2-STARTY][0][nenrei] ) / 2.0 ;
                }
            }
        }

       if ( HIHO74 == 74 ){
        if( HIHO74CHO == 1 ){
         if ( nendo < HIHO74YR+5 ){
        	cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][0] - TMQ[nendo-STARTY][2] )
                           / ( kouteki_cent[nendo-5-STARTY][0] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;

         }
         else {
        	cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][1] - TMQ[nendo-STARTY][2] )
                           / ( kouteki_cent[nendo-5-STARTY][1] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;

		 }
		}
		else if (HIHO74CHO == 0 ){
        	if ( nendo < HIHO74YR+2 ){
        		cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][0] - TMQ[nendo-STARTY][2] )
          	                       / ( kouteki_cent[nendo-5-STARTY][0] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;
          	}
          	else if( nendo < HIHO74YR+5 ){
          		cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][1] - TMQ[nendo-STARTY][2] )
          	                       / ( kouteki_cent[nendo-5-STARTY][0] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;
          	}
          	else {
          		cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][1] - TMQ[nendo-STARTY][2] )
          	                       / ( kouteki_cent[nendo-5-STARTY][2] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;
          	}
        } 
		else if(HIHO74CHO ==2){
	       	cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][0] - TMQ[nendo-STARTY][2] )
          	                       / ( kouteki_cent[nendo-5-STARTY][0] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;
		}
	   }
	   else {
       	cutritu1_cent[nendo-STARTY] = pow( ( kouteki_cent[nendo-2-STARTY][0] - TMQ[nendo-STARTY][2] )
          	                       / ( kouteki_cent[nendo-5-STARTY][0] - TMP[nendo-STARTY][2] ) , 1.0 / 3.0 ) * JYUMYO ;
       }
      }
    }
  }

  for ( nendo=CNENDO; nendo<=KE; nendo++ ) {
    if ( nendo-5 >= STARTY ) {
      if ( kouteki[nendo-5-STARTY][0] > 0.0 ) {
        cutritu2[nendo-STARTY] = 1.0 - cutritu1[nendo-STARTY] ;
      }
      if ( kouteki_cent[nendo-5-STARTY][0] > 0.0 ) {
        cutritu2_cent[nendo-STARTY] = 1.0 - cutritu1_cent[nendo-STARTY] ;
      }
    }
  }

  for ( nendo=CNENDO; nendo<=KE; nendo++ ) {
    if ( nendo-5 >= STARTY ) {
      if ( kouteki[nendo-5-STARTY][0] > 0.0 ) {
        cutritu3[nendo-STARTY] = 1.0 / ( 1.0 + ( cutritu1[nendo-STARTY]-1.0 )) - 1.0 ;
      }
      if ( kouteki_cent[nendo-5-STARTY][0] > 0.0 ) {
        cutritu3_cent[nendo-STARTY] = 1.0 / ( 1.0 + ( cutritu1_cent[nendo-STARTY]-1.0 )) - 1.0 ;
      }
    }
  }


/*  四ﾌ五入  */
  for ( nendo=CNENDO; nendo<=KE; nendo++ ) {
    cutritu1[nendo-STARTY] = raund( cutritu1[nendo-STARTY] , 6 ) ;
    cutritu1_cent[nendo-STARTY] = raund( cutritu1_cent[nendo-STARTY] , 6 ) ;
    cutritu2[nendo-STARTY] = raund( cutritu2[nendo-STARTY] , 4 ) ;
    cutritu2_cent[nendo-STARTY] = raund( cutritu2_cent[nendo-STARTY] , 4 ) ;
    cutritu3[nendo-STARTY] = raund( cutritu3[nendo-STARTY] , 4 ) ;
    cutritu3_cent[nendo-STARTY] = raund( cutritu3_cent[nendo-STARTY] , 4 ) ;
  }

/*  出力  */
  for ( nendo=CNENDO ; nendo<=(int)min(KE,KF); nendo++ ){
    fprintf(fp_cutout , "%4d,%7.6f,%7.6f\n", nendo, cutritu3_cent[nendo-STARTY], cutritu3_cent[nendo-STARTY] );
  }

/*  ファイルクローズ  */
  fclose(fp_cutout);

    sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-mold.csv", BANGO, BANGO) ;
    if ((fp_cutout = fopen(filename, "w")) == NULL) {
         fprintf(stderr, "出力cutファイルを開けません!\n");
         exit (2); /* 終了 */
    }

/*  出力  */
  for ( nendo=CNENDO ; nendo<=(int)min(2110,KE); nendo++ ){
    fprintf(fp_cutout , "%4d,%7.6f,%7.6f\n", nendo, cutritu3[nendo-STARTY], cutritu3[nendo-STARTY] );
  }

/*  ファイルクローズ  */
  fclose(fp_cutout);


/*  テスト出力  */
    sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-cutsyosai.csv", BANGO, BANGO) ;
    if ((fp_cutout = fopen(filename, "w")) == NULL) {
         fprintf(stderr, "出力cutファイルを開けません!\n");
         exit (2); /* 終了 */
    }

    fprintf(fp_cutout , "被保険者数全体,,,74まで,,カット率１,,カット率２,,カット率３,,TMP,,TMQ, \n" );
    /*  タイトル行  */
    fprintf(fp_cutout , "年度,年度末,年度間,年度末,年度間,年度末,年度間,年度末,年度間,年度末,年度間,年度末,年度間,年度末,年度間\n" );
    /*  本格書き込み  */
    for ( nendo=KS; nendo<=KF; nendo++ ) {
      fprintf(fp_cutout , "%4d,", nendo );
      fprintf(fp_cutout , "%lf,",  kouteki[nendo-STARTY][0] );
      fprintf(fp_cutout , "%lf,",  kouteki_cent[nendo-STARTY][0] );
      fprintf(fp_cutout , "%lf,",  kouteki[nendo-STARTY][1] );
      fprintf(fp_cutout , "%lf,",  kouteki_cent[nendo-STARTY][1] );
      fprintf(fp_cutout , "%7.6f,",  cutritu1[nendo-STARTY] );
      fprintf(fp_cutout , "%7.6f,",  cutritu1_cent[nendo-STARTY] );
      fprintf(fp_cutout , "%7.6f,",  cutritu2[nendo-STARTY] );
      fprintf(fp_cutout , "%7.6f,",  cutritu2_cent[nendo-STARTY] );
      fprintf(fp_cutout , "%7.6f,",  cutritu3[nendo-STARTY] );
      fprintf(fp_cutout , "%7.6f,",  cutritu3_cent[nendo-STARTY] );
      fprintf(fp_cutout , "%lf,",  TMP[nendo-STARTY][1] );
      fprintf(fp_cutout , "%lf,",  TMP[nendo-STARTY][2] );
      fprintf(fp_cutout , "%lf,",  TMQ[nendo-STARTY][1] );
      fprintf(fp_cutout , "%lf\n",  TMQ[nendo-STARTY][2] );
    }


/*  ファイルクローズ  */
  fclose(fp_cutout);


}

