help-octave
[Top][All Lists]
Advanced

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

Re: equivalent for C-style init: structname varname[] = {...} ?


From: Dimitri Maziuk
Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
Date: Mon, 19 Nov 2012 11:35:57 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.10) Gecko/20121030 Thunderbird/10.0.10

On 11/19/2012 09:59 AM, Jordi Gutiérrez Hermoso wrote:

> Right, if you have in C
> 
>     typedef struct {
>         const char* name;
>         float value;
>     } S;
> 
>     S s = {"hello", 3.14},
> 
>     printf("%s = %f\n", s.name, s.value);
> 
> Then in Octave you can do,
> 
>     s.name = "hello";
>     s.value = single(3.14) ## You wanted single, not double, right?
> 
>     printf("%s = %f\n", s.name, s.value);
> 
> amongst other possible syntaxes for defining a struct.
> 
> Struct arrays are similar in Octave and C too, except that Octave
> allows a different way of indexing struct arrays that C doesn't.

Yeah right. So how come
    rc = [];
    row = [];
    resno = tbl( 1 ).idx;
    for i = tbl
        if( i.idx != resno )
            row( 1 ) = resno;
            row( 2 ) = i.resid;
            if( (row( 3 ) + row( 4 )) > -200 )
                 rc = [ rc ; row ];
            endif
            for j = 3 : 9
                row( j ) = -100.0;
            endfor
        endif
        switch( toupper( i.atomid ) )
            case "CA" ; row( 3 ) = i.val;
            case "CB" ; row( 4 ) = i.val;
            case "HA"
                row
                row( 5 )
                i
                i.val
                row( 5 ) = i.val;
...

Output:
---------------------------------------------------

octave:1> rc = pipe2lacs( "../88268_3.txt" )
row =

    49    14  -100  -100  -100  -100  -100  -100  -100

ans = -100
i =

  scalar structure containing the fields:

    idx = 2
    resid =  14
    atomid = HA
    val = 4.410

ans = 4.410
error: pipe2lacs: A(I) = X: X must have the same size as I
------------------------------------------------

this is on "row( 5 ) = i.val;" line... the fun part is I can break out
into debug mode and type "row( 5 ) = i.val" and it will work without error.

Because map ("hash", red-black, doesn't matter) values are all of "class
T" -- either strings or numbers, but not both. What's amazing is that
sometimes octave actually manages to cast them to the right type.

-- 
Dimitri Maziuk
Programmer/sysadmin
BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]