0

I would like to create a file image from panchromatic image with the new image = the panchromatic *0.05678345 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)
    ;imagelistt=FILE_SEARCH('D:\quickbird\test.tif', COUNT=count)
    ;envi_open_file, imagelistt, r_fid=tfid,NO_REALIZE=1
    ;map_info=envi_get_map_info(fid=tfid)



    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 to correct the code.

Lien

user30985
  • 573
  • 1
  • 6
  • 19

1 Answers1

0

It is not clear from context if this is happening right from the first instance of the loop or in subsequent iterations. One way of freeing up memory is to use the temporary() function: it frees up the memory space used by an array. In your case, you could use:

br = temporary(pan) * 0.1* K_pan)/Pan_Width

And later

envi_write_envi_file, temporary(br), map_info=map_info, out_name=outname+'_rad.dat', r_fid=fid, interleave=1
VBB
  • 1,305
  • 7
  • 17
  • Please let me know if you have any followup questions. If this solves your problem, please mark the answer as accepted. – VBB Aug 12 '14 at 11:33
  • It solves my problem. I wonder that whether I marked the answer as accepted or not. If not, please guide me how to mark the answer as accepted. Thanks. – user30985 Aug 13 '14 at 21:30