	PROGRAM RNMGSA
C
C	AUTHOR	: G. GUELFI
C
C	DATE	: 17-MAY-84
C
C
C
C
C
C	WHERE
C
C
C	FILSPC	IS AREA FOR ICSI DATA
C	ICH2	IS CHANNEL NUMBER
C
C
C
C
C
	INTEGER*2 FILSPC(39),DEFEXT(4),GSACOM(4),IDATA(8192)
	INTEGER*2 SY0,SY1,SY3,SPACE
	LOGICAL*1 IT,NDATA,YDATA
	DATA DEFEXT/3RGPB,3RGPB,3RDAT,3RDAT/
	DATA GSACOM/3RSY0,3RGSA,3RCOM,3RGPB/
	DATA NDATA/'N'/,YDATA/'Y'/
	DATA SY0/3RSY0/,SY1/3RSY1/,SY3/3RSY3/,SPACE/3R   /
	IBUFF = 8192
C
C	DO YOU WISH TO RENAME FILE
C
4	WRITE(7,1)
1	FORMAT('$DO YOU WISH TO RENAME GSACOM 
	1( OR ANOTHER P/BACK)  -  Y OR N    ')
	ACCEPT 6 ,IT
6	FORMAT(A1)
	IF (IT.NE.YDATA.AND.IT.NE.NDATA) GOTO 4
	IF (IT.EQ.NDATA) GOTO 70
C
C	ENTER CSI COMMAND
C
5	WRITE(7,10)
10	FORMAT('0ENTER FILE NAME   (E.G. TS0001   N.B. STORED ON SY1:) '//,
	1' ( OR SY0:P1=SY1:TESTRT
	2  OR TS0002  FOR OESTRN - STORED ON SY1:)',//)
	IF (ICSI(FILSPC,DEFEXT, , ,0).NE.0) GOTO 5
C
C	USED TO DETERMINE DEFAULT DEVICE
C
D	WRITE(7,200)FILSPC(16),SPACE,FILSPC(1),FILSPC(2),GSACOM(2)
200	FORMAT(' ',4O6,O6,'16 SY0 1 2 GSACOM 2')
	IF (FILSPC(1).EQ."15270.OR.FILSPC(1).EQ.0) FILSPC(1) = SY1
	IF (FILSPC(16).EQ."15270) FILSPC(16) = SY0
D	WRITE(7,200)FILSPC(16),FILSPC(1),SY0,SY1
C
C	CHECK FOR RENMAING GSACOM.GPB
C
	IF (FILSPC(2).NE.0) GOTO 13
	L = 17
	DO 14 I = 2,4
	FILSPC(I) = FILSPC(L)
	FILSPC(L) = GSACOM(I)
14	L = L + 1
C
C	OPEN GSACOM.GPB OR INPUT P/BACK
C
13	IF (FILSPC(1).GE.SY3) FILSPC(1) = SY1
	ICH1 = IGETC()
	IF (ICH1.EQ.0) ICH1 = IGETC()
	IF (ICH1.LT.0) STOP ' NO CHANNEL AVAILABLE'
C
C	FETCH HANDLER AND CHECK IF DESIGNATED FILE EXISTS
C
	IF (IFETCH(FILSPC(16)).EQ.0) GOTO 11 
11	IBGSA = LOOKUP (ICH1,FILSPC(16))
	IF (IBGSA.GT.0) GOTO 9
	WRITE(7,16)IBGSA	
16	FORMAT('0',I6,' LOOKUP ERROR ON INPUT FILE'//)
	GOTO 70
9	ICH2 = IGETC()
	IF (ICH2.EQ.0) ICH2 = IGETC()
	IF (ICH2.LT.0) STOP ' NO CHANNEL AVAILABLE'
C
C	FETCH HANDLER AND CHECK IF DESIGNATED FILE EXISTS
C
	IF (IFETCH(FILSPC(1)).EQ.0) GOTO 12 
	WRITE(7,15)
15	FORMAT('0OUTPUT DEVICE NOT VALID USE SY0: OR SY1:',//)
	GOTO 5
12	ILOK = LOOKUP (ICH2,FILSPC(1))
	IF (ILOK + 1) 20,30,40
30	STOP 'ENTRY CHANNEL ALREADY IN USE '
40	WRITE(7,50)
50	FORMAT('$FILE ALREADY EXISTS - TYPE  Y OVERWRITE FILE    ')
	ACCEPT 60 ,IT
60	FORMAT(A1)
	IF (IT.NE.YDATA.AND.IT.NE.NDATA) GOTO 40
	CALL CLOSEC(ICH2)
	CALL IFREEC(ICH2)
	IF (IT.EQ.YDATA) GOTO 20
	GOTO 5
C
C	OPEN NEW FILE
C
20	IE =IENTER(ICH2,FILSPC(1),IBGSA)
	IF (IE.EQ.IBGSA) GOTO 25
	IF (IE.EQ.-2) WRITE(7,22)
22	FORMAT('0OUTPUT DEVICE IS FULL CHOOSE ANOTHER DRIVE IE SY2',//)
	WRITE(7,23)IE
23	FORMAT('0',I6,' IENTER ERROR IN RNMGSA',//)
	GOTO 5
25	CONTINUE	!CALL SCCA
	ITRAN = IBUFF/256
	ITR = 0
	ITW = 0
	DO  17 I = 1,IBGSA
	IF ((IBGSA-ITW).LT.ITRAN) ITRAN = IBGSA - ITW
	IWDS = ITRAN*256
	CALL READW(IWDS,IDATA,ITR,ICH1)
	CALL WRITW(IWDS,IDATA,ITW,ICH2)
C	WRITE(7,3000)I,ITW,ITRAN,IBGSA
3000	FORMAT(' I,ITW,ITRAN,IBGSA',10I6)
	IF (ITW.EQ.(IBGSA)) GOTO 19
17	CONTINUE
19	CONTINUE	!CALL SCCA
	J = M - 1
	DO 18 M = 1,14
	J = M - 1
	CALL CLOSEC(J)
18	CALL IFREEC(J)
70	CALL BGAMMA('CA')
	END
