Works beautifully with several versions of Matlab; I really love the way it handles comments, too.
I wanted to suppress some of the terminal output, since I use large xml files and generally am only interested in small sections in any one program. There's an easy way to get around that, but since it took me awhile to find it, I'll share it:
t=evalc('[mystruct tree] = xml_read(cfgfile);');
Thanks, this was very close to what I was looking for and worked as an example of using the low level NetCDF routines.
I wanted to pass the data back to a calling routine as a structure, and also wanted to remove the singleton dimensions, so I updated the getVar call to:
eval(['dstruct.' varname '= double(squeeze(netcdf.getVar(ncid,i)));']) ;
Since I also wanted to load the attributes into another structure, I needed to add some steps to handle attribute names that are not legal field names, converting spaces etc to underscores; also the assign statements for character attributes needed to be modified for that.
An excellent example file for the Matlab help would be a routine that loads a NetCDF file, modifies some fields, and writes out a new NetCDF. That would cover all the bases, I think. In the absence of that, this was a big help - thanks!
I decided I wanted to display the contents of singletons and strings, instead of their size and type, since I'm storing metadata in complex structures. That update was easy to add, a couple of lines checking the size and type. The original will also be useful when I really just want the structure itself.
Thanks for sharing this, Andrew.
Works fine, thanks. Of course I have one suggestion!
Instead of requiring that the structure name be passed separately as a string, get the name by calling inputname(1). I found that useful little trick here on File Exchange, in the structstuct function.