Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

some troubles with my program

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Hi,
I have to convet to ascii many binary files.

This is my program.

#!/usr/bin/perl

system("ls td*.bil > listado");
open(FILE,"<listado") or die "Input file: Cannot open file\n\n";
$filea=<FILE>;

while($filea ne ""){
chomp($filea);
$size1 = -s $filea;
print $filea." ".$size1."\n";

open(FILE1,"<$filea") or die "Input file: Cannot open file\n\n";
binmode FILE1;
open(OUT,">$filea.hexa.txt");
open(OUT1,">$filea.contadores.txt");
open(OUT2,">$filea.abonados.txt");

$[=1;
@b=();
$j=1;
$i=0;
$k=0;

while ($i < $size1){
$ch = getc(FILE1);
$part2 = unpack("H2",$ch);
$b[$j]=$part2;
$i ++ ;


if( $b[$j-104] eq "f1" && $b[$j-103] eq "f9" && $b[$j-102] eq "f4" && $b[$j-101] eq "f1" && $b[$j] eq "40")
{
for($k=$j-104;$k<=$j;$k++)
{
printf OUT1 "%s",$b[$k];
}
$j=1;
printf OUT1 "\n";
}
elsif( $b[$j-107] eq "f0" && $b[$j-106] eq "f1"&& $b[$j-105] eq "f0" && $b[$j-104] eq "f8" && $b[$j-1] eq "a3" && $b[$j] eq "00")
{
$cont+=1;
for($k=$j-107;$k<=$j;$k++)
{
printf OUT "%s",$b[$k];
if($k>14 && $k<27){$m+=1;$abonado_a .= $b[$k];if($m==12){$abonado_a =~ s/0//g;$abonado_a=~s/a/0/g;print OUT2 $abonado_a."|"}}
elsif($k>30 && $k<43){$n+=1;$abonado_b .= $b[$k];if($n==12){$abonado_b =~ s/0//g;$abonado_b=~s/a/0/g;print OUT2 $abonado_b."|"}}
elsif($k>44 && $k<47){$o+=1;printf OUT2 "%0+2s",hex $b[$k];if($o==2){print OUT2 "|"}}
elsif($k>46 && $k<51){$p+=1;printf OUT2 "%0+2s",hex $b[$k];if($p==4){print OUT2 "|"}}
elsif($k>50 && $k<55){$q+=1;printf OUT2 "%0+2s",hex $b[$k];if($q==4){print OUT2 "|"}}
elsif($k>54 && $k<59){$r+=1;printf OUT2 "%0+2s",hex $b[$k];if($r==4){print OUT2 "|"}}
elsif($k>58 && $k<61){$s+=1;$minutos .= $b[$k];if($s==2){printf OUT2 "%0+4s",hex $minutos}}
elsif($k>60 && $k<63){$t+=1;printf OUT2 "%0+2s",hex $b[$k];if($t==2){print OUT2 "|"}}
elsif($k>69 && $k<72){$u+=1;$ruta_in .= $b[$k];if($u==2){printf OUT2 "%0+4s|",hex $ruta_in}}
elsif($k>71 && $k<74){$v+=1;$tg_in .= $b[$k];if($v==2){printf OUT2 "%0+6s|",hex $tg_in}}
elsif($k>73 && $k<76){$w+=1;$ruta_out .= $b[$k];if($w==2){printf OUT2 "%0+4s|",hex $ruta_out}}
elsif($k>75 && $k<78){$x+=1;$tg_out .= $b[$k];if($x==2){printf OUT2 "%0+6s|%s\n",hex $tg_out,$cont}}
else{}
}
printf OUT "|%s\n",$cont;
$m=$n=$o=$p=$q=$r=$s=$t=$u=$v=$w=$x=0;
$abonado_a="";
$abonado_b="";
$minutos="";
$ruta_in="";
$tg_in="";
$ruta_out="";
$tg_out="";
$j=1;
}
elsif( $b[$j-105] eq "f0" && $b[$j-104] eq "f1"&& $b[$j-103] eq "f0" && $b[$j-102] eq "f6" && $b[$j-1] eq "90" && $b[$j] eq "00")
{
$cont+=1;
for($k=$j-105;$k<=$j;$k++)
{
printf OUT "%s",$b[$k];
if($k>14 && $k<27){$m+=1;$abonado_a .= $b[$k];if($m==12){$abonado_a =~ s/0//g;$abonado_a=~s/a/0/g;print OUT2 $abonado_a."|"}}
elsif($k>30 && $k<43){$n+=1;$abonado_b .= $b[$k];if($n==12){$abonado_b =~ s/0//g;$abonado_b=~s/a/0/g;print OUT2 $abonado_b."|"}}
elsif($k>44 && $k<47){$o+=1;printf OUT2 "%0+2s",hex $b[$k];if($o==2){print OUT2 "|"}}
elsif($k>46 && $k<51){$p+=1;printf OUT2 "%0+2s",hex $b[$k];if($p==4){print OUT2 "|"}}
elsif($k>50 && $k<55){$q+=1;printf OUT2 "%0+2s",hex $b[$k];if($q==4){print OUT2 "|"}}
elsif($k>54 && $k<59){$r+=1;printf OUT2 "%0+2s",hex $b[$k];if($r==4){print OUT2 "|"}}
elsif($k>58 && $k<61){$s+=1;$minutos .= $b[$k];if($s==2){printf OUT2 "%0+4s",hex $minutos}}
elsif($k>60 && $k<63){$t+=1;printf OUT2 "%0+2s",hex $b[$k];if($t==2){print OUT2 "|"}}
elsif($k>69 && $k<72){$u+=1;$ruta_in .= $b[$k];if($u==2){printf OUT2 "%0+4s|",hex $ruta_in}}
elsif($k>71 && $k<74){$v+=1;$tg_in .= $b[$k];if($v==2){printf OUT2 "%0+6s|",hex $tg_in}}
elsif($k>73 && $k<76){$w+=1;$ruta_out .= $b[$k];if($w==2){printf OUT2 "%0+4s|",hex $ruta_out}}
elsif($k>75 && $k<78){$x+=1;$tg_out .= $b[$k];if($x==2){printf OUT2 "%0+6s|%s\n",hex $tg_out,$cont}}
else{}
}
printf OUT "|%s\n",$cont;
$m=$n=$o=$p=$q=$r=$s=$t=$u=$v=$w=$x=0;
$abonado_a="";
$abonado_b="";
$minutos="";
$ruta_in="";
$tg_in="";
$ruta_out="";
$tg_out="";
$j=1;
}
else{}
$j+=1;
}
$filea=<FILE>;
}
close FILE;
close FILE1;
close OUT;
close OUT1;
close OUT2;

out : *.hexa.txt

f0f1f0f8f26001b4b6060001015658151a00000000000000000a000000a18aaa5166320000000000000000031f1721050117211c06172301010001200500000000000000002001650008008c00000000000000000000005658151a000000000000000001000004039090a300|1
f0f1f0f8f26001b4b7060001015651468700000000000000000a0000006693239000000000000000000000031f1722110617222c001723010500001105000000000000000022011200120077000000000000000000000056514687000000000000000001000004039090a300|2
f0f1f0f8f26001b4b806000101311654a878000000000000000a000000663aa42000000000000000000000031f17221d02172220091723040300001f04000000000000000012013c001f023f0000000000000000000000311654a8780000000000000001000004038090a300|3
f0f1f0f8f26001b4b9060001015658257200000000000000000a0000006714343000000000000000000000031f1713030717130c0117230507000f3506000000000000000020004e00080061000000000000000000000056582572000000000000000001000004039090a300|4
f0f1f0f8f26001b4ba060001015667142900000000000000000a0000006524a18000000000000000000000031f170516061705190817230700001d2902000000000000000012008c001f03a0000000000000000000000056671429000000000000000001000004039090a300|5
f0f1f0f8f26001b4bb060001015663325400000000000000000a0000006567694000000000000000000000031f172131031721340217230a0100011109000000000000000020001a00110062000000000000000000000056633254000000000000000001000004039090a300|6
f0f1f0f8f26001b4bc060001015658a44a00000000000000000a0000006567222000000000000000000000031f1722250317222c0817230c0100001b0300000000000000001f03800006017100000000000000000000005658a44a000000000000000001000004039090a300|7
f0f1f0f8f26001b4bd060001015651194500000000000000000a000000a194794731a10000000000000000031f171f0303171f070117230e020004070100000000000000001f038d001200f5000000000000000000000056511945000000000000000001000004039090a300|8
f0f1f0f8f26001b4be060001015652a46200000000000000000a0000006626159000000000000000000000031f1722130017221c0017230e0800002e0800000000000000001f019d0012023b00000000000000000000005652a462000000000000000001000004039090a300|9
f0f1f0f8f26001b4bf060001015663559400000000000000000a0000006611337000000000000000000000031f17220d091722110017230f0300003a0300000000000000002000ca00110218000000000000000000000056635594000000000000000001000004039090a300|10

out1: *.abonados.txt
56514687|6693239|0331|23341706|23344400|23350105|00001705|0034|000274|0018|000119|2
3116540878|6630042|0331|23342902|23343209|23350403|00003104|0018|000316|0031|000575|3
56582572|6714343|0331|23190307|23191201|23350507|00155306|0032|000078|0008|000097|4
56671429|6524018|0331|23052206|23052508|23350700|00294102|0018|000140|0031|000928|5
56633254|6567694|0331|23334903|23335202|23351001|00011709|0032|000026|0017|000098|6
56580440|6567222|0331|23343703|23344408|23351201|00002703|0031|000896|0006|000369|7
56511945|019479473101|0331|23310303|23310701|23351402|00040701|0031|000909|0018|000245|8
56520462|6626159|0331|23341900|23342800|23351408|00004608|0031|000413|0018|000571|9
56635594|6611337|0331|23341309|23341700|23351503|00005803|0032|000202|0017|000536|10

my program doesn`t print 1,19,37,55,... lines into *.abonados.txt file.
I don`t undestand. If I use the same cicle to print both *.hexa.txt and *.abonados.txt files.

Thanks a lot

malpa
 
Hi,

I`m sorry. I made a mistake with the arrays.


Thanks

malpa.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top