Reading data from WFD files

All about WUFI 2D
Post Reply
Bakonyi Daniel
WUFI User
WUFI User
Posts: 1
Joined: Fri Jan 13, 2012 12:39 am -1100
Location: Hungary
Contact:

Reading data from WFD files

Post by Bakonyi Daniel »

Hi,

I am using Matlab as a post processor for WUFI2D, so I nedd to export raw data from the naetive .wfd file. Untill now I've been trying to use the java code you posted to get the data (http://www.wufi-forum.com/viewtopic.php?t=556), but now I encountered problems. The RH data I export is damaged: the rows get mixed together. I also had problems compiling the java code in the frist place.
Could you send me a newer version of the java code, or help me fix mine?

Best regards,
Bakonyi Dániel
veitner
WUFI SupportTeam IBP
WUFI SupportTeam IBP
Posts: 135
Joined: Tue Mar 08, 2005 11:14 pm -1100

Post by veitner »

Hi,

what do you mean with 'mixed'?
There is no newer version right now.

But there is a tiny sample (IntelliJ Project) for download at:
WUFI2D-FileData.tgz

and some java doc:
doc.tar.gz


and here comes another sample (paste it to a file named 'Gui.java':

<file Gui.java>

package main;

import main.core.data.IGrid;
import main.core.data.IMaterial;
import main.core.data.IWufiData;
import main.core.data.constants.OneArrayResults;
import main.core.data.dt.primitives.MyPoint;
import main.core.data.factory.WufiDataFactory;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/*
* @author veitner
* Date: Nov 14, 2011
* Time: 10:03:05 AM
*/

/**
* $Id: Gui.java $
*/
public class Gui extends JFrame {

private void printLayout(IGrid g, java.util.List<IMaterial> mat,
StringBuffer sb) {
sb.append("Materialclassification (0 is unassigned or a boundary
if next neighbour !=0):\n");
for (int j = 0; j < g.getGridLayoutY().size(); j++) {
for (int i = 0; i < g.getGridLayoutX().size(); i++) {
IMaterial m = g.getGridElement(i, j).getMaterial();
int id = (m == null ? 0 : mat.indexOf(m) + 1);
sb.append(id).append(" ");
}
sb.append("\n");
}
sb.append("\n");
}

private void printData(String id, float[][] data, StringBuffer sb) {
sb.append(id).append("=(");
for (int i = 0; i < data.length; i++) {
sb.append("(");
for (int j = 0; j < data.length; j++) {
sb.append(data[j]);
if (j < data.length - 1) {
sb.append(",");
}
}
sb.append(")");
if (i < data.length - 1) {
sb.append(",");
}
}
sb.append(")\t");

}

public Gui() {
super("sample");
JPanel p = new JPanel();
final JTextField te = new JTextField();
te.setMinimumSize(new Dimension(180, (int)
te.getPreferredSize().getHeight() + 4));
te.setSize(te.getMinimumSize());
te.setPreferredSize(te.getMinimumSize());
p.add(te, BorderLayout.NORTH);

final JTextArea ta = new JTextArea();
ta.setEditable(false);
JScrollPane sp = new JScrollPane(ta);
sp.setMinimumSize(new Dimension(250, 220));
sp.setPreferredSize(sp.getMinimumSize());
add(sp, BorderLayout.CENTER);

JButton btn = new JButton("...");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory()) return true;
String s = f.getAbsolutePath();
return s.toLowerCase().endsWith("wfd");
}

@Override
public String getDescription() {
return "*.wfd|*.wfd";
}
});
if (fc.showOpenDialog(null) ==
JFileChooser.APPROVE_OPTION) {
StringBuffer sb = new StringBuffer();
te.setText(fc.getSelectedFile().getName());
WufiDataFactory wdf = new WufiDataFactory();

try {
IWufiData wd =
wdf.getWufiData(fc.getSelectedFile());
IGrid g = wd.getGrid();
sb.append("Grid:\nx=(");
java.util.List<Float> l = g.getGridLayoutX();
for (int i = 0; i < l.size() - 1; i++) {
sb.append(l.get(i)).append(",");
}
sb.append(l.get(l.size() - 1)).append(")\n");
sb.append("y=(");
l = g.getGridLayoutY();
for (int i = 0; i < l.size() - 1; i++) {
sb.append(l.get(i)).append(",");
}
sb.append(l.get(l.size() - 1)).append(")\n\n");

printLayout(g, wd.getMaterials(), sb);

Map<Enum, float[][]> temp = new HashMap<Enum,
float[][]>();

int x = 1;
int y = 1;
while (g.getGridElement(x, y).getMaterial() ==
null) { //find a non null element
x++;
}

MyPoint pos = new MyPoint(x, y, x + 1, y +
1); //select 4 elements

/*either this and iterate through the data
HashSet<MyPoint> hsPos = new HashSet<MyPoint>();
hsPos.add(pos);
ICalculationResult cr =
wd.getCalculationResults(OneArrayResults.ksTeta,hsPos,wd.getCalcInfo().getStartDate(), wd.getCalcInfo().getEndDate());
or that*/
sb.append("some Data:\n");
for (long step = 0; step < 5/*maxSteps*/; step
++) {
sb.append("Step:
").append(step).append("\n");
if
(wd.getCalcInfo().getResultOptions().get(OneArrayResults.ksTeta))
{ //temperature

wd.getResultElements(OneArrayResults.ksTeta, step, pos,
temp); //retrieve the data
}

if
(wd.getCalcInfo().getResultOptions().get(OneArrayResults.ksRH)) { //rel.
humidity

wd.getResultElements(OneArrayResults.ksRH, step, pos, temp); //retrieve
the data
}

if
(wd.getCalcInfo().getResultOptions().get(OneArrayResults.ksWC)) {//
water content

wd.getResultElements(OneArrayResults.ksWC, step, pos, temp); //retrieve
the data
}

if
(wd.getCalcInfo().getResultOptions().get(OneArrayResults.ksPd))
{//partial press of vapour

wd.getResultElements(OneArrayResults.ksPd, step, pos, temp); //retrieve
the data
}
float[][] d;
if
(temp.containsKey(OneArrayResults.ksTeta)) {
d = temp.get(OneArrayResults.ksTeta);
printData("teta", d, sb);
}
if (temp.containsKey(OneArrayResults.ksRH))
{
d = temp.get(OneArrayResults.ksRH);
printData("rh", d, sb);
}
if (temp.containsKey(OneArrayResults.ksWC))
{
d = temp.get(OneArrayResults.ksWC);
printData("wc", d, sb);
}
if (temp.containsKey(OneArrayResults.ksPd))
{
d = temp.get(OneArrayResults.ksPd);
printData("pd", d, sb);
}
sb.append("\n");
}

ta.setText(sb.toString());

} catch (IOException e1) {
e1.printStackTrace();
}

}
}
});
p.add(btn, BorderLayout.EAST);

add(p, BorderLayout.NORTH);

JButton btn1 = new JButton("Close");
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
add(btn1, BorderLayout.SOUTH);
pack();
}

public static void main(String[] args) {
Gui gui = new Gui();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Rectangle r = gui.getBounds();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
r.translate((d.width - r.width) / 2, (d.height - r.height) / 2);
gui.setBounds(r);
gui.setVisible(true);

}

}

Best regards,
Veit
hmsalonv
WUFI User
WUFI User
Posts: 7
Joined: Fri Feb 23, 2007 5:42 am -1100

Re: Reading data from WFD files

Post by hmsalonv »

Thank you for the piece of code. I was able to get it working and it is a good start for me. However, I am not very familiar with java in general and the commands to retrieve and print data from wfd-files to other file formats. Could you possibly provide the lines of code to extract for example all Temps and RHs for all node points at all timesteps and how to output that to a file? I am looking for outputting data in a format like for example x,y,t,rh for a given time for all nodes.

Thanks,
Mikael
Christian Bludau
WUFI SupportTeam IBP
WUFI SupportTeam IBP
Posts: 1160
Joined: Tue Jul 04, 2006 10:08 pm -1100
Location: IBP Holzkirchen, the home of WUFI
Contact:

Re: Reading data from WFD files

Post by Christian Bludau »

Hello Mikael,
you can do that for T, RH and WC by just using WufiMotion. Right click on the time step, then export...
Christian
Post Reply