Thread: Open several files , read it and then write

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    24

    Open several files , read it and then write

    Hi pals

    Im gonna explain what I need to do.
    First I would like to open 400 files e.g ISO1.dat,..ISO400.dat, within this files I have datas which means numbers for instance( X,Y,Z are vectors)
    ISO1.dat has X1,Y1,Z1 vectors
    ISO2.dat has X1,Y2,Z2 vectors
    ISO3.dat has X1,Y3,Z3 vectors
    I only need to read X and Y
    then write in a unique file X1,Y1,Y2,Y3...Y400
    How Can I do it

    Tks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Pretty much just like you described. So let's see your attempt.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    I love it! When people ask us to do there home. And some fantastic comments ahead to come lol.

    Yo viking, show us your code man..

    ~ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #4
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    you might try some for loops and fopens. haha

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm thinking your OS will not allow you to open 400 files all at once. Remember that you can write out results from the first 20 files, and then open up the next 20 files, and continue writing to the same output file. You can't use wildcards in filenames you want opened, so you'll need to have them logically organized, with specific names, or in a specific directory of their own, or some combination of these two things.

    If for some reason, you need to re-open an output file to write more data to it, you can use the append mode to keep all the current data in the file, and just add the new data, right onto the end of the output file.

    You'll save yourself a lot of time and trouble, if you take awhile, and write down exactly how you intend to do this, step by step. As if you were going to do it by hand. Make sure that you have a clear vision of what you want the program to do, step by step.

    That makes it so much easier to code it up, ask smart questions on the forum, and finish up with a good program.
    Last edited by Adak; 10-02-2009 at 06:26 AM.

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    I would suggest you use either the CRT or the Windows API and probably, with 400 files all named similar, sprintf() will come in handy. I have exactly 2 code readers and zero mind readers, so post what you have tried so far.
    Last edited by abachler; 10-02-2009 at 10:55 AM.

Popular pages Recent additions subscribe to a feed