interpolator.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. voltlogger_analyzer
  3. Copyright (C) 2015 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #define _GNU_SOURCE
  16. #include "configuration.h"
  17. #include "macros.h"
  18. #include <stdio.h> /* getline() */
  19. #include <stdlib.h> /* atof() */
  20. #include <unistd.h> /* getopt() */
  21. #include <math.h>
  22. #include <assert.h>
  23. #include "error.h"
  24. #include "analyzer.h"
  25. enum functype {
  26. FT_SIN,
  27. FT_REPEAT,
  28. };
  29. typedef enum functype functype_t;
  30. static char *const functypes[] = {
  31. [FT_REPEAT] = "repeat",
  32. NULL
  33. };
  34. int main(int argc, char *argv[]) {
  35. functype_t functype = FT_REPEAT;
  36. char realtime = 0;
  37. float frequency = 50;
  38. int concurrency = 1, addperiods = 0;
  39. int channelsNum = 1;
  40. char *checkpointpath = NULL;
  41. FILE *input = stdin;
  42. FILE *output = stdout;
  43. // Initializing output subsystem
  44. {
  45. int output_method = OM_STDERR;
  46. int output_quiet = 0;
  47. int output_verbosity = 9;
  48. int output_debuglevel = 9;
  49. error_init(&output_method, &output_quiet, &output_verbosity, &output_debuglevel);
  50. }
  51. // Parsing arguments
  52. char c;
  53. while ((c = getopt (argc, argv, "ri:N:f:F:c:C:e:s:a:")) != -1) {
  54. char *arg;
  55. arg = optarg;
  56. switch (c)
  57. {
  58. case 'f': {
  59. char *value;
  60. functype = getsubopt(&arg, functypes, &value);
  61. break;
  62. }
  63. case 'F':
  64. frequency = atof(optarg);
  65. break;
  66. case 'r':
  67. realtime = 1;
  68. break;
  69. case 'N':
  70. channelsNum = atoi(optarg);
  71. break;
  72. case 'c':
  73. concurrency = atoi(optarg);
  74. break;
  75. case 'C':
  76. checkpointpath = arg;
  77. break;
  78. case 'i':
  79. assert ((input = fopen(arg, "r")) != NULL);
  80. break;
  81. case 'a':
  82. addperiods = atoi(optarg);
  83. break;
  84. default:
  85. abort ();
  86. }
  87. }
  88. switch (functype) {
  89. case FT_REPEAT:
  90. vl_interpolate_repeat(input, output, channelsNum, 0, addperiods, checkpointpath, concurrency, frequency, realtime);
  91. break;
  92. default:
  93. fprintf(stderr, "Unknown approximation function\n");
  94. abort ();
  95. }
  96. return 0;
  97. }