sub PackMatrix { my $avMatrix= shift(@_); my $nRows= 0 + @$avMatrix; my $nCols= 0 + @{ $avMatrix->[0] }; my $ptrSize= length(pack"p",""); my $ptrLen= $ptrSize*$nRows; my $rowLen= length(pack"f",0)*$nCols; my $dataLen= $rowLen*$nRows; my $packedMatrix; if( pack("p",$packedMatrix) != pack("I",0+\$packedMatrix) ) { die "This platform has strange pointers!"; } length($packedMatrix)= $ptrLen + $dataLen; $packedMatrix= "\0" x $ptrLen; for my $avRow ( @$avMatrix ) { die "Row has ",0+@$avRow," entries instead of $width!" unless $width == 0+@$avRow; $packedMatrix .= pack("f$width",@$avRow); } my $ptr= $ptrLen + \$packedMatrix; for my $i ( 0..$#$avMatrix ) { substr( $packedMatrix, $i*$ptrSize, $ptrSize )= pack "I", $ptr; $ptr += $rowLen; } return \$packedMatrix; }