Skip to content

Commit

Permalink
Merge pull request #169 from fact-project/fix_168
Browse files Browse the repository at this point in the history
Fix 168
  • Loading branch information
kbruegge authored Dec 1, 2016
2 parents 3c15ef8 + d2df341 commit ec61fef
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#Changelog for the fact-tools

## Version 0.17.1 -- 29.11.2016

* Fix a null pointer exception that was thrown in `FITSWriter.finish` in case no
data item was ever written

## Version 0.17.0 -- 21.11.2016

* Improvements on Single Pulse Extractor
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.sfb876</groupId>
<artifactId>fact-tools</artifactId>
<name>fact-tools</name>
<version>0.17.0</version>
<version>0.17.1</version>
<url>http://sfb876.de/fact-tools/</url>

<description>
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/fact/io/FITSWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,16 @@ public void resetState() throws Exception {

@Override
public void finish() throws Exception {
FitsUtil.pad(bf, rowSize * numEventsWritten);
bf.close();
Fits fits = new Fits(url.getPath());
BinaryTableHDU bhdu = (BinaryTableHDU) fits.getHDU(1);
bhdu.getHeader().setNaxis(2, (int) numEventsWritten);
bhdu.getHeader().rewrite();

if (initialized) {
FitsUtil.pad(bf, rowSize * numEventsWritten);
bf.close();
Fits fits = new Fits(url.getPath());
BinaryTableHDU bhdu = (BinaryTableHDU) fits.getHDU(1);
bhdu.getHeader().setNaxis(2, (int) numEventsWritten);
bhdu.getHeader().rewrite();
} else {
bf.close();
}
}

public void setKeys(Keys keys) {
Expand All @@ -250,4 +253,8 @@ public void setUrl(URL url) {
public void setExtname(String extname) {
this.extname = extname;
}

public long getNumEventsWritten() {
return numEventsWritten;
}
}
61 changes: 61 additions & 0 deletions src/test/java/fact/io/FITSWriterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
*
*/
package fact.io;

import junit.framework.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import stream.Data;
import stream.Keys;
import stream.data.DataFactory;

import java.io.File;
import java.net.URL;


/**
* @author maxnoe
*/
public class FITSWriterTest {
static Logger log = LoggerFactory.getLogger(FITSWriterTest.class);

@Test
public void testFitsWriterNoItems() throws Exception {
FITSWriter fitsWriter = new FITSWriter();
File f = File.createTempFile("test_fits", ".fits");
log.info(f.getAbsolutePath());

URL url = new URL("file:" + f.getAbsolutePath());
fitsWriter.setUrl(url);
fitsWriter.init(null);
fitsWriter.finish();
}

@Test
public void testFitsWriter() throws Exception {
FITSWriter fitsWriter = new FITSWriter();
File f = File.createTempFile("test_fits", ".fits");
log.info(f.getAbsolutePath());

URL url = new URL("file:" + f.getAbsolutePath());
fitsWriter.setUrl(url);
fitsWriter.setKeys(new Keys("*"));

fitsWriter.init(null);

Data item = DataFactory.create();
item.put("EventNum", 1);
item.put("TriggerType", 4);
item.put("NROI", 300);
item.put("NPIX", 1440);
item.put("x", 0.0);
item.put("y", 5.0);
item.put("array", new double[]{1.0, 2.0, 3.0});

fitsWriter.process(item);
Assert.assertEquals(fitsWriter.getNumEventsWritten(), 1);
fitsWriter.finish();
}
}

0 comments on commit ec61fef

Please sign in to comment.