Search:  
Location: Met Dept home : Marc's Home Page : FAAM Data Set : IDL routines for FAAM data sets


Extracting the data in IDL

netCDF files and be read into almost anything. In IDL there are some built in routines that make it fairly simple to read in netCDF variables once you seen it done. A simple program to extract an IDL variable would be something like this:

;================================================
; Marc 27/5/06
; Retrieves a variable (var_name) from a netCDF file (filename)
;================================================
pro getvar_basic,var_name,filename,var
;------------------------------------------------
; Open netcdf file and get an ID for file (ncid)
;------------------------------------------------
ncid=ncdf_open(filename,/nowrite)
;------------------------------------------------
; Find the variable ID
;------------------------------------------------
varid=ncdf_varid(ncid,var_name)
;------------------------------------------------
; Get variable
;------------------------------------------------
ncdf_varget,ncid,varid,var
;------------------------------------------------
; close netcdf file and end routine
;------------------------------------------------
ncdf_close,ncid
end
This program can be found at /home/marc/faam/idl/getvar_basic.pro and you could extract PARA1024 with the following:
IDL> .run /home/marc/faam/idl/getvar_basic
% Compiled module: GETVAR_BASIC.
IDL> getvar_basic,'PARA1024','core_faam_20060216_r1_b175.nc',clir
% Loaded DLM: NCDF.
where the data in PARA1024 will be stored in clir and you're currently in the directory containing core_faam_20060216_r1_b175.nc (otherwise replace 'core_faam_20060216_r1_b175.nc' with '/export/smoke/raid/sws00ejh/core_faam_20060216_r1_b175.nc'). You can then view the data, e.g.
IDL> print,size(clir)
           2           1       24781           4       24781
IDL> print,clir(0,50)
      409.863
The `size' command in this case tells us that we have a 2D array, first dimension is one, second dimension is 24781, the 4 means we have float data, and the final 24781 is the total number of data points. IDL indices start at 0, so clir(0,50) is actually the first column and 51st row of clir.

This data could be plotted with the following:

IDL> getvar_basic,'Time','core_faam_20060216_r1_b175.nc',time
IDL> clir1d=clir(0,*)
IDL> plot,time,clir1d
where you'll probably need to add some of the plot arguments, like yrange=[??, ??], to get a useful plot.

It's useful to add any directories containing IDL files that you'll use regularly to your IDL_PATH, so you might add /home/marc/faam/idl/ to your IDL_PATH, i.e. add

export IDL_PATH="$IDL_PATH:/home/marc/faam/idl/"
into your .kshrc file. IDL will look in directories contained in your IDL_PATH for any programs, so that instead of writing
IDL> .run /home/marc/faam/idl/getvar_basic
you can just write
IDL> .run getvar_basic
and IDL will find it. It might be more sensible to create your own IDL directory and put anything you're likely to use regularly in there - and you then free to alter the files as you like.

read_faam.pro

Because it looks like the data we'll get from FAAM are all going to follow the same slightly quirky layout I've written a couple of routines in /home/marc/faam/idl/read_faam.pro.

The first routine simple displays some header information, e.g.

IDL> .run /home/marc/faam/idl/read_faam
% Compiled module: READHEADER.
% Compiled module: GETVAR.
IDL> readheader,'core_faam_20060216_r1_b175.nc'
Time(24781):time of measurement
PARA0515:SECS(1,24781):
Data time in seconds from midnight on day the flight starts - may exceed 86400. 
PARA0516:IAS(32,24781):Indicated air speed from the aircraft RVSM system. 
PARA0517:TAS(32,24781):
True air speed from the aircraft RVSM system and deiced temperature. 
PARA0520:TTDI(32,24781):
True air temperature from the Rosemount deiced temperature sensor. 
PARA0525:NDTT(32,24781):
True air temperature from the Rosemeount non-deiced temperature sensor. 
PARA0529:DEWP(4,24781):Dew point from the General Eastern instrument. 
PARA0537:HBT(4,24781):
Uncorrected brightness temperature from the Heimann radiometer 
PARA0560:ROLL(32,24781):Roll from Honeywell H423 INU. 
PARA0561:PTCH(32,24781):Pitch from Honeywell H423 INU. 
PARA0562:IHDG(32,24781):Heading from Honeywell H423 INU. 
PARA0568:CNC(1,24781):
Total condensation nucleus concentration from TSI 3025A. 
PARA0572:TWC(64,24781):Total water content from the TWC instrument.
It provides the variable names with their short names (might be easier to remember), their dimensions and the long name is also included. This might be easier that going through the header file.

The second routine is similar to getvar_basic.pro but it allows you to use the short_name - as well as the variable name - and will get the flag array for this variable as well, e.g.

IDL> getvar,'SECS','core_faam_20060216_r1_b175.nc',secs,secs_flag
% NCDF_VARID: Variable not found  "SECS".
Found SECS (real name was PARA0515)
Found flag variable (PARA0515FLAG)
IDL> print,secs(0,66),secs_flag(0,66)
      26986.0   0



Tel: +44 (0)118 378 6507 © The University of Reading.
Fax: +44 (0)118 378 8905 Find Us (Postal Address, Maps, Etc)
Email: marc@met.rdg.ac.uk