From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,51e55e05054fdc6e,start X-Google-Attributes: gid1164f8,public From: speck@stsci.edu Subject: Help Replace USEROPEN Macro w/ Fortran Date: 1996/08/30 Message-ID: <1996Aug30.122330@stsci.edu> X-Deja-AN: 177479804 organization: Space Telescope Science Institute, Baltimore, MD 21218 newsgroups: comp.sys.dec I'm trying to replace an old macro USEROPEN routine with a Fortran routine. The Fortran open statement which calls (via USEROPEN) the old macro routine is: open (UNIT=logical_unit_num, FILE=file_name, STATUS='OLD', # SHARED, READONLY, iostat=ios1, USEROPEN=open_old_chan) The macro routine attempts to open the file. If successful, it determines the channel number and places it into common, so that the afore-mentioned Fortran routine can access the channel number. My Fortran replacement routine, shown below, is opening the file and placing the same channel number into common as the macro routine. However, when I try to perform a SYS$CRMPSC (create mapped section) which uses the channel number, the macro version of open_old_chan results in a smooth error-free run, but the Fortran version of open_old_chan results in SYS$CRMPSC returning -1 as the address in the map space. Any ideas, based upon inspecting the code below, as to what is wrong with the Fortran? First, here is the macro routine open_old_chan, with comments to elucidate the function of the routine: _____________________ BEGIN MACRO LISTING .TITLE OPEN_OLD_CHAN ;**** ; %T PROLOG ; ; Module Name: ; ------------ ; Open_Old_Chan ; ; Keyphrase: ; ---------- ; Open a channel to an existing file ; ; Description: ; ------------ ; This module is designed to be used as the USEROPEN routine in a FORTRAN ; OPEN statement. It opens an existing file specified in the OPEN ; statement and returns the channel number assigned via ; a common block. When this module is used to open the file, no FORTRAN ; I/O may be performed on the file. All I/O must be performed using ; $QIOs. ; ; Source File Name: ; ----------------- ; OPENOLDCHAN ; ; Argument List: ; -------------- ; FAB /Input-Output /See RMS manuals ; File access block ; ; Function Value Returned: ; ------------------------ ; I*4 /System service completion code returned from $OPEN ; ; Global Data Referenced (see DD for complete definitions): ; --------------------------------------------------------- ; CHANNEL /Common block containing the channel number assigned to the file ; CHAN /Write ; ; File and Device Access (see DD for complete definitions): ; --------------------------------------------------------- ; Arbitrary file specified in FAB /Opened ; ; Local Data: ; ----------- ; NONE ; ; Modules Called: ; --------------- ; $OPEN (VAX/VMS Library) ; $FAB_STORE (VAX/VMS Library) ; ; Comments: ; --------- ; NONE ; ; History: ; -------- ; Version Date Author Description ; 3 18-DEC-1986 BAO Added file sharing field (SHR) user ; interlock argument (UPI) - definitely ; required under VMS 4.4. ; 2 04-AUG-1983 W Implementation complete (Build 1) ; ; PDL: ; ---- ; %S CALL Open_Old_Chan ; ; Set file open options to user-open and contiguous-best-try ; CALL $OPEN to open the file ; IF an error occurred THEN ; RETURN the status code from $OPEN ; ENDIF ; Get the channel number assigned to the file from the FAB and / ; store it in CHANNEL.CHAN ; RETURN success ;**** ; ;FORTRAN Named Common - used to return the channel number ; .PSECT CHANNEL PIC,GBL,SHR,NOEXE,OVR,LONG CHAN: .WORD ; ; .PSECT CODE PIC,SHR,NOWRT,LONG .ENTRY OPEN_OLD_CHAN,^M ; ;Set up the FAB ; MOVL 4(AP),R2 ;move FAB address into R2 ;use the $FAB_STORE macro to modify the File Access Block of the file ;FAB is in R2, use FOP (File processing options of): ; UFO - user file open (needed for section files), cannot use the ; $CONNECT macro to allow FORTRAN IO to it anymore ; CBT - contigous best try, ;use SHR (File sharing) option UPI - user interlock. Required since FOP UFO ; option specified. ; ; $FAB_STORE FAB=R2,FOP=,SHR= ; ;Open the file ; $OPEN FAB=R2 BLBS R0,10$ RET ; ;Return the channel number to the FORTRAN main program ;by moving it to the common block ; 10$: MOVW FAB$L_STV(R2),CHAN ; ; move a normal status to R0 MOVL #SS$_NORMAL,R0 RET .END _____________________ END MACRO LISTING And here is the Fortran (without comments) with which I'm trying to replace it: integer*4 function open_old_chan(fab, rab, lun) implicit none include '($FABDEF)' ! File Access Block Structure include '($RABDEF)' ! Record Access Block Structure include '($SYSSRVNAM)' ! System service name declarations include '($SSDEF)' record /FABDEF/ fab, /RABDEF/ rab integer*4 lun integer*2 chan common /channel/ chan ! set the UFO and CBT bits fab.fab$l_fop = fab$v_ufo .OR. fab$v_cbt ! set the UPI bit fab.fab$b_shr = fab$v_upi ! open the file, return on error open_old_chan = sys$open(fab) if (open_old_chan .eq. 0) then chan = 0 return endif ! Read channel number into common block chan = fab.fab$l_stv open_old_chan = SS$_NORMAL return end