fprintf behaviour

I use IGOR to group and sort EDS spectra (counts vs. energy) which I then want to export and quantify in external software. The latter needs to read a header from a spectrum to identify instrument settings. I load this header from an existing spectrum and store it as a global string variable. The string header may look like this (
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



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?



I would not be shocked to discover that fprintf is printing into a fixed-sized buffer. Try printing the header using Fbinwrite then print the remainder with a separate fprintf call.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Thanks!
FBinWrite worked but in the end I changed my header load procedure that now creates a header text wave instead of a string.