UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor namnninh
Visitor
15,462 Views
Registered: ‎01-05-2010

TCL question: How to put a new line for each wrriten value in a file

Hi;

 

   I wrote a TCL program which read an image data from a file and conver it into binary format (01..) and save in another file. I want to put a new line for each write so the output file is in the following format:

00010110

01010101

.. etc

 

 

Thanks,

 

NN

 

My program is below.

 

   set infile [open "inputFile" r]
   set outfile [open "outputFile" w]

    fconfigure $infile -translation binary
    fconfigure $outfile -translation binary

 

 while {![eof $infile]} {

     # read one byte

     set line [read  $infile 1]    

    #convert to binary format
      binary scan $line B* value

    # write to a file

      puts -nonewline $outfile $value

 }

 

 close $infile
 close $outfile 

0 Kudos
2 Replies
Highlighted
Visitor e.charre
Visitor
15,450 Views
Registered: ‎02-06-2010

Re: TCL question: How to put a new line for each wrriten value in a file

hello,

at the end of your file, you can try :

  

 

# write to a file puts -nonewline $outfile $value puts $outfile "\n"

 else, don't use binary translation for outputFile, but CRLF :

 

fconfigure $outfile -translation crlf

  I hope it can help you.

 

 

 

0 Kudos
Visitor namnninh
Visitor
15,442 Views
Registered: ‎01-05-2010

Re: TCL question: How to put a new line for each wrriten value in a file

Hello,

 

 It works.

 

Thank you very much.

 

NN

0 Kudos