; $Id: readngfit.pro,v 1.2 2002/01/14 20:59:26 amunter Exp $
function readngfit,filen

;read the nist data of type "I"

; OUPUTS:
;               a data structure consisting of:
;                 d.points - integer - # of points in scan
;                 d.heads - integer - # of header parameters
;                 d.pars - integer - # of scan parameters
;                 d.text - string array - 2 lines of descriptive text
;                 d.hdef - string array - definition of header parameters
;                 d.hnum - float array - header parameters
;                 d.prp - string array - definition of scan parameters
;                 d.data - 2D float array - scan data (parameter,point#)

qpoints=0
qheads=1
qtext=['','']
qhdef=STRARR(30)
qhnum=FLTARR(30)
qprp=STRARR(30)
qdata=FLTARR(30,5000)
qpars=0

;for 'ng' type data, the number of parameters are not fixed(d.pars)
;it has to be determined by reading the line before the data

temp=''
ttemp=''
teemp=''
temmp=''
tempp=''


junk=''

j=0.0
openr,unit,filen,/get_lun

i=0

i=strlen(filen)

if (i lt 12) then qtext(0)=filen else qtext(0)=strmid(filen,i-12,8)




readf,unit,junk
readf,unit,junk
readf,unit,junk

i=0
temp='ddd'


while ( temp ne '' ) do begin
        temp=readword(junk,i)
        if temp eq 'Motor' then begin   
                qpars=qpars+1
                i=i+2
                temp=readword(junk,i)
                qprp(qpars-1)='A'+temp
        endif
        i=i+1

endwhile 

qpars=qpars+2
qprp(qpars-2)='I'
qprp(qpars-1)='SIGI'



on_ioerror,quit

junks:

readf,unit,junk

for i=0,qpars-2 do begin
        temp=readword(junk,i)
        reads,temp,j,format='(f)'
        qdata(i,qpoints)=j
endfor

; error of I
qdata(qpars-1,qpoints)=sqrt(qdata(qpars-2,qpoints))

qpoints=qpoints+1

goto, junks

quit:

on_ioerror,null

qhdef(0)='Noheader'
qhnum(0)=0

scan={points:qpoints,heads:qheads,pars:qpars,text:qtext,$
      hdef:qhdef(0:qheads-1), $
      hnum:qhnum(0:qheads-1),prp:qprp(0:qpars-1),$
      data:qdata(0:qpars-1,0:qpoints-1)}

return,scan
end
