fprintf behaviour
ChrLie
print header
):•print header
#FORMAT : EMSA/MAS Spectral Data File
#VERSION : 1.0
#TITLE : Base(1)
#DATE : 20-SEP-2013
#TIME : 13:55: 6
#OWNER :
#NPOINTS : 2048
#NCOLUMNS : 1
#XUNITS : keV
#YUNITS : Intensity
#DATATYPE : XY
#XPERCHAN : 0.010000000
#OFFSET : 0.000000000
#CHOFFSET : 0.000000
#SIGNALTYPE : EDS
#XLABEL : X-Ray Energy
#YLABEL : X-Ray Intensity
#BEAMKV -kV: 15.0
#EMISSION -uA: 0.0000
#PROBECUR -nA: 1.0000
#BEAMDIAM -nm: 0.0
#MAGCAM : 0.0
#OPERMODE : IMAG
.
. //more lines to follow
.
#SPECTRUM :
After the last entry "#SPECTRUM :" the actual data would follow. The header in this particular case contains about 540 entries (lines). My export function looks like:
function ExportSpectrum(header, spectrum)
string header
wave spectrum
Variable refnum
string filename = NameOfWave(spectrum)
Duplicate/O/Free spectrum Energy
Energy = x
Open/Z=2 /P = SpectrumPath /T="emsa" refnum as FileName+".emsa" // path exists from loading header
if (V_flag == -1) //User cancelled dialog
return -1
endif
fprintf refnum, Header // writes header file to file, followed by return
wfprintf refnum, "%g, %12d,\r\n", Energy, spectrum // writes energy and count data to file, followed by return
fprintf refnum, "#ENDOFDATA : \r\n"
Close refnum
return 1
end
string header
wave spectrum
Variable refnum
string filename = NameOfWave(spectrum)
Duplicate/O/Free spectrum Energy
Energy = x
Open/Z=2 /P = SpectrumPath /T="emsa" refnum as FileName+".emsa" // path exists from loading header
if (V_flag == -1) //User cancelled dialog
return -1
endif
fprintf refnum, Header // writes header file to file, followed by return
wfprintf refnum, "%g, %12d,\r\n", Energy, spectrum // writes energy and count data to file, followed by return
fprintf refnum, "#ENDOFDATA : \r\n"
Close refnum
return 1
end
The problem is that
fprintf refnum header
does not write the header completely to file (same for fprintf 1 header
and the history window) but a large portion of the string is missing. Would that be for some reason an expected behaviour?
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
September 21, 2013 at 06:17 pm - Permalink
FBinWrite worked but in the end I changed my header load procedure that now creates a header text wave instead of a string.
September 22, 2013 at 06:20 am - Permalink