./
write_csv_pp.pro
Author information
- Author
Paulo Penteado (http://www.ppenteado.net), Feb/2013 This file contains write_csv_pp, and a copy of IDL's write_csv routines (renamed write_csv_pp_original and write_csv_convert_pp_original), since write_csv_pp requires an edit on the original write_csv.
Routines
result = write_csv_convert_pp_original(data)
write_csv_pp_original, Filename, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, HEADER=HEADER, TABLE_HEADER=TABLE_HEADER, append=append
The WRITE_CSV procedure writes data to a "comma-separated value" (comma-delimited) text file.
write_csv_pp, file, data1 [, data2] [, data3] [, data4] [, data5] [, data6] [, data7] [, data8] [, titlesfromfields=titlesfromfields] [, divide=divide] [, _ref_extra=_ref_extra] [, verbose=verbose]
A simple wrapper for write_csv, to write csv files using a structure's field names as column titles (setting titlesfromfields), ccepting nested structures, and with the option of writing the file by pieces.
Routine details
top source write_csv_convert_pp_original
result = write_csv_convert_pp_original(data)
Parameters
- data
Statistics
Lines: | 37 lines |
McCabe complexity: | 4 |
top source write_csv_pp_original
write_csv_pp_original, Filename, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, HEADER=HEADER, TABLE_HEADER=TABLE_HEADER, append=append
The WRITE_CSV procedure writes data to a "comma-separated value" (comma-delimited) text file.
This routine writes CSV files consisting of an optional line of column headers, followed by columnar data, with commas separating each field. Each row is a new record.
This routine is written in the IDL language. Its source code can be found in the file write_csv.pro in the lib subdirectory of the IDL distribution.
Parameters
- Filename
A string containing the name of the CSV file to write.
- Data1
The data values to be written out to the CSV file. The data arguments can have the following forms: * Data1 can be an IDL structure, where each field contains a one-dimensional array (a vector) of data that corresponds to a separate column. The vectors must all have the same number of elements, but can have different data types. If Data1 is an IDL structure, then all other data arguments are ignored. * Data1 can be a two-dimensional array, where each column in the array corresponds to a separate column in the output file. If Data1 is a two-dimensional array, then all other data arguments are ignored. * Data1...Data8 are one-dimensional arrays (vectors), where each vector corresponds to a separate column in the output file. Each vector can have a different data type.
- Data2
- Data3
- Data4
- Data5
- Data6
- Data7
- Data8
Keywords
- HEADER
Set this keyword equal to a string array containing the column header names. The number of elements in HEADER must match the number of columns provided in Data1...Data8. If HEADER is not present, then no header row is written.
TABLE_HEADER Set this keyword to a scalar string or string array containing extra table lines to be written at the beginning of the file.
- TABLE_HEADER
- append
Author information
- History:
Written, CT, VIS, Nov 2008 MP, VIS, Oct 2009: Added keyword SKIP_HEADER Dec 2010: Better handling for byte and double precision data.
Statistics
Lines: | 140 lines |
McCabe complexity: | 21 |
top source write_csv_pp
write_csv_pp, file, data1 [, data2] [, data3] [, data4] [, data5] [, data6] [, data7] [, data8] [, titlesfromfields=titlesfromfields] [, divide=divide] [, _ref_extra=_ref_extra] [, verbose=verbose]
A simple wrapper for write_csv, to write csv files using a structure's field names as column
titles (setting titlesfromfields
), ccepting nested structures, and with the option of writing the
file by pieces.
Parameters
- file in required type=string
Passed to write_csv, specifies the name of the file to write.
- data1 in required
Passed to write_csv, after the variable has its structures flattened by a call to
pp_struct_unravel
.- data2 in optional
Passed unaltered to write_csv.
- data3 in optional
Passed unaltered to write_csv.
- data4 in optional
Passed unaltered to write_csv.
- data5 in optional
Passed unaltered to write_csv.
- data6 in optional
Passed unaltered to write_csv.
- data7 in optional
Passed unaltered to write_csv.
- data8 in optional
Passed unaltered to write_csv.
Keywords
- titlesfromfields in optional
If set, the column titles in the csv file are made by the field names in data1.
- divide in optional default=1
Used to split the file writing into
divide
pieces. This is useful to save memory, since IDL's
write_csv
creates a temporary string array with the whole file contents, before writing it to the file, and that array can be several times larger than the input array.
- _ref_extra in out optional
Any other parameters are passed, unaltered, to / from write_csv.
- verbose in optional default=0
If set, write_csv_pp will inform which piece of the file it is currently writing
Examples
Make a simple structure array and write it to a csv file:
s={a:1,b:{c:2.5,d:-9,e:0},f:1.8}
s2=replicate(s,2)
s2[1].a=-1
s2[1].f=-1.8
write_csv_pp,'write_csv_pp_test.csv',s2,/titlesfromfields
;A,B_C,B_D,B_E,F
;1,2.50000,-9,0,1.80000
;-1,2.50000,-9,0,-1.80000
Author information
- Author:
Paulo Penteado (http://www.ppenteado.net), Feb/2013
Other attributes
- Requires:
Statistics
Lines: | 39 lines |
McCabe complexity: | 5 |
File attributes
Modification date: | Thu Oct 9 14:27:01 2014 |
Lines: | 350 |
Docformat: | rst rst |