Ignore:
Timestamp:
05/16/06 14:41:08 (18 years ago)
Author:
pinsard
Message:

update according to idl-NetCDF-v04.tar.gz available via http://www.ittvis.com/codebank/search.asp?FID=418; side effects are not tested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ReadWrite/idl-NetCDF/ncdf_read.pro

    r67 r70  
    8787;; global attributes 
    8888 
    89 gatts=replicate({name:'', $ 
    90                  datatype:'', $ 
    91                  length:0L, $ 
    92                  values:ptr_new()}, $ 
    93                 info.ngatts) 
    94 for iatt=0,info.ngatts-1 do begin 
    95     name=ncdf_attname(id,iatt,/global) 
    96     gatts[iatt].name=name 
    97     att=ncdf_attinq(id,name,/global) 
    98     gatts[iatt].length=att.length 
    99     gatts[iatt].datatype=att.datatype 
    100     ncdf_attget,id,name,vals,/global 
    101     gatts[iatt].values=ptr_new(vals) 
    102 endfor 
     89if info.ngatts gt 0 then begin 
     90    gatts=replicate({name:'', $ 
     91                     datatype:'', $ 
     92                     length:0L, $ 
     93                     values:ptr_new()}, $ 
     94                    info.ngatts) 
     95    for iatt=0,info.ngatts-1 do begin 
     96        name=ncdf_attname(id,iatt,/global) 
     97        gatts[iatt].name=name 
     98        att=ncdf_attinq(id,name,/global) 
     99        gatts[iatt].length=att.length 
     100        gatts[iatt].datatype=att.datatype 
     101        ncdf_attget,id,name,vals,/global 
     102        gatts[iatt].values=ptr_new(vals) 
     103    endfor 
     104endif else begin 
     105    ;; arbitary scalar value 
     106    ;; an empty list would be sensible but IDL doesn't support it 
     107    gatts=-1 
     108endelse 
    103109 
    104110 
     
    108114vatts=replicate(ptr_new(),info.nvars) 
    109115for ivar=0,info.nvars-1 do begin 
    110     vatts[ivar]=ptr_new(replicate({name:'', $ 
    111                                       datatype:'', $ 
    112                                       length:0L, $ 
    113                                       values:ptr_new()}, $ 
     116    if vinfo[ivar].natts gt 0 then begin 
     117        vatts[ivar]=ptr_new(replicate({name:'', $ 
     118                                       datatype:'', $ 
     119                                       length:0L, $ 
     120                                       values:ptr_new()}, $ 
    114121                                      vinfo[ivar].natts)) 
    115     for iatt=0,vinfo[ivar].natts-1 do begin 
    116         name=ncdf_attname(id,ivar,iatt) 
    117         (*vatts[ivar])[iatt].name=name 
    118         att=ncdf_attinq(id,ivar,name) 
    119         (*vatts[ivar])[iatt].length=att.length 
    120         (*vatts[ivar])[iatt].datatype=att.datatype 
    121         ncdf_attget,id,ivar,name,vals 
    122         (*vatts[ivar])[iatt].values=ptr_new(vals) 
    123     endfor 
     122        for iatt=0,vinfo[ivar].natts-1 do begin 
     123            name=ncdf_attname(id,ivar,iatt) 
     124            (*vatts[ivar])[iatt].name=name 
     125            att=ncdf_attinq(id,ivar,name) 
     126            (*vatts[ivar])[iatt].length=att.length 
     127            (*vatts[ivar])[iatt].datatype=att.datatype 
     128            ncdf_attget,id,ivar,name,vals 
     129            (*vatts[ivar])[iatt].values=ptr_new(vals) 
     130        endfor 
     131    endif else begin 
     132        vatts[ivar]=ptr_new(-1) 
     133        ;; Pointer to arbitrary scalar -- analogous to case of lack of 
     134        ;; global attributes above.  We could put a <NullPointer> here 
     135        ;; instead, but try to be friendlier to code that might try 
     136        ;; to dereference it. 
     137    endelse 
    124138endfor 
    125139 
Note: See TracChangeset for help on using the changeset viewer.