	PROGRAM RMDEMO2
C+
C
C                              Copyright (C) 1981
C         Digital Equipment Corporation, Maynard, Massachusetts 01754
C
C   This software is furnished under a license and may be used and  copied
C   only  in  accordance  with  the  terms  of  such  license and with the
C   inclusion of the above copyright notice.  This software or  any  other
C   copies  thereof may not be provided or otherwise made available to any
C   other person.  No title to and ownership of  the  software  is  hereby
C   transferred.
C
C   The information in this software is subject to change  without  notice
C   and  should  not  be  construed  as  a commitment by Digital Equipment
C   Corporation.
C
C   Digital Equipment Corporation assumes no responsibility for the use or
C   reliability  of  its  software  on  equipment which is not supplied by
C   Digital Equipment Corporation.
C
C+
C
C	Version: 	1.0
C
C	Date: 		20-October-1982
C
C	Authors: 	Thomas A. Turano
C
C	Purpose:	This program starts a task RMDMO2 on a LABSTATION 23
C			node. This program then reads a 3 record file from 
C			disk and transferrs each record as a 4096 byte
C			buffer across DECNET to the remote node which then
C			outputs, through a MNCDA module, each buffer as it
C			is received.
C
C			
C			The communication occurs via transparent DECNET
C			calls by the VAX host. 
C
C
C
C-
	IMPLICIT INTEGER*4	(A-Z)
	INTEGER*2	channel,status_block(4),iflag
	INTEGER*2	storbuf(2048)
	INTEGER*4 	stat
	CHARACTER	taskname*15/'::"TASK=RMDMO2"'/
	CHARACTER*1 	nodename(6)
	CHARACTER*1	parsename(6)	!array to hold parsed name
	CHARACTER*6	fullname	!name to be passed to net
	CHARACTER*21 	task
	BYTE		buffer(4096)
	EXTERNAL	IO$_WRITEVBLK,IO$_DEACCESS,IO$M_SYNCH
	EXTERNAL	ss$_NORMAL,SS$_NOSUCHNODE,SS$_REMOTE
	EQUIVALENCE	(storbuf(1),buffer(1))
	EQUIVALENCE	(fullname,parsename)
	INCLUDE 	'SYS$LIBRARY:FORIOSDEF'

C
C	introduction
C

	WRITE(5,10)
10	FORMAT('0',T15,'RMDEMO2 will start the task on the MINC node.')
		
C
C  	assign logical unit to filename, structure the file and
C  	open the file
C

	OPEN(unit=3,name='rmdmo.dat',disp='save',type='unknown',
     1       access='direct',organization='relative',
     2       recordtype='fixed',shared,initialsize=700,blocksize=2048,
     3       recl=1029,err=50)
	GOTO 65				!if no error, access network

C
C 	display the error condition
C

50	CONTINUE
	WRITE(5,60)
60	FORMAT('0','UNABLE TO OPEN FILE. ABNORMAL TERMINATION OF PROGRAM.')
	GOTO 999			!just exit

C
C  	access the network
C
C	any name less than 6 characters must be padded with blanks ON LEFT
C

65	WRITE(5,66)
66	FORMAT('$',T15,'Enter the name of the node to be accessed.')
	READ(5,67)(nodename(I),I=1,6)
67	FORMAT(6A1)
	DO 68 j=1,6
	  IF(nodename(j).EQ.' ')GOTO 69	!search for a blank, if found branch
68	CONTINUE
	j=7		    !no blank found, use entire name
69	DO 70 k=1,6
	  parsename(k)=' '  !blank parsed name initially
70	CONTINUE
	ii=0
	DO 72 jj=j-1,1,-1   !copy node name into parsed name
	  ii=ii+1
	  kk=7-ii
	  parsename(kk)=nodename(jj)
72	CONTINUE
	task=fullname//taskname 	!concatenate node and task name
	stat=SYS$ASSIGN(task,channel,,)
	  IF(stat.EQ.%loc(SS$_REMOTE)) GOTO 100   !if no error get the buffers
	  IF(stat.NE.%loc(SS$_NOSUCHNODE))GOTO 80!if error with device display 
	WRITE(5,75)			    ! it else give generic message
75	FORMAT('0',T15,'INVALID NODE NAME.')
	GOTO 65
80	WRITE(5,85)
85	FORMAT('0',T15,'NETWORK FAILURE. ABNORMAL TERMINATION OF PROGRAM.')
	GOTO 400			    !terminate

C
C  	transmit 3 buffers
C

100 	CONTINUE
	DO 200	J=1,3

C
C  	read record from disk
C	unlocking any locked record
C

120	CONTINUE
	UNLOCK (unit=3)
	READ (3'J,iostat=jerr,err=135)storbuf	! write buffer to disk
	UNLOCK (unit=3)
	GOTO 150
135	IF(jerr.EQ.FOR$IOS_SPERECLOC)GOTO 120	! if error is record locked
C						!  branch to try again else
	GOTO 360				!  just get out

C
C	display a message that the buffer is being sent
C

150	WRITE(5,160)
160	FORMAT('0',T15,'Buffer being transmitted.')

C
C  	get buffer, by QIO and WAIT call
C

	stat=SYS$QIOW(,%val(channel),IO$_WRITEVBLK,status_block,
     1                               ,,%ref(buffer),%val(4096),,,,)
	  IF(stat.EQ.%loc(SS$_NORMAL)) GOTO 180 !if successful continue, else
	  call lib$stop(%val(stat))
	  GOTO 400			  ! shutdown cleanly

C
C	display buffer received message
C

180	WRITE(5,185)
185	FORMAT('0',T15,'Buffer received by remote node.')
200	CONTINUE

C
C	upon reception of 3 buffers get out
C

	GOTO 400

C
C	unsuccessful write, set error flag
C

360	CONTINUE	
	UNLOCK (unit=3)				! when leaving leave unlocked
	WRITE(5,370)
370	FORMAT('0','UNABLE TO READ FILE. ABNORMAL TERMINATION OF PROGRAM.')

C
C  	deaccess the network
C

400	CONTINUE

	tempfunc=%LOC(IO$_DEACCESS).OR.%LOC(IO$M_SYNCH)
	stat=SYS$QIO(%VAL(channel),%VAL(tempfunc))

C
C	close the file on the disk
C

	CLOSE (unit=3)

C
C	termination message
C

900	CONTINUE
	WRITE(5,910)
910	FORMAT('0',T30,'RMDEMO2 completed.')
999	CONTINUE
	CALL exit
	END

