Changeset 70


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

Location:
trunk/ReadWrite/idl-NetCDF
Files:
7 edited

Legend:

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

    r67 r70  
    1 FUNCTION ncdf_listdims, ncid, sizes = sizes 
     1FUNCTION ncdf_listdims,ncid 
    22 
    3   n = (ncdf_inquire(ncid)).ndims 
     3n=(ncdf_inquire(ncid)).ndims 
    44 
    5   sizes = lonarr(n) 
    6   names = strarr(n) 
     5names=strarr(n) 
    76 
    8   for i = 0, n-1 do begin 
    9     ncdf_diminq, ncid, i, name, size 
    10     names[i] = name 
    11     sizes[i] = size 
    12   endfor 
     7for i=0,n-1 do begin 
     8    ncdf_diminq,ncid,i,name,size 
     9    names[i]=name 
     10endfor 
    1311 
    14   return, names 
     12return,names 
    1513 
    1614end 
  • trunk/ReadWrite/idl-NetCDF/ncdf_quickread/README_ncdf_quickread.txt

    r67 r70  
    2828 
    2929         ncverbose : set equal to 1 if you want to include attributes 
     30 
     31         ncfields : Set to a string which is a space-separated list of 
     32                    variables to read.  Only the variables specified will be 
     33                    read in (and where ncverbose is set, only the attributes 
     34                    associated with these variables and the global attributes). 
     35                    If unset or the null string, then reads all fields. 
    3036 
    31374) Type:  @ncdf_quickread 
  • trunk/ReadWrite/idl-NetCDF/ncdf_quickread/ncdf_quickread.pro

    r67 r70  
    55 
    66__commands= $ 
    7   ncdf_quickread_helper(ncfile,verbose=ncverbose,prefix=ncprefix,/reform) 
     7           ncdf_quickread_helper(ncfile,verbose=ncverbose,prefix=ncprefix, $ 
     8                                 fields=ncfields,/reform) 
    89 
    910for __loop=0,n_elements(__commands)-1 do $ 
  • trunk/ReadWrite/idl-NetCDF/ncdf_quickread/ncdf_quickread_helper.pro

    r67 r70  
    3434;                           is used to remove dimensions of size 1. 
    3535;  02 Oct 03  A.M.Iwi       Change into helper routine for ncdf_quickread 
     36;  11 Aug 04  A.M.Iwi       Add "fields" option to read only certain fields. 
     37;                           Also, only stringify attributes of type CHAR. 
    3638;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    3739 
     
    139141 
    140142function ncdf_quickread_helper, infile, verbose=verbose,  $ 
    141                                 prefix=prefix, reform=reform 
     143                                prefix=prefix, fields=fields, $ 
     144                                reform=reform 
    142145on_error,2 
    143146compile_opt hidden 
     
    169172commands="__ncid = NCDF_OPEN('"+infile+"')" 
    170173 
     174subset=0 
     175if n_elements(fields) ne 0 then begin 
     176  if (fields ne '') then begin 
     177      subset=1 
     178      subfields=strsplit(fields,/extract) 
     179  endif 
     180endif 
     181 
    171182; Place the desired variables in local arrays. 
    172183for i=0, ncidinfo.Nvars-1 do begin  
    173184   vardata = NCDF_VARINQ(ncid, i) 
    174    varname = ncdf_quickread_validatename(vardata.Name)  
    175    if keyword_set(prefix) then varname=prefix+varname 
    176    commands=$ 
    177      [commands,"NCDF_VARGET, __ncid, "+strcompress(string(i))+", "+varname] 
    178    if keyword_set(reform) and vardata.ndims ge 2 $ 
    179      then commands=[commands,varname+'=reform('+varname+')'] 
    180    if (keyword_set(verbose)) then begin 
    181       for j=0, vardata.Natts-1 do begin 
    182          att = NCDF_ATTNAME(ncid, i, j) 
    183          attname = strcompress(varname+"_"+strcompress(att,/REMOVE_ALL)) 
    184          commands=$ 
    185            [commands,"NCDF_ATTGET, __ncid, "+strcompress(string(i))+$ 
    186             ", '"+att+"', "+attname] 
    187          commands=$ 
    188            [commands,attname+" = STRING("+attname+")"] 
    189       endfor 
     185   if not subset then begin 
     186       wanted=1 
     187   endif else begin 
     188       match = where(subfields eq vardata.Name, nmatch) 
     189       wanted=(nmatch ne 0) 
     190   endelse 
     191   if wanted then begin 
     192       varname = ncdf_quickread_validatename(vardata.Name)  
     193       if keyword_set(prefix) then varname=prefix+varname 
     194       commands=$ 
     195                [commands,"NCDF_VARGET, __ncid, "+strcompress(string(i))+", "+varname] 
     196       if keyword_set(reform) and vardata.ndims ge 2 $ 
     197         then commands=[commands,varname+'=reform('+varname+')'] 
     198       if (keyword_set(verbose)) then begin 
     199           for j=0, vardata.Natts-1 do begin 
     200               att = NCDF_ATTNAME(ncid, i, j) 
     201               attname = strcompress(varname+"_"+strcompress(att,/REMOVE_ALL)) 
     202               commands=$ 
     203                        [commands,"NCDF_ATTGET, __ncid, "+strcompress(string(i))+$ 
     204                         ", '"+att+"', "+attname] 
     205               attinfo = ncdf_attinq(ncid, i, att) 
     206               if attinfo.datatype eq 'CHAR' then $ 
     207                 commands=[commands,attname+" = STRING("+attname+")"] 
     208           endfor 
     209       endif 
    190210   endif 
    191211endfor 
     
    198218     commands=$ 
    199219       [commands,"NCDF_ATTGET, __ncid, /GLOBAL, '"+name+"', "+attname] 
    200      commands=$ 
    201        [commands,attname+" = STRING("+attname+")"] 
     220     attinfo = ncdf_attinq(ncid, /global, name) 
     221     if attinfo.datatype eq 'CHAR' then $ 
     222       commands=[commands,attname+" = STRING("+attname+")"] 
    202223  endfor 
    203224endif 
    204225 
     226ncdf_close,ncid 
    205227commands=[commands,"NCDF_CLOSE, __ncid"] 
    206228 
  • trunk/ReadWrite/idl-NetCDF/ncdf_quickwrite/README_ncdf_quickwrite.txt

    r67 r70  
    188188                   time = UNLIMITED ; // (100 currently) 
    189189           variables: 
    190                    float pressure(time, latitude, longitude) ; 
     190                   double pressure(time, latitude, longitude) ; 
    191191                           pressure:units = "pascals" ; 
    192192                           pressure:missing_value = 1.e+10f ; 
     
    195195                   float latitude(latitude) ; 
    196196                           latitude:units = "degrees" ; 
    197                    float ubar(time, latitude) ; 
     197                   double ubar(time, latitude) ; 
    198198                           ubar:units = "m s-1" ; 
    199199                   int year(time) ; 
  • trunk/ReadWrite/idl-NetCDF/ncdf_quickwrite/ncdf_quickwrite_verbose.pro

    r67 r70  
    1616print,*__ncdf.commands,format='(a)' 
    1717 
    18 ;for __loop=0,__ncdf.ncommands-1 do $ 
    19 ;  if not execute((*__ncdf.commands)[__loop]) then stop 
    20  
    21 for __loop=0,__ncdf.ncommands-1 do begin & print,(*__ncdf.commands)[__loop] & if not execute((*__ncdf.commands)[__loop]) then stop & endfor 
     18for __loop=0,__ncdf.ncommands-1 do $ 
     19  if not execute((*__ncdf.commands)[__loop]) then stop 
    2220 
    2321ncdf_quickwrite_helper3,__ncdf 
  • 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.