Save Complex 2D Wave As FixedField
hrodstein
// SaveComplex2DWaveAsFixedField(pathName, fileName, header, cw, fieldWidth, digitsAfterDP, fullPathOut)
// Writes a 2D complex wave to a text file using FORTRAN-style fixed field formatting.
// To try it, execute this:
// MakeTestData(10,5); Test()
Function SaveComplex2DWaveAsFixedField(pathName, fileName, header, cw, fieldWidth, digitsAfterDP, fullPathOut)
String pathName // Symbolic path name or "" for dialog
String fileName // Output file name or "" for dialog
String header // Header text to be written to file or "" if none. Should end with CRLF.
Wave/C cw
Variable fieldWidth
Variable digitsAfterDP
String &fullPathOut // Output: Full path to saved file or "" if error or user cancels
fullPathOut = ""
Variable refNum = 0
Open /P=$pathName /T=".dat" refNum as fileName
if (GetRTError(0))
return -1 // Error opening file
endif
if (refNum == 0)
return -1 // User cancelled
endif
FStatus refNum
fullPathOut = S_path + S_fileName
fprintf refNum, "%s", header
Variable numRows = DimSize(cw, 0)
Variable numColumns = DimSize(cw, 1)
Variable row, column
for(row=0; row<numRows; row+=1)
for(column=0; column<numColumns; column+=1)
String text
Variable/C cval = cw[row][column]
Variable rVal = real(cval), iVal = imag(cval)
fprintf refNum, "%*.*E%*.*E", fieldWidth, digitsAfterDP, rVal, fieldWidth, digitsAfterDP, iVal
endfor
fprintf refNum, "\r\n"
endfor
Close refNum
return 0
End
Function MakeTestData(rows,columns)
Variable rows,columns
Make /O /C /N=(rows,columns) mat = cmplx(gnoise(1), gnoise(1))
End
Function Test()
DoWindow/K FixedFieldNotebook
String pathName = "Igor" // "" gives dialog
String fileName = "FixedField.dat"
String header = "This is a test of the SaveComplex2DWaveAsFixedField routine\r\n"
String fullPathOut
Variable timerRefNum = StartMSTimer
Variable result = SaveComplex2DWaveAsFixedField(pathName, fileName, header, mat, 14, 5, fullPathOut)
Variable elapsed = StopMSTimer(timerRefNum) / 1E6
if (result == 0)
Printf "Elapsed time: %g\r", elapsed
OpenNotebook /P=$pathName /N=FixedFieldNotebook /K=1 fullPathOut
Notebook FixedFieldNotebook font="Courier New"
endif
End
// Writes a 2D complex wave to a text file using FORTRAN-style fixed field formatting.
// To try it, execute this:
// MakeTestData(10,5); Test()
Function SaveComplex2DWaveAsFixedField(pathName, fileName, header, cw, fieldWidth, digitsAfterDP, fullPathOut)
String pathName // Symbolic path name or "" for dialog
String fileName // Output file name or "" for dialog
String header // Header text to be written to file or "" if none. Should end with CRLF.
Wave/C cw
Variable fieldWidth
Variable digitsAfterDP
String &fullPathOut // Output: Full path to saved file or "" if error or user cancels
fullPathOut = ""
Variable refNum = 0
Open /P=$pathName /T=".dat" refNum as fileName
if (GetRTError(0))
return -1 // Error opening file
endif
if (refNum == 0)
return -1 // User cancelled
endif
FStatus refNum
fullPathOut = S_path + S_fileName
fprintf refNum, "%s", header
Variable numRows = DimSize(cw, 0)
Variable numColumns = DimSize(cw, 1)
Variable row, column
for(row=0; row<numRows; row+=1)
for(column=0; column<numColumns; column+=1)
String text
Variable/C cval = cw[row][column]
Variable rVal = real(cval), iVal = imag(cval)
fprintf refNum, "%*.*E%*.*E", fieldWidth, digitsAfterDP, rVal, fieldWidth, digitsAfterDP, iVal
endfor
fprintf refNum, "\r\n"
endfor
Close refNum
return 0
End
Function MakeTestData(rows,columns)
Variable rows,columns
Make /O /C /N=(rows,columns) mat = cmplx(gnoise(1), gnoise(1))
End
Function Test()
DoWindow/K FixedFieldNotebook
String pathName = "Igor" // "" gives dialog
String fileName = "FixedField.dat"
String header = "This is a test of the SaveComplex2DWaveAsFixedField routine\r\n"
String fullPathOut
Variable timerRefNum = StartMSTimer
Variable result = SaveComplex2DWaveAsFixedField(pathName, fileName, header, mat, 14, 5, fullPathOut)
Variable elapsed = StopMSTimer(timerRefNum) / 1E6
if (result == 0)
Printf "Elapsed time: %g\r", elapsed
OpenNotebook /P=$pathName /N=FixedFieldNotebook /K=1 fullPathOut
Notebook FixedFieldNotebook font="Courier New"
endif
End
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More