⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dispinitpara.cpp

📁 这个是数据打孔重传程序的源代码
💻 CPP
字号:
/**********************************************/
/* Initial parameters loader   
/* int DispInitParaF(struct BasicParaS * ctrl)
/*      Written by: Ouyang Ziyue,
/*            Date: Jun 6th, 2007,
/*        Function: It loads the basic parameters to initialize the LDPC evaluation platform,
/* Input parameter:
/*        The input parameters are all stored in the file of "InitPara.ini".
/* Output parameter:
/*        ctrl is a predefined struct which is used to keep all the necessary parameters,
/*        The return value is a flag to indicate that whether this function is executed successfully.
/* Note:
/*        ctrl should be built before this function is called, and the configuration file 
/*        "InitPara.ini" should be set correctly ahead.
/**********************************************/

#include "parameter_sets.h"

int DispInitParaF(struct BasicParaS * ctrl)
{
	//////////////////////////////////////////////////////////////////
	// Declaration
	FILE * fpInitPara;		//定义文件指针
	char buffer[120];
	const char * H_Matrix_Type_S[6] = {"H_1_2", "H_2_3_A", "H_2_3_B", "H_3_4_A", "H_3_4_B", "H_5_6"};
	const char * Modulation_Type_S[4] = {"BPSK", "QPSK", "16QAM", "64QAM"};
	const char * Decoding_Type_S[3] = {"Sum-Product", "Log-Sum-Product", "Min-Sum"};
	const char * Noise_Mode_S[2] = {"Eb/No", "SNR"};
	int i;
	FILE * fpOut = fopen("output.txt", "a");
	
	//////////////////////////////////////////////////////////////////
	//Initialization
	if ((fpInitPara=fopen("InitPara.ini","r"))==NULL)
	{
		printf("Can't open the file 'InitPara.ini'\n");
		exit(0);
	}

	for (i=0; i<5; i++)
		fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%s", &buffer);
	printf("The basic check matrix is %s ..\n", buffer);
	fprintf(fpOut, "The basic check matrix is %s ..\n", buffer);
	for (i=0; i<6; i++)
	{
		if (strcmp(buffer, H_Matrix_Type_S[i])==0)
		{
			ctrl->typeH = i;
			break;
		}
	}


	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%d", &ctrl->codeN);
	if (((ctrl->codeN-576)%96) != 0)
	{
		printf("The length of the code word isn't supported here\n");
		exit(0);
	}
	printf("The length of the code word is %d ..\n", ctrl->codeN);
	fprintf(fpOut, "The length of the code word is %d ..\n", ctrl->codeN);

	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%s", buffer);
	printf("The type of Modulation is %s..\n", buffer);
	fprintf(fpOut, "The type of Modulation is %s..\n", buffer);
	for (i=0; i<4; i++)
	{
		if (strcmp(buffer,Modulation_Type_S[i])==0)
		{
			ctrl->typeModu=i;
			break;
		}
	}	

	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%s", buffer);
	printf("The type of Decoding is %s..\n", buffer);
	fprintf(fpOut, "The type of Decoding is %s..\n", buffer);
	for (i=0; i<3; i++)
	{
		if (strcmp(buffer, Decoding_Type_S[i])==0)
		{
			ctrl->typeDecode = i;
			break;
		}
	}
	
	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%d", &ctrl->maxIter);
	printf("The maximum time of iteration of decoding is %d ..\n", ctrl->maxIter);
	fprintf(fpOut, "The maximum time of iteration of decoding is %d ..\n", ctrl->maxIter);

	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%s", &buffer);
	printf("The relation between signal and noise is %s ..\n", buffer);
	fprintf(fpOut, "The relation between signal and noise is %s ..\n", buffer);
	for (i=0; i<2; i++) 
	{
		if (strcmp(buffer, Noise_Mode_S[i]) == 0)
		{
			ctrl->noiseMode = i;
			break;
		}
	}


	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%d", &ctrl->totalNumFrames);
	if (ctrl->totalNumFrames >= 20)
	{
		printf("Too many points !!! \n");
		return 1;
	}
	else 
	{
		printf("The number of points of Eb/No is %d ..\n", ctrl->totalNumFrames);
		fprintf(fpOut, "The number of points of Eb/No is %d ..\n", ctrl->totalNumFrames);
	}

	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	printf("The range of Eb/No is: ");
	fprintf(fpOut, "The range of Eb/No is: ");
	for (i=0; i<ctrl->totalNumFrames; i++) 
	{
		fscanf(fpInitPara, "%f", &ctrl->Eb_No[i]);
		printf("%.2f ", ctrl->Eb_No[i]);
		fprintf(fpOut, "%.2f ", ctrl->Eb_No[i]);
	}
	printf("\n");
	fprintf(fpOut, "\n");
	
	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	printf("The number of frames per Eb/No is: ");
	fprintf(fpOut, "The number of frames per Eb/No is: ");
	for (i=0; i<ctrl->totalNumFrames; i++) {
		fscanf(fpInitPara, "%d", &ctrl->nFrames[i]);
		printf("%d ", ctrl->nFrames[i]);
		fprintf(fpOut,"%d ", ctrl->nFrames[i]);
	}
	printf("\n");
	fprintf(fpOut,"\n");

	fgets(buffer, 120, fpInitPara);
	fgets(buffer, 120, fpInitPara);
	fscanf(fpInitPara, "%d", &ctrl->maxRetrans);
	printf("The maximum number of retransmissions is %d ..\n", ctrl->maxRetrans);
	fprintf(fpOut, "The maximum number of retransmissions is %d ..\n", ctrl->maxRetrans);


	
	
	//////////////////////////////////////////////////////////////////
	// Insert the loading programs here ..
	ctrl->numCols = 24;
	switch(ctrl->typeH) {
	case 0:
		ctrl->numRows = 12;
		ctrl->r = 2.0;		
		break;
	case 1:
		ctrl->numRows = 8;
		ctrl->r = 1.5;		
		break;
	case 2:
		ctrl->numRows = 8;
		ctrl->r = 1.5;	
		break;
	case 3:
		ctrl->numRows = 6;
		ctrl->r = 4.0/3;	
		break;
	case 4:
		ctrl->numRows = 6;
		ctrl->r = 4.0/3;	
		break;
	case 5:
		ctrl->numRows=4;
		ctrl->r = 1.2;		
		break;		
	default:
		exit(0);
	}

	ctrl->zfactor = ctrl->codeN/24;
	ctrl->numOutBits = ctrl->codeN;	
	ctrl->numChk = ctrl->numRows*ctrl->zfactor;
	ctrl->numVar = ctrl->numOutBits;
	ctrl->codeM = ctrl->numChk;
	ctrl->numInBits = ctrl->numOutBits - ctrl->numChk;
	ctrl->codeK = ctrl->numInBits;
	
		
	//////////////////////////////////////////////////////////////////
	fclose(fpInitPara);	
	fclose(fpOut);

	return 0;
}




















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -