;+
;judge arr type
;+
PRO sesShmData::JudgeType , type , imageType , dimX , dimY , image
	COMPILE_OPT IDL2
	arrType = ['BYTE','INT','LONG','FLOAT','DOUBLE' , $
	           'COMPLEX','UINT','ULONG','LONG64','ULONG64']
	temp = Where(type EQ arrType ,count)
	CASE temp OF
		0:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = bytarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = bytarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		1:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = intarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = intarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		2:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = lonarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = lonarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		3:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = fltarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = fltarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		4:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = dblarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = dblarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		5:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = complexarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = complexarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		6:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = uintarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = uintarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		7:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = ulonarr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = ulonarr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		8:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = lon64arr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = lon64arr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
		9:BEGIN
			IF imageType EQ 2 THEN BEGIN
				image = ulon64arr(Fix(dimX),Fix(dimY))

			ENDIF ELSE BEGIN
				image = ulon64arr(Fix(imageType), Fix(dimX),Fix(dimY))
			ENDELSE
		END
	ELSE:
	ENDCASE
END
;+
;write data
;+
PRO sesShmData::WriteData , path , image
	COMPILE_OPT IDL2
	Openw, lun, path, /Get_Lun
	Writeu, lun, image
	Free_Lun, lun

END
;+
;destroy link
;+
PRO sesShmData::ShmClose , segname

	COMPILE_OPT IDL2

	Shmunmap, segname

END
;+
;link image
;+
FUNCTION sesShmData::ShmLink , imageDir = imageDir     , $
                               name = name           , $
                               dimX = dimX           , $
                               dimY = dimY           , $
                               imageType = imageType , $
                               segName = segName     , $
                               type = type

	COMPILE_OPT IDL2
	self->JudgeType , type	, imageType	, dimX , dimY , image
	image = BytArr(3,Fix(dimX),Fix(dimY))
	r_image=BytArr(Fix(dimX),Fix(dimY))
   	g_image=BytArr(Fix(dimX),Fix(dimY))
   	b_image=BytArr(Fix(dimX),Fix(dimY))
	openr,lun,imageDir,/get_lun
	Readu, lun, r_image
	Readu, lun, g_image
	Readu, lun, b_image
;	Readu, lun, image
	Free_Lun,lun
	image[0,*,*]=Temporary(r_image)
    image[1,*,*]=Temporary(g_image)
    image[2,*,*]=Temporary(b_image)
	Return,image
END
;+
;Write data
;+
PRO sesShmData::Create, tempDir, name , Copy  , $
						textName = textName   , $
						Data = data           , $
                        DimX = dimX           , $
                        DimY = dimY           , $
                        DimZ = dimZ           , $
                        title = title         , $
                        MinMaxXY = MinMaxXY   , $
                        seg = seg             , $
                        newName = newName
	COMPILE_OPT IDL2
	sep = (self.oSystem).sep
	imageDir = tempDir+sep+name
	copyDir = tempDir+sep+Copy
    path = tempDir+sep+textName

	Openw, lun, imageDir, /Get_Lun
	Writeu, lun, data
	Free_Lun, lun

	Openw, lun, copyDir, /Get_Lun
	Writeu, lun, data[*,*]
	Writeu, lun, data[*,*]
	Writeu, lun, data[*,*]
	Free_Lun, lun

	type = Size(data,/tname)

	OpenW, lun , path , /Get_Lun
	PrintF, lun, imageDir
	PrintF, lun, copyDir
	PrintF, lun, name
	PrintF, lun, String(Strtrim(dimX,2))
	PrintF, lun, String(Strtrim(dimY,2))
	PrintF, lun, String(Strtrim(dimZ,2))
	PrintF, lun, type
	FOR i = 0 , 5 DO BEGIN
		PrintF, lun, title[i]
	ENDFOR
	PrintF, lun, newName
	PrintF, lun, seg
	PrintF, lun, String(Strtrim(MinMaxXY[0],2))
	PrintF, lun, String(Strtrim(MinMaxXY[1],2))
	Free_Lun,lun
END
;+
;clean up
;+
PRO sesShmData::CleanUp
	COMPILE_OPT IDL2

END
;+
;initialize
;+
FUNCTION sesShmData::Init , oSystem = oSystem
	COMPILE_OPT IDL2
	self.oSystem = oSystem

;	self->Create, tempDir, name, Data = data

	Return, 1

END
;+
;SingImage class name
;+
PRO sesShmData__Define
	COMPILE_OPT IDL2
	void = { sesShmData                           , $
			 oSystem            :    Obj_New()      $
		   }

END