;read_cips_ncdf2.pro ; ; Laboratory for Atmospheric and Space Physics ; University of Colorado, Boulder, Colorado, USA ; 2012 ; ; FILENAME: ; read_cips_ncdf2.pro ; ; AUTHOR: ; Cora E. Randall, with input from Jim Craft ; ; DATE: 30 March 2012. ; ; MODIFIED: ; Cora Randall, 13 May 2012. ; Cora Randall, 25 Feb 2023 ; ; PURPOSE: ; Code to read in CIPS level 2 or level 3a data. ; ; CALL: ; This is intended to be run as or within an IDL program. ; Run it from the command line: .run read_cips_ncdf2 ; Must edit the "path=" and "file=" lines to define the path ; and filename of the cips ncdf file. ; ; DIFFERENCES BETWEEN READ_CIPS_NCDF1.PRO AND READ_CIPS_NCDF2.PRO: ; read_cips_ncdf1.pro is a function. It returns all variables in a structure. ; The path and filename are included in the call statement. ; ; read_cips_ncdf2.pro is a program. It reads all variables individually into the main level. ; The path and filename are included in the first two statements in the code. ; ; NOTES ; To get the CIPS PMC level 3a longitude/latitude grid, download the ncdf ; or IDL save file from https://lasp.colorado.edu/aim/download/pmc/l3a. ; ; Some of the strings were mistakenly written out as bytes in the CIPS ncdf files. ; This code includes a fix for this, but it does not always work properly. ; See data documentation. path='C:\CIPS\documentation\read_codes\RAA_level2a_83335\' ;Path to CIPS *.nc data file file='cips_raa_2a_orbit_83335_2022-182_v01.10_r06_cat.nc' ;CIPS *.nc data file ncfile1=path+file ncid=ncdf_open(ncfile1) ;Open the *.nc file result=ncdf_inquire(ncid) ;Inquire about the data nvars=result.nvars ;# variables in the file ;Read in the data for ivar=0,nvars-1 do begin result=ncdf_varinq(ncid,ivar) ;get the data name, type, dimensions ;Puts data into array called "data" and variable name into "result.name": ncdf_varget,ncid,ncdf_varid(ncid,result.name),data ; Invoke some magic to check for string data ; masquerading as byte data, but don't convert ; byte data blindly, i.e., quality_flags is a 2-dimensional ; array of byte data. ; (This is done to account for a bug in the ncdf write routine.) if ( ( size( data, /n_dimensions ) EQ 1 ) && $ ( size( data, /type ) EQ 1 ) ) then $ data = string( data ) ;Extract each variable from the "data" structure and name it ; the corresponding "name" from "result.name": if Execute(result.name + ' = data') eq 0 then $ Print, ' "Execute" command failed -- are you in Virtual Machine mode?' endfor print,' ' print, 'All variables for '+file+' are now loaded into IDL.' print,' ' end