Esempio n. 1
0
int main(int argc, char** argv){
    int retval = 0;
    int i, Navg;
    param_obj param;
    kw_obj kw;
    ts_obj ts;
    vsip_mview_f *dtaIn, *gramOut;
    if(retval += param_read(argv[1],&param)){
        printf("Failed to read parameter file\n");
        exit(-1);
    }
    param_log(&param);
    kw_init(&kw, &param);
    ts_init(&ts, &param);
    /* simulate time series and beamform */
    Navg = (int) param.Navg;
    dtaIn = ts_instance(&ts);
    gramOut = kw_instance(&kw);
    kw_zero(&kw);
    for(i=0; i<Navg; i++){
        ts_zero(&ts);
        ts_sim_noise(&ts);
        ts_sim_nb(&ts);
        komega(&kw,dtaIn);
    }
    /* beamform done. Gram should be in gramOut */
    /*************/    
    /* Massage gram data and save to file for plotting */
      for(i=0; i<vsip_mgetrowlength_f(gramOut); i++)
      {/* move zero to middle */
         vsip_vview_f *v = vsip_mcolview_f(gramOut, i);
         vsip_vfreqswap_f(v);
         vsip_vdestroy_f(v);
      }
      {/* massage the data for plot*/
         vsip_scalar_f max = vsip_mmaxval_f(gramOut, NULL),min;
         vsip_scalar_f avg = vsip_mmeanval_f(gramOut);
         vsip_mclip_f(gramOut,0.0, max, avg/100000.0, max, gramOut);
         vsip_mlog10_f(gramOut,gramOut);
         min = -vsip_mminval_f(gramOut, NULL);
         vsip_smadd_f(min, gramOut, gramOut);
         max = vsip_mmaxval_f(gramOut, NULL);
         vsip_smmul_f(1.0/max, gramOut, gramOut);
      }
      { /* output data and plot with octave */
         FILE *fptr = fopen("gramOut","w");
         size_t size = vsip_mgetrowlength_f(gramOut) * vsip_mgetcollength_f(gramOut);
         vsip_scalar_f *out = (vsip_scalar_f*)malloc(size * sizeof(vsip_scalar_f));
         vsip_mcopyto_user_f(gramOut, VSIP_COL, out);
         fwrite(out,size,sizeof(vsip_scalar_f),fptr);
         fclose(fptr);
         free(out);
      }
    /* cleanup */
    kw_fin(&kw);
    ts_fin(&ts);
    param_free(&param);
    return retval;
}
Esempio n. 2
0
/**
* @brief	从保存终端系统参数的存储模块中读取参数保存到全局变量中
* @param[in]  none
* @param[out] 存储终端参数的全局变量
* @return     unsigned char  0  :SUCCESS   else : 错误代码
* @note
*/
int ReadTerminalPara(void)
{
    unsigned long			checkvalue;
    int		ret;

    if (param_mod_state == 0)
    {
        ret = param_init(sizeof(TTerminalPara));
        if (ret)
        {
            if (ret == -3 || ret == -4 || ret == -6)
            {
                ret = param_format(sizeof(TTerminalPara));
                if (ret)
                {
                    return ret;
                }
            }
            else
            {
                return ret;
            }
        }

        param_mod_state = 1;
    }

    ret = param_read((unsigned char*)&g_param,sizeof(TTerminalPara));
    if(ret)
    {
        return ret;
    }



#if 1
    //计算校验值是否正确
    checkvalue = crc32(0,(unsigned char*)&g_param.line_after_mark,sizeof(TTerminalPara) - 4);
    if (g_param.checkvalue != checkvalue)
    {
        //参数的校验值不对
        return 2;
    }

    // 检查参数是否正确
    if ((g_param.endtag[0] != 0x55)||(g_param.endtag[1] != 0xAA)||(g_param.endtag[2] != 0x5A)||(g_param.struct_ver != 1))
    {
        //参数的结束标记不对
        return 3;
    }


    //检查其余参数是否正确
    //@todo....
#endif
    return 0;
}