diff --git a/MAC/APL/PAC/MatlabCal/configure.in b/MAC/APL/PAC/MatlabCal/configure.in index 9227a4e8b450e2f34f74b842336d014cc53efeed..6341655a9adf9914c9a9014b5f9462fc93d66d2a 100644 --- a/MAC/APL/PAC/MatlabCal/configure.in +++ b/MAC/APL/PAC/MatlabCal/configure.in @@ -59,6 +59,7 @@ dnl dnl Output Makefiles dnl AC_OUTPUT( +include/APL/MatlabCal/Makefile src/Makefile test/Makefile Makefile diff --git a/MAC/APL/PAC/MatlabCal/include/APL/MatlabCal/Makefile.am b/MAC/APL/PAC/MatlabCal/include/APL/MatlabCal/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..99467abb1885c73e16e1b3f7a250d72b6d7731b0 --- /dev/null +++ b/MAC/APL/PAC/MatlabCal/include/APL/MatlabCal/Makefile.am @@ -0,0 +1,9 @@ +INSTHDRS = +NOINSTHDRS = +TCCHDRS = +pkgincludedir = $(includedir)/APL/MatlabCal +pkginclude_HEADERS = $(INSTHDRS) $(TCCHDRS) +noinst_HEADERS = $(NOINSTHDRS) +DOCHDRS = $(INSTHDRS) $(NOINSTHDRS) + +include $(top_srcdir)/Makefile.common diff --git a/MAC/APL/PAC/MatlabCal/src/Makefile.am b/MAC/APL/PAC/MatlabCal/src/Makefile.am index 9945a32506821f04dae28c44dbdf14ea52a87dd4..4f23c9ab7e3330c46becf3eac27fd6f37cac8bdc 100644 --- a/MAC/APL/PAC/MatlabCal/src/Makefile.am +++ b/MAC/APL/PAC/MatlabCal/src/Makefile.am @@ -2,17 +2,27 @@ AM_CPPFLAGS = -I$(top_builddir)/include MATLAB_COMPILER = mcc -libMatlabCal.so: calibrate.m - $(MATLAB_COMPILER) -v -W cpplib:libMatlabCal -T link:lib $< +lib%.so : %.m + $(MATLAB_COMPILER) -v -W cpplib:lib$* -T link:lib $< + mkdir -p $(pkgincludedir)/ + cp lib$*.h $(pkgincludedir)/$*.h + cp lib$*.so $(libdir)/ + +#libMatlabCal.so: calibrate.m +# $(MATLAB_COMPILER) -v -W cpplib:libMatlabCal -T link:lib $< +# mkdir -p $(pkgincludedir)/ +# cp libMatlabCal.h $(pkgincludedir)/ +# cp libMatlabCal.so $(libdir)/ EXTRA_DIST = -BUILT_SOURCES = libMatlabCal.so +BUILT_SOURCES = libcalibrate.so + +#lib_LTLIBRARIES = libcalibrate.la +#libcalibrate_la_SOURCES = calibrate.m -#pkgincludedir=$(includedir)/APL/CAL_Protocol -#pkginclude_HEADERS = \ $(BUILT_SOURCES) -clean-local: - rm -f *.ph +pkgincludedir = $(includedir)/APL/MatlabCal +#pkginclude_HEADERS = $(BUILT_SOURCES) include $(top_srcdir)/Makefile.common diff --git a/MAC/APL/PAC/MatlabCal/src/calibrate.m b/MAC/APL/PAC/MatlabCal/src/calibrate.m index f2f6edbc47569e290a17cec4f3e788fffbe97b64..1606e2349b5f4a0c058047d99e622b4be190ed6a 100644 --- a/MAC/APL/PAC/MatlabCal/src/calibrate.m +++ b/MAC/APL/PAC/MatlabCal/src/calibrate.m @@ -28,6 +28,10 @@ function [cal, flags] = calibrate(acc, antpos, srcpos, freq) % % Stefan Wijnholds, 19 November 2008 + % make sure Matlab does not claim all CPUs + maxNumCompThreads(1); + disp(['Calibration routine will use ' num2str(maxNumCompThreads) ' cores']); + % parameters c = 2.99792e8; % speed of light in m/s uvlimlambda = 4; % baseline restriction in wavelength @@ -292,4 +296,4 @@ function C = khatrirao(A, B) for n = 1:size(A, 2) C(:, n) = kron(A(:, n), B(:, n)); end -end % end function khatrirao \ No newline at end of file +end % end function khatrirao diff --git a/MAC/APL/PAC/MatlabCal/test/Makefile.am b/MAC/APL/PAC/MatlabCal/test/Makefile.am index 33c6e700c33b1119ff4dc43ce17392298a1ff9d7..a09ba321ff89e88f912a8092131d8af34c2a3e97 100644 --- a/MAC/APL/PAC/MatlabCal/test/Makefile.am +++ b/MAC/APL/PAC/MatlabCal/test/Makefile.am @@ -8,7 +8,7 @@ sbin_PROGRAMS = \ tCalibrate tCalibrate_SOURCES = $(BUILT_SOURCES) tCalibrate.cc -tCalibrate_LDADD = -lMatlabCal -L../src/ $(LOFAR_DEPEND) +tCalibrate_LDADD = -lcalibrate $(LOFAR_DEPEND) tCalibrate_DEPENDENCIES = $(LOFAR_DEPEND) BUILT_SOURCES = diff --git a/MAC/APL/PAC/MatlabCal/test/tCalibrate.cc b/MAC/APL/PAC/MatlabCal/test/tCalibrate.cc index 0fe4be1826f8123503ce4852c09fef4fbfd2ced7..02aff416067f971e5d68a406b489536ca0be0d95 100644 --- a/MAC/APL/PAC/MatlabCal/test/tCalibrate.cc +++ b/MAC/APL/PAC/MatlabCal/test/tCalibrate.cc @@ -1,4 +1,4 @@ -#include <libMatlabCal.h> +#include <APL/MatlabCal/calibrate.h> #include <iostream> #include <fstream> #include <iterator> @@ -8,108 +8,108 @@ using namespace std; int driver(int argc, char **argv) { - if (!mclInitializeApplication(NULL, 0)) - { - cerr << "Failed to initialize the MCR" << endl; - return -1; - } - if (!libMatlabCalInitialize()) - { - cerr << "Failed to initialize libMatlabCal.s0" << endl; - return -2; - } - cout << "MCR and libMatlabCal.so successfully initialized" << endl; - - - try - { - // get array covariance cube - ifstream caldata("20080118_083229_acc_512x96x96.dat"); - double *data = new double[2 * 512 * 96 * 96]; - caldata.read(reinterpret_cast<char *>(data), 2 * 512 * 96 * 96 * sizeof(double)); - const mwSize dim[3] = {96, 96, 512}; - mwArray acc(3, dim, mxDOUBLE_CLASS, mxCOMPLEX); - int dataidx = 0; - for (int sb = 1; sb <= 512; sb++) - { - for (int idx2 = 1; idx2 <= 96; idx2++) - { - for (int idx1 = 1; idx1 <= 96; idx1++) - { - acc(idx1, idx2, sb).Real() = data[dataidx]; - acc(idx1, idx2, sb).Imag() = data[dataidx + 1]; - dataidx += 2; + + try { + // get array covariance cube + ifstream caldata("20080118_083229_acc_512x96x96.dat"); + double *data = new double[2 * 512 * 96 * 96]; + caldata.read(reinterpret_cast<char *>(data), 2 * 512 * 96 * 96 * sizeof(double)); + const mwSize dim[3] = {96, 96, 512}; + mwArray acc(3, dim, mxDOUBLE_CLASS, mxCOMPLEX); + int dataidx = 0; + for (int sb = 1; sb <= 512; sb++) { + for (int idx2 = 1; idx2 <= 96; idx2++) { + for (int idx1 = 1; idx1 <= 96; idx1++) { + acc(idx1, idx2, sb).Real() = data[dataidx]; + acc(idx1, idx2, sb).Imag() = data[dataidx + 1]; + dataidx += 2; + } + } } - } - } - delete[] data; - - // get antenna positions - ifstream antfile("antpos.dat"); - double *antdata = new double[3 * 48]; - antfile.read(reinterpret_cast<char *>(antdata), 3 * 48 * sizeof(double)); - mwArray antpos(48, 3, mxDOUBLE_CLASS); - antpos.SetData(antdata, 3 * 48); - delete[] antdata; - - // get source positions for test data - ifstream srcfile("srcpos.dat"); - double *srcposdata = new double[3 * 3]; - srcfile.read(reinterpret_cast<char *>(srcposdata), 3 * 3 * sizeof(double)); - mwArray srcpos(3, 3, mxDOUBLE_CLASS); - srcpos.SetData(srcposdata, 3 * 3); - delete[] srcposdata; - - // get center frequencies of subband - ifstream freqfile("frequencies.dat"); - double *freqdata = new double[512]; - freqfile.read(reinterpret_cast<char *>(freqdata), 512 * sizeof(double)); - mwArray freq(512, 1, mxDOUBLE_CLASS); - freq.SetData(freqdata, 512); - delete[] freqdata; - - // up to this point, the code has been verified - - // call calibrate-function - mwArray calresult; - mwArray mflags; - calibrate(2, calresult, mflags, acc, antpos, srcpos, freq); - - // retrieve data - double *cal_real = new double[512 * 96]; - double *cal_imag = new double[512 * 96]; - double *flags = new double[512 * 96]; - calresult.Real().GetData(cal_real, 512 * 96); - calresult.Imag().GetData(cal_imag, 512 * 96); - mflags.GetData(flags, 512 * 96); - ofstream calfile("calresult.dat"); - calfile.write(reinterpret_cast<char *>(cal_real), 512 * 96 * sizeof(double)); - calfile.write(reinterpret_cast<char *>(cal_imag), 512 * 96 * sizeof(double)); - ofstream flagfile("flags.dat"); - flagfile.write(reinterpret_cast<char *>(flags), 512 * 96 * sizeof(double)); - delete[] flags; - delete[] cal_imag; - delete[] cal_real; + delete[] data; + + // get antenna positions + ifstream antfile("antpos.dat"); + double *antdata = new double[3 * 48]; + antfile.read(reinterpret_cast<char *>(antdata), 3 * 48 * sizeof(double)); + mwArray antpos(48, 3, mxDOUBLE_CLASS); + antpos.SetData(antdata, 3 * 48); + delete[] antdata; + + // get source positions for test data + ifstream srcfile("srcpos.dat"); + double *srcposdata = new double[3 * 3]; + srcfile.read(reinterpret_cast<char *>(srcposdata), 3 * 3 * sizeof(double)); + mwArray srcpos(3, 3, mxDOUBLE_CLASS); + srcpos.SetData(srcposdata, 3 * 3); + delete[] srcposdata; + + // get center frequencies of subband + ifstream freqfile("frequencies.dat"); + double *freqdata = new double[512]; + freqfile.read(reinterpret_cast<char *>(freqdata), 512 * sizeof(double)); + mwArray freq(512, 1, mxDOUBLE_CLASS); + freq.SetData(freqdata, 512); + delete[] freqdata; + + // up to this point, the code has been verified + + // call calibrate-function + mwArray calresult; + mwArray mflags; + calibrate(2, calresult, mflags, acc, antpos, srcpos, freq); + + // retrieve data + double *cal_real = new double[512 * 96]; + double *cal_imag = new double[512 * 96]; + double *flags = new double[512 * 96]; + calresult.Real().GetData(cal_real, 512 * 96); + calresult.Imag().GetData(cal_imag, 512 * 96); + mflags.GetData(flags, 512 * 96); + ofstream calfile("calresult.dat"); + calfile.write(reinterpret_cast<char *>(cal_real), 512 * 96 * sizeof(double)); + calfile.write(reinterpret_cast<char *>(cal_imag), 512 * 96 * sizeof(double)); + ofstream flagfile("flags.dat"); + flagfile.write(reinterpret_cast<char *>(flags), 512 * 96 * sizeof(double)); + delete[] flags; + delete[] cal_imag; + delete[] cal_real; } - catch(const mwException& e) - { - cerr << e.what() << endl; - return -3; + catch(const mwException& e) { + cerr << e.what() << endl; + return -3; } - catch(...) - { - cerr << "Unexpected error" << endl; - return -4; + catch(...) { + cerr << "Unexpected error" << endl; + return -4; } - libMatlabCalTerminate(); - mclTerminateApplication(); - cout << "All garbage has been successfully collected" << endl; return 0; } int main() { mclmcrInitialize(); - return mclRunMain((mclMainFcnType)driver, 0, NULL); + + if (!mclInitializeApplication(NULL, 0)) { + cerr << "Failed to initialize the MCR" << endl; + return -1; + } + if (!libcalibrateInitialize()) { + cerr << "Failed to initialize libcalibrate.so" << endl; + return -2; + } + cout << "MCR and libcalibrate.so successfully initialized" << endl; + + cout << "@@@@@ RUN 1 @@@@@" << endl; + mclRunMain((mclMainFcnType)driver, 0, NULL); + cout << "@@@@@ RUN 2 @@@@@" << endl; + mclRunMain((mclMainFcnType)driver, 0, NULL); + + libcalibrateTerminate(); + mclTerminateApplication(); + + cout << "All garbage has been successfully collected" << endl; + + return (0); }