home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:19374 comp.os.vms:20520
- Newsgroups: local.unix.help,comp.lang.c,comp.os.vms
- Path: sparky!uunet!eco.twg.com!eco.twg.com!larry
- From: larry@eco.twg.com (Lawrence B. Henry III)
- Subject: Re: Using C to read Fortran Files
- Message-ID: <1993Jan7.171849.17042@eco.twg.com>
- Lines: 50
- Sender: larry@vishnu.eco.twg.com (Lawrence B. Henry III)
- Nntp-Posting-Host: eco.twg.com
- Reply-To: larry@eco.twg.com
- Organization: The Wollongong Group (East Coast Operations)
- References: <C0Fyo3.70D@ccu.umanitoba.ca> <C0G1rw.81L@ccu.umanitoba.ca> <C0GHCC.Cwp@ccu.umanitoba.ca> <1993Jan7.030702.4174@dbased.nuo.dec.com>
- Date: Thu, 7 Jan 93 17:18:49 GMT
- Lines: 50
-
-
- In article <1993Jan7.030702.4174@dbased.nuo.dec.com>, lionel@quark.enet.dec.com (Steve Lionel) writes:
- |>
- |>In article <C0GHCC.Cwp@ccu.umanitoba.ca>, kaarts@ccu.umanitoba.ca
- |>(Kenneth John Aarts) writes...
- |>>
- |>>>I have a fortran program that does essentially
- |>>
- |>>> open(unit=1,"test",status='new')
- |>>> write(1,10) 'cArt'
- |>>>10 format(a4)
- |>>> end
- |>>
- |>>>and then a C program that reads it:
- |>>
- |>>> int d1,d2,d3,d4,d5;
- |>>> FILE *fp;
- |>>> fp=fopen("test","r");
- |>>> fscanf(fp,"%c%c%c%c%c",&d1,&d2,&d3,&d4,&d5);
- |>>> printf("%d %d %d %d %d\n",d1,d2,d3,d4,d5);
- |>>
- |>>>The output of the C program is:
- |>>
- |>>> 10 65 114 116 13
- |>>
- |>>> LF A r t CR
- |>>
- |>>>However, a fortran program reading the test program does see cArt.
- |>>
- |>
- |>It is the VAX C Run-Time Library which is doing this to you; it "interprets"
- |>the FORTRAN carriage control, turning the leading "c" into an LF, as that's
- |>what would happen if you printed the line on a terminal or printer. WHY
- |>it does this I don't know, nor do I know how to stop it, but I thought
- |>that at the least you should know where the problem is located.
- |>
- |>All I can suggest is that, if possible, open the file from FORTRAN
- |>specifying CARRIAGECONTROL='LIST'. I'll see what I can dig up about
- |>solutions from the VAX C end.
-
- Try changing the way you open the file to something like:
-
- i = open("test", O_RDONLY, "rat=ftn");
- fp = fdopen(i, "r");
-
- not sure if this solves your problem.. but checking the VAX C documentation
- it seem to imply it will.. The "rat=ftn" tells the open call that the record
- attributes of the file contain FORTRAN print control.
-
- -Larry.
-