--- netcdfdataset.cpp.new1	2008-08-21 14:20:03.000000000 -0800
+++ netcdfdataset.cpp	2008-08-21 14:23:28.000000000 -0800
@@ -1387,7 +1387,7 @@
                             ":", CSLT_HONOURSTRINGS|CSLT_PRESERVEESCAPES );
 
     if( EQUAL( poDS->papszName[0], "NETCDF" ) ) {
-	if( ( CSLCount(poDS->papszName) == 3  ) ){
+	if( ( CSLCount(poDS->papszName) >= 3  ) ){
 	    poDS->pszFilename = strdup( poDS->papszName[1] );
 	}
     }
@@ -1415,7 +1415,7 @@
 /* -------------------------------------------------------------------- */
 /*      Does the request variable exist?                                */
 /* -------------------------------------------------------------------- */
-    if( ( CSLCount(poDS->papszName) == 3  ) ){
+    if( ( CSLCount(poDS->papszName) >= 3  ) ){
 	status = nc_inq_varid( cdfid, poDS->papszName[2], &var);
 	if( status != NC_NOERR ) {
 	    CPLError( CE_Warning, CPLE_AppDefined, 
@@ -1618,15 +1618,31 @@
     }
     i=0;
 
+/* -------------------------------------------------------------------- */
+/*      Allow selection of individual band using extended syntax        */
+/*      NETCDF:"filename":subdataset:index0:index1:...:indexN           */
+/*      where index0,...,indexN are indicies of higher-order dimensions */
+/* -------------------------------------------------------------------- */
+    if( ( CSLCount(poDS->papszName)-1 == nd  ) ){
+    	nTotLevCount = 1;
+    	lev_count = 1;
+      	i = atoi(poDS->papszName[nd]);
+      	for (j=nd-2; j > 1; j--) {
+       		lev_count *= poDS->panBandZLev[ j-1 ];
+       		i += atoi(poDS->papszName[nd+j-3])*lev_count;
+      	}
+      	CPLDebug( "GDAL_netCDF", "selecting zero-based band %d\n", i );
+    }
+
     for ( unsigned int lev = 0; lev < nTotLevCount ; lev++ ) {
 	char ** papszToken;
 	papszToken=NULL;
 
 	netCDFRasterBand *poBand =
-            new netCDFRasterBand(poDS, var, nDim, lev,
+            new netCDFRasterBand(poDS, var, nDim, i,
                                  poDS->panBandZLev, poDS->panBandDimPos, i+1 );
 
-	poDS->SetBand( i+1, poBand );
+	poDS->SetBand( lev+1, poBand );
 	i++;
    } 
 
@@ -1634,7 +1650,7 @@
     CPLFree( poDS->panBandDimPos );
     CPLFree( poDS->panBandZLev );
     
-    poDS->nBands = i;
+    poDS->nBands = nTotLevCount;
 
     // Handle angular geographic coordinates here
 

