;+ ; NAME : nkrget (procedure) ; PURPOSE : ; read header and images from norikura formatted file ; CATEGORY : ; idl/lib/nkr ; CALLING SEQUENCE : ; nkrget,file,h,img,img_no=ino,nset=nset,all=all,/quiet,rotate=rot ; INPUTS : ; file : filename [may be an array] ; OPTIONAL INPUT PARAMETERS : ; none ; KEYWORD PARAMETERS : ; h : header structure ; img : image array ; img_no : specify image no. for nset>1. ; if img_no=-1, return only nset ; nset : return number of images ; all : extract all images in img(*,*,*) ; quiet : don't print any message ; rotate : rotate direction ; OUTPUTS : ; none ; COMMON BLOCKS : none ; SIDE EFFECTS : none ; RESTRICTIONS : none ; PROCEDURE : ; If file is an array, the results are saved in img(*,*,*) ; MODIFICATION HISTORY : ; K.I. '91/10/31 ; K.I. '92/04/19 ; pos_info ; K.I. '93/01/20 ; allow '~/' ; K.I. '93/01/21 ; allow float image ; K.I. '93/01/24 ; multiple file OK ; K.I. '93/01/26 ; fact keyword ; K.I. '93/01/31 ; quiet keyword, data_type ge 3 --> fltarr ; K.I. '93/02/07 ; for h.nf > 1 ; K.I. '93/04/29 ; quiet keyword ; K.I. '93/10/07 ; file=filea(0) ; K.I. '94/01/27 ; rot keyword ;- ;==================================================================== ;NAME : nkrread1 (procedure) ;FUNCTION : read 1 image with Norikura header from Unit ; and and make data arrange correction ; K.I. '92/04/19 ; K.I. '93/01/06 ;==================================================================== pro nkrread1,Unit,h,img,quiet=quiet h = nkrhead() readu,Unit,h one=h.one if one eq 256 then begin hswab,h if not keyword_set(quiet) then $ print,' one = 256 --> 1 ; swap operation' endif ;print,'nx=',h.nx,' ny=',h.ny,' nf=',h.nf,' nbyt=',h.nbyt ysize=h.ny*h.nf case h.nbyt of 1: begin img=bytarr(h.nx,ysize) end 2: begin if h.data_type eq 3 then img=bytarr(h.nx,ysize*2) $ else img=intarr(h.nx,h.ny,h.nf) end 4: begin if h.data_type eq 1 then img=lonarr(h.nx,h.ny,h.nf) $ else img=fltarr(h.nx,h.ny,h.nf) end endcase readu,Unit,img if (h.nbyt eq 2) then begin if (h.data_type eq 1) or (h.data_type eq 2) then begin if (one eq 256) then byteorder,img ; swap operation endif if (h.data_type eq 3) then begin ; data_type 3 arrange if(h.nf ne 1) then begin print,'data type not compatible with nkrget' stop endif if not keyword_set(quiet) then $ print,' data_type 3 --> 1 ; data arrange' img=fix(img(0:h.nx-1,0:h.ny-1)+256*img(0:h.nx-1,h.ny:h.ny*2-1)) h.data_type=1 endif endif end ;******************************************************************** ;NAME : nkrget (procedure) ;FUNCTION : get header and image from norikura formatted file ; K.I. '91/10/31 ; '93/01/20 ;==================================================================== pro nkrget,filea,h,img,img_no=ino,nset=nset,all=all,fact=fact, $ quiet=quiet,rotate=rot ; filea : filename [array] ; h : header structure ; img : image array ; img_no : specify image no. for nset>1. ; if img_no=-1, return only nset ; nset : return number of images ; all : extract all images in img(*,*,*) ; fact : size factor ; rotate : rotate direction if not keyword_set(fact) then fact=1 if not keyword_set(quiet) then quiet=0 else quiet=1 ; ---------- for multiple files -------- nfile=n_elements(filea) if nfile gt 1 then begin if not keyword_set(quiet) then $ print,format='(I5," images are read into ",$)',nfile h1=nkrhead() h=replicate(h1,nfile) for i=0,nfile-1 do begin nkrgeth,filea(i),h1 if fact ne 1 then begin h1.nx=fix(h1.nx*fact) h1.ny=fix(h1.ny*fact) endif h(i)=h1 endfor ; ---- determine type and dimension of the image --- nbyt=max(h.nbyt) data_type=max(h.data_type) if keyword_set(rot) then begin if rot eq 1 or rot eq 3 or rot eq 4 or rot eq 6 then begin ntmp=h.nx & h.nx=h.ny & h.ny=ntmp endif endif nx=max(h.nx) & ny=max(h.ny) if nbyt eq 1 then begin img=bytarr(nx,ny,nfile) & type='BYTARR' endif else if nbyt eq 2 then begin img=intarr(nx,ny,nfile) & type='INTARR' endif else if nbyt eq 4 then begin if data_type ge 3 then begin img=fltarr(nx,ny,nfile) & type='FLTARR' endif else begin img=lonarr(nx,ny,nfile) & type='LONARR' endelse endif else if nbyt eq 8 then begin img=dblarr(nx,ny,nfile) & type='DBLARR' endif if not keyword_set(quiet) then $ print,type+'( '+ $ strcompress(string(nx),/remove)+', '+ $ strcompress(string(ny),/remove)+', '+ $ strcompress(string(nfile),/remove)+' )' if keyword_set(ino) then img_no=ino else img_no=1 for i=0,nfile-1 do begin nkrget,filea(i),h1,img1,img_no=img_no,fact=fact,quiet=quiet, $ rotate=rot img(0:h1.nx-1,0:h1.ny-1,i) = img1 endfor return endif else begin file=filea(0) endelse print,format='("nkrget ",A," : ",$)',file ; ---------- file check ---------- if strmid(file,0,1) eq '~' then $ file1=getenv('HOME')+strmid(file,1,strlen(file)-1) $ else file1=file ff=findfile(file1) !error=0 if ff(0) eq '' then begin !error=1 print,' not found !' return endif ; ---------- image no. check ------------ get_lun,Unit openr,Unit,file ; ---------- obtain nset (number of image contained) ------------ nset=0 while not eof(Unit) do begin h = nkrhead() readu,Unit,h if strmid(h.hdr_id,0,3) ne 'HDR' then begin print,' not norikura formatted data!' close,Unit !error=2 return endif if h.one eq 256 then hswab,h point_lun,-Unit,pos point_lun,Unit,pos+ $ long(h.offset)+long(h.nx)*long(h.ny)*long(h.nf)*long(h.nbyt) nset=nset+1 ; print,nset,h.nx,h.ny,h.nf,h.nbyt endwhile if keyword_set(ino) then begin if (ino eq -1) then begin close,Unit free_lun,Unit if not keyword_set(quiet) then $ print,' nset=',nset return endif endif ; -------- get ino (target image no.) ---------- if keyword_set(all) then ino=1 if not keyword_set(ino) then begin if (nset gt 1) then begin print,format='(" contains ",I3," images. ",$)',nset read,' Enter image no. => ',ino endif else begin ino=1 endelse endif if (ino gt nset) then begin if not keyword_set(quiet) then $ print,'this file has only ',nset,' images. img_no set to ',nset ino=nset endif ; ------ skip ino-1 images ---------- point_lun,Unit,0 for i=1,ino-1 do begin h = nkrhead() readu,Unit,h if h.one eq 256 then hswab,h point_lun,-Unit,pos point_lun,Unit,pos+ $ long(h.offset)+long(h.nx)*long(h.ny)*long(h.nf)*long(h.nbyt) endfor if not keyword_set(quiet) then begin if ino gt 1 then print,fix(ino)-1,' images skipped' else print,'' endif ; ---------- read data -------------- if keyword_set(all) then begin if not keyword_set(quiet) then $ print,nset,' images extracted' ysize=h.ny*h.nf if h.nbyt eq 1 then img=bytarr(h.nx,ysize,nset) if h.nbyt eq 2 then img=intarr(h.nx,ysize,nset) h=replicate(h,nset) for i=0,nset-1 do begin nkrread1,Unit,h1,img1 h(i)=h1 img(*,*,i)=img1 endfor endif else begin nkrread1,Unit,h,img endelse close,Unit free_lun,unit ; ---------- fact --------------------- if fact ne 1 then begin nx=fix(h.nx*fact) ny=fix(h.ny*fact) if ((nx-nx/h.nx*h.nx eq 0) or (h.nx-h.nx/nx*nx eq 0)) and $ ((ny-ny/h.ny*h.ny eq 0) or (h.ny-h.ny/ny*ny eq 0)) then begin ;print,' REBIN used' img=rebin(img,nx,ny) endif else begin ;print,' CONGRID used' img=congrid(img,nx,ny,/interp) endelse h.nx=nx h.ny=ny endif ; ---------- rotate --------------------- if keyword_set(rot) then begin img=rotate(img,rot) if rot eq 1 or rot eq 3 or rot eq 4 or rot eq 6 then begin ntmp=h.nx h.nx=h.ny h.ny=ntmp endif endif end