In article <11**********************@z14g2000cwz.googlegroups .com>,
Karthik <ks******@gmail.com> wrote:
I have an ASCII text file which contains 1's,0's and *'s.
The file looks something like this
0 1 1 * 1
1 1 0 * *
* 0 1 0 1
I want to create an image file which shows the 1's in green squares,
0's in red squares and *'s in yellow squares.
I have a ton of these files and would like to create a script which
does the whole process of conversion and dumps out an image file in one
go.
Image files can be in jpeg/gif/png/eps/ps and the script can be in
perl/tcl/c/c++ or any thing else
You can encode the files in ppm (portable pixmap file format) and
then convert to another format, such as by using 'ppmtogif' or
a program such as 'xv'.
Or, since perl is one of your options, you could use one of the perl
graphics libraries from cpan.org and do it all in one go.
The below sample encoding script is OT for C, but you can
convert it to C code if you want ;-)
$ cat rgy
#!/bin/ksh
[[ $# -ne 1 ]] && echo "Usage: $0 toppm FILE" >&2 && exit
FID=$1
NFID=$FID.ppm
[[ ! -f "$FID" ]] && echo "Not a readable file: $FID" >&2 && exit
((WID=$(head -1 $FID | wc -c) / 2))
((HIGH=$(wc -l < $FID)))
(
echo "P3"
echo "# $FID converted to ppm format"
echo "$WID $HIGH"
echo "# 1 is the maximum colour intensity"
echo "1"
sed -e 's/0/R/g' -e 's/1/G/g' -e 's/\*/Y/g' \
-e 's/R/1 0 0/g' -e 's/G/0 1 0/g' -e 's/Y/1 1 0/g' $FID | fmt -66
) > $NFID
$ cat testfid
0 1 1 * 1
1 1 0 * *
* 0 1 0 1
$ ./rgy testfid
$ cat testfid.ppm
P3
# testfid converted to ppm format
5 3
# 1 is the maximum colour intensity
1
1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0
1 0 0 0 1 0 1 0 0 0 1 0
--
Usenet is like a slice of lemon, wrapped around a large gold brick.