1. Equal Distribution

------=_NextPart_000_0095_01C0B077.6ECEFE70
	charset="iso-8859-1"

I've got 28 files that take up 8.54 MB that I want to compress and
efficiently distribute to diskettes. I am using Junko's compressor algorithm
and I'm assuming equal compression percentages for each file to make things
easier.

Can anybody drop me a clue as to how I would best equally distribute those
files? I'd like to set a limit to distribute to disk; for instance, I would
specify 1MB or less of file data to each diskette (because I have other
files I need on there as well), then the program would figure that out and
give me a file listing of which files go to which diskette.

I've attached a simple tab-delimited file of the filenames and sizes for use
as an example...

Thanks!
ck


------=_NextPart_000_0095_01C0B077.6ECEFE70
	name="Illinois Template File Listing.txt"

new topic     » topic index » view message » categorize

2. Re: Equal Distribution

CK Lester wrote:

> Can anybody drop me a clue as to how I
> would best equally distribute those files?

You could write the files as a 'single' file, spread across several disks.
For example (untested code):

   -- list of files
   constant files = { "this", "that", "other" }

   -- constants
   disk = 1 -- current disk number
   at = 0 -- offset into disk
   disksize = 100 -- bytes per disk

   -- the 'fat' table
   fat = open( "fat", "w" )

   -- write the files
   handle = open( sprintf( "disk%d", {disk} ), "w" )
   for i = 1 to length( files ) do

      -- read the file
      data = read_file( file[i] )

      -- write to fat file
      printf( fat, "%d, %d, %d, %d",
         {file[i], disk, at, length(data)} )

      -- write the data
      for i = 1 to length( data ) do
         putc( handle, data[i] )

         -- move ahead
         at += 1

         -- spans disk?
         if at > disksize then
            -- close old file
            close( handle )

            -- increment disk number
            disk += 1

            -- open new disk file
            handle = open( sprintf( "disk%d.dat", {disk} ), "w" )

         end if

      end for

   end for

   close( handle )
   close( fat )

Reversing this (reading the file layouts from the fat table) allows the
files to be reconstructed from the data files.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: Equal Distribution

I needed same thing few months back to copy games on CD and Pete Eberlein
gave me this excelent code which worked for me:

Here is his whole message:



On Fri, 7 Apr 2000 20:40:41 +0200, =?iso-8859-2?B?qWtvZGE=?=
<tone.skoda at SIOL.NET> wrote:

>anybody written or knows of program which sorts blocks of different size in
1 unit so that this unit is maximally used.
>
>I have many games of different sizes (150MB,300MB...)which I want to copy
to CD which has size 650 MB. I want the space on CD to be maximally used.
>anybody smart enough to write it for me?
>I know it's quite simple algorithm. you have to combine all combinations
and select the best.
>

Here's some box packing routines that will probably do the trick.  It packs
the fewest elements into each box if the items are sorted in ascending
order.
  bestitems = {}
  for i = length(items) to 1 by -1 do
    if items[i] <= boxsize then
      temp = pack(items[1..i-1]&items[i+1..length(items)], boxsize-items[i])
      thissize = items[i]
      for j = 1 to length(temp) do
        thissize += temp[j]
      end for
      if thissize > bestsize then
        bestsize = thissize
        bestitems = items[i] & temp
      end if
    end if
  end for
  return bestitems
end function

procedure pack_boxes(sequence items, integer boxsize)
  sequence temp
  integer j
  while length(items) do
    temp = pack(items, boxsize)
    ? temp
    for i = 1 to length(temp) do
      j = find(temp[i], items)
      items = items[1..j-1]&items[j+1..length(items)]
    end for
  end while
end procedure

pack_boxes({2,3}, 4)            puts(1, "\n")
pack_boxes({2,3,4}, 5)          puts(1, "\n")
pack_boxes({2,3,4,5}, 5)        puts(1, "\n")
pack_boxes({3,4,5,6}, 10)       puts(1, "\n")
pack_boxes({3,4,5,6}, 15)       puts(1, "\n")









----- Original Message -----
From: CK Lester <cklester at yahoo.com>
To: EUforum <EUforum at topica.com>
Sent: Monday, March 19, 2001 8:25 PM
Subject: Equal Distribution


>
>
> I've got 28 files that take up 8.54 MB that I want to compress and
> efficiently distribute to diskettes. I am using Junko's compressor
algorithm
> and I'm assuming equal compression percentages for each file to make
things
> easier.
>
> Can anybody drop me a clue as to how I would best equally distribute those
> files? I'd like to set a limit to distribute to disk; for instance, I
would
> specify 1MB or less of file data to each diskette (because I have other
> files I need on there as well), then the program would figure that out and
> give me a file listing of which files go to which diskette.
>
> I've attached a simple tab-delimited file of the filenames and sizes for
use
> as an example...
>
> Thanks!
> ck
>
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: Equal Distribution

Well, my code had a bug in it, so here's a tested version:

-- span.ex
include file.e

integer
    at,             -- position of current byte
    disk,           -- current disk number
    handle,         -- handle of file being written
    fat,            -- handle to 'fat' file
    bytesPerDisk    -- bytes per disk

sequence
    files,          -- list of files to write
    data            -- data from current file

-- your files go here...
files = {
    "wininet.h",
    "webshelp.hlp",
    "webshelp.cnt",
    "shepherd.exw",
    "http.ew",
    "test.ex" }

function read_file( sequence filename )
    -- read a file, return sequence containing data
    integer handle
    sequence data
    object result

    -- open the file
    handle = open( filename, "r" )
    data = ""
    while 1 do
        result = getc( handle )
        if result = -1 then
            exit
        else
            data &= result
        end if
    end while
    close( handle )
    return data
end function

-- fat table
fat = open( "fat.dat", "w" )

-- fat header
printf( fat, "files=%d\n", length( files ) )

-- set size of disk
bytesPerDisk = 1000

-- output file
disk = 1
at = 0
handle = open( sprintf( "disk%d.dat", {disk} ), "w" )
for i = 1 to length( files ) do
    data = read_file( files[i] )
    printf( fat, "name=%s,disk=%d,at=%d,bytes=%d\n",
            {files[i],disk,at,length(data)} )
    for j = 1 to length( data ) do
        at += 1
        if at > bytesPerDisk then
            close( handle )
            disk += 1
            handle = open( sprintf( "disk%d.dat", {disk} ), "w" )
            at = 1
        end if
        puts( handle, data[j] )
    end for
end for

-- fat footer
printf( fat, "disks=%d\n", disk )

-- close the files
close( handle )
close( fat )


this only writes the file. to recreate the datafile, all you need to do is
build all the data files into a large data file. the fat contains the names
and position of the data. Actual position of the data is:

   ((disk-1)*bytesPerDisk)+(at-1)

I've left that portion as an exercise to the reader (since it involves
prompting the user to enter the proper disk, and so on), but here's a
routine that can be used to get the parameters from the fat data file:

function get_parm( sequence parm, sequence string )
    integer at
    at = match( parm & "=", string )
    at += length( parm ) + 1
    string = string[at..length(string)]
    at = find( ',', string )
    if at then
        string = string[1..at-1]
    end if
    return string
end function

For example:

   s = get_parm( "name", parms )

will return the "name" parameter.

Also, I'd leave a bit of room on each disk; quite often diskettes go bad,
and the disk repair routines that Windows has can only repair sectors if
there is space on the floppy to move the repaired data to. sad

I hope this helps! If you really want the decompression routine, I can throw
that together, too.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

5. Re: Equal Distribution

I've got a customized install program that requires the compressed files be
in the "files" folder on the floppy drive. The installer makes sure the
template files get to the right place. There's a bit of hand-holding during
the install, because a lot of people, though familiar with the applications,
aren't familiar with the use of templates in those apps.

-ck

> On 20 Mar 2001, at 5:56, CK Lester wrote:
>
> > Thanks for the help, David, and others...
> >
> > An important requirement here is that I can replace a file on one of the
> > diskettes if ever necessary... like for updates. So, they have to exist
on
> > the disk(s) as separate files.
>
> I just had a thought,, what if you zipped them, or used some other
compression? As
> one large compressed file, sector size wouldn't matter anymore. Even
uncompressed,
> if they were appended to each other, they'd use entire sectors too, except
for the last
> file. You could expand them to the user's harddrive for faster and more
reliable access
> at install time.
>
> Kat

new topic     » goto parent     » topic index » view message » categorize

6. Re: Equal Distribution

On 20 Mar 2001, at 6:46, CK Lester wrote:

> 

> 
> I've got a customized install program that requires the compressed files be
> in the "files" folder on the floppy drive. The installer makes sure the
> template files get to the right place. There's a bit of hand-holding during
> the install, because a lot of people, though familiar with the applications,
> aren't familiar with the use of templates in those apps.

You know the directory name takes up the same space as filename, right? and 
anything over an 8.3 name eats more clusters/sectors. If i were this concerned
over
floppy space, i'd encode the destination dir into the file's name, and put them
all into
root dir on the floppy as an 8.3 name, with no subdirs on the floppy. 

For instance: 
templ1.tlt -- goes into template dir
menu.exe --  goes somewhere else
splash.gif -- goes to pic dir

Kat

 
> -ck
> 
> > On 20 Mar 2001, at 5:56, CK Lester wrote:
> >
> > > Thanks for the help, David, and others...
> > >
> > > An important requirement here is that I can replace a file on one of the
> > > diskettes if ever necessary... like for updates. So, they have to exist
> on
> > > the disk(s) as separate files.


> > I just had a thought,, what if you zipped them, or used some other
> compression? As
> > one large compressed file, sector size wouldn't matter anymore. Even
> uncompressed,
> > if they were appended to each other, they'd use entire sectors too, except
> for the last
> > file. You could expand them to the user's harddrive for faster and more
> reliable access
> > at install time.
> >
> > Kat
> 
> 
> 
> 
> 
> 
> 
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu