home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!newsserver.jvnc.net!yale.edu!think.com!ames!agate!stanford.edu!rutgers!uwvax!zazen!psl.wisc.edu!chsra2.chsra.wisc.edu!DSPENCER
- From: dspencer@chsra2.chsra.wisc.edu
- Newsgroups: comp.os.vms
- Subject: Re: Using C to read Fortran File
- Message-ID: <1993Jan7.142349.23336@pslu1.psl.wisc.edu>
- Date: 7 Jan 93 14:23:49 GMT
- Sender: news@pslu1.psl.wisc.edu (USENET News System)
- Reply-To: spencer@macc.wisc.edu
- Organization: CHSRA/UW-MADISON, MADISON, WI
- Lines: 57
-
- In article <C0G1rw.81L@ccu.umanitoba.ca>, kaarts@ccu.umanitoba.ca (Kenneth John Aarts) writes:
- >In <C0Fyo3.70D@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.
- >
- >>How do I get C to find the c in cArt?
- >
- >A little more information:
- >
- >This is all done on VMS. The fortran created file has a 'fortran carriage
- >control' record attribute.
-
- change the "r" fopen attribute to "rb". The file Fortran writes out in this
- case has the RMS file attributes
- RMS FILE ATTRIBUTES
-
- File Organization: sequential
- Record Format: variable
- Record Attributes: fortran
- Maximum Record Size: 0
- Longest Record: 4
- Blocks Allocated: 4, Default Extend Size: 0
- End-of-File VBN: 1, Offset: %X'0006'
- File Monitoring: disabled
- Global Buffer Count: 0
-
- Telling VAXC to do a read binary appears to override the interpretation of the
- 'fortran' record attribute, and I get the following output
-
- 99 65 114 116 0
-
- -----------------------------------------------
- Dan Spencer spencer@vms.macc.wisc.edu
- Center for Health Systems Research and Analysis
- UW-Madison
-