/***************************************
*                                      *
*          file_write                  *
*                                      *
*                                      *
***************************************/

#include <iostream>
#include "snaps.h"
#include "kisosu.h"
#include "file_open.h"
#include "cntl.h"
#include "econ.h"

void file_write()
{
	// 変数宣言
	int nendo;
	int seido;
	int sotai_nendo;
	int nenrei;
	int shikyu_keitai;
	double Kokko_Nendomatu[SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Kokko_Nendomatu_P[SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Tanka_Nendomatu[SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Tanka_Nendomatu_P[SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Tanka_Kokko_Nendomatu[SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Tanka_Kokko_Nendomatu_P[SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Kyoshutukin_Nendomatu[9][SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Kyoshutukin_Nendomatu_P[9][SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Kyoshutukin_Kokko_Nendomatu[9][SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	double Kyoshutukin_Kokko_Nendomatu_P[9][SAISHUNENDO - SHONENDO + 1][MAX_JUKYU - NENREI_SUM + 1][3];
	
	// ゼロクリア
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU ; nenrei++ )
		{
			for( shikyu_keitai = SUM ; shikyu_keitai <= KAKYU ; shikyu_keitai++ )
			{
				Kokko_Nendomatu[nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				Kokko_Nendomatu_P[nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				Tanka_Nendomatu[nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				Tanka_Nendomatu_P[nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				Tanka_Kokko_Nendomatu[nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				Tanka_Kokko_Nendomatu_P[nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				for( seido = SUM ; seido <= NORIN ; seido++ )
				{
					Kyoshutukin_Nendomatu[seido][nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
					Kyoshutukin_Nendomatu_P[seido][nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
					Kyoshutukin_Kokko_Nendomatu[seido][nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
					Kyoshutukin_Kokko_Nendomatu_P[seido][nendo - SHONENDO][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				}
			}
		}
	}
	
	
	// メインルーチン
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		sotai_nendo = nendo - SHONENDO;
		
		// 拠出金に関するデータを年度末現在で作成
		for( nenrei = UNDER_63 ; nenrei <= MAX_JUKYU ; nenrei++ )
		{
			for( shikyu_keitai = KIHON ; shikyu_keitai <= KAKYU ; shikyu_keitai++ )
			{
				Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
				 = Kyufu_Nendomatu[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][ZENHAN]
				 * Kokko_Wariai[nendo - 1 - ( SHONENDO - 1 )]
				 + Kyufu_Nendomatu[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][KOUHAN]
				 * Kokko_Wariai[nendo - ( SHONENDO - 1 )];
				
				if( nendo == SAISHUNENDO )
				{
					Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
					 = Kyufu_Nendomatu_P[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][ZENHAN]
					 * Kokko_Wariai[nendo - ( SHONENDO - 1 )]
					 + Kyufu_Nendomatu_P[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][KOUHAN]
					 * Kokko_Wariai[nendo - ( SHONENDO - 1 )];
				}
				else
				{
					Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
					 = Kyufu_Nendomatu_P[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][ZENHAN]
					 * Kokko_Wariai[nendo - ( SHONENDO - 1 )]
					 + Kyufu_Nendomatu_P[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][KOUHAN]
					 * Kokko_Wariai[nendo + 1 - ( SHONENDO - 1 )];
				}
				Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][SUM] += Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai];
				Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][SUM] += Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai];
			}
			
			for( shikyu_keitai = SUM ; shikyu_keitai <= KAKYU ; shikyu_keitai++ )
			{
				if( SanteiTaishou[SUM][sotai_nendo][SUM] > 0. )
				{
					Tanka_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
					 = Kyufu_Nendomatu[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][SUM]
					 / SanteiTaishou[SUM][sotai_nendo][SUM] / 12.;
					
					Tanka_Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
					 = Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] / SanteiTaishou[SUM][sotai_nendo][SUM] / 12.;
				}
				else
				{
					Tanka_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
					Tanka_Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
				}
				
				if( nendo == SAISHUNENDO )
				{
					if( SanteiTaishou[SUM][sotai_nendo][SUM] > 0. )
					{
						Tanka_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = Kyufu_Nendomatu_P[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][SUM]
						 / SanteiTaishou[SUM][sotai_nendo][SUM] / 12.;
						
						Tanka_Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] / SanteiTaishou[SUM][sotai_nendo][SUM] / 12.;
					}
					else
					{
						Tanka_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
						Tanka_Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
					}
				}
				else
				{
					if( SanteiTaishou[SUM][sotai_nendo + 1][SUM] > 0. )
					{
						Tanka_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = Kyufu_Nendomatu_P[SUM][sotai_nendo][nenrei - NENREI_SUM][SUM][SUM][KYOSHUTU][shikyu_keitai][SUM]
						 / SanteiTaishou[SUM][sotai_nendo + 1][SUM] / 12.;
						Tanka_Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] / SanteiTaishou[SUM][sotai_nendo + 1][SUM] / 12.;
					}
					else
					{
						Tanka_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
						Tanka_Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] = 0.;
					}
				}
				
				for( seido = KOUNEN ; seido <= NORIN ; seido++ )
				{
					Kyoshutukin_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
					 = SanteiTaishou[seido][sotai_nendo][SUM] * Tanka_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] * 12.;
					
					Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
					 = SanteiTaishou[seido][sotai_nendo][SUM] * Tanka_Kokko_Nendomatu[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] * 12.;
					
					if( nendo == SAISHUNENDO )
					{
						Kyoshutukin_Nendomatu_P[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = SanteiTaishou[seido][sotai_nendo][SUM] * Tanka_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] * 12.;
						Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = SanteiTaishou[seido][sotai_nendo][SUM] * Tanka_Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] * 12.;
					}
					else
					{
						Kyoshutukin_Nendomatu_P[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = SanteiTaishou[seido][sotai_nendo + 1][SUM] * Tanka_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] * 12.;
						Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai]
						 = SanteiTaishou[seido][sotai_nendo + 1][SUM] * Tanka_Kokko_Nendomatu_P[sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] * 12.;
					}
					
					Kyoshutukin_Nendomatu[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][shikyu_keitai]
					 += Kyoshutukin_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai];
					Kyoshutukin_Nendomatu_P[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][shikyu_keitai]
					 += Kyoshutukin_Nendomatu_P[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai];
					
					Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][shikyu_keitai]
					 += Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai];
					Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][shikyu_keitai]
					 += Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai];
				}
			}
		}
	}
	
	// ファイル作成
	write_BeginData( fpout );
	for( shikyu_keitai = KIHON ; shikyu_keitai <= KAKYU ; shikyu_keitai++ )
	{
		fprintf( fpout , "shikyu_keitai:%d\n" , shikyu_keitai );
		for( seido = KOUNEN ; seido <= KOKKYO ; seido++ )
		{
			for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
			{
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 2 , 1 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", 0. );
				}
				fprintf( fpout , "%20.14le\n", 0. );
			}
			for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 2 , 1 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu_P[seido][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu_P[seido][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 2 , 2 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu[seido][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
			{
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 2 , 3 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", 0. );
				}
				fprintf( fpout , "%20.14le\n", 0. );
			}
			for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 2 , 3 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 2 , 4 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
		}
		for( seido = JR ; seido <= JT ; seido++ )
		{
			for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
			{
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 4 , 1 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", 0. );
				}
				fprintf( fpout , "%20.14le\n", 0. );
			}
			for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 4 , 1 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu_P[seido][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu_P[seido][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 4 , 2 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu[seido][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
			{
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 4 , 3 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", 0. );
				}
				fprintf( fpout , "%20.14le\n", 0. );
			}
			for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 4 , 3 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido - 4 , 4 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
		}
		for( seido = CHIKYO ; seido <= SHIGAKU ; seido++ )
		{
			for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
			{
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido , 1 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", 0. );
				}
				fprintf( fpout , "%20.14le\n", 0. );
			}
			for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido , 1 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu_P[seido][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu_P[seido][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido , 2 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu[seido][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
			{
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido , 3 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", 0. );
				}
				fprintf( fpout , "%20.14le\n", 0. );
			}
			for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido , 3 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu_P[seido][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
			
			for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
			{
				sotai_nendo = nendo - SHONENDO;
				fprintf( fpout , "%d,%d,%d," , nendo - 2000 , seido , 4 );
				for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
				{
					fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
				}
				fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu[seido][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
			}
		}
		
		for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
		{
			fprintf( fpout , "%d,%d,%d," , nendo - 2000 , 6 , 1 );
			for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
			{
				fprintf( fpout , "%20.14le,", 0. );
			}
			fprintf( fpout , "%20.14le\n", 0. );
		}
		for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
		{
			sotai_nendo = nendo - SHONENDO;
			fprintf( fpout , "%d,%d,%d," , nendo - 2000 , 6 , 1 );
			for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
			{
				fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu_P[NORIN][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
			}
			fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu_P[NORIN][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
		}
		
		for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
		{
			sotai_nendo = nendo - SHONENDO;
			fprintf( fpout , "%d,%d,%d," , nendo - 2000 , 6 , 2 );
			for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
			{
				fprintf( fpout , "%20.14le,", Kyoshutukin_Nendomatu[NORIN][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
			}
			fprintf( fpout , "%20.14le\n", Kyoshutukin_Nendomatu[NORIN][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
		}
		
		for( nendo = SHONENDO ; nendo <= SHONENDO ; nendo++ )
		{
			fprintf( fpout , "%d,%d,%d," , nendo - 2000 , 6 , 3 );
			for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
			{
				fprintf( fpout , "%20.14le,", 0. );
			}
			fprintf( fpout , "%20.14le\n", 0. );
		}
		for( nendo = SHONENDO + 1 ; nendo <= SAISHUNENDO ; nendo++ )
		{
			sotai_nendo = nendo - SHONENDO;
			fprintf( fpout , "%d,%d,%d," , nendo - 2000 , 6 , 3 );
			for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
			{
				fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu_P[NORIN][sotai_nendo - 1][nenrei - NENREI_SUM][shikyu_keitai] );
			}
			fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu_P[NORIN][sotai_nendo - 1][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
		}
		
		for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
		{
			sotai_nendo = nendo - SHONENDO;
			fprintf( fpout , "%d,%d,%d," , nendo - 2000 , 6 , 4 );
			for( nenrei = NENREI_SUM ; nenrei <= MAX_JUKYU - 1 ; nenrei++ )
			{
				fprintf( fpout , "%20.14le,", Kyoshutukin_Kokko_Nendomatu[NORIN][sotai_nendo][nenrei - NENREI_SUM][shikyu_keitai] );
			}
			fprintf( fpout , "%20.14le\n", Kyoshutukin_Kokko_Nendomatu[NORIN][sotai_nendo][MAX_JUKYU - NENREI_SUM][shikyu_keitai] );
		}
	}
}
