[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fixed problem

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.


  • Subject: Re: Fixed problem
  • Date: Fri, 19 Nov 1999 08:53:42 -0700 (MST)

Steve,

I was extremely busy yesterday so I couldn't remember the syntax for the
multidimensional arrarys, etc. I modified the the example you sent, using
the 1st dim as unlimited, thats what my understanding was yesterday.
The original example is dependent on the manner that perl stores
strings in arrays thats why the padstr function is used so one gets
what one expects. Sometime the API don't work as expected. Don't
ever think I will not answer a question, sometimes I need time to get to
the problem.

Robb...

atachment sent

On Thu, 18 Nov 1999, Steve Diggs wrote:

> Robb,
> 
> Thanks for all of your help.  I'm eager to see what you came up with, but
> I think that I solved the problem.  I've attached a zipfile which is an
> email exchange that you guys had a little while back with a user that was
> almost as annoying as me!
> 
> Let me know what you think.
> 
> -sd
> --
> --------------------------------------------------------------------
> Steve Diggs                                   Voice: (858)534-1108
> Scripps Institution of Oceanography           FAX  : (858)534-7383
> WOCE Hydrographic Program Office/STS          EMAIL: address@hidden
> 9500 Gilman Drive                             WWW  : whpo.ucsd.edu
> La Jolla, CA 92093-0214
> --------------------------------------------------------------------
> 

===============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
address@hidden             WWW: http://www.unidata.ucar.edu/
===============================================================================
#!/opt/bin/perl
  use NetCDF ;
  $ncid   = NetCDF::create("demo.nc", NetCDF::CLOBBER ) ;
  $dimid = NetCDF::dimdef($ncid, 'recNum', NetCDF::UNLIMITED);
  $stadim = NetCDF::dimdef($ncid,"stations",10) ;
  $strlen = 10 ;
  $strdim = NetCDF::dimdef($ncid,"strlen", $strlen) ;
  $varid  = NetCDF::vardef($ncid,"station",NetCDF::CHAR,[$dimid,$strdim]);
  NetCDF::endef($ncid) ;

  @names = ( "abcdef", "ABCDEF","A", "B", "C", "D", "E", "F", "G", "H" ) ;
  for ($i = 0 ; $i < 10 ; $i++ ) {
      $names[ $i ] = padstr( $names[ $i ], $strlen ) ;
      NetCDF::varput( $ncid, $varid, [$i,0], [1, $strlen], \$names[ $i ] ) ;
      #NetCDF::varput( $ncid, $varid, [$i,0], [1,10], "??????????" ) ;
      }

  #NetCDF::varput( $ncid, $varid, [3,2], [2,7], \@names ) ;

  NetCDF::close($ncid) ;

        
# pad str to correct length
sub padstr
{
( $str, $len ) = @_ ;

my( $size, $i ) ;

$size = length( $str ) ;

for( $i = $size; $i < $len; $i++ ) {
        $str .= "\0" ;
        #print "$str,\n" ;
}
if( $size > $len ) {
        print STDOUT "String length is over $len chars long:\n $str\n" ;
        $str = substr( $str, 0, $len ) ;
        #exit 0 ;
}
return $str ;
}
__END__

And this is what I get from ncdump:

ncdump demo.nc
netcdf demo {
dimensions:
        recNum = UNLIMITED ; // (10 currently)
        stations = 10 ;
        strlen = 10 ;
variables:
        char station(recNum, strlen) ;
data:

 station =
  "abcdef",
  "ABCDEF",
  "A",
  "B",
  "C",
  "D",
  "E",
  "F",
  "G",
  "H" ;
}