“结构”的版本间差异

来自Shiyin's note
跳到导航 跳到搜索
第4行: 第4行:
===结构(数组)的生成===
===结构(数组)的生成===
str = mrd_struct(['fld1', 'fld2'], ['0','dblarr(10,10)'],3)
str = mrd_struct(['fld1', 'fld2'], ['0','dblarr(10,10)'],3)
;调用create_struct,但是远比create_struct方便
''调用create_struct,但是远比create_struct方便''


===重命名Tags:rename_tags===
===重命名Tags:rename_tags===
newstruct = rename_tags(struct, oldtagnames, newtagnames)
newstruct = rename_tags(struct, oldtagnames, newtagnames)
''适用于同时重命名多个Tags''

===增加Tags: add_tag和add_tags===
===增加Tags: add_tag和add_tags===
*add_tag 一次增加一个tag
*add_tag 一次增加一个tag
add_tag, oldstruct, tagname, tagtype, newstruct, structyp=structyp
add_tag, oldstruct, tagname, tagtype, newstruct, structyp=structyp
;structyp: a string with the name of the new structure. f already defined the program will crash.
''structyp: a string with the name of the new structure. f already defined the program will crash.''


*add_tags 可以同时增加多个Tag
*add_tags 可以同时增加多个Tag
第18行: 第18行:
values =['0d', '0d', 'intarr(1000, 1000)', "'NGC3035'"]
values =['0d', '0d', 'intarr(1000, 1000)', "'NGC3035'"]
add_tags, oldstruct, tagnames, values,new_struct
add_tags, oldstruct, tagnames, values,new_struct
;参见jadd_tag的程序[http://astro.berkeley.edu/~johnjohn/idl.html#JJADD_TAG]
''参见jadd_tag的程序[http://astro.berkeley.edu/~johnjohn/idl.html#JJADD_TAG]''


===删除Tags: remove_tags===
===删除Tags: remove_tags===
newstruct = remove_tags(oldstruct, tagnames)
newstruct = remove_tags(oldstruct, tagnames)
;可以同时移除多个Tags,tagname是个数组即可
''可以同时移除多个Tags,tagname是个数组即可''


===其它===
===其它===

2014年12月16日 (二) 09:25的版本

结构(数组)的生成和修改

sdssidl里面有一组程序,可以更好的生成和编辑结构,且完全适用于结构数组

结构(数组)的生成

str = mrd_struct(['fld1', 'fld2'], ['0','dblarr(10,10)'],3)

调用create_struct,但是远比create_struct方便

重命名Tags:rename_tags

newstruct = rename_tags(struct, oldtagnames, newtagnames)

适用于同时重命名多个Tags

增加Tags: add_tag和add_tags

  • add_tag 一次增加一个tag
add_tag, oldstruct, tagname, tagtype, newstruct, structyp=structyp

structyp: a string with the name of the new structure. f already defined the program will crash.

  • add_tags 可以同时增加多个Tag
tagnames=['ra', 'dec', 'image', 'name']
values  =['0d', '0d',  'intarr(1000, 1000)', "'NGC3035'"]
add_tags, oldstruct, tagnames, values,new_struct

参见jadd_tag的程序[1]

删除Tags: remove_tags

newstruct = remove_tags(oldstruct, tagnames) 可以同时移除多个Tags,tagname是个数组即可

其它

  • 结构很容易增加一个tag,比如
A= {tag1:0.,tag2:'Name'}
B=create_struct(A,'tag3',1L)
  • 结果数组经常被用来读入数据文件,如果该数据文件加上一列数据,如何较方便的操作。
一种方法如下:
A= {tag1:0.,tag2:'Name'}
B= {tag1:1.,tag2:'Name2',tag3:10L}
A2=  replicate(A,10)
B2 = replicate(B,10)
struct_assign,A,B ;把A的数值付给B
print,B ;可以看到B的前两列已经变成A的数值,但B的第三列被充0,所以这时候可以再给B.tag3赋值。
还有一种方法,但没上面那么直观
str={a: 0l, b: }
str_arr=REPLICATE(str,10)
ref_str = reform_struct(str_arr, /tag_array, 10)
ref_str = create_struct(ref_str, 'c' ,make_array(10))
help, ref_str, /str