📄 main.c
字号:
/** \file */#include <stdio.h>#include <stddef.h>#include <stdlib.h>#include <math.h>#include <assert.h>#include <string.h>#include <gsl/gsl_rng.h>#include <gsl/gsl_randist.h>#include "ieee802154a.h"#ifndef DARWIN#include <argp.h>const char *argp_program_version ="IEEE 802.15.4a channel generator (0.1)";const char *argp_program_bug_address ="<ruben.merz@epfl.ch> and <manuel.flury@epfl.ch>";/* Program documentation. */static char doc[] ="IEEE 802.15.4a channel generator";/* A description of the arguments we accept. */static char args_doc[] = "ARG1 ARG2";/* The options we understand. */static struct argp_option options[] = { {"model", 'm', "MODEL", 0, "Use the channel model MODEL", 0 }, {"samples", 'n', "SAMPLE", 0, "SAMPLE channel samples are produced", 0 }, {"fs", 'f', "FS", 0, "Sampling frequency FS (in GHz)", 0 }, {"threshold", 't', "TRESH", 0, "Threshold for the minimum path amplitude (in dB)", 0 }, {"debug", 'd', 0, 0, "Debugging output", 0 }, {"seed", 's', "SEED", 0, "Seed of the RNG", 0 }, {"output", 'o', "FILE", 0, "Output to FILE instead of standard output", 0 }, { 0, 0, 0, 0, 0, 0 }};/* Used by main to communicate with parse_opt. */struct arguments { char *args[2]; /* arg1 & arg2 */ int cm; int samples; int debug; long int seed; double fs; double thld_db; char *output_file;}; /* Parse a single option. */static error_tparse_opt (int key, char *arg, struct argp_state *state){ /* Get the input argument from argp_parse, which we know is a pointer to our arguments structure. */ struct arguments *arguments = state->input; switch (key) { case 'm': arguments->cm = atoi(arg); break; case 'n': arguments->samples = atoi(arg); break; case 'f': arguments->fs = atof(arg); break; case 't': arguments->thld_db = atof(arg); break; case 'd': arguments->debug = 1; break; case 's': arguments->seed = atoi(arg); break; case 'o': arguments->output_file = arg; break; case ARGP_KEY_ARG: if (state->arg_num > 0) /* Too many arguments. */ argp_usage (state); arguments->args[state->arg_num] = arg; break; case ARGP_KEY_END: if (state->arg_num > 0) /* Too many arguments. */ argp_usage (state); break; default: return ARGP_ERR_UNKNOWN; } return 0;} /* Our argp parser. */static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };#endif/** * \brief free the memory */voidclean_up(gsl_rng * r, ieee802154a_channel_cluster* channel_cluster, ieee802154a_channel_cont* channel_cont, ieee802154a_channel_discr* channel_discr);intmain(int argc, char **argv){ ieee802154a_parameters param; ieee802154a_channel_cluster channel_cluster; ieee802154a_channel_cont channel_cont; ieee802154a_channel_discr channel_discr; int channel_model; const gsl_rng_type * T; gsl_rng * r;#ifndef DARWIN struct arguments arguments; /* Default values. */ arguments.cm = 1; arguments.samples = 1; arguments.fs = 8.0; arguments.thld_db = 40.0; arguments.seed = 197; arguments.debug = 0; arguments.output_file = ""; /* Parse our arguments; every option seen by parse_opt will be reflected in arguments. */ argp_parse (&argp, argc, argv, 0, 0, &arguments); channel_model = arguments.cm; channel_discr.fs = arguments.fs; /* Set sampling frequency in GHz */ channel_cluster.thld_db = arguments.thld_db;#else channel_model = 0; channel_discr.fs = 50.0; channel_cluster.thld_db = 30.0;#endif /* create a generator chosen by the environment variable GSL_RNG_TYPE */ gsl_rng_env_setup(); T = gsl_rng_default; r = gsl_rng_alloc(T);#ifndef DARWIN if (arguments.seed != 0) { gsl_rng_default_seed = arguments.seed; gsl_rng_set (r, gsl_rng_default_seed); } /* Or use the environment variable GSL_RNG_SEED */ if (arguments.debug == 1) { fprintf(stdout,"UWB channel generator\n"); fprintf(stdout,"channel model %d, fs = %.2f GHz, threshold = %.2f dB\n", channel_model,channel_discr.fs,channel_cluster.thld_db); if (strcmp(arguments.output_file,"")!=0) fprintf(stdout,"Write output to %s\n",arguments.output_file); fprintf(stdout,"GSL random number generator seed = %lu\n", gsl_rng_default_seed); }#endif param = load_ieee802154a_parameters(channel_model); get_L(&channel_cluster,param.barL,r); get_T_l(&channel_cluster, ¶m, r); get_tau_kl(&channel_cluster, &channel_cont, ¶m, r); convert_discrete(&channel_cont, &channel_discr, channel_discr.fs); /* Be careful with this one */#ifndef DARWIN print_channel(&channel_cont,&channel_discr,arguments.output_file);#else print_channel(&channel_cont,&channel_discr,"channel.txt");#endif /* Clean up everything */ clean_up(r, &channel_cluster, &channel_cont, &channel_discr); /* Done, say goodbye */ exit(0);}voidclean_up(gsl_rng * r, ieee802154a_channel_cluster* channel_cluster, ieee802154a_channel_cont* channel_cont, ieee802154a_channel_discr* channel_discr){ gsl_rng_free(r); free_channel_cluster(channel_cluster); free_channel_cont(channel_cont); free_channel_discr(channel_discr);}/* float myfunction(float x, int powfer) *//* { *//* return powf(x-3,powfer); *//* } */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -