IO:File

R

Rich_Elswick

I am opening a ~32 meg file using:

$data->read(file => $ascfile , delimiter => ',') or die
"Couldn't read data!";

It loads the data, but none of the rest of my program runs. It is like
a limit is hit and then it doesn't do anything else.

My next line is essentially:

my $gd = $graph->plot( $data ) or die "Can't plot graph";

This uses the GD::Graph::Data and GD::Graph::mixed modules.

Any suggestions? Is there some memory or other limit? Where can I get
help on this one?

Thanks!

Rich Elswick
Test Engineer
Cobasys L.L.C.
 
X

xhoster

Rich_Elswick said:
I am opening a ~32 meg file using:

$data->read(file => $ascfile , delimiter => ',') or die
"Couldn't read data!";

Where does $data come from? If $data holds an IO::File object, then I
croak out with the message:
usage: $io->read(BUF, LEN [, OFFSET]) at -e line 1

IO::File seems to inherit read from IO::Handle. IO::Handle doesn't support
using read the way you are trying to use it.
It loads the data, but none of the rest of my program runs. It is like
a limit is hit and then it doesn't do anything else.

Does it exit, or spin the CPU, or just freeze? Are you sure it doesn't
print a warning/error that you for some reason aren't noticing?
My next line is essentially:

my $gd = $graph->plot( $data ) or die "Can't plot graph";

This uses the GD::Graph::Data and GD::Graph::mixed modules.

Add a warn statement before this line, so you know if it ever gets here
or not.
Any suggestions? Is there some memory or other limit? Where can I get
help on this one?

Can you make a program we can run to demonstrate the problem?

Xho
 
R

Rich_Elswick

The $data object is:
my $data = GD::Graph::Data->new();

I need to look at that closer. I almost emailed the author of the GD
module, but I haven't yet. I may just do that now. Thanks!

Here is an example program. It requires a comma seperate file as an
argument with 3 columns of data. Column1 = time, Column2 = Voltage,
Column3 = Current

#!c:/perl/bin/perl.exe
# #!/usr/bin/perl -w

#
# A mixed stock graph
# usese ActiveState Module: GDGraph

use strict;
use GD;
use GD::Graph::Data;
use GD::Graph::mixed;
use IO::File;
use Getopt::Long; # Perl module used to parse arguments from the
command line.
use File::Basename; # to get the filebase name for creating parsed
data directory
use File::Find; # get all files and and sub-directory files.

# Variable Declaration
my $buffer; # for binary data reading/writing
my $argc; # number of arguments at execution
my $debug; # option flag - used to print diagnostic info
to screen

my $ascfile; # ASCII input file (*.asc)
my $ascDir; # output folder name for parsed data.
my $ascPath; # output directory path to parsed data.
my $fh_output; # array of output file handles for the output
files

my $record_cnt=1;
my $line_cnt;
my $recfile_cnt=1;

my $prev_pct; # Currect completion
my $record; # The current record being processed.
my $file_cnt = 0; # counter of the number of $line_cnt / 30,000
in the file.

my $file_index = 1;
my @my_dirs;
my $inputFile;

my $graph;
my $data = GD::Graph::Data->new();

my $debug;
my $forcewrite;
my $dataVer;
my $cfg_filename;
my $extractOnly;



#new page
# --------------------------------------------------------
#
# Subroutine: "Main" process - program entry point
#
# --------------------------------------------------------

# special system variable which forces Perl to 'flush' after every
print.
$|=1;


printf(
"\n----------------------------Starting-------------------------------------\n");
printf( "CSV Reporting of Results : test.pl - Version 01.0 December 2,
2005\n");
print "Program started: ", scalar localtime, "\n";

file_verify(); # Open Input File to ensure it exists

die "All arguments must be directories!"
if grep {!-d} @ARGV;

#open MASTER, '>', 'output.cvs';
my $fdir; # output file directory to be created.

@my_dirs = @ARGV;
$fdir = shift @ARGV;

# special system variable which forces Perl to 'flush' after every
print.
$|=1;

parse_directory($ascfile);


print "\nProgram finished: ", scalar localtime, "\n";
printf(
"\n-----------------------------Ending--------------------------------------\n");

# END of Main Process ------------------------------------

sub file_verify {

my $type; #junk

# Input Argument
# -> Input File - ascii input file
$argc = @ARGV; # count the number of input arguments

if ( $argc < 1 ) {
printf( "Usage Model:[perl] csvReport.pl infile.csv [-c|C
config.cfg] [-v1|-v2] [-dD] [-F]\n");
printf( " -> [perl] csvReport.pl \n");
printf( " - perl is the script interpreter. \n");
printf( " - asc2csv.pl is the perl script
(instructions) \n");
printf( " ");
printf( " -> Argument 1 Input file (required) \n" );
printf( " ");
exit;
}

($ascfile) = shift @ARGV;
($ascDir,$ascPath,$type) = fileparse($ascfile, qr{\.csv});

unless (open(ASCFILE, "$ascfile")) {
die "Fatal Error: Cannot open $ascfile for input: $!";
}
}
#
-----------------------------------------------------------------------------

#
-----------------------------------------------------------------------------
# This function will continue until there is no more log files to open.
sub parse_directory {


# next line works.
printf("Opening input file... $ascfile \n"); # debug statement
$graph = new GD::Graph::mixed(900, 600) or die "Can't create graph!";

#parse out the file name.

$data->read(file => $ascfile , delimiter => ',') or die "Couldn't
read data!"; #replaced stock_data.dat

if($ascfile =~ /m220/)
{
graphMsg220($graph);
}
else{}

# Plot the data - generate the plot data
printf("Plotting the data to the graph object \$gd. \n");

my $gd = $graph->plot( $data ) or die "Can't plot graph";

# Write the PNG to a file.

my $outputFile = $ascfile . ".jpg";
printf("Opening output file... $outputFile \n");
open OUT, ">$outputFile" or die "Couldn't open for output: $!";
binmode(OUT);
#print OUT $gd->png();
print OUT $gd->jpeg();
close OUT;
$data->reset();
# close LOG;
# }
}
# END of file_verify Function ----------------------------


#
-----------------------------------------------------------------------------
sub graphMsg220
{
# set the file properties.

# Set the general attributes

$graph->set(
title => " Report - Message 220 - $_",
types => [qw(lines lines)],
dclrs => [qw(red blue)],
transparent => 0,
);

# Set the attributes for the x-axis

$graph->set(
x_label => 'Time (Seconds)', # replaced Day of
Year
x_tick_number => 5,
x_label_skip => 5,
x_labels_vertical => 1,
);

$graph->set(
y_max_value => ($data->get_min_max_y_all())[1]+25,
y_tick_number => 20,
y_all_ticks => 1,
y_number_format => sub { int(shift); }, # '$'.
);

# Set the legend

$graph->set_legend('Voltage', 'Current');
$graph->set_legend_font(gdLargeFont);
$graph->set(legend_placement => 'BL');
}
# END of graphMsg220 Function ---------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top