The lack of a debugger is having me stomped now.
I need to save the # of iterations so I added
if ( iterations == undefined )
{
this.iterations = new Array;
this.iterations.push(1);
}
else
{
this.iterations = new Array;
this.iterations.push(iterations);
}
iterations is an int
then
outputCSVSequence( file, this.iterations, "iterations" );
Everything OK so far. But when I add
this.iterations = inputCSVSequence( lines, "iterations" );
the script hangs on execution and I have to kill PI
I tried debugging with console.writeln but it hangs before anything is written. If I change this.iterations = inputCSVSequence( lines, "iterations" ) to this.iterations = inputCSVSequence( lines, "rows" ) it does not hang.
I can not see what could cause this.
Whole function below if someone cares to take a look.
function LineRepairCSVFile( filePath, columns, rows, iterations )
{
this.filePath = filePath;
if ( columns == undefined )
this.columns = new Array;
else
this.columns = columns;
if ( rows == undefined )
this.rows = new Array;
else
this.rows = rows;
if ( iterations == undefined )
{
this.iterations = new Array;
this.iterations.push(1);
}
else
{
this.iterations = new Array;
this.iterations.push(iterations);
}
//console.writeln("Iter: " + this.iterations);
/*
* Writes column and row coordinates to this CSV file.
*/
this.write = function()
{
function outputCSVSequence( file, items, title )
{
// file.outTextLn( format( "%s,%d", title, items.length ) );
file.outTextLn( title + format( ",%d", items.length ) );
if ( items.length > 0 )
{
for ( var i = 0; ; )
{
file.outText( format( "%d", items[i] ) );
if ( ++i == items.length )
break;
file.outText( ',' );
}
file.outTextLn( '' );
}
}
var file = new File;
file.createForWriting( this.filePath );
outputCSVSequence( file, this.columns, "columns" );
outputCSVSequence( file, this.rows, "rows" );
outputCSVSequence( file, this.iterations, "iterations" );
file.close();
};
/*
* Reads column and row coordinates from this CSV file.
*/
this.read = function()
{
function inputCSVSequence( lines, title )
{
var items = new Array
for ( var i = 0; i < lines.length; ++i )
if ( lines[i].indexOf( title ) == 0 )
{
var tokens = lines[i].split( ',' );
console.writeln(tokens);
if ( tokens.length > 0 )
{
var n = parseInt( tokens[1] );
if ( n > 0 )
{
var tokens = lines[i+1].split( ',' );
if ( tokens.length >= n )
for ( var i = 0; i < n; ++i )
items.push( parseInt( tokens[i] ) );
}
}
}
return items;
}
function getTextLines( buffer )
{
var lines = new Array;
for ( var bol = 0; ; )
{
var eol = buffer.linearSearch( 0x0A, bol ); // LF
if ( eol < 0 )
eol = buffer.length;
lines.push( buffer.utf8ToString( bol, eol-bol ).trim() );
bol = eol + 1;
if ( bol > buffer.upperBound )
break;
}
return lines;
}
var file = new File;
file.openForReading( this.filePath );
var buffer = file.read( DataType_ByteArray, file.size );
file.close();
var lines = getTextLines( buffer );
console.writeln(lines);
this.columns = inputCSVSequence( lines, "columns" );
this.rows = inputCSVSequence( lines, "rows" );
this.iterations = inputCSVSequence( lines, "iterations" );
};
}
regards
Mats