bar code for golden book / cd?

Records, publishing, shop etc.
Post Reply
User avatar
ravanwin
Posts: 5060
Joined: Thu Aug 26, 2004 8:08 pm
Location: edinburgh
Contact:

bar code for golden book / cd?

Post by ravanwin » Wed Jul 04, 2007 6:02 pm

can we make a barcode for the golden hour book?

anyone?

ryan

swithun
Posts: 2683
Joined: Wed Mar 29, 2006 12:24 pm

Post by swithun » Wed Jul 04, 2007 8:01 pm

Give me the ISBN and I'll give you the barcode. I wrote a program which would generate bar codes from 12 digit numbers - 2 DDMMYY birthdays for example.

Barcodes are fascinating. For most products, there is a country code, an organisation code and a product code. Countries can use a range of numbers. Organisations are given a code, and they can allocate their own product codes. The last digit is a checksum to ensure that the code is read correctly. Companies which make lots of products have short organisation codes.

There are 3 different ways to represent each number in the code - A, B and C. A and B are used for the numbers 2 to7. The combination of bars from A and B encodes the first digit, which doesn't have any bars associated with it. The C series is used for the last 6 digits. I can't remember the sum for the last digit, but it is something like the sum of the odd (1st, 3rd etc) numbers multiplied by 3 plus the sum of the even (2nd, 4th etc) modulus 10.

For ISBN numbers, they all start with 978, so that leaves 9 digits for the rest.

User avatar
ravanwin
Posts: 5060
Joined: Thu Aug 26, 2004 8:08 pm
Location: edinburgh
Contact:

Post by ravanwin » Wed Jul 04, 2007 9:35 pm

s-dawg, your new avatar should be a bar code.#
r

swithun
Posts: 2683
Joined: Wed Mar 29, 2006 12:24 pm

Post by swithun » Thu Jul 05, 2007 10:31 am

Here is the Fortran program I wrote for generating the barcode. You can compile it with the command

Code: Select all

f77    barcode.f   -o barcode
and run it in a pipeline with some other programs for scaling up the PBM and converting it to PNG format like

Code: Select all

echo "1 2 3 4 5 6 7 8 9 0 1 2" | ./barcode | pnmscale 4 | pnmtopng > barcode.png

Code: Select all

c
c output PBM format image of barcode
c
      program barcode
      integer data_file
      integer i, j, k, p, height, width
      integer checksum
      integer given(13), parity(0:9, 2:7), codes(3, 0:9, 7)
      parameter (data_file = 10)
      parameter (height = 20, width = 97)

c
c read in parity and codes from data file
c
      open (data_file, FILE="barcode_data.dat", STATUS="OLD")
      do i = 0, 9
        read (data_file, 910) (parity(i, j), j = 2, 7)
      enddo
      do i = 1, 3
        do j = 0, 9
          read (data_file, 920) (codes(i, j, k), k = 1, 7)
        enddo
      enddo
      close (data_file)

c
c read in given numbers and calculate checksum
c
      read (*,*) (given(i), i = 1, 12)
      given(13) = checksum(given)

c
c output
c
      write (*, 940) "P1"
      write (*, 950) width, height + 2
c top line of white
      do i = 1, width
        write (*, 960) 0
      enddo
      do k = 1, height
c left guard bars
        write (*, 940) "0 1 0 1"
        do i = 2, 7
          p = parity(given(1), i)
          write (*, 920) (codes(p, given(i), j), j = 1, 7)
        enddo
c centre guard bars
        write (*, 940) "0 1 0 1 0"
        do i = 8, 13
          write (*, 920) (codes(3, given(i), j), j = 1, 7)
        enddo
c right guard bars
        write (*, 940) "1 0 1 0"
      enddo
c bottom line of white
      do i = 1, width
        write (*, 960) 0
      enddo

c
c formats
c
 910  format (6I2)
 920  format (7I2)
 940  format (A)
 950  format (2I3)
 960  format (I2)

      stop
      end

c
c calculate and return checksum from given digits
c
      integer function checksum(given)
      integer i, total, given(12)

      total = 0
      do i = 1, 12
        total = total + given(i)
        if (0 == MOD(i, 2)) then
          total = total + (2 * given(i))
        endif
      enddo

      checksum = MOD(10 - MOD(total, 10), 10)

      return
      end
The data file barcode_data.dat is:

Code: Select all

1 1 1 1 1 1 
1 1 2 1 2 2 
1 1 2 2 1 2 
1 1 2 2 2 1 
1 2 1 1 2 2 
1 2 2 1 1 2 
1 2 2 2 1 1 
1 2 1 2 1 2 
1 2 1 2 2 1 
1 2 2 1 2 1 
0 0 0 1 1 0 1
0 0 1 1 0 0 1
0 0 1 0 0 1 1
0 1 1 1 1 0 1
0 1 0 0 0 1 1
0 1 1 0 0 0 1
0 1 0 1 1 1 1
0 1 1 1 0 1 1
0 1 1 0 1 1 1
0 0 0 1 0 1 1
0 1 0 0 1 1 1 
0 1 1 0 0 1 1 
0 0 1 1 0 1 1 
0 1 0 0 0 0 1 
0 0 1 1 1 0 1 
0 1 1 1 0 0 1 
0 0 0 0 1 0 1 
0 0 1 0 0 0 1 
0 0 0 1 0 0 1 
0 0 1 0 1 1 1 
1 1 1 0 0 1 0 
1 1 0 0 1 1 0 
1 1 0 1 1 0 0 
1 0 0 0 0 1 0 
1 0 1 1 1 0 0 
1 0 0 1 1 1 0 
1 0 1 0 0 0 0 
1 0 0 0 1 0 0 
1 0 0 1 0 0 0 
1 1 1 0 1 0 0

Post Reply