Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

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:

> 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...

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:

Or

copy file1+file2 newFile

is a little more intuitive...

In a previous article, dpb <bozart@gmail.com> wrote:

 .. 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...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc