package nmrsvd; import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; /** *
Title: SVD denoising of FID
* *SVD:
* *Copyright: Copyright (c) 2010
* *Company: www.pascal-man.com
* * @author Pascal P. Man * @version 2.0 */ public class Frame1 extends JFrame { /** * */ private static final long serialVersionUID = 1L; private SVDController controller = new SVDController(); private Graph ggSVD = new Graph(); //for SVD plotting private int labelHeight = 20, // label height buttonHeight = 30, // button height panelHeight = 400, // panel height panelWidth = 502; // panel width 402->502 modified 26 march 2012 /***************************************** * Menu bar * *****************************************/ JMenuBar menuBar = new JMenuBar(); JMenu menuFile = new JMenu("File"); JMenu menuView = new JMenu("View"); JMenuItem menuItemShowMatrix = new JMenuItem("Show matrix"); JMenuItem menuItemShowSVD = new JMenuItem("Show SVD"); JMenuItem menuItemOpen = new JMenuItem("Open 4-octet integer binary file..."); JMenuItem menuItemSaveCopy = new JMenuItem("Save original 4-octet integer binary file..."); JMenuItem menuItemSaveDenoised = new JMenuItem("Save denoised fid as binary..."); JMenuItem menuItemOpenSVD = new JMenuItem("Open SVD..."); JMenuItem menuItemSaveSVD = new JMenuItem("Save SVD..."); JFileChooser fileChooserfc = new JFileChooser(); /*************************************** * Panel Matrix * ***************************************/ //panelMatrix contains panelFid JPanel panelMatrix = new JPanel(); JPanel panelFid = new JPanel(); JPanel panelHeader = new JPanel(); JPanel panelFidData = new JPanel(); JLabel labelFidRe = new JLabel("Real"); JLabel labelFidIm = new JLabel("Imaginary"); JLabel labelFid1 = new JLabel("FID"); JLabel labelFid2 = new JLabel("FID"); JTextArea textAreaFIDReal = new JTextArea(); JTextArea textAreaFIDImag = new JTextArea(); JScrollPane scrollPaneFid = new JScrollPane(); JButton buttonClearFID = new JButton("Clear FID"); JButton buttonRunSVD = new JButton("Run SVD"); //--------------------------------------------- JPanel panelMatrixDim = new JPanel(); JPanel panelRadio = new JPanel(new GridLayout(0, 1)); ButtonGroup groupEndian = new ButtonGroup(); final String stringBigEndian = "big endian"; final String stringLittleEndian = "little endian (Bruker)"; boolean bigEndian = false; JRadioButton radioButtonBigEndian = new JRadioButton(stringBigEndian); JRadioButton radioButtonLittleEndian = new JRadioButton(stringLittleEndian); JLabel labelConversion = new JLabel("File conversion: "); JLabel labelNbDataTD = new JLabel("Initial number of complex points: "); JLabel labelTD = new JLabel("TD / 2 = "); JLabel labelNbData = new JLabel("Effective number of complex points: "); JLabel labelTDeff = new JLabel("TDeff / 2 = "); JLabel labelNbMatrixColumn = new JLabel("Number of Hankel matrix column:"); JTextField textFieldTD = new JTextField(); JTextField textFieldSizeFID = new JTextField("0"); JTextField textFieldNbMatrixColumn = new JTextField("10"); /*************************************** * Panel S V D * ***************************************/ JPanel panelSVD = new JPanel(); JPanel panelEigenValue = new JPanel(); JPanel panelEigenValueHeader = new JPanel(); JPanel panelEigenValueData = new JPanel(); JLabel labelEigen = new JLabel("Singular values"); JTextField textFieldSVD = new JTextField("2"); JTextArea textAreaEigenValue = new JTextArea(); JScrollPane scrollPaneEigenValue = new JScrollPane(); JButton buttonHankel = new JButton("Hankel"); public Frame1() { try { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(new Dimension(530, 480)); // 400-> 530, 460->480 26 march 2012 setTitle("www.pascal-man.com: X64 GPU 2012-SVD denoising FID"); jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } /** * Component initialization. * * @throws java.lang.Exception */ private void jbInit() throws Exception { /* SVDMVCModelGPU modela = new SVDMVCModelGPU(); try { modela.essaisetBaseIndex(); } catch (Exception e) { buttonRunSVD.setBackground(Color.yellow); } */ panelMatrix.setVisible(true); panelSVD.setVisible(false); //modified 23 march 2012 menuFile.setEnabled(true); menuView.setEnabled(true); /*************************************** * Menu bar * ***************************************/ fileChooserfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); setJMenuBar(menuBar); menuBar.add(menuFile); menuFile.add(menuItemOpen); menuFile.add(menuItemSaveCopy); menuFile.add(menuItemSaveDenoised); menuFile.addSeparator(); menuFile.add(menuItemSaveSVD); menuFile.add(menuItemOpenSVD); menuItemSaveSVD.setEnabled(false); menuItemOpenSVD.setEnabled(false); menuBar.add(menuView); menuView.add(menuItemShowMatrix); menuView.add(menuItemShowSVD); menuItemShowMatrix.setEnabled(false); menuItemShowSVD.setEnabled(true); //application area this.setBackground(Color.white); this.getContentPane().setLayout(null); /*************************************** * Panel Matrix * ***************************************/ panelMatrix.setLayout(null); panelMatrix.setBackground(Color.white); //modified 25 aout 2012 panelMatrix.setBounds(2, 2, panelWidth, panelHeight); panelMatrix.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelMatrix); //Panel FIDData panelFid.setBounds(2, 2, 200, panelHeight - 4); panelMatrix.add(panelFid); panelFid.setBackground(Color.pink); panelFid.setLayout(null); panelFid.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelHeader.setBounds(10, 7, 180, 2 * labelHeight); panelHeader.setLayout(null); panelHeader.setBackground(Color.pink); labelFidRe.setBounds(0, 0, 90, labelHeight); panelHeader.add(labelFidRe); labelFidIm.setBounds(90, 0, 90, labelHeight); panelHeader.add(labelFidIm); labelFid1.setBounds(0, labelHeight, 90, labelHeight); panelHeader.add(labelFid1); labelFid2.setBounds(90, labelHeight, 90, labelHeight); panelHeader.add(labelFid2); panelFid.add(panelHeader); scrollPaneFid.setBounds(10, 50, 180, 240); scrollPaneFid.getViewport().add(panelFidData); panelFid.add(scrollPaneFid); panelFidData.setLayout(new GridLayout(1, 2)); panelFidData.add(textAreaFIDReal); panelFidData.add(textAreaFIDImag); textAreaFIDReal.setBackground(Color.orange); textAreaFIDImag.setBackground(Color.yellow); textAreaFIDReal.setMargin(new Insets(5, 5, 5, 5)); textAreaFIDImag.setMargin(new Insets(5, 5, 5, 5)); textAreaFIDReal.setEditable(true); textAreaFIDImag.setEditable(true); buttonRunSVD.setBounds(40, 300, 115, buttonHeight); buttonRunSVD.setBackground(Color.red); panelFid.add(buttonRunSVD); buttonClearFID.setBounds(40, 350, 115, buttonHeight); buttonClearFID.setBackground(Color.red); panelFid.add(buttonClearFID); //Panel MatrixDim panelMatrixDim.setBounds(204, 2, 296, panelHeight-4); //184->296 26 march 2012 panelMatrix.add(panelMatrixDim); panelMatrixDim.setBackground(Color.pink); panelMatrixDim.setLayout(null); panelMatrixDim.setFont(new Font("TimesRoman", Font.PLAIN, 14)); labelConversion.setBounds(10, 30, 165, labelHeight); labelConversion.setFont(new Font("TimesRoman", Font.PLAIN, 14)); panelMatrixDim.add(labelConversion); panelRadio.setBounds(10, 50, 165, 50); panelMatrixDim.add(panelRadio); radioButtonBigEndian.setActionCommand(stringBigEndian); radioButtonBigEndian.setFont(new Font("TimesRoman", Font.PLAIN, 12)); radioButtonBigEndian.setSelected(false); radioButtonBigEndian.setBackground(Color.orange); radioButtonLittleEndian.setActionCommand(stringLittleEndian); radioButtonLittleEndian.setFont(new Font("TimesRoman", Font.PLAIN, 12)); radioButtonLittleEndian.setSelected(true); radioButtonLittleEndian.setBackground(Color.yellow); //Group the radio buttons. groupEndian.add(radioButtonBigEndian); groupEndian.add(radioButtonLittleEndian); panelRadio.add(radioButtonBigEndian); panelRadio.add(radioButtonLittleEndian); labelNbDataTD.setBounds(10, 120, 250, labelHeight); //165-> 250 labelNbDataTD.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelMatrixDim.add(labelNbDataTD); labelTD.setBounds(10, 140, 165, labelHeight); labelTD.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelMatrixDim.add(labelTD); textFieldTD.setBounds(90, 140, 70, labelHeight); //50->70 textFieldTD.setEnabled(false); panelMatrixDim.add(textFieldTD); labelNbData.setBounds(10, 120+3*labelHeight, 250, labelHeight); //165-> 250 labelNbData.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelMatrixDim.add(labelNbData); labelTDeff.setBounds(10, 140+3*labelHeight, 100, labelHeight); labelTDeff.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelMatrixDim.add(labelTDeff); textFieldSizeFID.setBounds(90, 140+3*labelHeight, 70, labelHeight); //50->70 panelMatrixDim.add(textFieldSizeFID); labelNbMatrixColumn.setBounds(10, 180+3*labelHeight, 250, labelHeight); //160-> 250 labelNbMatrixColumn.setFont(new Font("TimesRoman", Font.PLAIN, 12)); panelMatrixDim.add(labelNbMatrixColumn); textFieldNbMatrixColumn.setBounds(90, 200+3*labelHeight, 70, labelHeight); //50->70 panelMatrixDim.add(textFieldNbMatrixColumn); /*************************************** * Panel S V D * ***************************************/ panelSVD.setLayout(null); panelSVD.setBackground(Color.yellow); panelSVD.setBounds(2, 2, panelWidth, panelHeight); panelSVD.setFont(new Font("TimesRoman", Font.PLAIN, 12)); this.getContentPane().add(panelSVD); //Panel EigenValue panelEigenValue.setBounds(2, 2, panelWidth - 4, panelHeight - 4); panelSVD.add(panelEigenValue); panelEigenValue.setBackground(Color.pink); panelEigenValue.setLayout(null); panelEigenValue.setFont(new Font("TimesRoman", Font.PLAIN, 12)); //Panel EigenValueHeader panelEigenValueHeader.setBounds(10, 7, 120, labelHeight); panelEigenValueHeader.setLayout(null); panelEigenValueHeader.setBackground(Color.pink); labelEigen.setBounds(0, 0, 120, labelHeight); panelEigenValueHeader.add(labelEigen); panelEigenValue.add(panelEigenValueHeader); scrollPaneEigenValue.setBounds(10, labelHeight+10, 260, 80); scrollPaneEigenValue.getViewport().add(panelEigenValueData); panelEigenValue.add(scrollPaneEigenValue); panelEigenValueData.setLayout(new GridLayout(1,1)); panelEigenValueData.add(textAreaEigenValue); textAreaEigenValue.setBackground(Color.orange); textAreaEigenValue.setMargin(new Insets(5, 5, 5, 5)); textAreaEigenValue.setEditable(true); textFieldSVD.setBounds(290, labelHeight+10, 95, buttonHeight); textFieldSVD.setBackground(Color.white); panelEigenValue.add(textFieldSVD); buttonHankel.setBounds(290, 100-labelHeight, 95, buttonHeight); buttonHankel.setBackground(Color.red); panelEigenValue.add(buttonHankel); ggSVD.setBounds(10, 110, panelWidth-25, 275); ggSVD.setBackground(Color.pink); panelEigenValue.add(ggSVD); ggSVD.setVisible(false); //very important buttonRunSVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonRunSVD.getText() == "Run SVD") { controller.buttonRunSVD() ; }; } }); buttonClearFID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonClearFID.getText() == "Clear FID") { controller.buttonClearFID() ; }; } }); buttonHankel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (buttonHankel.getText() == "Hankel") { controller.buttonHankel(); }; } }); menuItemShowMatrix.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowMatrix.getText() == "Show matrix") { controller.menuItemShowMatrix(); }; } }); menuItemShowSVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemShowSVD.getText() == "Show SVD") { controller.menuItemShowSVD(); }; } }); menuItemOpen.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemOpen.getText() == "Open 4-octet integer binary file...") { controller.menuItemOpen(); }; } }); menuItemSaveCopy.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemSaveCopy.getText() == "Save original 4-octet integer binary file...") { controller.menuItemSaveCopy(); }; } }); menuItemSaveDenoised.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemSaveDenoised.getText() == "Save denoised fid as binary...") { controller.menuItemSave(); }; } }); menuItemSaveSVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemSaveSVD.getText() == "Save SVD...") { controller.menuItemSaveSVD(); }; } }); menuItemOpenSVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { if (menuItemOpenSVD.getText() == "Open SVD...") { controller.menuItemOpenSVD(); }; } }); radioButtonLittleEndian.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { controller.radioButtonLittleEndianChecked(); } }); radioButtonBigEndian.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { controller.radioButtonBigEndianChecked(); } }); } /************************************************************************ * * * controller SVDController * * * ************************************************************************/ private class SVDController { public SVDMVCModelGPU model = new SVDMVCModelGPU(); public SVDController() { } //------------------------// // MenuItemShowMatrix // //------------------------// private void menuItemShowMatrix() { panelMatrix.setVisible(true); panelSVD.setVisible(false); //modified 23 march 2012 menuItemShowMatrix.setEnabled(false); menuItemShowSVD.setEnabled(true); menuItemOpen.setEnabled(true); menuItemSaveDenoised.setEnabled(true); menuItemSaveSVD.setEnabled(false); menuItemOpenSVD.setEnabled(false); } //------------------------// // MenuItemShowSVD // //------------------------// private void menuItemShowSVD() { panelMatrix.setVisible(false); panelSVD.setVisible(true); menuItemShowMatrix.setEnabled(true); menuItemShowSVD.setEnabled(false); menuItemOpen.setEnabled(false); menuItemSaveCopy.setEnabled(false); menuItemSaveDenoised.setEnabled(false); menuItemSaveSVD.setEnabled(true); menuItemOpenSVD.setEnabled(true); } //------------------// // MenuItemOpen // //------------------// private void menuItemOpen() { int returnVal = fileChooserfc.showOpenDialog(Frame1.this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooserfc.getSelectedFile(); if (file != null) { //Make sure the user didn't choose a directory DataInputStream in = new DataInputStream(new FileInputStream(file)); String ssr = "", ssi = ""; int n = 0; int i = 0; if (bigEndian) { while ((n = in.available()) > 0 ) { int a = in.readInt(); if ((i % 2) == 0) { ssr += a + "\n"; } else { ssi += a + "\n"; } i++; } } else { int byte1, byte2, byte3, byte4; while ((n = in.available()) > 0 ) { synchronized (this) { byte1 = in.read(); byte2 = in.read(); byte3 = in.read(); byte4 = in.read(); } if (byte4 == -1) { throw new EOFException(); } int a = (byte4 << 24) + ((byte3 << 24) >>> 8) + ((byte2 << 24) >>> 16) + ((byte1 << 24) >>> 24); if ((i % 2) == 0) { ssr += a + "\n"; } else { ssi += a + "\n"; } i++; } // while } //else in.close(); textAreaFIDReal.setText(ssr); textAreaFIDImag.setText(ssi); //number of complex points in the initial FID, -1 due to carriage return int lineCount = textAreaFIDReal.getLineCount() - 1; textFieldTD.setText(String.valueOf(lineCount)); textFieldSizeFID.setText(String.valueOf(lineCount)); model.setTD(lineCount); int sizeTDeff = Integer.parseInt(textFieldSizeFID.getText()); model.setTDeff(sizeTDeff); } } catch (IOException e) {System.err.println(e);} } } //-----------------------------------------------------// // Menu menuItemSaveCopy... // //-----------------------------------------------------// private void menuItemSaveCopy() { int returnVal = fileChooserfc.showSaveDialog(Frame1.this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooserfc.getSelectedFile(); if (file != null) { //Make sure the user didn't choose a directory DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); //number of lines - 1, due to carriage return for textArea int nbComplex = textAreaFIDReal.getLineCount() - 1; int fr[] = new int[nbComplex]; int fi[] = new int[nbComplex]; String s = textAreaFIDReal.getText(); int spaceAt = 0, startingForm = 0; String[] amplReal = new String[nbComplex]; for (int i = 0; i < nbComplex; i++) { spaceAt = s.indexOf("\n", startingForm); if (spaceAt == -1) break; amplReal[i] = s.substring(startingForm, spaceAt); startingForm = spaceAt + 1; fr[i] = Integer.parseInt(String.valueOf(amplReal[i])); } s = textAreaFIDImag.getText(); spaceAt = 0; startingForm = 0; String[] amplImag = new String[nbComplex]; int ntest = 0; for (int i = 0; i < nbComplex; i++) { spaceAt = s.indexOf("\n", startingForm); if (spaceAt == -1) break; amplImag[i] = s.substring(startingForm, spaceAt); startingForm = spaceAt + 1; fi[i] = Integer.parseInt(String.valueOf(amplImag[i])); } if (bigEndian) { for (int i = 0; i < nbComplex; i++) { //integer numbers for TopSpin out.writeInt(fr[i]); out.writeInt(fi[i]); } } else { for (int i = 0; i < nbComplex; i++) { //integer numbers for TopSpin out.write(fr[i] & 0xFF); out.write((fr[i] >>> 8) & 0xFF); out.write((fr[i] >>> 16) & 0xFF); out.write((fr[i] >>> 24) & 0xFF); out.write(fi[i] & 0xFF); out.write((fi[i] >>> 8) & 0xFF); out.write((fi[i] >>> 16) & 0xFF); out.write((fi[i] >>> 24) & 0xFF); } } out.close(); } } catch (IOException e) {System.err.println(e);} } } //--------------------------// // MenuItemSaveDenoised // //--------------------------// private void menuItemSave() { int returnVal = fileChooserfc.showSaveDialog(Frame1.this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooserfc.getSelectedFile(); if (file != null) { //Make sure the user didn't choose a directory DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); int nbTDhalf = Integer.parseInt(textFieldTD.getText()); int nbTDeffhalf = Integer.parseInt(textFieldSizeFID.getText()); double[] fr = model.getfidRe(); double[] fi = model.getfidIm(); int intf; if (bigEndian) { for (int i = 0; i < nbTDeffhalf; i++) { //integer numbers for TopSpin intf = (int) Math.round(fr[i]); out.writeInt(intf); intf = (int) Math.round(fi[i]); out.writeInt(intf); } //zerofilling if necessary to TD/2 for (int i = nbTDeffhalf; i < nbTDhalf; i++) { out.writeInt(0); out.writeInt(0); } } else { for (int i = 0; i < nbTDeffhalf; i++) { //integer numbers for TopSpin intf = (int) Math.round(fr[i]); out.write(intf & 0xFF); out.write((intf >>> 8) & 0xFF); out.write((intf >>> 16) & 0xFF); out.write((intf >>> 24) & 0xFF); intf = (int) Math.round(fi[i]); out.write(intf & 0xFF); out.write((intf >>> 8) & 0xFF); out.write((intf >>> 16) & 0xFF); out.write((intf >>> 24) & 0xFF); } //zerofilling if necessary to TD/2 for (int i = nbTDeffhalf; i < nbTDhalf; i++) { out.writeInt(0); out.writeInt(0); } out.close(); } } } catch (IOException e) {System.err.println(e);} } } //----------------------------------------------------// // Menu menuItemSaveSVD... // //----------------------------------------------------// private void menuItemSaveSVD() { int returnVal = fileChooserfc.showSaveDialog(Frame1.this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooserfc.getSelectedFile(); if (file != null) { //Make sure the user didn't choose a directory DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); try { ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(model); oos.close(); } catch (Exception ex) {System.err.println(ex);} //out.close(); } } catch (IOException e) {System.err.println(e);} } } //---------------------// // MenuItemOpenSVD // //---------------------// private void menuItemOpenSVD() { int returnVal = fileChooserfc.showOpenDialog(Frame1.this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooserfc.getSelectedFile(); if (file != null) { //Make sure the user didn't choose a directory DataInputStream in = new DataInputStream(new FileInputStream(file)); try { ObjectInputStream ois = new ObjectInputStream(in); model = (SVDMVCModelGPU) ois.readObject(); ois.close(); } catch (Exception ex) {System.err.println(ex);} //in.close(); } } catch (Exception e) {System.err.println(e);} } //SVD call double[] titi; titi = model.getSVD(); //Show eigenvalues String s2 = ""; for (int j = 0; j < model.getmvalue(); j++) { s2 += titi[j] + "\n"; } textAreaEigenValue.setText(""); //clear textAreaEigenValue.setText(s2); //SVD plotting double inc; double[] tmp = model.getSVD(); ggSVD.Graph("SVD", "n", "svd"); ggSVD.setSymbol(true); ggSVD.setLine(true); ggSVD.setColor(ggSVD.black); for (int i = 0; i < model.getmvalue(); i++) { inc = i; ggSVD.add(inc, tmp[i]); } ggSVD.showGraph(); //put FID in textAreaFIDReal and textAreaFIDImag String sfidre = "", sfidim = ""; double[] fr = model.getfidRe(); double[] fi = model.getfidIm(); int max = model.getmaxNbComplex(); for (int i = 0; i < max; i++) { sfidre += fr[i] + "\n"; sfidim += fi[i] + "\n"; } textAreaFIDReal.setText(sfidre); textAreaFIDImag.setText(sfidim); //modified 25 march 2012 textFieldTD.setText(String.valueOf(model.getTD())); textFieldSizeFID.setText(String.valueOf(model.getTDeff())); textFieldNbMatrixColumn.setText(String.valueOf(model.getmvalue())); } //--------------------// // ButtonClearFID // //--------------------// private void buttonClearFID() { textAreaFIDReal.setText(""); textAreaFIDImag.setText(""); } //--------------------// // ButtonRunSVD // //--------------------// private void buttonRunSVD() { provideFid(); int sizeTDeff = Integer.parseInt(textFieldSizeFID.getText()); model.setTDeff(sizeTDeff); //SVD call double[] titi; try { model.essaiZsvd(); } catch (Exception e) { buttonRunSVD.setBackground(Color.green); } titi = model.getSVD(); //Show eigenvalues String s2 = ""; for (int j = 0; j < model.getmvalue(); j++) { s2 += titi[j] + "\n"; } textAreaEigenValue.setText(s2); //SVD plotting double inc; double[] tmp = model.getSVD(); ggSVD.Graph("SVD", "n", "svd"); ggSVD.setSymbol(true); ggSVD.setLine(true); ggSVD.setColor(ggSVD.black); for (int i = 0; i < model.getmvalue(); i++) { inc = i; ggSVD.add(inc, tmp[i]); } ggSVD.showGraph(); panelMatrix.setVisible(false); panelSVD.setVisible(true); menuItemShowMatrix.setEnabled(true); menuItemShowSVD.setEnabled(false); menuItemOpen.setEnabled(false); menuItemSaveCopy.setEnabled(false); menuItemSaveDenoised.setEnabled(false); menuItemSaveSVD.setEnabled(true); // menuItemOpenSVD.setEnabled(true); // } //--------------------// // provideFid() // //--------------------// private void provideFid() { //number of complex points in the FID for SVD int lineCount = Integer.parseInt(textFieldSizeFID.getText()); model.setmaxNbComplex(lineCount); //number of columns for the Hankel matrix int numberColumnMatrix = Integer.parseInt(textFieldNbMatrixColumn.getText()); model.setnvalue(numberColumnMatrix); model.setmvalue(numberColumnMatrix); //convert experimental real part of FID intensities into numbers String sr = textAreaFIDReal.getText(), s1r = ""; int spaceAtr = 0, startingFormr = 0, ipr = 0; double[] tmpr = new double[model.getmaxNbComplex()]; for (int i = 0; i < lineCount; i++) { spaceAtr = sr.indexOf("\n", startingFormr); if (spaceAtr == -1)break; s1r = sr.substring(startingFormr, spaceAtr); tmpr[ipr] = Double.valueOf(s1r).doubleValue(); startingFormr = spaceAtr + 1; ipr++; } model.setfidRe(tmpr); //convert experimental imaginary part of FID intensities into numbers String si = textAreaFIDImag.getText(), s1i = ""; int spaceAti = 0, startingFormi = 0, ipi = 0; double[] tmpi = new double[model.getmaxNbComplex()]; for (int i = 0; i < lineCount; i++) { spaceAti = si.indexOf("\n", startingFormi); if (spaceAti == -1)break; s1i = si.substring(startingFormi, spaceAti); tmpi[ipi] = Double.valueOf(s1i).doubleValue(); startingFormi = spaceAti + 1; ipi++; } model.setfidIm(tmpi); } //----------------------------// // RadioButtonBigEndian // //----------------------------// private void radioButtonBigEndianChecked() { bigEndian = true; } //-------------------------------// // RadioButtonLittleEndian // //-------------------------------// private void radioButtonLittleEndianChecked() { bigEndian = false; } //--------------------// // ButtonHankel // //--------------------// private void buttonHankel() { //number of SVD elements used int nbSVD = Integer.parseInt(textFieldSVD.getText()); int mvalue = model.getmvalue(); //convert selected SVD elements into numbers double[] usedSVD = new double[mvalue]; String s = textAreaEigenValue.getText(), s1 = ""; int spaceAt = 0, startingForm = 0; for (int i = 0; i < nbSVD; i++) { spaceAt = s.indexOf("\n", startingForm); if (spaceAt == -1)break; s1 = s.substring(startingForm, spaceAt); usedSVD[i] = Double.valueOf(s1).doubleValue(); startingForm = spaceAt + 1; } //provide usedSVD to SVDMVCmodel model.setSVD(usedSVD); //show used SVD elements double[] titi = model.getSVD(); String s2 = ""; for (int j = 0; j < model.getmvalue(); j++) { s2 += titi[j] + "\n"; } textAreaEigenValue.setText(s2); try { model.createFID(); //put FID in textAreaFIDReal and textAreaFIDImag String sfidre = "", sfidim = ""; double[] fr = model.getfidRe(); double[] fi = model.getfidIm(); int max = model.getmaxNbComplex(); for (int i = 0; i < max; i++) { sfidre += fr[i] + "\n"; sfidim += fi[i] + "\n"; } textAreaFIDReal.setText(sfidre); textAreaFIDImag.setText(sfidim); panelSVD.setVisible(false); panelMatrix.setVisible(true); menuItemShowMatrix.setEnabled(false); menuItemShowSVD.setEnabled(true); menuItemOpen.setEnabled(true); menuItemSaveCopy.setEnabled(true); menuItemSaveDenoised.setEnabled(true); menuItemSaveSVD.setEnabled(false); // menuItemOpenSVD.setEnabled(false); // } catch (Exception e) { textAreaEigenValue.setBackground(Color.green); } } //end of buttonHankel() } //end of SVDController() } //end of Frame1