!***************************************************************************
!*****************************************************
!***Extract Data Set from Main Dialog Data Set Grid***
!*****************************************************
	SUBROUTINE GETDATA()
	USE WINTERACTER
	USE SHAREDVARS
	USE RESOURCE
	REAL XGRID,YGRID,MGRID
	INTEGER CGRID,IROW,IDAT
!***
!***Create plotting data set 
!***Create analysis data set 
!***If CPLOT = 1 data point plotted but not included in dataset
!***
	TYPE *,'ABOUT TO READ DATA'
	NPLOT=0
	NDAT=0
	DO IROW=1,100
		RESETERROR=InfoError(1)
		CALL WGridGetCellReal(IDF_MAIN_DATASET_GRID,1,IROW,XGRID)
		IF(InfoError(1).EQ.1010) CYCLE
		IF(XTRANSFORM.EQ.1) XGRID=LOG10(XGRID)
		CALL WGridGetCellReal(IDF_MAIN_DATASET_GRID,2,IROW,YGRID)
		IF(InfoError(1).EQ.1010) CYCLE
        	CALL WGridGetCellReal(IDF_MAIN_DATASET_GRID,3,IROW,MGRID)
		IF(InfoError(1).EQ.1010) CYCLE
		IF(YGRID.GT.MGRID.OR.MGRID.EQ.0) CYCLE
		CALL WGridGetCellCheckBox(IDF_MAIN_DATASET_GRID,4,IROW,CGRID)
		NPLOT=NPLOT+1
		XPLOT(NPLOT)=XGRID
		YPLOT(NPLOT)=YGRID/MGRID
		CPLOT(NPLOT)=CGRID
		MPLOT(NPLOT)=MGRID
		IF(CPLOT(IROW).EQ.1) CYCLE
		NDAT=NDAT+1
		XDAT(NDAT)=XGRID
		YDAT(NDAT)=YGRID
		MDAT(NDAT)=MGRID
		TYPE "('DATA',2I4,3F10.5)",IROW,NDAT,XDAT(NDAT),YDAT(NDAT),MDAT(NDAT)
	ENDDO
!***
!***Sort data by concentration
!***
	DO IDAT=1,NDAT-1
	DO JDAT=IDAT+1,NDAT
		IF(XDAT(IDAT).LE.XDAT(JDAT)) CYCLE
		TEMP=XDAT(IDAT)
		XDAT(IDAT)=XDAT(JDAT)
		XDAT(JDAT)=TEMP
	ENDDO
	ENDDO		
!***
!***Compute new data series for total Y's and M's and fraction survival per treatment
!***
	NTRT=1
	XTRT(1)=XDAT(1)
	YTRT(1)=YDAT(1)
	MTRT(1)=MDAT(1)
	NREP(1)=1
	REPDETECT=.FALSE.
	DO IDAT=2,NDAT
		IF(XDAT(IDAT).EQ.XDAT(IDAT-1)) THEN
			YTRT(NTRT)=YTRT(NTRT)+YDAT(IDAT)
			MTRT(NTRT)=MTRT(NTRT)+MDAT(IDAT)
			NREP(NTRT)=NREP(NTRT)+1
			REPDETECT=.TRUE.
		ELSE
			YTRTFRAC(NTRT)=YTRT(NTRT)/MTRT(NTRT)
			TYPE "(A3,2I4,4F10.4)",'TRT',NTRT,NREP(NTRT),XTRT(NTRT),YTRT(NTRT),MTRT(NTRT),YTRTFRAC(NTRT)
			NTRT=NTRT+1
			XTRT(NTRT)=XDAT(IDAT)
			YTRT(NTRT)=YDAT(IDAT)
			MTRT(NTRT)=MDAT(IDAT)
			NREP(NTRT)=1
		ENDIF
	ENDDO
	YTRTFRAC(NTRT)=YTRT(NTRT)/MTRT(NTRT)
	TYPE "('TRT',2I4,2X,4F10.4)",NTRT,NREP(NTRT),XTRT(NTRT),YTRT(NTRT),MTRT(NTRT),YTRTFRAC(NTRT)
	RETURN
	END

