Chart-Graph

 view release on metacpan or  search on metacpan

Graph/Gnuplot.pm  view on Meta::CPAN

    if (ref($matrix_ref) ne "ARRAY") {
	carp "Matrix data must be a reference to an array";
	return 0;
    }
    
    open (DATA, ">$file");
    
    $matrix_len = @{$matrix_ref};
    for (my $i = 0; $i < $matrix_len; $i++) {
	$entry_ref = $matrix_ref->[$i];
	
	if (ref($entry_ref) ne "ARRAY") {
	    carp "Matrix entry must be a reference to an array";
	    close DATA;
	    return 0;
	}
	
        # prints blank lines for blank entries, this allows 
        # the user to tell gnuplot to not connect lines between 
        # all points when displaying data with lines.
        if (@{$entry_ref} == 0)
        {
            print DATA "\n";
        }
        else
        {
if (0) {
            # check that each entry ONLY has two entries
            if (@{$entry_ref} != 2) {
                carp "Each entry must be an array of size 2";
                return 0;
            }
            print DATA $entry_ref->[0], "\t", $entry_ref->[1], "\n";
}
	    # XXX
            print DATA join("\t", @{$entry_ref}), "\n";
        }
    }
    close DATA;
    return 1;
}

#
#
# Subroutine: columns_to_file()
#
# Description: converts the column data input into a the gnuplot
#              data file format. please see www page for specifics
#              on this format.
#

sub _columns_to_file {
    my ($file, @columns) = @_;

    foreach my $dataset ( @columns ) {
        if (!(ref($dataset) eq "ARRAY")) {
            carp "Column data must be a reference to an array";
            return 0;
        }
   
        if ($#{$dataset} != $#{$columns[$[]}) {
            carp "All columns must be of same length";
            return 0;
        }
    }

    if ($#{$columns[$[]} == 0) {
        carp "Warning: Columns have no data!";
    }

    open (DATA, ">$file");
   
    for (my $i = 0; $i <= $#{$columns[$[]}; $i++) {
        foreach my $dataset ( @columns ) {
            print DATA "$dataset->[$i]\t";
        }
        print DATA "\n";
    }

    close DATA;
    return 1;
}


#
# Subroutine: file_to_file()
#
# Description: If a gnuplot data set was given in
#              file format, we simply copy the data 
#              and read it into 
#

sub _file_to_file {
    my ($file_out, $file_in) = @_;
    
    if (not $file_in) {
	carp "Data set file missing";
	return 0;
    }

    if (not -f $file_in) {
	carp "Data set file, '$file_in', does not exist.";
	return 0;
    }
    
    my $status = system("cp", "$file_in", "$file_out");
    
    if (not _chk_status($status)) {
	return 0;
    }
    
    return 1;
}

# 
# Subroutine: exec_gnuplot()
#
# Description: this executes gnuplot on the command file 
#              and data sets that we have generated.
#

sub _exec_gnuplot {
    my ($command_file) = @_;
    my $status = system("$gnuplot", "$command_file");
    
    if (not _chk_status($status)) {
	return 0;
    }
    
    return 1;
}	

#



( run in 0.873 second using v1.01-cache-2.11-cpan-97f6503c9c8 )