📄 init_system.cpp
字号:
/*
**********************************************************************************
FILENAME: simconfig.h
version 0.1
(C) Pan Yu, 2004
Declaration:
All right is deserved by author
Anyone use this source codes and remove author's name is prohibited
Without agreement,noboby can transfer this codes to others.
Fucntion Description:
Initialize the simulation program in this file and allocate memory !
*********************************************************************************
ChangeLog:
2004-07-10 : start
2004-07-11 : modify function Read_H_asc() for adapting different file format
2004-10-22 : add memory allocation for min-sum iteration function!
**********************************************************************************
*/
#include "init_system.h"
#include "sim_config.h"
//--------------------SNR range for simulation
#define Eb_N0_STEP 0.2
#define Eb_N0_START 2.0
#define Eb_N0_END 2.1//(3.0 + Eb_N0_STEP/2.)
/////////////////////////////////////////////////////
Str_sys_spt sys_spt;
void Read_H_asc(){
int i;
int x;
int y;
FILE *fpH;
fpH = fopen(H_FILE,"r");
if (fpH==NULL)
{
printf("H_FILE does not exist!!Check the file!\n");
exit(0);
}
fscanf(fpH,"%d %d",&sys_spt.row_num,&sys_spt.col_num);
//allcate memory for bit_nodes.size
sys_spt.bit_nodes.size = (int *)calloc(sys_spt.col_num,sizeof(int));
if (sys_spt.bit_nodes.size==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.size");
}
//allcate memory for check_nodes.size
sys_spt.check_nodes.size = (int *)calloc(sys_spt.row_num,sizeof(int));
if (sys_spt.check_nodes.size==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.size");
}
fscanf(fpH,"%d %d",&x,&y);
while(!feof(fpH))
{
sys_spt.check_nodes.size[x-1]++; //6
sys_spt.bit_nodes.size[y-1]++; //3
fscanf(fpH,"%d %d",&x,&y);
}
fclose(fpH);
//allcate memory for bit_nodes.index
sys_spt.bit_nodes.index = (int **)calloc(sys_spt.col_num,sizeof(int*));
if (sys_spt.bit_nodes.index==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.index");
}
for (i=0;i<sys_spt.col_num;i++)
{
sys_spt.bit_nodes.index[i] = (int *)calloc(sys_spt.bit_nodes.size[i],sizeof(int));
if (sys_spt.bit_nodes.index[i]==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.index[i]");
}
}
//allcate memory for check_nodes.index
sys_spt.check_nodes.index = (int **)calloc(sys_spt.row_num,sizeof(int*));
if (sys_spt.check_nodes.index==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.index");
}
for (i=0;i<sys_spt.row_num;i++)
{
sys_spt.check_nodes.index[i] = (int *)calloc(sys_spt.check_nodes.size[i],sizeof(int));
if (sys_spt.check_nodes.index[i]==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.index[i]");
}
}
//allocate memory for row_wt_profile
int *row_wt_profile;
row_wt_profile = (int *)calloc(sys_spt.row_num,sizeof(int));
if (row_wt_profile==NULL)
{
printf("Insufficient memory available for row_wt_profile");
}
//allocate memory for col_wt_profile
int *col_wt_profile;
col_wt_profile = (int *)calloc(sys_spt.col_num,sizeof(int));
if (col_wt_profile==NULL)
{
printf("Insufficient memory available for col_wt_profile");
}
fpH = fopen(H_FILE,"r");
fscanf(fpH,"%d %d",&x,&y); //row_num col_num
fscanf(fpH,"%d %d",&x,&y);
while(!feof(fpH))
{
sys_spt.check_nodes.index[x-1][row_wt_profile[x-1]] = y-1;
sys_spt.bit_nodes.index[y-1][col_wt_profile[y-1]] = x-1;
row_wt_profile[x-1]++;
col_wt_profile[y-1]++;
fscanf(fpH,"%d %d",&x,&y);
}
fclose(fpH);
sys_spt.max_col_wt = 0;
sys_spt.max_row_wt = 0;
for (i=0;i<sys_spt.col_num;i++)
{
if (sys_spt.max_col_wt<col_wt_profile[i])
{
sys_spt.max_col_wt = col_wt_profile[i];
}
}
for (i=0;i<sys_spt.row_num;i++)
{
if (sys_spt.max_row_wt<row_wt_profile[i])
{
sys_spt.max_row_wt = row_wt_profile[i];
}
}
free(row_wt_profile);
free(col_wt_profile);
}
void Read_H(){
int i,j;
int x;
FILE *fpH;
fpH = fopen(H_FILE,"r");
if (fpH==NULL)
{
printf("H_FILE does not exist!!Check the file!\n");
exit(0);
}
fscanf(fpH,"%d %d",&sys_spt.col_num,&sys_spt.row_num);
fscanf(fpH,"%d %d",&sys_spt.max_row_wt,&sys_spt.max_col_wt); //max_row_wt max_col_wt
//allcate memory for bit_nodes.size
sys_spt.bit_nodes.size = (int *)calloc(sys_spt.col_num,sizeof(int));
if (sys_spt.bit_nodes.size==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.size");
}
//allcate memory for check_nodes.size
sys_spt.check_nodes.size = (int *)calloc(sys_spt.row_num,sizeof(int));
if (sys_spt.check_nodes.size==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.size");
}
for (i=0;i<sys_spt.row_num;i++)
{
fscanf(fpH,"%d",&x); //row_wt profile
sys_spt.check_nodes.size[i]=x;
}
for (i=0;i<sys_spt.col_num;i++)
{
fscanf(fpH,"%d",&x); //col_wt profile
sys_spt.bit_nodes.size[i]=x;
}
//allcate memory for bit_nodes.index
sys_spt.bit_nodes.index = (int **)calloc(sys_spt.col_num,sizeof(int*));
if (sys_spt.bit_nodes.index==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.index");
}
for (i=0;i<sys_spt.col_num;i++)
{
sys_spt.bit_nodes.index[i] = (int *)calloc(sys_spt.bit_nodes.size[i],sizeof(int));
}
if (sys_spt.bit_nodes.index[i]==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.index[i]");
}
//allcate memory for check_nodes.index
sys_spt.check_nodes.index = (int **)calloc(sys_spt.row_num,sizeof(int*));
if (sys_spt.check_nodes.index==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.index");
}
for (i=0;i<sys_spt.row_num;i++)
{
sys_spt.check_nodes.index[i] = (int *)calloc(sys_spt.check_nodes.size[i],sizeof(int));
}
if (sys_spt.check_nodes.index[i]==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.index[i]");
}
for (i=0;i<sys_spt.row_num;i++)
{
for (j=0;j<sys_spt.check_nodes.size[i];j++)
{
fscanf(fpH,"%d",&x); //"1" locations in each row
sys_spt.check_nodes.index[i][j]=x;
}
}
for (i=0;i<sys_spt.col_num;i++)
{
for (j=0;j<sys_spt.bit_nodes.size[i];j++)
{
if (feof(fpH))
{
printf("File H.spmat is not full!!!!!");
exit(0);
}
fscanf(fpH,"%d",&x); //"1" locations in each row
sys_spt.bit_nodes.index[i][j]=x;
}
}
fclose(fpH);
}
void Read_G(){
int i,j,k;
int x;
FILE *fpQ;
fpQ = fopen(G_FILE,"r");
if (fpQ==NULL)
{
printf("G_FILE does not exist!!Check the file!\n");
exit(0);
}
//read G_sparse_matrix parameters from file
fscanf(fpQ,"%d %d",&sys_spt.message_bits,&sys_spt.check_bits);//message_bits and check_bits
if (sys_spt.check_bits!=(sys_spt.col_num-sys_spt.message_bits))
{
printf("Input parameters error:message_bits and check_bits in G file ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -