	PROGRAM RMDEMO1
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 RMDMO1 on a LABSTATION 23
C			node. This remote task then:
C			 
C			   1. Collects data and transmits it across DECNET 
C			to this program which writes the data to a file. 
C			To conserve disk space, only 3 buffers of data 
C			are collected.
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)	!buffer for input
	INTEGER*4 	stat
	CHARACTER	taskname*15/'::"TASK=RMDMO1"'/
	CHARACTER*1 	nodename(6)	!to hold the nodename as input
	CHARACTER*1	parsename(6)	!array to hold parsed name
	CHARACTER*6	fullname	!name to be passed to net
	CHARACTER*21 	task		!node and task names
	BYTE		buffer(4096)	!transmission buffer
	EXTERNAL	IO$_READVBLK,IO$_DEACCESS,IO$M_SYNCH
	EXTERNAL	ss$_NORMAL,SS$_NOSUCHNODE,SS$_REMOTE
	EQUIVALENCE	(storbuf(1),buffer(1))
	EQUIVALENCE     (parsename,fullname)
	INCLUDE 	'SYS$LIBRARY:FORIOSDEF'

C
C	introduction
C

	WRITE(5,10)
10	FORMAT('0',T15,'RMDEMO1 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
68	CONTINUE
	j=7
69	DO 70 k=1,6
	  parsename(k)=' '
70	CONTINUE
	ii=0
	DO 72 jj=j-1,1,-1
	  ii=ii+1
	  kk=7-ii
	  parsename(kk)=nodename(jj)
72	CONTINUE
	task=fullname//taskname 
	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  	read 3 buffers
C

100 	CONTINUE
	DO 200	J=1,3

C
C	display a waiting message while waiting for the buffer to arrive
C

150	WRITE(5,160)
160	FORMAT('0',T15,'Waiting to receive buffer.')

C
C  	get buffer, by QIO and WAIT call
C

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

C
C	display buffer received message
C

180	WRITE(5,185)
185	FORMAT('0',T15,'Buffer received.')

C
C  	write to disk
C	unlock any locked record
C

190	CONTINUE
	UNLOCK (unit=3)
	WRITE (3'J,iostat=jerr,err=195)storbuf	! write buffer to disk
	UNLOCK (unit=3)
	GOTO 200
195	CONTINUE
	IF(jerr.EQ.FOR$IOS_SPERECLOC)GOTO 190	! if error is record locked
C						!  branch to try again else
	GOTO 360				!  just get out
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 WRITE 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,'RMDEMO1 completed.')
999	CONTINUE
	CALL exit
	END

