 
  
   
    2012 Unidata NetCDF Workshop  > Developing generic netCDF software
 
2012 Unidata NetCDF Workshop  > Developing generic netCDF software  
 
25.0 Issues in Writing Generic NetCDF Software
There are several issues to be aware of in writing software designed to
read  arbitrary netCDF data.
The general structure of utility programs, such as the NCO
utilities or programs to copy netCDF data from a source file to a
target file is straightforward:
  - Find out how many dimensions are in the source file using a file
  inquire function.
- For each dimension, find out its name and length and create a
  corresponding dimension in the output file.  Preserve the unlimited
  dimension, if needed.
- Find out how many variables are in the source file using a file
  inquire function.
- For each source variable, find out its name, type, shape, and
  number of attributes.  Create a corresponding variable in the output
  file.  Loop through its attributes in the source file and create
  corresponding attributes, including all their values in the target
  file. 
- For each global (file-level) attribute, find its name, type, and
  values.  Create corresponding global attribute in the target
  file.
- For each variable, copy all its data values from the source file
  to the target file.
This last step can be tricky, because:
  - The code must work for a variable with any number of
  dimensions, so a simple set of nested loops with one loop for each
  dimension cannot be used.
  
- A variable may have more data
  than can fit in memory, so it is impractical to read all the values
  into memory at once and then write them all out.
  
- Even a
  single row of variable values may be too large to fit in memory, for example
  a variable of type double with a most rapidly varying dimension of
  size 231
  .  One solution: treat dimension indices like an odometer to
  iterate through variable data in a single loop.
  
 
 
 
  
   
    2012 Unidata NetCDF Workshop  > Developing generic netCDF software
  
2012 Unidata NetCDF Workshop  > Developing generic netCDF software