; pro rd2d ; ; Open a tgcm history and read a 2-d lat,lon field: ; ; ncfile: name of history file to read: ; ncfile = "FESEN.tiegcm1.marcond2.nc" ; ; var2d: name of 2-d field to read from ncfile: ; var2d = "ZIGM11" ;var2d = "trash" ; ; Open the file, and inquire: ; on_ioerror,badfile cdfid = ncdf_open(ncfile) print,'Opened file ',ncfile,' cdfid=',cdfid file_inq = ncdf_inquire(cdfid) ;help,file_inq,/struct ; ; Search for variable var2d: ; for ivar = 0,file_inq.nvars-1 do begin var = ncdf_varinq(cdfid,ivar) if var.name eq var2d then begin found = 1 print,'Found variable ',var2d ; help,var,/struct id = ivar goto,found endif endfor print,' ' & print,'>>> Could not find variable ',var2d,' on file ',ncfile return found: ; ; Confirm that variable is 3d (2d in space, one in time) ; var = ncdf_varinq(cdfid,id) if var.ndims ne 3 then begin print,' ' print,'>>> Variable ',var2d,' is not 3-d (2-d in space, 1 in time): ',$ 'var.ndims=',var.ndims return endif dimnames = strarr(3) dimsizes = intarr(3) for idim = 0,var.ndims-1 do begin ncdf_diminq,cdfid,var.dim(idim),dimname,dimsize dimnames[idim] = dimname dimsizes[idim] = dimsize endfor print,format="('Variable ',a,' is dimensioned (',3a8,') where:')",var2d,dimnames for i=0,2 do print,' ',dimnames[i],' = ',dimsizes[i] ; ; Read the variable. It will be vardat[dimsizes[0],dimsizes[1],dimsizes[2]) ; ncdf_varget,cdfid,id,vardat help,vardat ; ; Print var at time 1 (2nd time): ; for j=0,dimsizes[1]-1 do begin print,var2d,': j=',j,' vardat[*,j,1]=' print,vardat[*,j,1] endfor ; ; Here you could write the var to a formatted file, or do whatever with it... ; return badfile: print,'>>> Error opening file ',ncfile return end