#include <iostream>
#include <cstdlib>
#include "snaps.h"
#include "mkisosu.h"
#include "mfile_open.h"
#include "mcntl.h"
#include "mkiso.h"
#include "mecon.h"

void printout()
{
	int nendo;
	int seido;
	int goubetu;
	int sotai_nendo;
	int shinkyu;
	int kubun;
	int tokubetu_shurui;
	
	for( shinkyu = SUM ; shinkyu <= OLD ; shinkyu++ )
	{
		switch ( shinkyu )
		{
			case SUM :
				fprintf( fp_out[KEKKA_b] , "基礎年金給付費（新法＋旧法）\n");
				break;
			case NEW :
				fprintf( fp_out[KEKKA_b] , "基礎年金給付費（新法）\n");
				break;
			case OLD :
				fprintf( fp_out[KEKKA_b] , "基礎年金交付金\n");
				break;
		}
		fprintf( fp_out[KEKKA_b] , ",合計,国年,厚年,国共,地共,私学,\n");
		for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
		{
			sotai_nendo = nendo - SHONENDO;
			fprintf( fp_out[KEKKA_b] , "%15d," , nendo );
			
			for( seido = SUM ; seido <= CHIKYO ; seido++ )
			{
				fprintf( fp_out[KEKKA_b] , "%20.14le," , Kyufu[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][shinkyu][SUM][SUM][SUM][SUM] );
			}
			fprintf( fp_out[KEKKA_b] , "%20.14le\n" , Kyufu[SHIGAKU][sotai_nendo][NENREI_SUM - NENREI_SUM][shinkyu][SUM][SUM][SUM][SUM] );
		}
	}
	
	for( kubun = SUM ; kubun <= IZOKU ; kubun++ )
	{
		switch ( kubun )
		{
			case SUM :
				fprintf( fp_out[KEKKA_b] , "基礎年金給付費（合計）\n");
				break;
			case ROREI :
				fprintf( fp_out[KEKKA_b] , "基礎年金給付費（老齢）\n");
				break;
			case SHOGAI :
				fprintf( fp_out[KEKKA_b] , "基礎年金給付費（障害）\n");
				break;
			case IZOKU :
				fprintf( fp_out[KEKKA_b] , "基礎年金給付費（遺族）\n");
			break;
		}
		for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
		{
			sotai_nendo = nendo - SHONENDO;
			fprintf( fp_out[KEKKA_b] , "%15d," , nendo);
			
			for( seido = SUM ; seido <= CHIKYO ; seido++ )
			{
				fprintf( fp_out[KEKKA_b] , "%20.14le," , Kyufu[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][SUM][kubun][SUM][SUM][SUM] );
			}
			fprintf( fp_out[KEKKA_b] , "%20.14le\n" , Kyufu[SHIGAKU][sotai_nendo][NENREI_SUM - NENREI_SUM][SUM][kubun][SUM][SUM][SUM] );
		}
	}
	
	fprintf( fp_out[KEKKA_b] , "基礎年金拠出金\n" );
	fprintf( fp_out[KEKKA_b] , ",単価,合計,国年,厚年,国共,地共,私学\n");
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		sotai_nendo = nendo - SHONENDO;
		fprintf( fp_out[KEKKA_b] , "%15d," , nendo );
		
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Tanka[sotai_nendo][NENREI_SUM - NENREI_SUM][SUM] );
		for( seido = SUM ; seido <= SHIGAKU ; seido++ )
		{
			fprintf( fp_out[KEKKA_b] , "%20.14le," , Kyoshutukin[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][SUM] );
		}
		fprintf( fp_out[KEKKA_b] , "\n" );
	}	
	
	fprintf( fp_out[KEKKA_b] , "基礎年金拠出金（国庫）\n" );
	fprintf( fp_out[KEKKA_b] , ",単価,国庫負担割合(年度末),合計,国年,厚年,国共,地共,私学\n" );
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		sotai_nendo = nendo - SHONENDO;
		fprintf( fp_out[KEKKA_b] , "%15d," , nendo );
		
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Tanka_Kokko[sotai_nendo][NENREI_SUM - NENREI_SUM][SUM] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Kokko_Wariai[nendo - ( SHONENDO - 1 )] );
		for( seido = SUM ; seido <= SHIGAKU ; seido++ )
		{
			fprintf( fp_out[KEKKA_b] , "%20.14le," , Kyoshutukin_Kokko[seido][sotai_nendo][NENREI_SUM - NENREI_SUM][SUM] );
		}
		fprintf( fp_out[KEKKA_b] , "\n" );
	}
	
	fprintf( fp_out[KEKKA_b] , "拠出金算定対象者\n" );
	fprintf( fp_out[KEKKA_b] , ",合計,１号,厚年２号,厚年３号,国共２号,国共３号,地共２号,地共３号,私学２号,私学３号\n" );
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		sotai_nendo = nendo - SHONENDO;
		fprintf( fp_out[KEKKA_b] , "%15d," , nendo );
		
		fprintf( fp_out[KEKKA_b] , "%20.14le," , SanteiTaishou[SUM][sotai_nendo][SUM] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , SanteiTaishou[KOKUNEN][sotai_nendo][1] );
		for( seido = KOUNEN ; seido <= SHIGAKU ; seido++ )
		{
			for( goubetu = 2 ; goubetu <= 3 ; goubetu++ )
			{
				fprintf( fp_out[KEKKA_b] , "%20.14le," , SanteiTaishou[seido][sotai_nendo][goubetu] );
			}
		}
		fprintf( fp_out[KEKKA_b] , "\n" );
	}
	
	fprintf( fp_out[KEKKA_b] , "特別国庫負担内訳\n" );
	fprintf( fp_out[KEKKA_b] , ",合計,免除,嵩上げ（納付）,嵩上げ（免除）,老福下支え,５年年金,２０歳前\n" );
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		sotai_nendo = nendo - SHONENDO;
		fprintf( fp_out[KEKKA_b] , "%15d," , nendo );
		
		for( tokubetu_shurui = SUM ; tokubetu_shurui <= TOKUBETU_20MAE ; tokubetu_shurui++ )
		{
			fprintf( fp_out[KEKKA_b] , "%20.14le," , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][tokubetu_shurui][SUM][SUM] );
		}
		fprintf( fp_out[KEKKA_b] , "\n" );
	}
	
	fprintf( fp_out[KEKKA_b] , "独自給付費等\n" );
	fprintf( fp_out[KEKKA_b] , ",一時金納付分,一時金付加分,新法寡婦年金,旧法寡婦年金免除分以外," );
	fprintf( fp_out[KEKKA_b] , "旧法寡婦年金免除分,付加年金,付加年金（人数）,１号被保険者数,住宅融資債権,業務勘定への繰入\n" );
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		fprintf( fp_out[KEKKA_b] , "%d," , nendo );
		
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Ichijikin[nendo - SHONENDO][NOUFU] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Ichijikin[nendo - SHONENDO][FUKA] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Kafu[nendo - SHONENDO][NEW] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Kafu[nendo - SHONENDO][OLD_NOUFU] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Kafu[nendo - SHONENDO][OLD_MENJO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Fuka[nendo - SHONENDO][SUM] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Fuka_Ninzu[nendo - SHONENDO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Hiho_Kokunen[nendo - SHONENDO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , Yuushi_Saiken[nendo - SHONENDO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le\n" , Fukushi[nendo - SHONENDO] );
	}
	
	fprintf( fp_out[KEKKA_b] , "経済前提\n" );
	fprintf( fp_out[KEKKA_b] , ",物価上昇率,賃金上昇率,運用利回り,改定率（67歳、調整前）,改定率（68歳、調整前）\n" );
	for( nendo = ECON_SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		fprintf( fp_out[KEKKA_b] , "%d," , nendo );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , cpi_up[nendo - ECON_SHONENDO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , base_up[nendo - ECON_SHONENDO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , interest_rate[nendo - ECON_SHONENDO] );
		fprintf( fp_out[KEKKA_b] , "%20.14le," , kaiteiritu[nendo - ECON_SHONENDO][UNDER_67 - UNDER_67] );
		fprintf( fp_out[KEKKA_b] , "%20.14le\n" , kaiteiritu[nendo - ECON_SHONENDO][68 - UNDER_67] );
	}
	
	fprintf( fp_out[KEKKA_b] , "妻積（各制度への分配額および残額）\n" );
	fprintf( fp_out[KEKKA_b] , ",国年,厚年,国共,地共,私学,妻積残額\n" );
	
	fprintf( fp_out[KEKKA_b] , "%d（原価）," , TUMATUMI_NENDO - 1 );
	fprintf( fp_out[KEKKA_b] , "%20.14e," , 0 );
	for( seido = KOUNEN ; seido <= SHIGAKU ; seido++ )
	{
		fprintf( fp_out[KEKKA_b] , "%20.14e," , 0 );
	}
	fprintf( fp_out[KEKKA_b] , "%20.14e\n" , Tumatumi_2014[SUM] );
	
	for( nendo = TUMATUMI_NENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		fprintf( fp_out[KEKKA_b] , "%d," , nendo );
		for( seido = KOKUNEN ; seido <= SHIGAKU ; seido++ )
		{
			fprintf( fp_out[KEKKA_b] , "%20.14e," , Tumatumi[seido][nendo - SHONENDO] );
		}
		fprintf( fp_out[KEKKA_b] , "%20.14e\n" , Tumatumi[SUM][nendo - SHONENDO] );
	}
	
	fprintf( fp_out[KEKKA_b] , "試算番号\n" );
	fprintf( fp_out[KEKKA_b] , "%s-%sb\n," , Version , Version_cut );
	
	fprintf( fp_out[KEKKA_KOKKO_b] , "年度,変更月,拠出金算定対象者数,年度末国庫負担割合,拠出金（計）,拠出金（前）,拠出金（後）," );
	fprintf( fp_out[KEKKA_KOKKO_b] , "拠出金国庫（計）,拠出金国庫（前）,拠出金国庫（後）,特別国庫（計）,特別国庫（前）,特別国庫（後）," );
	fprintf( fp_out[KEKKA_KOKKO_b] , "２０前障害（計）（再）,２０前障害（前）（再）,２０前障害（後）（再）\n" );
	for( nendo = SHONENDO ; nendo <= SAISHUNENDO ; nendo++ )
	{
		sotai_nendo = nendo - SHONENDO;
		fprintf( fp_out[KEKKA_KOKKO_b] , "%15d," , nendo );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%15d," , tuki[sotai_nendo] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , SanteiTaishou[SUM][sotai_nendo][SUM] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kokko_Wariai[nendo - ( SHONENDO - 1 )] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kyoshutukin[SUM][sotai_nendo][NENREI_SUM - NENREI_SUM][SUM] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kyoshutukin[SUM][sotai_nendo][NENREI_SUM - NENREI_SUM][ZENHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kyoshutukin[SUM][sotai_nendo][NENREI_SUM - NENREI_SUM][KOUHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kyoshutukin_Kokko[SUM][sotai_nendo][NENREI_SUM - NENREI_SUM][SUM] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kyoshutukin_Kokko[SUM][sotai_nendo][NENREI_SUM - NENREI_SUM][ZENHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Kyoshutukin_Kokko[SUM][sotai_nendo][NENREI_SUM - NENREI_SUM][KOUHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][SUM][SUM][SUM] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][SUM][SUM][ZENHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][SUM][SUM][KOUHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][TOKUBETU_20MAE][SUM][SUM] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le," , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][TOKUBETU_20MAE][SUM][ZENHAN] );
		fprintf( fp_out[KEKKA_KOKKO_b] , "%20.14le\n" , Tokubetukokko[sotai_nendo][NENREI_SUM - NENREI_SUM][TOKUBETU_20MAE][SUM][KOUHAN] );
	}
}

