source: trunk/SRC/ToBeReviewed/STRUCTURE/struct2string.pro @ 226

Last change on this file since 226 was 226, checked in by pinsard, 17 years ago

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
[226]5;
[150]6; @file_comments
7; Convert a structure to an "executable string"
[2]8;
[150]9; @categories
[157]10; Utilities
[226]11;
[150]12; @param STRUCT {in}{required}
13; A structure
[2]14;
[163]15; @keyword MAX_STRUCT_LENGTH {default=10000l}
[150]16; The maximum length of the structure
[226]17; permitted to convert the structure to string.
[2]18;
[150]19; @keyword DIRECT2STRING
20; To get a string instead an "executable string"
[2]21;
[150]22; @keyword CUT_IN_STRING
23; Try it
[2]24;
[150]25; @restrictions
26; Use tostr.pro, cf this function header!
[2]27;
[150]28; @examples
[2]29;
30;      IDL> print, struct2string(!d)
31;      create_struct('NAME','X','X_SIZE',891,'Y_SIZE',630,'X_VSIZE'
32;      ,891,'Y_VSIZE',630,'X_CH_SIZE',6,'Y_CH_SIZE',10,'X_PX_CM'
[226]33;      ,40.0000,'Y_PX_CM',40.0000,'N_COLORS',16777216,'TABLE_SIZE'
[2]34;      ,256,'FILL_DIST',1,'WINDOW',32,'UNIT',0,'FLAGS',328124,'ORIGIN'
35;      ,[0,0],'ZOOM',[1,1])
36;
[150]37; @history
[157]38; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]39;                      2000 07 03
[150]40;
41; @version
42; $Id$
43;
[2]44;-
45;------------------------------------------------------------
46;------------------------------------------------------------
47;------------------------------------------------------------
[226]48FUNCTION struct2string, struct, CUT_IN_STRING = cut_in_string, MAX_STRUCT_LENGTH = max_struct_length, DIRECT2STRING = direct2string
[114]49;
50  compile_opt idl2, strictarrsubs
51;
[2]52   if size(struct, /type) NE 8 then return,  ''
53   if NOT keyword_set(max_struct_length) then max_struct_length = 10000l
54   if n_tags(struct, /length) GT max_struct_length then begin
55      rien = report('The structure is too big to be converted to string! !C See the MAX_STRUCT_LENGTH keyword')
56      return, ''
57   endif
58   names = tag_names(struct)
59   case 1 of
60      keyword_set(direct2string):BEGIN
61         res = names[0]+'='+tostr(struct.(0))
62         if n_tags(struct) GT 1 then begin
63            FOR i = 1, n_tags(struct)-1 do begin
64               res = res+', '+names[i]+'='+tostr(struct.(i))
65            endfor
66         endif
[226]67
[2]68      END
69      keyword_set(CUT_IN_STRING):BEGIN
70         res = 'create_struct('''+names[0]+''','+tostr(struct.(0))+')'
71         if n_tags(struct) GT 1 then begin
72            FOR i = 1, n_tags(struct)-1 do begin
73               res = [res, 'create_struct(res,'''+names[i]+''','+tostr(struct.(i))+')']
74            endfor
75         endif
76      END
77      ELSE:BEGIN
78         res = 'create_struct('''+names[0]+''','+tostr(struct.(0))
79         if n_tags(struct) GT 1 then begin
80            FOR i = 1, n_tags(struct)-1 do begin
81               res = res+','''+names[i]+''','+tostr(struct.(i))
82            endfor
83         endif
84         res = res+')'
85      END
86   endcase
87   return, res
88end
Note: See TracBrowser for help on using the repository browser.