Changeset 70 for trunk/ReadWrite/idl-NetCDF
- Timestamp:
- 05/16/06 14:41:08 (18 years ago)
- 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 = sizes1 FUNCTION ncdf_listdims,ncid 2 2 3 n =(ncdf_inquire(ncid)).ndims3 n=(ncdf_inquire(ncid)).ndims 4 4 5 sizes = lonarr(n) 6 names = strarr(n) 5 names=strarr(n) 7 6 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 7 for i=0,n-1 do begin 8 ncdf_diminq,ncid,i,name,size 9 names[i]=name 10 endfor 13 11 14 return,names12 return,names 15 13 16 14 end -
trunk/ReadWrite/idl-NetCDF/ncdf_quickread/README_ncdf_quickread.txt
r67 r70 28 28 29 29 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. 30 36 31 37 4) Type: @ncdf_quickread -
trunk/ReadWrite/idl-NetCDF/ncdf_quickread/ncdf_quickread.pro
r67 r70 5 5 6 6 __commands= $ 7 ncdf_quickread_helper(ncfile,verbose=ncverbose,prefix=ncprefix,/reform) 7 ncdf_quickread_helper(ncfile,verbose=ncverbose,prefix=ncprefix, $ 8 fields=ncfields,/reform) 8 9 9 10 for __loop=0,n_elements(__commands)-1 do $ -
trunk/ReadWrite/idl-NetCDF/ncdf_quickread/ncdf_quickread_helper.pro
r67 r70 34 34 ; is used to remove dimensions of size 1. 35 35 ; 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. 36 38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 37 39 … … 139 141 140 142 function ncdf_quickread_helper, infile, verbose=verbose, $ 141 prefix=prefix, reform=reform 143 prefix=prefix, fields=fields, $ 144 reform=reform 142 145 on_error,2 143 146 compile_opt hidden … … 169 172 commands="__ncid = NCDF_OPEN('"+infile+"')" 170 173 174 subset=0 175 if n_elements(fields) ne 0 then begin 176 if (fields ne '') then begin 177 subset=1 178 subfields=strsplit(fields,/extract) 179 endif 180 endif 181 171 182 ; Place the desired variables in local arrays. 172 183 for i=0, ncidinfo.Nvars-1 do begin 173 184 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 190 210 endif 191 211 endfor … … 198 218 commands=$ 199 219 [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+")"] 202 223 endfor 203 224 endif 204 225 226 ncdf_close,ncid 205 227 commands=[commands,"NCDF_CLOSE, __ncid"] 206 228 -
trunk/ReadWrite/idl-NetCDF/ncdf_quickwrite/README_ncdf_quickwrite.txt
r67 r70 188 188 time = UNLIMITED ; // (100 currently) 189 189 variables: 190 floatpressure(time, latitude, longitude) ;190 double pressure(time, latitude, longitude) ; 191 191 pressure:units = "pascals" ; 192 192 pressure:missing_value = 1.e+10f ; … … 195 195 float latitude(latitude) ; 196 196 latitude:units = "degrees" ; 197 floatubar(time, latitude) ;197 double ubar(time, latitude) ; 198 198 ubar:units = "m s-1" ; 199 199 int year(time) ; -
trunk/ReadWrite/idl-NetCDF/ncdf_quickwrite/ncdf_quickwrite_verbose.pro
r67 r70 16 16 print,*__ncdf.commands,format='(a)' 17 17 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 18 for __loop=0,__ncdf.ncommands-1 do $ 19 if not execute((*__ncdf.commands)[__loop]) then stop 22 20 23 21 ncdf_quickwrite_helper3,__ncdf -
trunk/ReadWrite/idl-NetCDF/ncdf_read.pro
r67 r70 87 87 ;; global attributes 88 88 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 89 if 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 104 endif else begin 105 ;; arbitary scalar value 106 ;; an empty list would be sensible but IDL doesn't support it 107 gatts=-1 108 endelse 103 109 104 110 … … 108 114 vatts=replicate(ptr_new(),info.nvars) 109 115 for 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()}, $ 114 121 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 124 138 endfor 125 139
Note: See TracChangeset
for help on using the changeset viewer.