visad/src/main/java/ucar/nc2/iosp/grid/GridVariable.java
Variable makeVariable(NetcdfFile ncfile, Group g, String useName, RandomAccessFile raf) {
    assert records.size() > 0 : "no records for this variable";

    this.nlevels = getVertNlevels();
    this.ntimes = tcs.getNTimes();
    if (vname == null) {
      useName = StringUtil2.replace(useName, ' ', "_");
      this.vname = useName;
    }

    Variable v = new Variable(ncfile, g, null, vname);
    v.setDataType(DataType.FLOAT);

    Formatter dims = new Formatter();

    if (hasEnsemble()) {
      dims.format("ens ");
    }

    dims.format("%s ", tcs.getName());

    if (getVertIsUsed()) {
      dims.format("%s ",  getVertName());
      hasVert = true;
    }

    if (hcs.isLatLon()) {
      dims.format("lat lon");
    } else {
      dims.format("y x");
    }

    v.setDimensions(dims.toString());

    // add attributes
    GridParameter param = lookup.getParameter(firstRecord);
    if (param == null) return null;

    String unit = param.getUnit();
    if (unit == null) unit = "";
    v.addAttribute(new Attribute("units", unit));

    v.addAttribute(new Attribute("long_name", makeLongName()));
    v.addAttribute(new Attribute("missing_value", lookup.getFirstMissingValue()));
    if (!hcs.isLatLon()) {
      if (GridServiceProvider.addLatLon)
        v.addAttribute(new Attribute("coordinates", "lat lon"));
      v.addAttribute(new Attribute("grid_mapping", hcs.getGridName()));
    }

    addExtraAttributes(param, v);

    v.setSPobject(this);

    int nrecs = ntimes * nlevels;
    if (hasEnsemble()) nrecs *= ecs.getNEnsembles();
    recordTracker = new GridRecord[nrecs];

    if (log.isDebugEnabled()) log.debug("Record Assignment for Variable " + getName());
    boolean oneSent = false;

    for (GridRecord p : records) {
      int level = getVertIndex(p);
      if (!getVertIsUsed() && (level > 0)) {
        log.warn("inconsistent level encoding=" + level);
        level = 0;  // inconsistent level encoding ??
      }

      int time = tcs.findIndex(p);
      // System.out.println("time="+time+" level="+level);
      if (level < 0) {
        log.warn("LEVEL NOT FOUND record; level=" + level + " time= "
                + time + " for " + getName() + " file="
                + ncfile.getLocation() + "\n" + "   "
                + getVertLevelName() + " (type=" + p.getLevelType1()
                + "," + p.getLevelType2() + ")  value="
                + p.getLevel1() + "," + p.getLevel2() + "\n");

        getVertIndex(p);  // allow breakpoint
        continue;
      }

      if (time < 0) {
        log.warn("TIME NOT FOUND record; level=" + level + " time= "
                + time + " for " + getName() + " file="
                + ncfile.getLocation() + "\n" + " validTime= "
                + p.getValidTime() + "\n");

        tcs.findIndex(p);  // allow breakpoint
        continue;
      }

      oneSent = trackRecords(time, level, p, raf, oneSent);
    }

    // let all references to Index go, to reduce retained size LOOK
    records.clear();

    return v;
  }
Variable makeVariable(NetcdfFile ncfile, Group g, String useName, RandomAccessFile raf) {
    assert records.size() > 0 : "no records for this variable";

    this.nlevels = getVertNlevels();
    this.ntimes = tcs.getNTimes();
    if (vname == null) {
      useName = StringUtil2.replace(useName, ' ', "_");
      this.vname = useName;
    }

    Variable v = new Variable(ncfile, g, null, vname);
    v.setDataType(DataType.FLOAT);

    Formatter dims = new Formatter();

    if (hasEnsemble()) {
      dims.format("ens ");
    }

    dims.format("%s ", tcs.getName());

    if (getVertIsUsed()) {
      dims.format("%s ",  getVertName());
      hasVert = true;
    }

    if (hcs.isLatLon()) {
      dims.format("lat lon");
    } else {
      dims.format("y x");
    }

    v.setDimensions(dims.toString());

    // add attributes
    GridParameter param = lookup.getParameter(firstRecord);
    if (param == null) return null;

    String unit = param.getUnit();
    if (unit == null) unit = "";
    v.addAttribute(new Attribute("units", unit));

    v.addAttribute(new Attribute("long_name", makeLongName()));
    v.addAttribute(new Attribute("missing_value", lookup.getFirstMissingValue()));
    if (!hcs.isLatLon()) {
      if (GridServiceProvider.addLatLon)
        v.addAttribute(new Attribute("coordinates", "lat lon"));
      v.addAttribute(new Attribute("grid_mapping", hcs.getGridName()));
    }

    addExtraAttributes(param, v);

    v.setSPobject(this);

    int nrecs = ntimes * nlevels;
    if (hasEnsemble()) nrecs *= ecs.getNEnsembles();
    recordTracker = new GridRecord[nrecs];

    if (log.isDebugEnabled()) log.debug("Record Assignment for Variable " + getName());
    boolean oneSent = false;

    for (GridRecord p : records) {
      int level = getVertIndex(p);
      if (!getVertIsUsed() && (level > 0)) {
        log.warn("inconsistent level encoding=" + level);
        level = 0;  // inconsistent level encoding ??
      }

      int time = tcs.findIndex(p);
      // System.out.println("time="+time+" level="+level);
      if (level < 0) {
        log.warn("LEVEL NOT FOUND record; level=" + level + " time= "
                + time + " for " + getName() + " file="
                + ncfile.getLocation() + "\n" + "   "
                + getVertLevelName() + " (type=" + p.getLevelType1()
                + "," + p.getLevelType2() + ")  value="
                + p.getLevel1() + "," + p.getLevel2() + "\n");

        getVertIndex(p);  // allow breakpoint
        continue;
      }

      if (time < 0) {
        log.warn("TIME NOT FOUND record; level=" + level + " time= "
                + time + " for " + getName() + " file="
                + ncfile.getLocation() + "\n" + " validTime= "
                + p.getValidTime() + "\n");

        tcs.findIndex(p);  // allow breakpoint
        continue;
      }

      oneSent = trackRecords(time, level, p, raf, oneSent);
    }

    // let all references to Index go, to reduce retained size LOOK
    records.clear();

    return v;
  }
Variable makeVariable ( NetcdfFile ncfile , Group g , String useName , RandomAccessFile raf ) { assert records . size ( ) > 0 : "no records for this variable" ; this . nlevels = getVertNlevels ( ) ; this . ntimes = tcs . getNTimes ( ) ; if ( vname == null ) { useName = StringUtil2 . replace ( useName , ' ' , "_" ) ; this . vname = useName ; } Variable v = new Variable ( ncfile , g , null , vname ) ; v . setDataType ( DataType . FLOAT ) ; Formatter dims = new Formatter ( ) ; if ( hasEnsemble ( ) ) { dims . format ( "ens " ) ; } dims . format ( "%s " , tcs . getName ( ) ) ; if ( getVertIsUsed ( ) ) { dims . format ( "%s " , getVertName ( ) ) ; hasVert = true ; } if ( hcs . isLatLon ( ) ) { dims . format ( "lat lon" ) ; } else { dims . format ( "y x" ) ; } v . setDimensions ( dims . toString ( ) ) ; // add attributes GridParameter param = lookup . getParameter ( firstRecord ) ; if ( param == null ) return null ; String unit = param . getUnit ( ) ; if ( unit == null ) unit = "" ; v . addAttribute ( new Attribute ( "units" , unit ) ) ; v . addAttribute ( new Attribute ( "long_name" , makeLongName ( ) ) ) ; v . addAttribute ( new Attribute ( "missing_value" , lookup . getFirstMissingValue ( ) ) ) ; if ( ! hcs . isLatLon ( ) ) { if ( GridServiceProvider . addLatLon ) v . addAttribute ( new Attribute ( "coordinates" , "lat lon" ) ) ; v . addAttribute ( new Attribute ( "grid_mapping" , hcs . getGridName ( ) ) ) ; } addExtraAttributes ( param , v ) ; v . setSPobject ( this ) ; int nrecs = ntimes * nlevels ; if ( hasEnsemble ( ) ) nrecs *= ecs . getNEnsembles ( ) ; recordTracker = new GridRecord [ nrecs ] ; if ( log . isDebugEnabled ( ) ) log . debug ( "Record Assignment for Variable " + getName ( ) ) ; boolean oneSent = false ; for ( GridRecord p : records ) { int level = getVertIndex ( p ) ; if ( ! getVertIsUsed ( ) && ( level > 0 ) ) { log . warn ( "inconsistent level encoding=" + level ) ; level = 0 ; // inconsistent level encoding ?? } int time = tcs . findIndex ( p ) ; // System.out.println("time="+time+" level="+level); if ( level < 0 ) { log . warn ( "LEVEL NOT FOUND record; level=" + level + " time= " + time + " for " + getName ( ) + " file=" + ncfile . getLocation ( ) + "\n" + "   " + getVertLevelName ( ) + " (type=" + p . getLevelType1 ( ) + "," + p . getLevelType2 ( ) + ")  value=" + p . getLevel1 ( ) + "," + p . getLevel2 ( ) + "\n" ) ; getVertIndex ( p ) ; // allow breakpoint continue ; } if ( time < 0 ) { log . warn ( "TIME NOT FOUND record; level=" + level + " time= " + time + " for " + getName ( ) + " file=" + ncfile . getLocation ( ) + "\n" + " validTime= " + p . getValidTime ( ) + "\n" ) ; tcs . findIndex ( p ) ; // allow breakpoint continue ; } oneSent = trackRecords ( time , level , p , raf , oneSent ) ; } // let all references to Index go, to reduce retained size LOOK records . clear ( ) ; return v ; }
Make the netcdf variable. If vname is not already set, use useName as name

@param ncfile  netCDF file
@param g       group
@param useName use this as the variable name
@param raf read from here
@return the netcdf variable
Make the netcdf variable . If vname is not already set use useName as name