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.
On 8 May 2000, Jason Burks wrote: > > Robb, > I have some code that can be used to decode the strings read out of > the netcdf files in a slightly different manner than your example on > the support archives. This method uses the pack command. Just thought > I would send you the code: > This example reads out the station name into @statName list which is > decoded in the for loop and pushed into the @nameid list, an entry for > each station. $length is the max length of the string. > > ###################################################################### > NetCDF::varget($ncid,$varidName,\@start,\@count,\@statName); > > for ($counter=0; $counter<$#statName; $counter=$counter+$length-1) { > push @nameid, pack("C*",@statName[$counter..$counter+$length-1]); > } > ###################################################################### > Jason, Yes, the pack code is a much cleaner solution. Never thought of using it until lately. Will keep the code on-hand for future reference. Thanks, Robb... > Thought you might be interested in this. This is an alternative to the > code below: > > > for( $i = 0; $i <= $#STNS; $i += 4 ) { > for( $j = $i; $j < ( $i + $stn_name_len ); $j++ ) { > $station .= chr( $STNS[ $j ] ) ; > } > print "Station = $station\n" ; > undef( $station ) ; > } > > Jason > =============================================================================== Robb Kambic Unidata Program Center Software Engineer III Univ. Corp for Atmospheric Research address@hidden WWW: http://www.unidata.ucar.edu/ ===============================================================================