ISIS Logo
UTILITIES
EPICS Utilities
find_calibration_range_impl.cpp
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdlib.h>
3 #include <registryFunction.h>
4 #include <menuFtype.h>
5 #include <errlog.h>
6 #include <epicsString.h>
7 #include <epicsExport.h>
8 #include <string>
9 #include <vector>
10 #include <iostream>
11 #include <fstream>
12 
15 
16 
17 long find_calibration_range_impl(aSubRecord *prec) {
18  // Check for input types
19  if (prec->fta != menuFtypeSTRING)
20  {
21  errlogSevPrintf(errlogMajor, "%s incorrect input argument type A", prec->name);
22  return 1;
23  }
24  if (prec->ftb != menuFtypeSTRING)
25  {
26  errlogSevPrintf(errlogMajor, "%s incorrect input argument type B", prec->name);
27  return 1;
28  }
29  if (prec->ftc != menuFtypeSTRING)
30  {
31  errlogSevPrintf(errlogMajor, "%s incorrect input argument type C", prec->name);
32  return 1;
33  }
34  try {
35  std::string calibration_file_location = find_file(prec->a, prec->b, prec->c);
36  std::ifstream calibration_file;
37  // Load file
38  calibration_file.open(calibration_file_location);
39 
40  std::vector<std::vector<std::string>> lines;
41 
42  if (calibration_file.is_open())
43  {
44  // Iterate over the lines
45  while (calibration_file.peek() != EOF)
46  {
47  lines.push_back(getNextLineAndSplitOnComma(calibration_file));
48  }
49  calibration_file.close();
50  }
51 
52  // Get highest and lowest values in the first column of the calibration file
53  double low_limit = std::stod(lines[0][0]);
54  double high_limit = std::stod(lines[lines.size() - 1][0]);
55 
56  // Check the types of output values
57  if (prec->ftva != menuFtypeDOUBLE) {
58  errlogSevPrintf(errlogMajor, "%s incorrect output argument type A", prec->name);
59  return 1;
60  }
61  if (prec->ftvb != menuFtypeDOUBLE) {
62  errlogSevPrintf(errlogMajor, "%s incorrect output argument type B", prec->name);
63  return 1;
64  }
65 
66  // Set the values to the output PVs
67  (static_cast<double*>(prec->vala))[0] = high_limit;
68  (static_cast<double*>(prec->valb))[0] = low_limit;
69  }
70  catch (std::exception& e) {
71  errlogSevPrintf(errlogMajor, "%s exception: %s", prec->name, e.what());
72  return 1;
73  }
74  return 0; /* process output links */
75 }
std::string find_file(void *BDIR, void *TDIR, void *SPEC)
Finds the directory to the table file.
long find_calibration_range_impl(aSubRecord *prec)
std::vector< std::string > getNextLineAndSplitOnComma(std::ifstream &str)
Gets the next line of an input stream and splits on a comma.
Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5