Structure Format

This document explains the genesis of the format for return structures from ISIS services.

There are several things we want from a structure definition:


We will start with a C structure definition as our template. The example below might arise if we are returning a list of coordinates for objects in a region of the sky:

   struct
   {
      char name[20];

      int count;

      struct 
      {
	 double lon;
	 double lat;
	 char   csys[10];
      }
	 coords[256];
   }


But that's only the structure definition. In addition we need the initialization structure that will populate it:

   {
      "My region",
      3,
      {
	 {321.34443, 34.45692, "eq"},
	 {321.35454, 34.87421, "eq"},
	 {321.34671, 34.54532, "eq"}
      }
   }


However, we want the names and values together. In addition, since the return structure is being sent between programs and even over the net, and since we want the whole thing to be printable ASCII, there is not much point in carrying along type definitions. So we can restructure the above into the following:

   struct
   {
      name  = "My region";
      count = 3;

      struct 
      {
	 {
	    lon  = 321.34443;
	    lat  =  34.45692;
	    csys = "eq";
	 },

	 {
	    lon  = 321.35454;
	    lat  =  34.87421;
	    csys = "eq";
	 },

	 {
	    lon  = 321.34671;
	    lat  =  34.54532;
	    csys = "eq";
	 }
      }
	 coords;
   }


For parsibility, we need to be able to tell the difference between a "structure" (where values are matched to names) and "arrays" (where the data is ordered in a list. For subtle (and not really compelling) reasons we have also replaced semicolons with commas and braces with brackets:

   [struct
      name  = "My region",
      count = 3,

      coords =
      [array
	 [struct
	    lon  = 321.34443,
	    lat  =  34.45692,
	    csys = "eq",
	 ],

	 [struct
	    lon  = 321.35454,
	    lat  =  34.87421,
	    csys = "eq",
	 ],

	 [struct
	    lon  = 321.34671,
	    lat  =  34.54532,
	    csys = "eq",
	 ]
      ]
   ]


Since we aren't using this mechanism for bulk data transfer, we can string it all together with no breaks (shown here on four lines but all one line in the real output):

   [struct name   = "My region", count  = 3, coords = [array
   [struct lon  = 321.34443, lat  =  34.45692, csys = "eq"],
   [struct lon  = 321.35454, lat  =  34.87421, csys = "eq"],
   [struct lon  = 321.34671, lat  =  34.54532, csys = "eq"]]]


We could have compressed the format even further if we removed the duplicate lon, lat, csys references. However, leaving them in allows us to have arrays of unlike elements with equal ease:

   [struct name   = "My region", count  = 3, coords = [array
   [struct lon  = 321.34443, lat  =  34.45692, epoch="B1983.5"],
   [struct lon  = 321.35454, lat  =  34.87421, csys = "eq"],
   [struct file = "datalist.tbl", count = 347]]]]

which could be used (in this case) to include special information (e.g. epoch) or to say "there are 347 more coordinates in the file datalist.tbl").


Author: John Good
Address: jcg@ipac.caltech.edu
Last update: 18-Jul-2005