Re: write widget_table out to file? [message #62252] |
Fri, 29 August 2008 11:37 |
Juggernaut
Messages: 83 Registered: June 2008
|
Member |
|
|
On Aug 29, 1:57 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> Mike wrote:
>> I'd like to write the contents of a widget_table to a file. Seems
>> like something someone else may have already implemented. Do any of
>> you have something that your willing to share?
>
>> Mike
>
> WIDGET_CONTROL, table_ID, GET_VALUE=tblValue
>
> openW, lun, filename, /get_lun
> printf, lun, tblValue
> close,lun
> free_lun, lun
>
> Jean
Well if you want to take the easy way out....
|
|
|
Re: write widget_table out to file? [message #62253 is a reply to message #62252] |
Fri, 29 August 2008 10:57  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Mike wrote:
> I'd like to write the contents of a widget_table to a file. Seems
> like something someone else may have already implemented. Do any of
> you have something that your willing to share?
>
> Mike
WIDGET_CONTROL, table_ID, GET_VALUE=tblValue
openW, lun, filename, /get_lun
printf, lun, tblValue
close,lun
free_lun, lun
Jean
|
|
|
Re: write widget_table out to file? [message #62254 is a reply to message #62253] |
Fri, 29 August 2008 11:05  |
Juggernaut
Messages: 83 Registered: June 2008
|
Member |
|
|
On Aug 29, 2:01 pm, Bennett <juggernau...@gmail.com> wrote:
> On Aug 29, 12:54 pm, Mike <Michael.Mill...@gmail.com> wrote:
>
>> I'd like to write the contents of a widget_table to a file. Seems
>> like something someone else may have already implemented. Do any of
>> you have something that your willing to share?
>
>> Mike
>
> PRO write_csv, array, columnHeaders, $
> FILENAME=filename, $
> WIDTH=width
>
> ON_ERROR, 1
> IF n_elements(array) EQ 0 THEN $
> MESSAGE, 'No Array Passed.', /INFORMATIONAL
> type = size(array, /type)
> IF type EQ 10 THEN BEGIN
> IF size(array, /n_dimensions) GT 1 THEN $
> MESSAGE, 'Pointer can only be 1D.', /INFORMATIONAL
> max_size=intarr(n_elements(array))
> FOR i = 0, n_elements(array)-1 DO max_size[i]=(size(*array[i))[1]
> sData = strarr(n_elements(array), max(max_size))
> FOR i = 0, max(max_size)-1 DO BEGIN
> FOR j = 0, n_elements(array)-1 DO BEGIN
> IF i GT max_size[j]-1 THEN sData[j,i] = '' ELSE $
> sData[j,i]=(*array[j])[i]
> ENDFOR
> ENDFOR
> ENDIF
>
> ndims = size(array, /n_dimensions)
> sz = size(array)
> IF n_elements(columnHeaders) NE 0 THEN BEGIN
> length = n_elements(columnHeaders)
> IF length NE sz[ndims] THEN $
> MESSAGE, 'Column Header Vector Incorrect Size.', /INFORMATIONAL
> ENDIF
>
> IF n_elements(filename) EQ 0 THEN $
> filename=dialog_pickfile(/WRITE, file='yourdata.csv')
> IF filename EQ '' THEN RETURN
> IF n_elements(width) EQ 0 THEN width=1600
> IF type EQ 10 THEN xsize=n_elements(array) ELSE xsize=sz[ndims-1]
>
> OPENW, lun, filename, /get_lun, width=width
> IF n_elements(columnHeaders) NE 0 THEN BEGIN
> sColumns = strtrim(columnHeaders,2)
> sColumns[0:xsize-2] = sColumns[0:xsize-2] + ','
> PRINTF, lun, sColumns
> ENDIF
>
> IF type NE 10 THEN sData = strtrim(array,2)
>
> sData[0:xsize-2,*] = sData[0:xsize-2,*] + ','
> PRINTF, lun, sData
> CLOSE, lun
> FREE_LUN, lun
> END
The table from the widget has data in a 2D array in my experience
which is what you'd want to put in as the input "array" to the
write_csv function
|
|
|
Re: write widget_table out to file? [message #62255 is a reply to message #62253] |
Fri, 29 August 2008 11:03  |
Juggernaut
Messages: 83 Registered: June 2008
|
Member |
|
|
On Aug 29, 2:01 pm, Bennett <juggernau...@gmail.com> wrote:
> On Aug 29, 12:54 pm, Mike <Michael.Mill...@gmail.com> wrote:
>
>> I'd like to write the contents of a widget_table to a file. Seems
>> like something someone else may have already implemented. Do any of
>> you have something that your willing to share?
>
>> Mike
>
> PRO write_csv, array, columnHeaders, $
> FILENAME=filename, $
> WIDTH=width
>
> ON_ERROR, 1
> IF n_elements(array) EQ 0 THEN $
> MESSAGE, 'No Array Passed.', /INFORMATIONAL
> type = size(array, /type)
> IF type EQ 10 THEN BEGIN
> IF size(array, /n_dimensions) GT 1 THEN $
> MESSAGE, 'Pointer can only be 1D.', /INFORMATIONAL
> max_size=intarr(n_elements(array))
> FOR i = 0, n_elements(array)-1 DO max_size[i]=(size(*array[i))[1]
> sData = strarr(n_elements(array), max(max_size))
> FOR i = 0, max(max_size)-1 DO BEGIN
> FOR j = 0, n_elements(array)-1 DO BEGIN
> IF i GT max_size[j]-1 THEN sData[j,i] = '' ELSE $
> sData[j,i]=(*array[j])[i]
> ENDFOR
> ENDFOR
> ENDIF
>
> ndims = size(array, /n_dimensions)
> sz = size(array)
> IF n_elements(columnHeaders) NE 0 THEN BEGIN
> length = n_elements(columnHeaders)
> IF length NE sz[ndims] THEN $
> MESSAGE, 'Column Header Vector Incorrect Size.', /INFORMATIONAL
> ENDIF
>
> IF n_elements(filename) EQ 0 THEN $
> filename=dialog_pickfile(/WRITE, file='yourdata.csv')
> IF filename EQ '' THEN RETURN
> IF n_elements(width) EQ 0 THEN width=1600
> IF type EQ 10 THEN xsize=n_elements(array) ELSE xsize=sz[ndims-1]
>
> OPENW, lun, filename, /get_lun, width=width
> IF n_elements(columnHeaders) NE 0 THEN BEGIN
> sColumns = strtrim(columnHeaders,2)
> sColumns[0:xsize-2] = sColumns[0:xsize-2] + ','
> PRINTF, lun, sColumns
> ENDIF
>
> IF type NE 10 THEN sData = strtrim(array,2)
>
> sData[0:xsize-2,*] = sData[0:xsize-2,*] + ','
> PRINTF, lun, sData
> CLOSE, lun
> FREE_LUN, lun
> END
Hope that helps...at least get you on the right path. It's something
I've used in the path to write out data in a pointer or in a 2D array.
|
|
|
Re: write widget_table out to file? [message #62256 is a reply to message #62253] |
Fri, 29 August 2008 11:01  |
Juggernaut
Messages: 83 Registered: June 2008
|
Member |
|
|
On Aug 29, 12:54 pm, Mike <Michael.Mill...@gmail.com> wrote:
> I'd like to write the contents of a widget_table to a file. Seems
> like something someone else may have already implemented. Do any of
> you have something that your willing to share?
>
> Mike
PRO write_csv, array, columnHeaders, $
FILENAME=filename, $
WIDTH=width
ON_ERROR, 1
IF n_elements(array) EQ 0 THEN $
MESSAGE, 'No Array Passed.', /INFORMATIONAL
type = size(array, /type)
IF type EQ 10 THEN BEGIN
IF size(array, /n_dimensions) GT 1 THEN $
MESSAGE, 'Pointer can only be 1D.', /INFORMATIONAL
max_size=intarr(n_elements(array))
FOR i = 0, n_elements(array)-1 DO max_size[i]=(size(*array[i))[1]
sData = strarr(n_elements(array), max(max_size))
FOR i = 0, max(max_size)-1 DO BEGIN
FOR j = 0, n_elements(array)-1 DO BEGIN
IF i GT max_size[j]-1 THEN sData[j,i] = '' ELSE $
sData[j,i]=(*array[j])[i]
ENDFOR
ENDFOR
ENDIF
ndims = size(array, /n_dimensions)
sz = size(array)
IF n_elements(columnHeaders) NE 0 THEN BEGIN
length = n_elements(columnHeaders)
IF length NE sz[ndims] THEN $
MESSAGE, 'Column Header Vector Incorrect Size.', /INFORMATIONAL
ENDIF
IF n_elements(filename) EQ 0 THEN $
filename=dialog_pickfile(/WRITE, file='yourdata.csv')
IF filename EQ '' THEN RETURN
IF n_elements(width) EQ 0 THEN width=1600
IF type EQ 10 THEN xsize=n_elements(array) ELSE xsize=sz[ndims-1]
OPENW, lun, filename, /get_lun, width=width
IF n_elements(columnHeaders) NE 0 THEN BEGIN
sColumns = strtrim(columnHeaders,2)
sColumns[0:xsize-2] = sColumns[0:xsize-2] + ','
PRINTF, lun, sColumns
ENDIF
IF type NE 10 THEN sData = strtrim(array,2)
sData[0:xsize-2,*] = sData[0:xsize-2,*] + ','
PRINTF, lun, sData
CLOSE, lun
FREE_LUN, lun
END
|
|
|