|
|
 |
 |
 |
 |
Fortran Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
reading file
I want to read a file and dump it into another file. I dont need to read them in any specific way, for my purpose is solely to append it to another file. Is it possible to do it, without using any loops or array declarations?. The file essentiallly contains a series of lines containing various characters. sincerely dibyadeep
On 5 26 , 9 24 , thinktank <dibyad@gmail.com> wrote: > I want to read a file and dump it into another file. I dont need to > read them in any specific way, for my purpose is solely to append it > to another file. Is it possible to do it, without using any loops or > array declarations?. > The file essentiallly contains a series of lines containing various > characters.
just open the file to be append as "append" and write content to it. open("filename_to_append", position="append") If you don't limit the realization to Fortarn, the command "copy" is another choice.
well what I meant was that I wanted to read a file from the harddisk and append it to another file, not append something that is already in memory. if you have any suggestions do reply On May 26, 6:46 pm, zyf <zhangyunf@gmail.com> wrote:
> On 5 26 , 9 24 , thinktank <dibyad @gmail.com> wrote: > > I want to read a file and dump it into another file. I dont need to > > read them in any specific way, for my purpose is solely to append it > > to another file. Is it possible to do it, without using any loops or > > array declarations?. > > The file essentiallly contains a series of lines containing various > > characters. > just open the file to be append as "append" and write content to it. > open("filename_to_append", position="append") > If you don't limit the realization to Fortarn, the command "copy" is > another choice.
> The file essentiallly contains a series of lines containing various > characters.
well, if you were in a Unix environment I would just do cat newstuff >> oldfile, so I guess you are in windows.
Still, with fortran why not something like: character(len=1000) :: inputline ! Assuming you can specify some max record size, here 1000 open(10,file="newstuff") open(20,file="oldfile",position="append") do read(10,fmt="(a)",iostat=ios) inputline if ( ios /= 0 ) exit ! Likely end of file write(20,fmt="(a)") inputline end do OK, this uses loops and declarations, but programs usually do! Luckily I'm on Linux so I would just use the "cat" method :-)
Yes, the statement of the problem leaves a lot to be desired. Which platform are you in? Does it need to be in fortran? Is this a one time thing? If you are in unix, you can append like this cat newStuff >> oldStuff If you are in Windows, go ahead and open a DOS terminal from Start -> Programs -> Accessories -> Command Prompt then use the 'copy' command to copy both files into a third one...they will copied over in the order given. copy oldStuff newStuff bothStuff
program append_file1_to_file2 character(30) :: file1, file2, ch*1 call getarg(1,file1) call getarg(2,file2) open (1,file=file1,form='binary') open (2,file=file2,form='binary',position='append') do read (1,end=101) ch write (2) ch end do 101 stop end program "thinktank" <dibyad @gmail.com> wrote in message news:1180188025.994393.38450@n15g2000prd.googlegroups.com...
> well what I meant was that I wanted to read a file from the harddisk > and append it to another file, not append something that is already in > memory. if you have any suggestions do reply > On May 26, 6:46 pm, zyf <zhangyunf@gmail.com> wrote: >> On 5 26 , 9 24 , thinktank <dibyad@gmail.com> wrote: >> > I want to read a file and dump it into another file. I dont need to >> > read them in any specific way, for my purpose is solely to append it >> > to another file. Is it possible to do it, without using any loops or >> > array declarations?. >> > The file essentiallly contains a series of lines containing various >> > characters. >> just open the file to be append as "append" and write content to it. >> open("filename_to_append", position="append") >> If you don't limit the realization to Fortarn, the command "copy" is >> another choice.
You don't need to write any program. Just do copy oldfile /A addfile newfile <ret> This copies the file you want to add ("addfile")to the end of the old file ("oldfile" (ASSUMING ASCII LINES, else take away the /A) and creates a new ascii file "newfile" with both inside in the order stated.
On May 26, 10:30 pm, gsal <salger@gmail.com> wrote:
> Yes, the statement of the problem leaves a lot to be desired. > Which platform are you in? > Does it need to be in fortran? > Is this a one time thing? > If you are in unix, you can append like this > cat newStuff >> oldStuff > If you are in Windows, go ahead and open a DOS terminal from Start -> > Programs -> Accessories -> Command Prompt then use the 'copy' command > to copy both files into a third one...they will copied over in the > order given. > copy oldStuff newStuff bothStuff
Or copy file1+file2 newFile is a little more intuitive...
In a previous article, dpb <bozart@gmail.com> wrote:
>On May 26, 10:30 pm, gsal <salger @gmail.com> wrote: >> Yes, the statement of the problem leaves a lot to be desired. >> Which platform are you in? >> Does it need to be in fortran? >> Is this a one time thing? >> If you are in unix, you can append like this >> cat newStuff >> oldStuff >> If you are in Windows, go ahead and open a DOS terminal from Start -> >> Programs -> Accessories -> Command Prompt then use the 'copy' command >> to copy both files into a third one...they will copied over in the >> order given. >> copy oldStuff newStuff bothStuff >Or >copy file1+file2 newFile >is a little more intuitive...
.. and re. windows/DOS/commandline, if they not ascii files then use "copy/b ... " Chris
Would the command: TYPE FILE1.TXT >> FILE2.TXT from a DOS session work for you? It would append FILE1.TXT to the end of FILE2.TXT Does your FORTRAN supports a SYSTEM("TYPE FILE1.TXT >> FILE2.TXT") call? or perhaps SYSTEM("cat file1.txt >> file2.txt") for a *NIX type system? "thinktank" <dibyad @gmail.com> wrote in message news:1180185888.634630.124210@q19g2000prn.googlegroups.com...
> I want to read a file and dump it into another file. I dont need to > read them in any specific way, for my purpose is solely to append it > to another file. Is it possible to do it, without using any loops or > array declarations?. > The file essentiallly contains a series of lines containing various > characters. > sincerely > dibyadeep
|
 |
 |
 |
 |
|