                     ILL NeXus files for SANS November 2014
	     

The programs for treating SANS data described in the report ILLGH05T 
can use a cache data file for uncompressed data.  A new program nxs2as
can fill the cache with data transcribed from SANS .nxs files, allowing
use of these data without modifying any programs. Reading the files
directly would require modifying all programs to use the Fortran90
compiler needed for the hdf5 file access routines.

D33 data from the main detector are reduced to 128x128 square pixels. 
(For 99% of data taken on D17-SANS the data were recorded as 64x64 (1cm pixels) with gains of saving space, network overheads and efficient treatment). The higher resolution
of the D33 detector in the x direction only really comes into play for GSANS
and a few very specific SANS applications. Similarly NXS data for D11
recorded with 256x256 cells are converted to standard 128x128 datafiles.
An added advantage is that the concentrated data volumes have better
statistics, and can be viewed and listed more easily. The resolution is
usually dominated by the wavelength selector, with commensurate great reductions
in flux when this is reduced below 10%, which matches a 1cm detector
resolution at 10cm radius, a typical beamstop dimension.
The program takes NeXus parameters and copies these to the appropriate
place in the ascii files.  A dictionary locates the dataset in the NeXus file
and it is possible to rescale these values, or even specifically place
a value in the ascii file if the original value is incorrect. The dictionary
files are D11index.nxs, D22index.nxf and D33index.nxf.  Standard copies are
located in SAS_DIR, the program directory, however these may be copied to
the user’s work directory and edited.  The programs search first for these copies
before defaulting to the stored standard files.  A similar procedure is used
by the runnex program which lists selected parameters identified in the files
D11par.sel, D22par.sel and D33par.sel.  


1. General

The layout of these files do not quite conform to the standards proposed
by http://www.nexusformat.org where the basic concepts include maximising
the similarities and sharing instrument component definitions, names
and descriptions.

In a NeXus file (based on the HDF5 Hierachical Data Format from 
http://www.hdfgroup.org) the count data and instrument description
metadata are accessed through structured "path" names similar to the
nomenclature of a unix file system.  From the entry point, typically
/entry, or /entry0 etc. groups are created containing instrument details
e.g. /entry/instrument/detector1/data which contains the counts recorded.
For ease of access, like in a unix file system, this component is "linked"
to a secondary name /entry/data, easier to find generically.
The parameters of the detector necessary to treat the data are named as 
/entry/instrument/detector1/x_pixel_size etc.,
hence it is easy to add a second detector defined as
/entry/instrument/detector2. with its own data, pixel size, and geometry 
definition.  Attributes are added to each component which can include
units and other information on a per-item basis.
While NeXus does not impose the names a full set of recommended names is 
included with prototype instruments defined on the web site, and a 
validation/advice  service is offered there.

At the ILL the the generic instrument name "instrument" is replaced by the
actual instrument (normally defined as /entry/instrument/name) now becomes
/entry0/D22 or /entry0/D33   As a consequence the only method of accessing
the file has to be tailored for each instrument: the software needs a
dictionary to find the fundamental metadata and the names are not consistent
between instruments.  The detector data information lacks geometrical
descriptions designating the direction of the axes.  For D22 the
data array (C notation) is a three dimensional array (2012-3) (time,x,y)
for D33 the array is (time,y,x) In 2014 there has been a rationalisation 
to the D33 definition.
 By inspection the (x=0,y=0) appears to be in the bottom left hand corner, 
viewed from the sample. Most parameters use names derived from the control 
software, and do not follow the standard nomenclature.

File sizes (D33)

034129   	140292   ascii file (128,128)
034129.gz	 18090   compressed ascii file
034129.nxs	146679   NeXus file (with data compression) (1,128,256)



The utilities described here are adapted to open the SANS files using
dictionaries stylised for each instrument.

2. Data Access Software - basic hdf routines  h5bits.f90

The NeXus software has a prerequisite need for the HDF libaries plus
additional components.  the pre-compiled distributions do not include
these, requiring seeking compatible additional downloads. It is hence
simpler to read these data file using the basic HDF5 software, which is 
well-maintained, has useful ancillary tools and has a very efficient 
advisory service.

The basic HDF library is available in several binary distributions. The
routines here were all built from v1.8.5 source to have matching properties.
The build follows standard unix procedures (config, make, make test, make install)
and have been used for MacOS Leopard (10.5.8), gcc-4.2, Linux-64 (FC11) 
Linux32(Ubutu8), gcc-4.2, and PC-XP (Msys) gcc-4.5. 
In each case fortran and C++ compatibility was included.
For the PC using msys the compress utility gzlib was built first to obtain
the compression library header files.

To simplify usage the fortran90 routines to read and write the hdf files
were combined into a set of subroutines in the file h5bits.f90.  Once
compiled using the fortran header files (25000 lines) the object code can
be easily accessed from gfortran-f77 programs. Unfortunately use of gfortran 
requires that compatible compilers must be available.  For linux the shareable
library libgfortran.so.* has to be included with the program files and it is 
used by setting environment LD_LIBRARY_PATH to SAS_DIR (already set in sassetup); 
for OSX the equivalent is DYLD_LIBRARY_PATH.  

3. Utility Programs

h5nopp		opens an hdf5/.nxs/.h5 file
		lists datasets
		can read and type contents
		

nx_names          scans a .nxs file and lists datasets found writing these into
		  nxnames.nam

  [RonBook:~/dosd/htest] ron% ./h5nopp
 ILL-NeXus reread test 
Commands
 R  n         read dataset n
 I           show index
 T i1 i2     type i1,i2 elements
 V           info on dataset 
 E           Exit


 Give filename [034100.nxs] : 056927.nxs
 I
 file 056927.nxs length 10 Objects in the file:
/  (Group)
/entry0  (Group)
/entry0/D22  (Group)
/entry0/D22/Beam  (Group)
/entry0/D22/Beam/center_x  (Dataset)
/entry0/D22/Beam/center_y  (Dataset)
/entry0/D22/Beam/fast_shutter_actual  (Dataset)
/entry0/D22/Beam/fast_shutter_requested  (Dataset)
/entry0/D22/Beam/sample_ap_x_or_diam  (Dataset)
/entry0/D22/Beam/sample_ap_y  (Dataset)
/entry0/D22/Beam/sample_pressure  (Dataset)
/entry0/D22/Beam/tx_actual  (Dataset)
/entry0/D22/Beam/tx_offset  (Dataset)
/entry0/D22/Beam/tx_requested  (Dataset)
/entry0/D22/Beam/ty_actual  (Dataset)
/entry0/D22/Beam/ty_offset  (Dataset)
/entry0/D22/Beam/ty_requested  (Dataset)
/entry0/D22/attenuator  (Group)
/entry0/D22/attenuator/attenuation_value  (Dataset)
/entry0/D22/attenuator/description  (Dataset)
/entry0/D22/attenuator/position  (Dataset)
/entry0/D22/attenuator2  (Group)
/entry0/D22/attenuator2/actual_value  (Dataset)
/entry0/D22/beamstop  (Group)
/entry0/D22/beamstop/actual_beamstop_number  (Dataset)
/entry0/D22/beamstop/bx_actual  (Dataset)
/entry0/D22/beamstop/bx_offset  (Dataset)
/entry0/D22/beamstop/bx_requested  (Dataset)
/entry0/D22/beamstop/by_actual  (Dataset)
/entry0/D22/beamstop/by_offset  (Dataset)
/entry0/D22/beamstop/by_requested  (Dataset)
/entry0/D22/beamstop/description  (Dataset)
/entry0/D22/beamstop/height  (Dataset)
/entry0/D22/beamstop/wanted_beamstop_number  (Dataset)
/entry0/D22/beamstop/width_or_diam  (Dataset)
/entry0/D22/chopper  (Group)
/entry0/D22/chopper/phase  (Dataset)
/entry0/D22/chopper/rotation_speed  (Dataset)
/entry0/D22/collimation  (Group)
/entry0/D22/collimation/actual_position  (Dataset)
/entry0/D22/collimation/ap_size  (Dataset)
/entry0/D22/collimation/horizontal_slit_center  (Dataset)
/entry0/D22/collimation/horizontal_slit_center_offset  (Dataset)
/entry0/D22/collimation/horizontal_slit_width_actual  (Dataset)
/entry0/D22/collimation/is_circular_mode  (Dataset)
/entry0/D22/collimation/vertical_slit_center  (Dataset)
/entry0/D22/collimation/vertical_slit_center_offset  (Dataset)
/entry0/D22/collimation/vertical_slit_width_actual  (Dataset)
/entry0/D22/detector  (Group)
/entry0/D22/detector/dan_actual  (Dataset)
/entry0/D22/detector/dan_offset  (Dataset)
/entry0/D22/detector/dan_requested  (Dataset)
/entry0/D22/detector/det_actual  (Dataset)
/entry0/D22/detector/det_calc  (Dataset)
/entry0/D22/detector/det_offset  (Dataset)
/entry0/D22/detector/det_requested  (Dataset)
/entry0/D22/detector/detrate  (Dataset)
/entry0/D22/detector/detsum  (Dataset)
/entry0/D22/detector/dtr_actual  (Dataset)
/entry0/D22/detector/dtr_offset  (Dataset)
/entry0/D22/detector/dtr_requested  (Dataset)
/entry0/D22/detector/pixel_size_x  (Dataset)
/entry0/D22/detector/pixel_size_y  (Dataset)
/entry0/D22/flipper1  (Group)
/entry0/D22/flipper1/flip_voltage  (Dataset)
/entry0/D22/flipper1/requested_value  (Dataset)
/entry0/D22/flipper2  (Group)
/entry0/D22/flipper2/flip_voltage  (Dataset)
/entry0/D22/flipper2/requested_value  (Dataset)
/entry0/D22/flipper3  (Group)
/entry0/D22/flipper3/flip_voltage  (Dataset)
/entry0/D22/flipper3/requested_value  (Dataset)
/entry0/D22/flipper4  (Group)
/entry0/D22/flipper4/flip_voltage  (Dataset)
/entry0/D22/flipper4/requested_value  (Dataset)
/entry0/D22/name  (Dataset)
/entry0/D22/selector  (Group)
/entry0/D22/selector/rotation_speed  (Dataset)
/entry0/D22/selector/selrot_actual  (Dataset)
/entry0/D22/selector/selrot_offset  (Dataset)
/entry0/D22/selector/selrot_requested  (Dataset)
/entry0/D22/selector/seltrs_actual  (Dataset)
/entry0/D22/selector/seltrs_offset  (Dataset)
/entry0/D22/selector/seltrs_requested  (Dataset)
/entry0/D22/selector/wavelength  (Dataset)
/entry0/D22/selector/wavelength_res  (Dataset)
/entry0/data  (Group)
/entry0/data/data  (Dataset)
/entry0/duration  (Dataset)
/entry0/end_time  (Dataset)
/entry0/experiment_title  (Dataset)
/entry0/mode  (Dataset)
/entry0/monitor1  (Group)
/entry0/monitor1/data  (Dataset)
/entry0/monitor1/integral  (Dataset)
/entry0/monitor1/mode  (Dataset)
/entry0/monitor1/monrate  (Dataset)
/entry0/monitor1/monsum  (Dataset)
/entry0/monitor1/nbpickup  (Dataset)
/entry0/monitor1/preset  (Dataset)
/entry0/monitor1/time_of_flight  (Dataset)
/entry0/monitor2  (Group)
/entry0/monitor2/data  (Dataset)
/entry0/monitor2/integral  (Dataset)
/entry0/monitor2/mode  (Dataset)
/entry0/monitor2/monrate  (Dataset)
/entry0/monitor2/monsum  (Dataset)
/entry0/monitor2/preset  (Dataset)
/entry0/preset  (Dataset)
/entry0/reactor_power  (Dataset)
/entry0/run_number  (Dataset)
/entry0/sample  (Group)
/entry0/sample/air_temperature  (Dataset)
/entry0/sample/bath1_regulation_temperature  (Dataset)
/entry0/sample/bath1_setpoint_temperature  (Dataset)
/entry0/sample/bath1_temperature_requested  (Dataset)
/entry0/sample/bath2_regulation_temperature  (Dataset)
/entry0/sample/bath2_setpoint_temperature  (Dataset)
/entry0/sample/bath2_temperature_requested  (Dataset)
/entry0/sample/bath_selector_actual  (Dataset)
/entry0/sample/bath_selector_requested  (Dataset)
/entry0/sample/field_actual  (Dataset)
/entry0/sample/field_requested  (Dataset)
/entry0/sample/omega_actual  (Dataset)
/entry0/sample/omega_offset  (Dataset)
/entry0/sample/omega_requested  (Dataset)
/entry0/sample/phi_actual  (Dataset)
/entry0/sample/phi_offset  (Dataset)
/entry0/sample/phi_requested  (Dataset)
/entry0/sample/ps1_current  (Dataset)
/entry0/sample/ps1_voltage  (Dataset)
/entry0/sample/ps2_current  (Dataset)
/entry0/sample/ps2_voltage  (Dataset)
/entry0/sample/ps3_current  (Dataset)
/entry0/sample/ps3_voltage  (Dataset)
/entry0/sample/pslambda_current  (Dataset)
/entry0/sample/pslambda_voltage  (Dataset)
/entry0/sample/rack_temperature  (Dataset)
/entry0/sample/regulation_temperature  (Dataset)
/entry0/sample/sample_changer_target_value  (Dataset)
/entry0/sample/sample_changer_value  (Dataset)
/entry0/sample/sample_temperature  (Dataset)
/entry0/sample/san_actual  (Dataset)
/entry0/sample/san_offset  (Dataset)
/entry0/sample/san_requested  (Dataset)
/entry0/sample/sdi_actual  (Dataset)
/entry0/sample/sdi_offset  (Dataset)
/entry0/sample/sdi_requested  (Dataset)
/entry0/sample/setpoint_temperature  (Dataset)
/entry0/sample/shearrate_actual  (Dataset)
/entry0/sample/shearrate_requested  (Dataset)
/entry0/sample/sht_actual  (Dataset)
/entry0/sample/sht_offset  (Dataset)
/entry0/sample/sht_requested  (Dataset)
/entry0/sample/slit_actual  (Dataset)
/entry0/sample/slit_offset  (Dataset)
/entry0/sample/slit_requested  (Dataset)
/entry0/sample/str_actual  (Dataset)
/entry0/sample/str_offset  (Dataset)
/entry0/sample/str_requested  (Dataset)
/entry0/sample/temperature  (Dataset)
/entry0/sample/trs_actual  (Dataset)
/entry0/sample/trs_offset  (Dataset)
/entry0/sample/trs_requested  (Dataset)
/entry0/sample_description  (Dataset)
/entry0/start_time  (Dataset)
/entry0/user  (Group)
/entry0/user/name  (Dataset)
/entry0/user/namelocalcontact  (Dataset)
/entry0/user/proposal  (Dataset)
 Type R,V,T,E: r
 Give dsname [/entry0/data1/data1]  /entry0/D22/selector/wavelength
  Data items present, rank,dims,sum           1           1           1   0.000000    
 Type R,V,T,E: t
  first..last           1           1
 F values    10.99948    
 Type R,V,T,E: v
 Give dsname [/entry0/data1/data1]  /entry0/data/data
 dsname/size(bytes)   /entry0/data/data           4
 rank, dimensions           3           1         128         128
 integer dataset
 Type R,V,T,E: r
           1         128
         128       16384
  Data items present, rank,dims,sum       16384           3           1         128         128   80173.00    
 Type R,V,T,E: t 8192 8292
  first..last        8192        8292
 I values            
    0           0           0           0           0           0           0
    0           2           0           0           0           2           1
    2           0           2           1           1           0           1 
    1           1           2           3         171         376         360
  213          45           6           0           2           1           1
    1           0           1           2           0           0           1
    1           0           0           0           0           0           0
    0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0           0
 Type R,V,T,E: e

Note the raw detector data for D33 are in /entry0/data1/data1 (time,y,x)
                               D22 are in /entry0/data/data   (time,x,y)

  

./h5pp		as h5nopp and produces 2d pixel plots
                reads hdf5/.nxs/.h5 file and reduces multidetector
                data to (128x128 or 25x64x64) for plots


./nxs2as 	reads D22 and D33 NeXus files and reduces to 128x128
                writing out data as a standard ascii file (128x,128y)
		Note D22 stores (time,x,y)
		     D33 stores (time,y,x)
		Environment variables 
		 SAS_INSTRUMENT
		 SAS_DATA_PATH
		 SAS_CACHE
		 SAS_DIR
		Data are sought in SAS_DATA_PATH and, if not already
		in the cache directory they are transcribed
		The instrument name is used to seek the directory
		file eg D33nxs.sfl, D22nxs.sfl first looking in the
		current work directory, then in SAS_DIR.  This allows
		modification of a "standard file" for specific use.
                It functions in two modes; in the command-line mode
                ./nx2as run1 run2
                the default input directory is SAS_DATA_PATH and
                output to SAS_CACHE
                In prompt mode the input and output directories are
                given explicitly (and the output directory is subsequently
                set as SAS_DATA_PATH
		
          -------------------example of D33index.nxf ———————————
# D33 version 1.0 September 2012 Ron Ghosh
# scannx - shows datasets in .nxs files 
#
# 1    preset 1
# 3    time(0.1 secs)
# 4    total detector
# 5    total monitor
# 23   dvm    
# 26   s-det_m
# 29   temperature-set
# 30   regul-temperature
# 31   sample-temperature
# 51   detector_centre_x_address
# 52   detector_centre_y_address
# 53   wavelength
# 54   delta_wavelength
# 55   dx_pixel
# 56   dy_pixel 
# 15   two_theta(gamma)
# 65   omega
# 64   trs_translation
# 300  start_time
# 301  end_time
# 310  run_number
#
# 401  sample_description
# 400  experiment_title
#      D22
# 522  data_2d..from (time,x,y) to 128x128 in idon as IDAT(ix,iy)
#      left in common/h5work/id(3276800) as original
#      D33
# 533  data_2d  reduced and transposed from (time,y,x) to (128,128) IDAT(ix,iy)
/entry0/D33/attenuator/attenuation_value
/entry0/D33/attenuator/description
/entry0/D33/attenuator/position
/entry0/D33/beamstop/bx_actual
/entry0/D33/beamstop/bx_offset
/entry0/D33/beamstop/bx_requested
/entry0/D33/beamstop/by_actual
/entry0/D33/beamstop/by_offset
/entry0/D33/beamstop/by_requested
/entry0/D33/chopper1/CH1_phase
/entry0/D33/chopper1/CH1_rotation_speed
/entry0/D33/chopper2/CH2_phase
/entry0/D33/chopper2/CH2_rotation_speed
/entry0/D33/chopper3/CH3_phase
/entry0/D33/chopper3/CH3_rotation_speed
/entry0/D33/chopper4/CH4_phase
/entry0/D33/chopper4/CH4_rotation_speed
/entry0/D33/collimation/AttTr_actual_position
/entry0/D33/collimation/Coll1_actual_position
/entry0/D33/collimation/Coll2_actual_position
/entry0/D33/collimation/Coll3_actual_position
/entry0/D33/collimation/Coll4_actual_position
/entry0/D33/collimation/Dia1_actual_position
/entry0/D33/collimation/Dia2_actual_position
/entry0/D33/collimation/Dia3_actual_position
/entry0/D33/collimation/Dia4_actual_position
/entry0/D33/collimation/Dia5_actual_position
/entry0/D33/collimation/PoTr_actual_position
/entry0/D33/collimation/WvTr_actual_position
/entry0/D33/collimation/actual_position
/entry0/D33/collimation/ap_size
/entry0/D33/collimation/col1_actual_state
/entry0/D33/collimation/col2_actual_state
/entry0/D33/collimation/col3_actual_state
/entry0/D33/collimation/col4_actual_state
/entry0/D33/detector/det1_actual
/entry0/D33/detector/det1_calc
/entry0/D33/detector/det1_offset
/entry0/D33/detector/det1_requested
/entry0/D33/detector/det2_actual      26
/entry0/D33/detector/det2_calc
/entry0/D33/detector/det2_offset
/entry0/D33/detector/det2_requested
/entry0/D33/detector/detrate
/entry0/D33/detector/detsum
/entry0/D33/detector/pixel_size_x   55
/entry0/D33/detector/pixel_size_y   56
/entry0/D33/name
/entry0/D33/selector/rotation_speed
/entry0/D33/selector/selrot_actual
/entry0/D33/selector/selrot_offset
/entry0/D33/selector/selrot_requested
/entry0/D33/selector/seltrs_actual
/entry0/D33/selector/seltrs_offset
/entry0/D33/selector/seltrs_requested
/entry0/D33/selector/wavelength   53
/entry0/D33/selector/wavelength_res  54
/entry0/data1/data1        533
/entry0/data2/data2
/entry0/data3/data3
/entry0/data4/data4
/entry0/data5/data5
/entry0/data_raw1/data_raw1
/entry0/duration          3     10
/entry0/end_time          301
/entry0/experiment_title  400
/entry0/sample_description 401  
/entry0/instrument_name
/entry0/mode
/entry0/monitor1/data   5
/entry0/monitor1/integral
/entry0/monitor1/mode
/entry0/monitor1/monrate
/entry0/monitor1/monsum   
/entry0/monitor1/nbpickup
/entry0/monitor1/preset
/entry0/monitor1/time_of_flight
/entry0/monitor2/data
/entry0/monitor2/integral
/entry0/monitor2/mode
/entry0/monitor2/monrate
/entry0/monitor2/monsum
/entry0/monitor2/preset    1
/entry0/preset
/entry0/reactor_power
/entry0/run_number   310
/entry0/sample/bath1_regulation_temperature
/entry0/sample/bath1_setpoint_temperature
/entry0/sample/bath1_temperature_requested
/entry0/sample/bath2_regulation_temperature
/entry0/sample/bath2_setpoint_temperature
/entry0/sample/bath2_temperature_requested
/entry0/sample/field_actual
/entry0/sample/field_requested
/entry0/sample/omega_actual       65
/entry0/sample/omega_offset
/entry0/sample/omega_requested
/entry0/sample/phi_actual
/entry0/sample/phi_offset
/entry0/sample/phi_requested
/entry0/sample/regulation_temperature
/entry0/sample/sample_changer_target_value
/entry0/sample/sample_changer_value
/entry0/sample/san_actual
/entry0/sample/san_offset
/entry0/sample/san_requested
/entry0/sample/sdi1_actual     
/entry0/sample/sdi1_offset
/entry0/sample/sdi1_requested
/entry0/sample/sdi2_actual
/entry0/sample/sdi2_offset
/entry0/sample/sdi2_requested
/entry0/sample/setpoint_temperature
/entry0/sample/sht_actual
/entry0/sample/sht_offset
/entry0/sample/sht_requested
/entry0/sample/str_actual          
/entry0/sample/str_offset
/entry0/sample/str_requested
/entry0/sample/temperature        31
/entry0/sample/trs_actual         64
/entry0/sample/trs_offset
/entry0/sample/trs_requested
/entry0/start_time            300
/entry0/user/name
/entry0/user/namelocalcontact
/entry0/user/proposal
----------------------------------------------------------------------------
(the first line is used as a version comment; lines starting # are comments)
After the dataset name the corresponding parameter number in the ascii
file is given.  This may be followed by a multiplier (default=1) and
a default value.  Special sequence numbers are used to select data
for transposition, or character strings etc.  Parameters 200-300 locate
parameters transmitted via common/nxpars/parnxs(100) ; see routine sasanx below. 

Usage
     there is a silent mode
     
     ./nxs2as  first_run [last_run]
     
     and 
     
     ./nxs2as
     

Performance: nxs2as will transcribe 100 data files in about 3 seconds 
(2.4GHz MacBook)



runnex

looks in for .nxs file in SAS_DATA_PATH and slects parameters designated in
the local file D11par.sel, D22par.sel, D33par.sel

-----------------------------D33par.sel--------------------------------
[RonBook:~/dosd/htest] ron% cat d33par.sel
Comment : created manually (copied from h5dump -n 034100.nxs )
/entry0/monitor1/integral
/entry0/monitor1/monsum
/entry0/sample_description
/entry0/D33/selector/wavelength
/entry0/D33/detector/detrate
/entry0/D33/detector/detsum
/entry0/D33/detector/det1_actual
/entry0/D33/detector/det2_actual

------------------------------------------------------------------------

[RonBook:~/dosd/htest] ron% ./runnex
 runnex - NeXus file parameter listing

 Give first and last run numbers : 34130 34150
 Run                       integral    monsum      wavelength  detrate     detsum      det1_actual det2_actual 
  34130  "Det 2.2"     0.000      0.9336E+06   6.089       3548.      0.7412E+05   13.00       2.201    
  34131  "Det 2.2"     0.000      0.1248E+07   6.088       4020.      0.1107E+06   13.00       2.000    
  34132  "Det 2.2"     0.000      0.2834E+07   6.089       4028.      0.2546E+06   13.00       2.000    
  34133  "Det 2.2"     0.000      0.2159E+06   6.089       340.0       1655.       13.00       10.00    
  34134  "Det 102"     0.000      0.2015E+06   6.087       324.6       1476.       13.00       10.00    
  34135  "Det 102"     0.000      0.5361E+07   6.088       196.4      0.2357E+05   13.00       10.00    
  34136  "Det 102"     0.000      0.7149E+06   6.088       2.642       42.00       13.00       10.00    
  34137  "Det 10 Col4 "     0.000      0.1211E+07   6.089       337.7       9066.       13.00       10.00    
  34138  "Det 10 Col4 "     0.000      0.1736E+07   6.090       262.4       9967.       13.00       10.00    
  34139  "Det 10 Col4,"     0.000      0.2299E+07   6.090       255.1      0.1269E+05   13.00       10.00    
  34140  "Det 10 Col4,"     0.000      0.5215E+07   6.088       441.3      0.4982E+05   13.00       10.00    
  34141  "Det 10 Col3,"     0.000      0.1814E+07   6.089       122.8       4830.       13.00       10.00    
  34142  "Det 10 Col4,"     0.000      0.3963E+07   6.086       443.8      0.3818E+05   13.00       10.00    
  34143  "Det 10 Col3,"     0.000      0.3328E+07   6.086       127.4       9197.       13.00       10.00    
  34144  "Det 10 Col2,"     0.000      0.5534E+07   6.089       181.4      0.2177E+05   13.00       10.00    
  34145  "Det 10 Col1 "     0.000      0.4495E+07   6.089       195.8      0.1912E+05   13.00       10.00    
  34146  "Det 10 Col1 "     0.000      0.5521E+07   6.089       194.4      0.2333E+05   13.00       10.00    
  34147  "Flux 4.6ol1 "     0.000      0.1080E+07   4.589       53.55       1257.       13.00       13.00    
  34148  "Flux 4.6ol1 "     0.000      0.1380E+08   4.601       4212.      0.1264E+07   13.00       13.00    
  34149  "Flux 5.6ol1 "     0.000      0.1380E+08   5.000       4358.      0.1307E+07   13.00       13.00    
  34150  "Flux 6.6ol1 "     0.000      0.1378E+08   5.999       3203.      0.9608E+06   13.00       13.00    

NOTE it appears that det2_actual is the sample to detector distance for the
data in /entry0/data1/data1


4. Data read routines:


------------------------------h5bits.f90--------------------------------
! h5bits.f90 is an assembly of f90 routines intended to offer a simple f77
!            inteface to the hdf library for the principal file writing
!            functions        
!
! typically the character string arguments are last, simplifying certain
! link requirements
!
! The file has three levels, opening as root, which contains groups
! within which are (optionally) further groups, containing datasets 
! 
! As each component is opened the routine returns a "handle" identifier.
! The components are left open, since it is possible to add annotations
! (Attributes).  These are NAME,VALUE pairs with the value being real,
! integer or text; for text attributes there may be several lines of text.
!
! The dataset contents created here are either (multi-) dimensional arrays
! of integers or reals, or single lines of text.
!
! HDF5 File Operations  in h5bits.f90
! 
!      subroutine newh5(ier,id_f,fname)
!         Opens file fname; returns error ier and identifier id_f
!      subroutine endh5(ier,id_f)
!         Closes file id_f, returns error ier
!      subroutine oldh5(ier,id_f,fname,cmd
!         Opens file existing file fname returns id id_f if cmd is 'O'
!         Closes file id id_f if cmd is 'C'
! Groups
!      subroutine newgroup(ier,id_f, id_g, gname)
!         Opens group name gname in file id_f, returns error ier and 
!         group identifier id_g
!      subroutine endgroup(ier,id_g)
!         Closes group id_g
!
!
!
!Creating Datasets
!      subroutine newdsett(ier,id_f, id_d, text, dname)
!          Opens dataset name dname in existing placement id_f
!          plants one line of text 'text'
!          returns error ier and dataset id id_d  
!
!      subroutine newdsetf(ier,id_f, v, ir,idim, id_d,dname)
!          Opens dataset name dname in existing placement id_f
!          plants REAL array rank ir, dimensions in array idim(ir)
!          returns error ier and dataset id id_d  
!       
!
!      subroutine newdseti(ier,id_f, ii, ir,idim,id_d, dname)
!          Opens dataset name dname in existing placement id_f
!          plants INTEGER array rank ir, dimensions in array idim(ir)
!          returns error ier and dataset id id_d  
!
!      subroutine enddset(ier,id_d)
!          Closes dataset id_d
!
!      
!
! Attributes
!      subroutine newatt(ier,id_f,name,text)
!          Plants attribute name with text string  for entity id_f
!
!      subroutine newattn(ier,id_f,nl,name,text)
!          Plants attribute name with nl-line text string  for entity id_f
!
!      subroutine newatf(ier,id_f,name,fval)
!          Plants attribute name with  REAL value fval for entity id_f
!
!      subroutine newati(ier,id_f,name,ival)
!          Plants attribute name with  INTEGER value fval for entity id_f
!
!Reading Datasets
!      subroutine oldh5(ier,id_f,fname,cmd)
!       opens file fname cmd is "O" or "C" open/close
!
!      subroutine infods(ier,id_f,dsname,isiz,ir,idim,itype)
!        opens dsname returning size,rank,dims,type(0-C,1-I,2-F)
!
!      subroutine readds(ier,id_f,dsname,v,ir,idim,iitype)
!        returns contents of dsname in V
!        note idim(1) on input must be >= isiz

!      subroutine scanxs(fname,gname)
!        scans file and places names of datasets into commons
!        common/scannam/dsnames*100(500)
!        common/scannml/nfound,lennam(500)
!
!      common/h5lims/idmax,namax,ioneh5,ioph5
!      data idmax/3276800/,namax/500/,ioneh5/0/,ioph5/0/
!      work directory max is 3276800, dsnames limited to 500
!
!      set environment variable H5_DEBUG to true to show internal
!      messages.
!
! This is compiled using hdf5.f90 and other module files which are
! preassembled into hdf5.mod (from the hdf5 "include" directory, which
! greatly speeds up compilation yielding and shoud be located in the 
! same directory as h5bits.f90 to produce h5bits.o using:  
! gfortran -c h5bits.f90


sasanx

      subroutine sasanx(ierr,numor,nomexp,ddate,nt,text,np,par,nd,idon)
c
c     ier             integer      out  0 ok, else -1
c     numor           integer      in   1<=numor<=999999
c     inst            character*4  out  ints field in file
c     nomexp          character*10 out  nomexp in file
c     ddate           character*20 out  data and time of recording
c     nt              integer      out  number of text (a1)
c     text            character*1  out  text array
c     np              integer      out  number of real parameters
c     par             real         out  real parameters
c     nd              integer      out  number of integers in spectrum
c     idon            integer      out  spectrum

sasanx.f has essentially similar arguments to the existing sasas.f, but uses
the .nxf directory file to locate the .nxs parameters as in the nxs2as example.
Data (1,128,256) are converted to (128,128).  Data (100,128,256)
are not returned but are left in common/h5work/iv(NXYT)   NXYT=3276800
 

sasanx.f + h5bits.o

compile command

gfortran -o  xxx xxx.f sasanx.f h5bits.o libhdf5_fortran.a libhdf5.q -lz -lm


The utilities here are in three directories
MacOSX	hdfosx32
Linux   hdflinux32
PC      hdfmingw32

The MacOSX programs are built on Leopard 10.5.8, gfortran 4.2 compatible
with the SANS program distribution.  If the executables are copied to
SAS_DIR the necessary libraries should be there (shown in DYLIB_LIBRARY_PATH)


The Linux programs are compiled "static", except the plotting program h5pp
These should run on any linux system though the library gfortran.so.2 
should be stored in the program directory (qv utils) and LD_LIBRARY_PATH
should be set to this.


The MinGW programs run on XP and were compiled with MINGW gfortran v4.5


