Documentation for pp_lib

Generated by IDLdoc

single page | use frames     summary     class     fields     routine details     file attributes

./

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

Routines from write_csv_pp.pro

result = write_csv_convert_pp_original(data, noquote=noquote)
write_csv_pp_original, Filename, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, HEADER=HEADER, TABLE_HEADER=TABLE_HEADER, append=append, noquote=noquote

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] [, noquote=noquote]

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, noquote=noquote)

Parameters

data

Keywords

noquote

Statistics

Lines:
30 lines
Cyclomatic complexity:
11
Modified cyclomatic complexity:
5

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, noquote=noquote

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
noquote

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:
91 lines
Cyclomatic complexity:
45
Modified cyclomatic complexity:
29

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] [, noquote=noquote]

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

noquote in optional default=0

If set, string fields that do not contain commas or double-quotes will not be quoted. If not set (default), all string fields are quoted.

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,g:'h'} s2=replicate(s,2) s2[1].a=-1 s2[1].f=-1.8 s2[1].g='h,i' write_csv_pp,'write_csv_pp_test.csv',s2,/titlesfromfields
Which result in a file with:

A,B_C,B_D,B_E,F,G

1,2.50000,-9,0,1.80000,"h"

-1,2.50000,-9,0,-1.80000,"h,i"

Compare with using the noquote keyword:

write_csv_pp,'write_csv_pp_test.csv',s2,/titlesfromfields,/noquote

Which produces

A,B_C,B_D,B_E,F,G

1,2.50000,-9,0,1.80000,h

-1,2.50000,-9,0,-1.80000,"h,i"

On the first row, the string (the last column) is unquoted. On the second, it is still quoted because it contains a comma; without this quote, it would look like the row has an extra column.

Author information

Author:

Paulo Penteado (http://www.ppenteado.net), Feb/2013

Other attributes

Requires:

pp_struct_unravel

Statistics

Lines:
38 lines
Cyclomatic complexity:
19
Modified cyclomatic complexity:
19

File attributes

Modification date: Tue May 16 12:27:40 2017
Lines: 159
Docformat: rst rst