Unable to allocate memory: to make array for panchromatic file [message #89180] |
Thu, 31 July 2014 00:40  |
phamlien24
Messages: 6 Registered: July 2014
|
Junior Member |
|
|
I would like to create a file image from panchromatic image with the new image = the panchromatic *0.05678345/0.2846000 in IDL. However, the result has error:
% Unable to allocate memory: to make array.
Not enough space
% Execution halted at: Q_RAD_SIXSIN_GEN_P_221936 35
This is my code:
PRO q_rad_sixsin_gen_p_221936
ENVI, /RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT, LOG_FILE='batch.txt'
input_dir = 'D:\BA34\Panchromatic\BA34_pan_221936_10oct25'
input_dir_name_lenght=STRLEN(input_dir)
imagelist=FILE_SEARCH('D:\BA34\Panchromatic\BA34_pan_221936_ 10oct25\*.tif',COUNT=count)
COMPILE_OPT IDL2
FORWARD_FUNCTION ENVI_GET_DATA, ENVI_GET_MAP_INFO
FOR h=0, count-1 Do Begin
path_filename=imagelist[h]
K_pan= 0.05678345
Pan_Width= 0.2846000
envi_open_file, imagelist[h], r_fid=fid,NO_REALIZE=1
ENVI_FILE_QUERY,fid,DIMS=dims,NS=ns,NL=nl,sname=sname
map_info=envi_get_map_info(fid=fid)
filenamelength=STRLEN(sname)
outname=STRMID(sname,0,filenamelength-4)
dims=[-1L, 0, ns-1, 0, nl-1]
pan = ENVI_GET_DATA(FID=fid,dims=dims,pos=0)
br=fltarr(ns,1,nl)
br = (pan *(K_pan)/(Pan_Width))*0.1
envi_write_envi_file, br, map_info=map_info, out_name=outname+'_rad.dat', r_fid=fid, interleave=1
envi_file_mng, id=fid, /remove
ENDFOR
END
Thanks so much for your help.
Lien
|
|
|
Re: Unable to allocate memory: to make array for panchromatic file [message #89181 is a reply to message #89180] |
Thu, 31 July 2014 01:07   |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
Hi,
On 31.07.2014 09:40, phamlien24@gmail.com wrote:
> % Unable to allocate memory: to make array.
> Not enough space
try to "clean" your code.
Avoid declaring too many variables and either reassign the ones that are
not used anymore and pollute your memory or make use of temporary()
For example, this is bad:
IDL> ones = fltarr(5000,5000) + 1
IDL> twos = ones + 1
After these two statements you'll have two large arrays in memory even
if "ones" is not needed anymore. Two alternatives:
; Reassign
IDL> twos = fltarr(5000,5000) + 1
IDL> twos = twos + 1
; Temporary
IDL> ones = fltarr(5000,5000) + 1
IDL> twos = temporary(ones) + 1
To take an example of your code:
br=fltarr(ns,1,nl)
br = (pan *(K_pan)/(Pan_Width))*0.1
The first assignment is useless and memory expensive. Since IDL is
dynamically typed, there is absolutely no need to declare the variable
"br" since it will be overwritten on the next line.
Cheers,
Fabien
|
|
|
|
Re: Unable to allocate memory: to make array for panchromatic file [message #89184 is a reply to message #89180] |
Thu, 31 July 2014 01:47   |
phamlien24
Messages: 6 Registered: July 2014
|
Junior Member |
|
|
On Thursday, 31 July 2014 19:40:55 UTC+12, phaml...@gmail.com wrote:
> I would like to create a file image from panchromatic image with the new image = the panchromatic *0.05678345/0.2846000 in IDL. However, the result has error:
>
> % Unable to allocate memory: to make array.
>
> Not enough space
>
> % Execution halted at: Q_RAD_SIXSIN_GEN_P_221936 35
>
>
>
> This is my code:
>
>
>
> PRO q_rad_sixsin_gen_p_221936
>
> ENVI, /RESTORE_BASE_SAVE_FILES
>
> ENVI_BATCH_INIT, LOG_FILE='batch.txt'
>
>
>
> input_dir = 'D:\BA34\Panchromatic\BA34_pan_221936_10oct25'
>
> input_dir_name_lenght=STRLEN(input_dir)
>
> imagelist=FILE_SEARCH('D:\BA34\Panchromatic\BA34_pan_221936_ 10oct25\*.tif',COUNT=count)
>
>
>
> COMPILE_OPT IDL2
>
> FORWARD_FUNCTION ENVI_GET_DATA, ENVI_GET_MAP_INFO
>
>
>
> FOR h=0, count-1 Do Begin
>
> path_filename=imagelist[h]
>
>
>
>
>
> K_pan= 0.05678345
>
>
>
> Pan_Width= 0.2846000
>
>
>
> envi_open_file, imagelist[h], r_fid=fid,NO_REALIZE=1
>
> ENVI_FILE_QUERY,fid,DIMS=dims,NS=ns,NL=nl,sname=sname
>
> map_info=envi_get_map_info(fid=fid)
>
> filenamelength=STRLEN(sname)
>
> outname=STRMID(sname,0,filenamelength-4)
>
> dims=[-1L, 0, ns-1, 0, nl-1]
>
> pan = ENVI_GET_DATA(FID=fid,dims=dims,pos=0)
>
> br=fltarr(ns,1,nl)
>
> br = (pan *(K_pan)/(Pan_Width))*0.1
>
> envi_write_envi_file, br, map_info=map_info, out_name=outname+'_rad.dat', r_fid=fid, interleave=1
>
> envi_file_mng, id=fid, /remove
>
>
>
>
>
> ENDFOR
>
> END
>
>
>
> Thanks so much for your help.
>
>
>
> Lien
Thanks so much for your help, Fabien.
|
|
|
|