;------------------------------------------------------------------ ; TURNFILE -- Rotate big arrays on the harddisk ; (c) 16.10.1997 by Andreas Reigber ;------------------------------------------------------------------ ; ; direction : +1 - to the right ; -1 - to the left ; +2 - on the top ; memory : memory consumption in MB (default = 10MB) ; reverse : additional horizontal mirror ; float : array is float not complex ; rk : ESAR - rangecompressed SAR data ; directory : temporary directory (default /tmp) ;------------------------------------------------------------------ ; This software has been released under the terms of the GNU Public ; license. See http://www.gnu.org/copyleft/gpl.html for details. ;------------------------------------------------------------------ @rarr @sarr @reverse pro turnfile,file,direction,MEMORY=memory,FLIP=flip,FLOAT=float,RK1=rk1,RK2=rk2 $ ,DIRECTORY=directory,QUIET=quiet if not keyword_set(quiet) then print,"" if not keyword_set(quiet) then print,"---> TURNFILE" if not keyword_set(quiet) then print,"" case 1 of (direction eq 0) : goto,final (direction eq 1) : rot = 3 (direction eq 2) : rot = 2 (direction eq -1) : rot = 1 else: begin print,"FEHLER: Falsche Rotationsangabe !!" goto,final end endcase tim1 = systime(1) file1 = file file2 = file if not keyword_set(memory) then memory = 10 ; 10 MB Default mem = memory * 1.00e6 openr,in,file1,/get_lun,/xdr anzx = 0l anzy = 0l nrbyt = 0l if keyword_set(rk1) or keyword_set(rk2) then begin readu,in,nrbyt endif readu,in,anzx readu,in,anzy if keyword_set(rk1) or keyword_set(rk2) then begin varflop,anzx,anzy anzx2 = anzx anzy2 = anzy endif if keyword_set(rk1) then begin inf = fstat(in) anzy = (inf.size-12)/anzx/8 endif if keyword_set(rk2) then begin inf = fstat(in) anzx = (inf.size-12)/anzy/8 endif if keyword_set(float) then byt = 4 else byt = 8 bs = mem / byt bsx = floor(bs / anzy) bsy = floor(bs / anzx) if bsx gt anzx then begin bsx = anzx bsy = floor(bs/bsx) if bsy gt anzy then bsy = anzy endif if bsy gt anzy then begin bsy = anzy bsx = floor(bs/bsy) if blx gt anzx then bsx = anzx endif bsy_mod = anzy mod bsy bsx_mod = anzx mod bsx anz_blocks_y = anzy / bsy anz_blocks_x = anzx / bsx tmpdir = "/tmp" if keyword_set(directory) then tmpdir = directory tmpdir = tmpdir + "/" ;--------------------------------------------------------- if bsx_mod eq 0 then xx = anz_blocks_x else xx = anz_blocks_x + 1 if bsy_mod eq 0 then yy = anz_blocks_y else yy = anz_blocks_y + 1 if not keyword_set(quiet) then print," Filename : ",file1 if not keyword_set(quiet) then print," Groesse X : "+strcompress(anzx) if not keyword_set(quiet) then print," Groesse Y : "+strcompress(anzy) if not keyword_set(quiet) then print,"" if not keyword_set(quiet) then print," Speicherbedarf :"+strcompress(memory)," MB" if not keyword_set(quiet) then print," Anzahl temporärer Dateien : "+strcompress(xx*yy) if not keyword_set(quiet) then print," Temporäres Directory : "+tmpdir if not keyword_set(quiet) then print,"" ;---------------------------------->> Einlesen und zerstückeln if not keyword_set(quiet) then print," Daten zerstückeln und drehen..." block = fltarr(anzx,bsy) if not keyword_set(float) then block = complex(block) for i=0,anz_blocks_y-1 do begin readu,in,block index = 0 for j=0,anz_blocks_x-1 do begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_"+strcompress(j,/remove) sarr,filename,rotate(block[index:index+bsx-1,0:bsy-1],rot) index = index + bsx endfor if bsx_mod gt 0 then begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_last" sarr,filename,rotate(block[index:anzx-1,0:bsy-1],rot) endif endfor if bsy_mod gt 0 then begin block = fltarr(anzx,bsy_mod) if not keyword_set(float) then block = complex(block) readu,in,block index = 0 for j=0,anz_blocks_x-1 do begin filename = tmpdir+"flop_last_"+strcompress(j,/remove) sarr,filename,rotate(block[index:index+bsx-1,0:bsy_mod-1],rot) index = index + bsx endfor if bsx_mod gt 0 then begin filename = tmpdir+"flop_last_last" sarr,filename,rotate(block[index:anzx-1,0:bsy_mod-1],rot) endif endif free_lun,in ;---------------------------------------->> Wieder zusammensetzen if not keyword_set(quiet) then print," Daten wieder richtig zusammensetzen..." if direction eq -1 then begin ;------> Nach links gedreht block = fltarr(anzy,bsx) if not keyword_set(float) then block = complex(block) openw,out,file2,/get_lun,/xdr if keyword_set(rk1) or keyword_set(rk2) then begin writeu,out,long(8) writeu,out,anzx2 writeu,out,anzy2 endif else begin writeu,out,anzy writeu,out,anzx endelse for j=0,anz_blocks_x-1 do begin if bsy_mod gt 0 then begin filename = tmpdir+"flop_last_"+strcompress(j,/remove) rarr,filename,in block[0:bsy_mod-1,0:bsx-1] = in endif index = bsy_mod for i=anz_blocks_y-1,0,-1 do begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_"+strcompress(j,/remove) rarr,filename,in block[index:index+bsy-1,0:bsx-1] = in index = index + bsy endfor if keyword_set(flip) then block = reverse(block) writeu,out,block endfor if bsx_mod gt 0 then begin block = fltarr(anzy,bsx_mod) if not keyword_set(float) then block = complex(block) if bsy_mod gt 0 then begin filename = tmpdir+"flop_last_last" rarr,filename,in block[0:bsy_mod-1,0:bsx_mod-1] = in endif index = bsy_mod for i=anz_blocks_y-1,0,-1 do begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_last" rarr,filename,in block[index:index+bsy-1,0:bsx_mod-1] = in index = index + bsy endfor if keyword_set(flip) then block = reverse(block) writeu,out,block endif free_lun,out endif if direction eq +1 then begin ;------> Nach rechts gedreht openw,out,file2,/get_lun,/xdr if keyword_set(rk1) or keyword_set(rk2) then begin writeu,out,long(8) writeu,out,anzx2 writeu,out,anzy2 endif else begin writeu,out,anzy writeu,out,anzx endelse if bsx_mod gt 0 then begin block = fltarr(anzy,bsx_mod) if not keyword_set(float) then block = complex(block) index = 0 for i=0,anz_blocks_y-1 do begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_last" rarr,filename,in block[index:index+bsy-1,0:bsx_mod-1] = in index = index + bsy endfor if bsy_mod gt 0 then begin filename = tmpdir+"flop_last_last" rarr,filename,in block[index:index+bsy_mod-1,0:bsx_mod-1] = in endif if keyword_set(flip) then block = reverse(block) writeu,out,block endif block = fltarr(anzy,bsx) if not keyword_set(float) then block = complex(block) for j=anz_blocks_x-1,0,-1 do begin index = 0 for i=0,anz_blocks_y-1 do begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_"+strcompress(j,/remove) rarr,filename,in block[index:index+bsy-1,0:bsx-1] = in index = index + bsy endfor if bsy_mod gt 0 then begin filename = tmpdir+"flop_last_"+strcompress(j,/remove) rarr,filename,in block[index:index+bsy_mod-1,0:bsx-1] = in endif if keyword_set(flip) then block = reverse(block) writeu,out,block endfor free_lun,out endif if direction eq +2 then begin ;------> Auf den Kopf gedreht openw,out,file2,/get_lun,/xdr if keyword_set(rk1) or keyword_set(rk2) then begin writeu,out,long(8) writeu,out,anzy2 writeu,out,anzx2 endif else begin writeu,out,anzx writeu,out,anzy endelse if bsy_mod gt 0 then begin block = fltarr(anzx,bsy_mod) if not keyword_set(float) then block = complex(block) if bsx_mod gt 0 then begin filename = tmpdir+"flop_last_last" rarr,filename,in block[0:bsx_mod-1,0:bsy_mod-1] = in endif index = bsx_mod for j=anz_blocks_x-1,0,-1 do begin filename = tmpdir+"flop_last_"+strcompress(j,/remove) rarr,filename,in block[index:index+bsx-1,0:bsy_mod-1] = in index = index + bsx endfor if keyword_set(flip) then block = reverse(block) writeu,out,block endif block = fltarr(anzx,bsy) if not keyword_set(float) then block = complex(block) for i=anz_blocks_y-1,0,-1 do begin if bsx_mod gt 0 then begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_last" rarr,filename,in block[0:0+bsx_mod-1,0:bsy-1] = in endif index = bsx_mod for j=anz_blocks_x-1,0,-1 do begin filename = tmpdir+"flop_"+strcompress(i,/remove)+"_"+strcompress(j,/remove) rarr,filename,in block[index:index+bsx-1,0:bsy-1] = in index = index + bsx endfor if keyword_set(flip) then block = reverse(block) writeu,out,block endfor free_lun,out endif if not keyword_set(quiet) then print," Löschen der temporären Files in "+tmpdir spawn,"rm "+tmpdir+"flop_* &" tim2 = systime(1) if not keyword_set(quiet) then print,"" if not keyword_set(quiet) then print," Benötigte Zeit : ",strcompress((tim2-tim1)/60)," min" final: end