From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 11-JUN-1994 12:37:25.32
To:	EVERHART
CC:	
Subj:	Re: Fortran Unit #'s to "C" File-ID's??

Date: Sat, 11 Jun 1994 18:04:24 +0100
From: Arne Vajhoej <ARNE@kopc.hhs.dk>
Subject: Re: Fortran Unit #'s to "C" File-ID's??
To: flower@SDVAX2.ETDESG.TRW.COM, INFO-VAX@SRI.COM
Message-id: <01HDFAKLQI2A8WWGS1@kopc.hhs.dk>
X-VMS-To: KOPC::IN%"flower@SDVAX2.ETDESG.TRW.COM"
X-VMS-Cc: IN::"INFO-VAX@SRI.COM"
MIME-version: 1.0
Content-type: TEXT/PLAIN; CHARSET=ISO-8859-1
Content-transfer-encoding: 8BIT

> Is it possible to convert a Fortran Unit number for an open file to a "C" file-
> id that can then be used from within VAX-C to write to the same open file??

documented/supported code                      : NO
undocumented/unsupported break any minute code : YES

I will show 5 solutions to mixing I/O in FORTRAN and C: 3 supported +
2 unsupported.

Actually it is solution #5 that answers your question with a YES, but I
will strongly recommend you to implement one of the 3 first supported
solutions !

1) FORTRAN/RMS+C/RMS

   Supported.

   Example:

      INCLUDE '($FABDEF)'
      INCLUDE '($RABDEF)'
      INTEGER*4 STAT
      RECORD /FABDEF/FAB
      RECORD /RABDEF/RAB
      CHARACTER*3 FNM
      CHARACTER*33 BUF
      INTEGER*4 SYS$CREATE,SYS$CONNECT,SYS$PUT,SYS$DISCONNECT,SYS$CLOSE
      FNM='Z.Z'
      FAB.FAB$B_BID=FAB$C_BID
      FAB.FAB$B_BLN=FAB$C_BLN
      FAB.FAB$B_FAC=FAB$M_PUT
      FAB.FAB$B_FNS=LEN(FNM)
      FAB.FAB$L_FNA=%LOC(FNM)
      FAB.FAB$B_RAT=FAB$M_CR
      FAB.FAB$B_RFM=FAB$C_VAR
      STAT=SYS$CREATE(FAB,,)
      IF(IAND(STAT,1).EQ.0) CALL LIB$SIGNAL(%VAL(STAT))
      RAB.RAB$B_BID=RAB$C_BID
      RAB.RAB$B_BLN=RAB$C_BLN
      RAB.RAB$L_FAB=%LOC(FAB)
      STAT=SYS$CONNECT(RAB,,)
      IF(IAND(STAT,1).EQ.0) CALL LIB$SIGNAL(%VAL(STAT))
      BUF='This is a small test from FORTRAN'
      RAB.RAB$L_RBF=%LOC(BUF)
      RAB.RAB$W_RSZ=LEN(BUF)
      STAT=SYS$PUT(RAB,,)
      IF(IAND(STAT,1).EQ.0) CALL LIB$SIGNAL(%VAL(STAT))
      CALL SUBBO(RAB)
      BUF='This is a small test from FORTRAN'
      RAB.RAB$L_RBF=%LOC(BUF)
      RAB.RAB$W_RSZ=LEN(BUF)
      STAT=SYS$PUT(RAB,,)
      IF(IAND(STAT,1).EQ.0) CALL LIB$SIGNAL(%VAL(STAT))
      STAT=SYS$DISCONNECT(RAB,,)
      IF(IAND(STAT,1).EQ.0) CALL LIB$SIGNAL(%VAL(STAT))
      STAT=SYS$CLOSE(FAB,,)
      IF(IAND(STAT,1).EQ.0) CALL LIB$SIGNAL(%VAL(STAT))
      END

#include <rab.h>

int sys$put();
int lib$signal();

void subbo(struct RAB *rab)
{
   char buf[] = "This is a small test from C";
   int stat;
   rab->rab$l_rbf = &buf;
   rab->rab$w_rsz = sizeof(buf)-1;
   stat = sys$put(rab,0,0);
   if ((stat&1)==0) lib$signal(stat);
   return;
}

2) FORTRAN/FORRTL+C/RMS

   Supported.

   Example:

      INTEGER*4 FOR$RAB
      OPEN(UNIT=1,FILE='Z.Z',STATUS='NEW',CARRIAGECONTROL='LIST')
      WRITE(UNIT=1,FMT='(A)') 'This is a small test from FORTRAN'
      CALL SUBBO(%VAL(FOR$RAB(1)))
      WRITE(UNIT=1,FMT='(A)') 'This is a small test from FORTRAN'
      CLOSE(UNIT=1)
      END

#include <rab.h>

int sys$put();
int lib$signal();

void subbo(struct RAB *rab)
{
   char buf[] = "This is a small test from C";
   int stat;
   rab->rab$l_rbf = &buf;
   rab->rab$w_rsz = sizeof(buf)-1;
   stat = sys$put(rab,0,0);
   if ((stat&1)==0) lib$signal(stat);
   return;
}

3) FORTRAN/VAXCRTL+C/VAXCRTL

   Supported.

   Example:

      INTEGER*4 FP
      INTEGER*4 FOPEN
      FP=FOPEN(%VAL(%LOC('Z.Z'//CHAR(0))),%VAL(%LOC('w'//CHAR(0))))
      CALL FPRINTF(%VAL(FP),%VAL(%LOC('%s'//CHAR(10)//CHAR(0))),
     +  %VAL(%LOC('This is a small test from FORTRAN'//CHAR(0))))
      CALL SUBBO(%VAL(FP))
      CALL FPRINTF(%VAL(FP),%VAL(%LOC('%s'//CHAR(10)//CHAR(0))),
     +  %VAL(%LOC('This is a small test from FORTRAN'//CHAR(0))))
      CALL FCLOSE(%VAL(FP))
      END

#include <stdio.h>

void subbo(FILE *fp)
{
   char buf[] = "This is a small test from C";
   fprintf(fp,"%s\n",buf);
   return;
}

4) FORTRAN/FORRTL+C/FORRTL

   Unsupported.

   Example:

      OPEN(UNIT=1,FILE='Z.Z',STATUS='NEW',CARRIAGECONTROL='LIST')
      WRITE(UNIT=1,FMT='(A)') 'This is a small test from FORTRAN'
      CALL SUBBO(%VAL(1))
      WRITE(UNIT=1,FMT='(A)') 'This is a small test from FORTRAN'
      CLOSE(UNIT=1)
      END

#include <descrip.h>

void for$write_sf();
void for$io_t_ds();
void for$io_end();


void subbo(int unit)
{
   long fmt = 0x429;
   char buf[] = "This is a small test from C";
   $DESCRIPTOR(bufdes,buf);
   for$write_sf(unit,&fmt);
   for$io_t_ds(&bufdes);
   for$io_end();
   return;
}

5) FORTRAN/FORRTL+C/VAXCRTL

   Unsupported:

   Example:

      INTEGER*4 FOR$RAB
      OPEN(UNIT=1,FILE='Z.Z',STATUS='NEW',CARRIAGECONTROL='LIST')
      WRITE(UNIT=1,FMT='(A)') 'This is a small test from FORTRAN'
      CALL SUBBO(%VAL(FOR$RAB(1)))
      WRITE(UNIT=1,FMT='(A)') 'This is a small test from FORTRAN'
      CLOSE(UNIT=1)
      END

#include <stdio.h>
#include <rab.h>
#define fcb_l_rab 0x0f4;

#define garbfile "GARBAGE.DAT"

void subbo(struct RAB *forrab)
{
   char buf[] = "This is a small test from C";
   struct RAB *crab,save;
   FILE *fp;
   fp = fopen(garbfile,"w");
   crab = (int)(*fp) + fcb_l_rab;
   save = *crab;
   *crab = *forrab;
   fprintf(fp,"%s\n",buf);
   *crab = save;
   fclose(fp);
   delete(garbfile);
   return;
}

OK ?

                                                          Arne

Arne Vajhøj                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE
Business School of Southern Denmark     Internet:      ARNE@KO.HHS.DK


