Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Read values from multiple files in IDL

Writer Matthew Harrington

I have several files from which I'm trying to extract variables for brightness temperature, BT. I want to put all the variables into one array. This is what I have and so far. I've opened all the files but I can't figure out how to combine all the values.

filelist = FINDFILE(in_path+"ATMS-v11r1_npp_s"+date_str+"*nc",count=nfiles)
FOR i = 0, nfiles -1 DO BEGIN
PE1_fid=NCDF_OPEN(filelist(i))
field = 'BT'
NCDF_VARGET, pe1_fid, field, pe1_data
ENDFOR

2 Answers

You didn't say what size/type of variable BT is. I assumed it was a float scalar, but if not you would modify the definition of bt below to match.

filelist = file_search(in_path + 'ATMS-v11r1_npp_s' + date_str + '*nc', $ count=nfiles)
bt = fltarr(nfiles)
for i = 0, nfiles - 1 do begin pe1_fid = ncdf_open(filelist[i]) field = 'BT' ncdf_varget, pe1_fid, field, e1_data bt[i] = e1_data
endear

I also changed a few other things about your code:

  • FINDFILE is obsolete, use FILE_SEARCH
  • Don't index arrays using parentheses, use brackets (and compile_opt strictarr).
  • Use single quotes instead of double quotes for string literals.
0

With IDL version 8 or later you can simplify the code a bit, independent how many entries each of the e1_data fields contains:

filelist = FILE_SEARCH(in_path + 'ATMS-v11r1_npp_s' + date_str + '*nc', count=nfiles)
bt = []
FOR i = 0,nfiles-1 DO BEGIN pe1_fid = = ncdf_open(filelist[i]) field = 'BT' ncdf_varget, pe1_fid, field, e1_data bt = [bt, e1_data]
ENDFOR
7

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.