I am new to IDL
I am importing data from an NCDF4 into IDL. All the variables that are numeric import perfectly. However station name comes in as an array of 200. An example of the output is :-
84 82 69 76 69 87 95 65 69 82 79 32 32 32 0 0 0 0 0 0 0 0 .
etc.
I never experienced this problem with R. I tried using a string command but that won't work for. If I comment out the string command, the rest of the script work perfectly. My script is below
PRO Lat_Lon_Alt_Array
; This program is the extract the Latitute, Longigitude & Altitute
; with the Site name and file code.
; The purpose is to output the above dimensions from the station files
; into a csv file.
COMPILE_OPt IDL2
the_file_list = file_search('D:/Rwork/Project/25_Files/','*.nc')
;---------------------------------------------------------------
n_files=N_Elements(the_file_list)
station_name_st=string(n_files) ; try this
latitude_arr=DBLARR(n_files)
longitude_arr=DBLARR(n_files)
height_arr=DBLARR(n_files)
;----------------------------------------------------------------
FOR filein = 0, N_ElEMENTS (the_file_list)-1 DO BEGIN
station = NCDF_OPEN(the_file_list[filein])
;fred= NCDF_VARINQ(station,station_name)
NCDF_VARGET, station, 'station_name', station_name
NCDF_VARGET, station, 'lat', latitude
NCDF_VARGET, station, 'lon', longitude
NCDF_VARGET, station, 'alt', height
stop
;-------------------------------------------------------
;station_name_st[filein]=station_name
latitude_arr[filein]=latitude
longitude_arr[filein]=longitude
height_arr[filein]=height
;-----------------------------------------------------
Print,the_file_list[filein]
Print, 'station_name'
Print, station_name
Print,'lat'
Print,latitude
Print,'lon'
print,longitude
Print,'alt'
Print,height
HEADER=['File_Address','Latitude','Longitude','Altitude']
ENDFOR
WRITE_CSV, 'LatLon.csv',the_file_list,latitude_arr,longitude_arr,height_arr,$
HEADER=HEADER,TABLE_HEADER='LAT,LON & ALT OF STATIONS'
RETURN
END
In some instances, NetCDF files store "strings" as byte arrays. Your station_name
variable appears to be one of these cases. You just need to use the STRING
function to convert station_name
after reading it in with the NCDF_VARGET
procedure.
NCDF_VARGET, station, 'station_name', station_name
PRINT, station_name
84 82 69 76 69 87 95 65 69 82 79 32 32 32 0 0 0 0 0 0 0 0
station_name = STRING(station_name)
PRINT, station_name
TRELEW_AERO