FUNCTION READ_COUNTS, file ;+ ; For reading NetCDF files containing differential number counts ; produced by the Marsden et al. (2010) FIR galaxy evolution model. ; ; USAGE: data_struct = READ_COUNTS(filename) ; ; READ_COUNTS can be used to read both 1-D (dN/dS) and 2-D ; (d^2N/dS/dz) differential number counts, and both "bestfit" and ; "samp" files. ; ; The format of the output data structure can be viewed by typing ; ; IDL> HELP, data_struct, /STRUCT ; ; CREATED BY: gmarsden@phas.ubc.ca, 2010-10-06 ;- id = NCDF_OPEN(file) NCDF_VARGET, id, "lambda", lambda NCDF_VARGET, id, "flux", flux NCDF_VARGET, id, "counts", counts d = NCDF_INQUIRE(id) ; figure out if counts are 1d (dN/dS) or 2d (ddN/dS/dz) dored = 0B FOR i=0,d.ndims-1 DO BEGIN NCDF_DIMINQ, id, i, name, ndim IF name EQ "redshift" THEN BEGIN dored = 1B BREAK ENDIF ENDFOR ; figure out if these are chain samples or not nsamp = 1L FOR i=0,d.ndims-1 DO BEGIN NCDF_DIMINQ, id, i, name, ndim IF name EQ "sample" THEN BEGIN nsamp = ndim BREAK ENDIF ENDFOR IF dored THEN $ NCDF_VARGET, id, "redshift", red NCDF_ATTGET, id, "lambda", "units", lambdau lambdau = STRING(lambdau) NCDF_ATTGET, id, "flux", "units", fluxu fluxu = STRING(fluxu) NCDF_ATTGET, id, "counts", "units", countsu countsu = STRING(countsu) nbands = N_ELEMENTS(lambda) IF dored THEN $ data = {lambda:lambda, lambdau:lambdau, redshift:red, $ flux:flux, fluxu:fluxu, $ counts:counts, countsu:countsu, nbands:nbands, nsamp:nsamp} $ ELSE $ data = {lambda:lambda, lambdau:lambdau, flux:flux, fluxu:fluxu, $ counts:counts, countsu:countsu, nbands:nbands, nsamp:nsamp} NCDF_CLOSE, id RETURN, data END