use strict; use IPC::Run qw( run ); use Tie::File; use Fcntl 'O_RDONLY'; # ... cut ... my @ts = get_time_series(File=>$ncfile,Variable=>$ncvar,Id=>$nc_id); # ... cut ... sub get_time_series { my %args = @_; my $file = $args{File}; my $variable = $args{Variable}; my $id = $args{Id}; my $tmpfile = "$id.tmp"; # Example: # ncks -v vmro3 -d station,1,1 myfile.nc | grep "station\[" # my $command = qq(ncks -v $variable -d station,$id,$id $file | grep \"station\\[\" > $tmpfile); run $command; # This will write in file the following records: #station[3385]=3386 #time[0]=3287.02083333 station[3385]=3386 vmro3[3385]=1.53524e-08 mole mole-1 #time[1]=3287.0625 station[3385]=3386 vmro3[7513]=1.55109e-08 mole mole-1 #time[2]=3287.10416667 station[3385]=3386 vmro3[11641]=1.56481e-08 mole mole-1 my @ts; tie my @tmplines, 'Tie::File', $tmpfile, mode => O_RDONLY; foreach my $ii (1..$#tmplines) { my $line = $tmplines[$ii]; my @pa = anytrim(split(/\s/,$line)); my ($dummy,$value) = split(/=|\s/,$pa[2]); push @ts, $value; } unlink $tmpfile or die "$tmpfile: $!"; return @ts; }