comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: HDF Data sets containg strings?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: HDF Data sets containg strings? [message #13307 is a reply to message #13302] Mon, 02 November 1998 00:00 Go to previous messageGo to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David Fanning wrote:

> Richard Penrose (rpenrose@uk.ibm.com) writes:
>
>> I would very much like to be able to append an array of three character
>> strings to an HDF file using the 'HDF_SD_ADDDATA' command. I have tried
>> to do this without any luck, and can find no documentation to help me
>> with this.
>>
>> In the end I have had to resort to appending a 3*n dimensional array,
>> i.e. 3 characters * however many dimensions are required.
>>
>> Does anyone have a solution to this problem, I would be most grateful!
>
> I'm no HDF expert by any means, [...]

me neither, but what David suggests next


> [...]. For character data, I guess I would
> use a byte array. [...]

prompts me to adevrtise my str2byte function that may help you getting byte
arrays with fixed length from strings with variable length. Please find it
attached below.

Regards,
Martin.

--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Engineering&Applied Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------



; $Id: str2byte.pro,v 1.1 1998/10/09 19:53:32 mgs Exp $
;----------------------------------------------------------- --
;+
; NAME:
; STR2BYTE (function)
;
; PURPOSE:
; Convert a string into a byte vector of a given length
; for output in binary data files.
;
; CATEGORY:
; Tools
;
; CALLING SEQUENCE:
; bstr = STR2BYTE(string [,length])
;
; INPUTS:
; STRING -> The string to be converted
;
; LENGTH -> Length of the byte vector. Default is to use the
; length of the string. If LENGTH is shorter, the string
; will be truncated, if it is longer, it will be filled
; with blanks (32B).
;
; KEYWORD PARAMETERS:
; none
;
; OUTPUTS:
; A byte vector of the specified length
;
; SUBROUTINES:
;
; REQUIREMENTS:
;
; NOTES:
;
; EXAMPLE:
; ; write a 80 character string into a binary file
; openw,lun,'test.dat',/F77_UNFORMATTED,/get_lun
; writeu,lun,str2byte('Test string',80)
; free_lun,lun
;
; MODIFICATION HISTORY:
; mgs, 24 Aug 1998: VERSION 1.00
;
;-
; Copyright (C) 1998, Martin Schultz, Harvard University
; This software is provided as is without any warranty
; whatsoever. It may be freely used, copied or distributed
; for non-commercial purposes. This copyright notice must be
; kept with any copy of this software. If this software shall
; be used commercially or sold as part of a larger package,
; please contact the author to arrange payment.
; Bugs and comments should be directed to mgs@io.harvard.edu
; with subject "IDL routine str2byte"
;----------------------------------------------------------- --


function str2byte,str,len

if (n_elements(str) eq 0) then return,[0B]

; if len argument is not given, use actual string size
if (n_elements(len) eq 0) then len=strlen(str)
if (len le 0) then return,[0B]

; convert string to byte; cut if too long
bytstr = byte(strmid(str,0,len))

; make result array of desired length
result = bytarr(len)+32B ; byte array, fill with spaces

; copy string into result array
result[0:n_elements(bytstr)-1] = bytstr

return,result

end
  • Attachment: str2byte.pro
    (Size: 2.12KB, Downloaded 85 times)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Differences between ' and ", syntax error (bug?)
Next Topic: Re: Object Surface Shaded by Elevation (LONG)

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 08:57:57 PDT 2025

Total time taken to generate the page: 0.32092 seconds