This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
You have to first create the variable, eg: NetcdfFileWriteable ncfle = new NetcdfFileWriteable(); // from netHead ncfle.setName(outfle); // output file name // define dimensions Dimension netOut_nStrings = ncfile.addDimension("netOut_nStrings", 2); Dimension netOut_strLen = ncfile.addDimension("netOut_strLen", 10); // define Variable "netOut" Dimension[] dims = new Dimension[2]; dims[0] = netOut_nStrings ; dims[1] = netOut_strLen ; ncfile.addVariable("netOut", char.class, dims); try { ncfle.create(); // create CDF binary file } catch (IOException e) { System.out.println("ERROR creating file"); } if you look at the user manual, it has some complete examples http://www.unidata.ucar.edu/packages/netcdf-java/manual.htm more info at http://www.unidata.ucar.edu/packages/netcdf-java/ ----- Original Message ----- From: "Unidata Support" <address@hidden> To: <address@hidden> Sent: Tuesday, July 09, 2002 10:13 AM Subject: 20020709: Exception in thread "main" java.lang.IllegalArgumentException > > Bob Van Wie tried to send this to the netcdf-java list, but he is not > subscribed. > > Tom > > ------- Forwarded Message > > >To: address@hidden > >From: address@hidden > >Subject: BOUNCE address@hidden: Non-member submission from [address@hidden] > >Organization: UCAR/Unidata > >Keywords: 200207091601.g69G1OH27403 > > >From address@hidden Tue Jul 9 10:01:23 2002 > Received: from nodc.noaa.gov (alcatraz.nodc.noaa.gov [140.90.235.254]) > by unidata.ucar.edu (UCAR/Unidata) with ESMTP id g69G1Ma27399 > for <address@hidden>; Tue, 9 Jul 2002 10:01:22 -0600 (MDT) > Organization: UCAR/Unidata > Keywords: 200207091601.g69G1Ma27399 > Received: from client by server id MAA53810511; Tue, 9 Jul 2002 12:01:21 -0400 (EDT) > From: address@hidden > Message-Id: <address@hidden> > Received: from client by client id MAA31408714; Tue, 9 Jul 2002 12:01:21 -0400 (EDT) > Date: Tue, 9 Jul 2002 12:01:21 -0400 (EDT) > > July 9, 2002 > Hello all, > > In running the following java program, I receive > the following error message when attempting to write the > file owith the statement: > > Exception in thread "main" java.lang.IllegalArgumentException: > NetcdfFileWriteable.write illegal variable name netOut > at ucar.nc2.NetcdfFileWriteable.write > > > > What is wrong with the output statement ? > > What is the purpose of the integer array "origin" ? > > > Please help. > > Bob Van Wie > address@hidden > > > import ucar.ma2.*; > import ucar.nc2.*; > > public class cdf > { > public net nt; > NetcdfFileWriteable ncfile; > > cdf( ) { // constructor > net nt = new net( ); > nt.netHead( ); > } // end constructor > public static void main( String args[] ) { > new cdf( ); > } > } // end cnvMeds > > import ucar.ma2.*; > import ucar.nc2.*; > import java.io.IOException; > > public class net extends NetcdfFile { > > static String outfle = "netOut"; > static String seg[] = new String[2]; > > net( ) { super(); } > > public void netHead( ) { > int[] origin = new int[2]; > int numSegs = 2; > > NetcdfFileWriteable ncfle = new NetcdfFileWriteable(); // from netHead > ncfle.setName(outfle); // output file name > > try { > ncfle.create(); // create CDF binary file > } catch (IOException e) { System.out.println("ERROR creating file"); } > System.out.println( "ncfle = " + ncfle ); > > seg[0] = "TEMP"; seg[1] = "PSAL"; > System.out.println( seg[0] + " seg " + seg[1] ); > ArrayChar ac = new ArrayChar.D2( 2, 4 ); > Index ima = ac.getIndex(); > for( int j=0; j < 2; j++ ) { > ac.setString( ima.set(j), seg[j]); > } > > try { > ncfle.write( "netOut", origin, ac ); // <-- TROUBLE !! > } catch (IOException e) { System.out.println("ERROR writing file"); } > try { > ncfle.close(); > } catch (IOException e) { System.out.println("ERROR closing file"); } > } // end netHead > } > > > ------- End of Forwarded Message >