NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: 20020709: Exception in thread "main" java.lang.IllegalArgumentException

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" <support@xxxxxxxxxxxxxxxx>
To: <semmerson@xxxxxxxxxxxxxxxx>
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: netcdf-java-approval@xxxxxxxxxxxxxxxx
> >From: owner-netcdf-java@xxxxxxxxxxxxxxxx
> >Subject: BOUNCE netcdf-java@xxxxxxxxxxxxxxxx: Non-member submission from
[bob@xxxxxxxxxxxxx]
> >Organization: UCAR/Unidata
> >Keywords: 200207091601.g69G1OH27403
>
> >From support@xxxxxxxxxxxxxxxx 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 <netcdf-java@xxxxxxxxxxxxxxxx>; 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: bob@xxxxxxxxxxxxx
> Message-Id: <200207091601.MAA53810511@xxxxxxxxxxxxx>
> 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
>                         Robert.Van.Wie@xxxxxxxx
>
>
> 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
>


  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: