Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 complex data importation
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
atrain




PostPosted: Tue May 31, 2005 12:08 am   Post subject: complex data importation

Im trying to import data in sets of 5 (4 coords, 1 object type) from more than 1 file
im using a flexable 2d array per set

I can get it to detect how many files and open them in order, but getting the data into the array i messed something up...

If you see how u can help, plz do...

code:

var objects : flexible array 1 .. 1, 1 .. 5 of int % New object handling system
var numberoflevels : int := 0
var numberofsets : int := 0
var null : int

procedure getlevels
    var file : int
    var file2 : int
    loop
        numberoflevels := numberoflevels + 1
        exit when File.Exists ("map" + intstr (numberoflevels) + ".t") = false

    end loop
    numberoflevels := numberoflevels - 1 % Last thing broke, remember?
   
   
  for i : 1 .. numberoflevels

        open : file, "map" + intstr (i) + ".t", get
        loop
            exit when eof (file)
            get : file, null
            numberofsets := numberofsets + 1
        end loop

        numberofsets := numberofsets div 5 % FIND OUT HOW MANY OBJECTS
       

        close (file) % CLOSE AND REOPEN
        open : file2, "map" + intstr (i) + ".t", get

        for j : 1 .. numberofsets
            loop
                exit when eof (file2)
                numberofsets := numberofsets + 1
                for k : 1 .. 5
                    get : file2, objects (j, k)
                end for
                new objects, numberofsets, 5

            end loop
            close (file2)
      end for
    end for
end getlevels
getlevels

for i : 1 .. numberofsets - 1
    for j : 1 .. 5
        put objects (i, j)
    end for
end for

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Tue May 31, 2005 2:39 pm   Post subject: (No subject)

Woah...no need to get so complicated!
You know the exact structure of each file and its contents. So extract the entire file into a flexible array and then sort through the array to find what you need.
Or you could do that dynamically, but that's a lot more challenging.
If you absolutely must, add flags to your objects. So, the set of 5 numbers could begin and end with "#" or something like that, and any other 'objects' you have could be handled similarly.

A few pointers:
It's great that you're using procedures, please keep that up. But in the immortal words of Cervantes:
"[procedures] shoudl know as little about the outside world as possible."
You shouldn't have any of your Global Variables editted directly by the procedure unless you're calling a procedure that alters global variables Very Happy.
Keep things dynamic and use paramters (AKA arguments) as often as you can.

You can smooth your "numberoflevels" thing by simply incorporating your "File.Exists" boolean into your extraction. Adding the count there will do just as good of a job.

Turing:

variable1 := variable1 + 3
% *Rewrite*
variable1 += 3
% These mean the same.


Just a minor point, you needn't have 2 seperate file streams if you're only ever going to have 1 file open at a time. Once you've close "file" you can use it again to open the files once more. It's just that expendable!
atrain




PostPosted: Tue May 31, 2005 4:37 pm   Post subject: (No subject)

Nah, i figured it out...

basicly, the file structure is sets of 4 coordanates (x1, y1, x2, y2) then a object type

With that i was importing from every map instead of 1

I fixed it

first it finds how many files
then it probes inside the one u chose to find how many sets

then it does 2 for loops

for i: 1..numberofsets
for j: 1..5
get : file, objects (i,j)
end for
end for

So it works great now....
Thanx anywayz!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: