;+------------------------------------------------------------------- ; pro get_tidi_atts, atts, file = file, filter = filter, ncid = ncid, $ debug = debug, verbose = verbose ; ; Purpose: Reads a TIDI NetCDF file and stores the global ; attributes in the structure atts, i.e. atts. ; ; NOTE: Attribute is filled with '--' if not defined for the file. ; ; atts structure of global attributes, i.e. atts. ; ; file full filename of TIDI NetCDF file that's to be read in ; ; filter wildcard for searching for the filename, if file not given ; ; ncid if a NetCDF file is already open, you can just pass in ; the file unit number, ncid ; ; /debug looks in debug directory first, if file not given ; if ( KEYWORD_SET( debug ) ) then $ dirpath = '/tidi/tidi_software/retrieve/debug/2002/' $ else dirpath = '/data/tidi/' ; ; /verbose prints attributes and values to terminal ; ; History: ; 18 Nov 2002 MLC initial coding ; 18 Dec 2002 MLC added ability to pass in the ncid instead of ; file name to acces NetCDF file ; ;-------------------------------------------------------------------- ; If file not given or ncid not given, then pick file with a dialog box defined_ncid = N_ELEMENTS( ncid ) if ( NOT KEYWORD_SET( file ) and NOT defined_ncid ) then begin file = '' file = dialog_pickfile( /must_exist, path = dirpath, filter = filter, $ /read, title = 'Select a NetCDF File') if file eq '' then begin print, 'get_tidi_atts-I-no file selected' return endif endif on_ioerror, badfle ; Open NetCDF file if ( NOT defined_ncid ) then begin ncid = ncdf_open( file, /nowrite ) if ( KEYWORD_SET( verbose ) ) then print, 'File: ', file endif ; Define the attributes structure - VERY IMPORTANT that the following ; name array matches the order of ; this attribute structure struct_atts = { atts_struct, $ title: '', $ data_product_type: '', $ mission: '', $ source: '', $ data_product_version: '', $ product_format_version: '', $ software_name: '', $ software_version: '', $ calibration_version: '', $ filename: '', $ input_file: '', $ cpf_filename: '', $ pvat_filename: '', $ date_created: '', $ magnetic_latitude_model: '', $ solar_beta_angle: '', $ oband_ratio_source: '', $ att_s_var: '', $ att_h_var: '' $ } atts = struct_atts ; Set names of the attributes - VERY IMPORTANT that name array matches ; the order of the attribute structure names name = [ 'title', $ 'data_product_type', $ 'mission', $ 'source', $ 'data_product_version', $ 'product_format_version', $ 'software_name', $ 'software_version', $ 'calibration_version', $ 'filename', $ 'input_file', $ 'cpf_filename', $ 'pvat_filename', $ 'date_created', $ 'magnetic_latitude_model', $ 'solar_beta_angle', $ 'oband_ratio_source', $ 'att_s_var', $ 'att_h_var' $ ] value = strarr(N_ELEMENTS(name)) ncdf_attget, ncid, 'software_name', sw_name, /global ; Now get each value and display name/value pair, if /verbose is set for i = 0, N_ELEMENTS(name)-1 do begin ncdf_control, 0, /noverbose ii = ncdf_attinq(ncid, name[i], /global) ncdf_control, 0, /verbose if ( ii.datatype eq 'UNKNOWN' or $ (string(sw_name) eq 'RETRIEVE' and $ name[i] eq 'oband_ratio_source') ) then begin att_value = '--' endif else begin ncdf_attget, ncid, name[i], att_value, /global endelse value[i] = TRIM(string(att_value)) if ( KEYWORD_SET( verbose ) ) then print, name[i],': ',value[i] endfor ; Now store the values in the attributes structure for j = 0, N_ELEMENTS(name)-1 do atts.(j) = value[j] leave: if ( NOT defined_ncid ) then ncdf_close, ncid ; close NetCDF file return badfle: print, 'Error with NetCDF ', file, ': ', !error_state.msg return ;:; END