35 #define SIGSCALE_VERSION \ 36 "SIGSCALE V1.0 apply scaling relations to input signals" 40 #include <tfxx/commandline.h> 41 #include <tfxx/error.h> 42 #include <tfxx/seitosh.h> 43 #include <datrwxx/channeltranslation.h> 47 #include <tfxx/xcmdline.h> 48 #include <tfxx/stringfunc.h> 49 #include <tfxx/rangestring.h> 50 #include <tfxx/rangelist.h> 51 #include <tfxx/misc.h> 52 #include <datrwxx/readany.h> 53 #include <datrwxx/writeany.h> 55 #include <aff/iterator.h> 57 using datrw::tsoft::Econversion;
58 using datrw::tsoft::ChannelDescription;
59 using datrw::tsoft::SFFchannelid;
60 using datrw::tsoft::channel;
82 const double VL[4] = { 1.32412, 1.11732, 0.923142, 0.079767 };
83 const double VU[4] = { 1.69812, 1.42013, 1.139350, 0.999614 };
84 const int ND[4] = { 10, 11, 12, 11};
85 const double A [4][12] =
86 {{ 7.556358, -5.917261, 0.237238, -0.334636, -0.058642, -0.019929,
87 -0.020715, -0.014814, -0.008789, -0.008554, 0.000000, 0.000000},
88 {17.304227, -7.894688, 0.453442, 0.002243, 0.158036, -0.193093,
89 0.155717, -0.085185, 0.078550, -0.018312, 0.039255, 0.000000},
90 {71.818025, -53.799888, 1.669931, 2.314228, 1.566635, 0.723026,
91 -0.149503, 0.046876, -0.388555, 0.056889, 0.116823, 0.058580},
92 {287.756797, -194.144823, -3.837903, -1.318325, -0.109120, -0.393265,
93 0.146911, -0.111192, 0.028877, -0.029286, 0.015619, 0.000000}};
103 std::cout <<
" to be implemented " << std::endl;
104 std::cout <<
" range " << range << std::endl;
112 return( (
double)(1.0/0.00385) * ((ohms/(
double)100.0) - (
double)1.0) );
128 return( (volts - 6.0) * 0.250) ;
136 double a, b, c, Ro, Rt, T;
142 b = 3.84 * 0.001 * Ro;
143 a = 4.94 * 0.000001 * Ro;
145 T = ((-b) + sqrt((b*b) - (4.0*a*c))) / (2.0*a);
155 double x, t, v, vl, vu;
158 if ( volts < 0.24963 )
163 if ( volts > 1.698120 )
177 x = ((v-vl)-(vu-v))/(vu-vl);
179 if ( x <= -1.0 || x >= 1.0 ) x = 0 ;
182 for( i=0; i<nd; i++ )
183 t = t +
A[range][i]*cos(i*acos(x));
194 double x, t, v, vl, vu;
198 if ( volts < 0.24963 )
203 if ( volts > 1.698120 )
219 x = ((v-vl)-(vu-v))/(vu-vl);
221 if ( x <= -1.0 || x >= 1.0 ) x = 0 ;
224 for( i=0; i<nd; i++ )
225 t = t +
A[range][i]*cos(i*acos(x));
239 return(100.0 + (volts * -12.3871)) ;
252 return(100.0 + (volts * -10.2328)) ;
277 else if ( volts > 1.8 )
281 dPSI = (volts - 0.1996) * 626.2525 ;
310 else if ( volts > 1.8 )
314 dPSI = (volts - 0.1996) * 3757.5150 ;
344 else if ( volts > 1.8 )
348 KPa = (volts - 0.1996) * 4317.8590 ;
378 else if ( volts > 1.8 )
382 KPa = (volts - 0.1996) * 25907.1541 ;
413 else if ( volts > 1.8 )
417 dPSI = (volts - 0.1996) * 3131.263 ;
448 else if ( volts > 1.8 )
452 KPa = (volts - 0.1996) * 21589.295 ;
483 else if ( volts > 1.8 )
487 MPa = (volts - 0.1996) * 21.589295 ;
518 else if ( volts > 1.8 )
522 MPa = (volts - 0.1996) * 4.317859 ;
552 else if ( volts > 1.8 )
556 MPa = (volts - 0.1996) * 25.90715 ;
586 else if ( volts > 9.9 )
589 dFanPercent = (volts - 1.6) * 12.04819 ;
602 const double& chanval)
604 double retval, V, Vcor;
608 case datrw::tsoft::SIDIODE:
609 case datrw::tsoft::SIDIODE1:
612 case datrw::tsoft::PT100:
615 case datrw::tsoft::PT100V:
619 case datrw::tsoft::PT100_K:
622 case datrw::tsoft::PT100V_K:
626 case datrw::tsoft::PSI_1_1:
629 case datrw::tsoft::GEPLHe19:
632 case datrw::tsoft::GEPLHe23:
635 case datrw::tsoft::TD:
638 case datrw::tsoft::TDV:
641 case datrw::tsoft::MASFLO1:
647 retval = ( -39.35 + (48.390 * V) - (11.737 * V * V) + (2.3064 * V * V * V) ) ;
653 case datrw::tsoft::H2OFLO1:
656 case datrw::tsoft::SIDIODE2:
659 if ( Vcor > 1.25 ) { Vcor = chanval - (0.2363 * ( chanval - 1.25 )); }
663 case datrw::tsoft::SIDIODE3:
665 Vcor = chanval/4.98 ;
668 case datrw::tsoft::SIDIODE4:
670 Vcor = chanval/4.98 ;
671 if ( Vcor > 1.25) { Vcor = Vcor - (0.2363 * ( Vcor - 1.25 )); }
674 case datrw::tsoft::POWERV:
678 { retval = chanval * chanval; }
680 case datrw::tsoft::PSI_500:
683 case datrw::tsoft::PSI_3000:
686 case datrw::tsoft::KPA_3447:
689 case datrw::tsoft::KPA_20684:
692 case datrw::tsoft::PSI_2500:
695 case datrw::tsoft::KPA_17236:
698 case datrw::tsoft::MPA_17236:
701 case datrw::tsoft::MPA_3447:
704 case datrw::tsoft::MPA_20684:
707 case datrw::tsoft::FAN16:
710 case datrw::tsoft::C20P4:
711 retval = chanval * 20.4;
713 case datrw::tsoft::CNSP:
714 case datrw::tsoft::CNFD:
718 std::cerr <<
"WARNING: \n" 719 <<
" unknown channel conversion code: " << ConvCode <<
"\n";
736 case datrw::tsoft::SIDIODE:
737 return "SIDIODE";
break;
738 case datrw::tsoft::SIDIODE1:
739 return "SIDIODE1";
break;
740 case datrw::tsoft::PT100:
741 return "PT100";
break;
742 case datrw::tsoft::PT100V:
743 return "PT100V";
break;
744 case datrw::tsoft::PT100_K:
745 return "PT100_K";
break;
746 case datrw::tsoft::PT100V_K:
747 return "PT100V_K";
break;
748 case datrw::tsoft::PSI_1_1:
749 return "PSI_1_1";
break;
750 case datrw::tsoft::GEPLHe19:
751 return "GEPLHe19";
break;
752 case datrw::tsoft::GEPLHe23:
753 return "GEPLHe23";
break;
754 case datrw::tsoft::TD:
756 case datrw::tsoft::TDV:
758 case datrw::tsoft::MASFLO1:
759 return "MASFLO1";
break;
760 case datrw::tsoft::H2OFLO1:
761 return "H2OFLO1";
break;
762 case datrw::tsoft::SIDIODE2:
763 return "SIDIODE2";
break;
764 case datrw::tsoft::SIDIODE3:
765 return "SIDIODE3";
break;
766 case datrw::tsoft::SIDIODE4:
767 return "SIDIODE4";
break;
768 case datrw::tsoft::POWERV:
769 return "POWERV";
break;
770 case datrw::tsoft::PSI_500:
771 return "PSI_500";
break;
772 case datrw::tsoft::PSI_3000:
773 return "PSI_3000";
break;
774 case datrw::tsoft::KPA_3447:
775 return "KPA_3447";
break;
776 case datrw::tsoft::KPA_20684:
777 return "KPA_20684";
break;
778 case datrw::tsoft::PSI_2500:
779 return "PSI_2500";
break;
780 case datrw::tsoft::KPA_17236:
781 return "KPA_17236";
break;
782 case datrw::tsoft::MPA_17236:
783 return "MPA_17236";
break;
784 case datrw::tsoft::MPA_3447:
785 return "MPA_3447";
break;
786 case datrw::tsoft::MPA_20684:
787 return "MPA_20684";
break;
788 case datrw::tsoft::FAN16:
789 return "FAN16";
break;
790 case datrw::tsoft::C20P4:
791 return "C20P4";
break;
792 case datrw::tsoft::CNSP:
793 return "CNSP";
break;
794 case datrw::tsoft::CNFD:
795 return "not found";
break;
797 return "unknown";
break;
811 int main(
int iargc,
char* argv[])
818 "usage: sigscale [-v] [-o] [-itype type] [-otype type]" "\n" 819 " outfile infile [t:T] [f:F] [infile [t:T] [f:F] ... ]" "\n" 820 " or: sigscale --help|-h" "\n" 821 " or: sigscale --xhelp" "\n" 827 "outfile name of output file" "\n" 828 "infile name of input file" "\n" 829 " t:T select traces T, where T may be any range" "\n" 830 " specification like \'3-4\' or \'5,6,7-12,20\'" "\n" 831 " f:F specifies an input file format differing from" "\n" 832 " the format selected by \"-type\"" "\n" 834 "-xhelp print detailed information regarding file formats" "\n" 836 "-DEBUG produce debug output" "\n" 837 "-DEBREP report internal scaling values for debugging" "\n" 838 "-o overwrite output" "\n" 839 "-itype type choose input file format (default: sff)" "\n" 840 "-otype type choose output file format (default: sff)" "\n" 842 "This program is designed for auxilliary data from superconduction\n" 843 "gravimeter SG056 at BFO. It uses scling relations provided by GWR\n" 844 "to convert sample values to meaningful physical units." 848 using namespace tfxx::cmdline;
849 static Declare options[]=
858 {
"itype",arg_yes,
"sff"},
860 {
"otype",arg_yes,
"sff"},
862 {
"DEBUG",arg_no,
"-"},
864 {
"xhelp",arg_no,
"-"},
866 {
"DEBREP",arg_no,
"-"},
881 cerr << usage_text << endl;
882 cerr << tfxx::seitosh::repository_reference << endl;
887 Commandline cmdline(iargc, argv, options);
890 if (cmdline.optset(0))
892 cerr << usage_text << endl;
893 cerr << help_text << endl;
894 datrw::supported_data_types(cerr);
895 cerr << endl << tfxx::seitosh::repository_reference << endl;
900 if (cmdline.optset(6))
902 cerr << usage_text << endl;
904 datrw::online_help(cerr);
905 cerr << endl << tfxx::seitosh::repository_reference << endl;
914 opt.
debug=cmdline.optset(5);
916 opt.
debrep=cmdline.optset(7);
936 TFXX_assert(cmdline.extra(),
"missing output file");
937 std::string outfile=cmdline.next();
938 TFXX_assert(cmdline.extra(),
"missing input file");
939 tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline,
cmdlinekeys);
940 if ((arguments.size()>1) && opt.
verbose)
942 cout <<
"NOTICE: file specific information (SRCE line and file FREE)" <<
944 <<
" will be taken from first file only!" << endl;
952 if (opt.
verbose) { cout <<
"open output file " << outfile << endl; }
956 std::ifstream file(outfile.c_str(),std::ios_base::in);
957 TFXX_assert((!file.good()),
"ERROR: output file exists!");
959 std::ios_base::openmode oopenmode
961 std::ofstream ofs(outfile.c_str(), oopenmode);
968 tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
969 while (infile != arguments.end())
972 if (opt.
verbose) { cout <<
"open input file " << infile->name << endl; }
978 std::ios_base::openmode iopenmode
979 =datrw::ianystream::openmode(inputformat);
980 std::ifstream ifs(infile->name.c_str(), iopenmode);
981 datrw::ianystream is(ifs, inputformat);
990 sff::FREE infilefree;
992 filefree.append(
"block read from first input file:");
993 filefree.append(infilefree);
995 if (os.handlesfilefree()) { os << filefree; }
998 sff::SRCE insrceline;
1000 if (os.handlessrce()) { os << insrceline; }
1007 typedef tfxx::RangeList<int> Trangelist;
1008 bool doselect=infile->haskey(
tracekey);
1009 Trangelist traceranges=
1010 tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(
tracekey));
1015 if ((!doselect) || traceranges.contains(itrace))
1017 TFXX_debug(opt.
debug,
"main",
"process trace #" << itrace );
1019 { std::cout <<
" process trace #" << itrace <<
":"; }
1025 TFXX_debug(opt.
debug,
"main",
1026 " series and WID2 are read");
1035 ChannelDescription CD;
1037 sid.station=wid2.station;
1038 sid.channel=wid2.channel;
1039 sid.instrument=wid2.instype;
1040 sid.auxid=wid2.auxid;
1045 aff::Iterator<Tseries> I(series);
1056 TFXX_debug(opt.
debug,
"main",
1057 " series and WID are written");
1060 if (os.handlesinfo()) { os << info; }
1062 if (is.hasfree() ||
true)
1064 sff::FREE tracefree;
1067 tracefree.append(
"read from file " + infile->name);
1068 tracefree.append(
"applied scaling for conversion code \"" 1070 if (os.handlestracefree()) { os << tracefree; }
1072 TFXX_debug(opt.
debug,
"main",
1073 "trace #" << itrace <<
" successfully processed");
1078 TFXX_debug(opt.
debug,
"main",
"skip trace #" << itrace );
1080 { std::cout <<
" skip trace #" << itrace << std::endl; }
double convert_v_to_Pres_KPa_0_3447(double volts)
double convert_v_to_Pres_MPa_0_3447(double volts)
double convert_pt100_ohms_to_Kelvin(double ohms)
int main(int iargc, char *argv[])
double convert_pt100_ohms_to_celsius(double ohms)
double convert_v_to_Pres_MPa_0_20684(double volts)
double convert_td_ohms_to_celsius(double ohms)
double convert_sidiode_volts_to_kelvin_with_correction(double volts)
aff::Series< double > Tseries
double convert_volts_to_psi(double volts)
double convert_v_to_Pres_KPa_0_17236(double volts)
static const char * cmdlinekeys[]
static const char formatkey[]
double convert_sidiode_volts_to_kelvin(double volts)
double convert_v_to_FAN16(double volts)
double convert_to_display_units(const Econversion &ConvCode, const double &chanval)
double convert_v_to_Pres_PSI_0_3000(double volts)
std::string conversion_code(const Econversion &ConvCode)
void report_sidiode_table(int range)
double convert_GEPLHe19_volts_to_percent(double volts)
const char *const tracekey
key to select traces
double convert_v_to_Pres_PSI_0_500(double volts)
double convert_v_to_Pres_MPa_0_17236(double volts)
double convert_v_to_Pres_PSI_0_2500(double volts)
aff::Series< double > Tseries
double convert_v_to_Pres_KPa_0_20684(double volts)
double convert_GEPLHe23_volts_to_percent(double volts)