                     Adding "plugins" to read novel data formats

Rather than adding new read-in routines to libraries and adding
alternative data reading options into programs, which require
rebuilding and distributing the new programs, the routines
below illustrate an open-ended approach to solving this
problem.



      subroutine ginin(fname,ier,errmsg)
c
c     This set of routines uses external programs to read data into
c     a common format temporary file which is then read here to return
c     data to the application.
c     The input is the name of the data file fname
c     The external program name(s) are found using this calling
c     program's name say exename together with three letter extension name 
c     of the data file.  If three digits are found in the extension the
c     type is set to ILL. If no or more than three letters are
c     found then DEF is used as a default.  This is uppercased,  
c     say WWW, then the environment variable  EXENAME_WWW is examined 
c     for the helper program name.  Since it is likely the same helpers
c     will be used repeatedly a default exename of SAS_ or REF_ can
c     be set in the environment variable
c     e.g. > SET SAS_XML=xml2gin
c     The output file exename.gin is then 
c     initialised before running the helper program. This finds the name 
c     of exename.gin in its command line.  It then overwrites exename.gin
c     with data derived from the primary data source.  The main program
c     continues and rereads exename.int, finding it hsa been updated,
c     and obtains data from it.
c
c     Additional switches in the environment string are passed to the 
c     helper routine which may select specific metadata (floats or strings)
c     into the intermediate file with the 4-column tabulated data.  Floats
c     are identified by a labelstrng with units. 
c
c     This allows a mixture of data files each with its own extension and
c     helper program to be mixed in sequence.
c     If an error is found the logfile exenam.log may have useful
c     comments on the last reading attempt. An error message is
c     returned to this calling application if the data file is absent,
c     the enviroment variable is absent, or the helper program is not found.
c
c     Ron Ghosh, August 2009   reghosh@gmail.com 


Typical usage is shown with sasmpl.exe, a general sans plotting
program.  The environment variables are set:

> set SAS_ILL=illp1
> set SAS_XML=xmlp1
or
> set SAS_XML=xml2gin    (a more complex program which can rescale
parameters (eg nm to A)  or provide absent but necessary parameters;
these are read from a file xml2gin.dcy) 

and these "helper" programs are called from sasmpl to read a mixture of
ILL standard data or canSAS XML data.
