DMelt:IO/5 DIF File Format

From HandWiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Member

DIF file format

Similar to CSV, the DIF file format is used to create readable text entries in the files.

You can use this format to fill spreadsheets and read them in spreadsheet programs (OpenOffice.org Calc, Excel, Gnumeric, StarCalc). The format is a text file, encoded in ASCII, with a header and body. This is especially useful for a number of DataMelt data holders discussed in Data Structures section. The Java class for this format is called jhplot.io.HFileDIF jhplot.io.HFileDIF.

Here is a simple Python example showing how to create a DIF file

from jhplot import *
from jhplot.io import *

p=P1D("X-Y values with error 0.5 on Y")
p.add(1,2,0.5)   
p.add(2,10,0.5)
p.add(3,61,0.5)

f=HFileDIF("test.dif","w")
f.write(p)

The output file "test.dif" can be read in OpenOffice or any other spreadsheet programs.

Here is a more complicated example:

from java.util import Random
from jhplot  import *
from jhplot.io  import *

h1 = H1D("Histogram",20, -2.0, 2.0)
rand = Random()
for i in range(100):
      h1.fill(rand.nextGaussian())
f=HFileDIF("histo.dif","w")
f.write(h1)

This example writes histogram to the DIF file which then can be opened in other programs.