 ; Copyright (c) 1998-2021 A.P. Hitchcock  All rights reserved
;+
;NAME:
;	AX_CHANGE_HDF5
;
;LAST CHANGED: -----------------------------------  19-Jun-2 (aph)
;
;PURPOSE:
;	This function does not work !!!!1

;  Possible IDL Function to modify contents of an *.hdf5 file
; explored for generating hdf5 files for Soleil prociessing


; set up to generate parameter file for Soleil ptycho stack 13-006 from that for 13-004

;CATEGORY:
;	AXIS: image utility (runs stand alone)
;
;CALLING SEQUENCE:
;  RESULT =  AX_CHANGE_HDF5()
;
;CALLED FROM AXIS:
;	stand alone
;
;INPUTS:
;
;
;KEYWORDS:

;
;OUTPUTS: modified *.hdf5 file
;
;COMMON BLOCKS:
;	@AXIS_COM	standard set of common blocks
;
;MODIFICATION HISTORY:
; (19-Jun-21 aph)  INCOMPLETE !!!!  saved a bunch of script used to attemt this job


Function ax_change_hdf5


@axis_com
on_error,2

; open exitisting hdf5 file
f=pickfile2()
h4= h5_parse(f, /read_data)

help, h4.entry1.camera, /struct		; list parts of "camera"

e4=h4.entry1.camera.energy._data	; get energy array

e6=e4(30:45)						; isolate the energies for stack 6 from stack 4

help, h4.entry1.camera.data._data, /struct	; check size of the data array (set of STXM images)

data4 = h4.entry1.camera.data._data

data6=double(fltarr(20,20,30))			; leave as an emty array


; update internal dimensioing of data array
dim4 = h6.entry1.camera.data._dimensions

dim6 = intarr(3)
dim6 = [20,20,30]
dim6 = ulong64(dim6)

; update internal file name

fname4 = h4.entry1.camera.data._file

fname6 = 'E:\data\XRM\Soleil\2021\21-06-ptycho\06-13\stack_006\Stack_20210613_006.hdf5'		; edited to match folder and file name

; Modify h4 to make h6

h6 = h4
h6.entry1.camera.data._file = fname6
h6.entry1.camera.data._data = data6
h6.entry1.camera.energy._data = e6

; ---- write out revised *.hdf5 file
 h5_create, fname6, h6


; ######################
; when ran , the h5_crerate made the new file, but
;  1) the contents were the same as h4 - i.e. re-assigning the contensts did not work
;  2) error meesage
;
;		H5_CREATE: Unable to create attribute: HDF5_Version
;		Error occurred at: H5_CREATE         779 C:\RSI\IDL63\lib\h5_create.pro
; ######################

print, "Generated modified hdf5 file : ", fname6

end
