[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kst-plot] /: Add SINDIR type to dirfile_maker test
From: Barth Netterfield <null () kde ! org>
Date: 2018-08-30 21:59:46
Message-ID: E1fvUyg-00088B-OY () code ! kde ! org
[Download RAW message or body]
Git commit bed17c1116fbdc7f111f0b4cf7726178a9c2c895 by Barth Netterfield.
Committed on 30/08/2018 at 21:59.
Pushed by netterfield into branch 'master'.
Add SINDIR type to dirfile_maker test
A +82 -0 devel-docs/dirfile_strings_sindir.notes
M +23 -3 tests/dirfile_maker/dirfile_maker.c
https://commits.kde.org/kst-plot/bed17c1116fbdc7f111f0b4cf7726178a9c2c895
diff --git a/devel-docs/dirfile_strings_sindir.notes b/devel-docs/dirfile_strings_sindir.notes
new file mode 100644
index 00000000..d755c689
--- /dev/null
+++ b/devel-docs/dirfile_strings_sindir.notes
@@ -0,0 +1,82 @@
+Before I forget about this, here's some notes on string vector fields in
+GetData-0.10, in case you're still interested in adding support for them
+into kst:
+
+
+- A scalar string array (SARRAY) is declared like this:
+
+ sarray_field SARRAY string0 string1 string2 string3 ...
+
+
+
+- A string vector field (SINDIR) is declared like this:
+
+ field SINDIR index_field sarray_field
+
+ Where "index_field" is interpreted as an integer. If
+ index_field[i] = n, then field[i] = sarray_field[n]. The SINDIR has
+ the same number of samples-per-frame as index_field. SARRAY indices
+ start from zero.
+
+
+
+- The dirfile->VectorList() function doesn't include SINDIRs in the
+ list it returns (just numeric vector fields), which means no changes
+ should be needed in kst to use GetData-0.10 as-is.
+
+ Use _dirfile->FieldListByType(SindirEntryType) to get a list of
+ SINDIRs.
+
+
+
+- In C++, to retrieve SINDIR data, there's an alternate function signature
+ for _dirfile->GetData lacking the DataType field:
+
+ size_t GetData(const char *field_code, gd_off64_t first_frame,
+ gd_off64_t first_sample, size_t num_frames, size_t
+ num_samples, const char** data_out) const;
+
+ It fills data_out[] with pointers to immutable C strings. The
+ pointers point directly into the SARRAY data store, so don't call
+ free() on them.
+
+
+
+- Internally, GetData doesn't think of SINDIR data as strings, but as
+ integers of width sizeof(const char*). It treats the SARRAY field as
+ a non-interpolated lookup table to map values of the index field
+ into pointers values (=integers) which it returns.
+
+ As a result, if two samples of the index_field are equal, then the
+ pointers returned for those two samples are equal as well. (This is
+ stronger than just saying that the two string values on those samples
+ are the same.)
+
+
+
+- On samples where the index_field is out of range of the SARRAY, NULL
+ is returned.
+
+
+
+- Calling _dirfile->SamplesPerFrame() on a SINDIR works (you get the SPF
+ of the index field).
+
+
+
+- Calling _dirfile->NativeType() on a SINDIR will return
+ GetData::String (which it also does for SARRAY and STRING fields).
+
+
+
+- For backwards compatibility, you can use the GD_GETDATA_INT_VERSION CPP
+ macro, introduced in GetData-0.9, for conditional compilation of
+ GetData-0.10 features:
+
+ #if defined GD_GETDATA_INT_VERSION && GD_GETDATA_INT_VERSION >= 1000
+ ...
+ #endif
+
+-don
+
+
diff --git a/tests/dirfile_maker/dirfile_maker.c b/tests/dirfile_maker/dirfile_maker.c
index a8ccf6e5..369b78ea 100644
--- a/tests/dirfile_maker/dirfile_maker.c
+++ b/tests/dirfile_maker/dirfile_maker.c
@@ -15,7 +15,7 @@ struct DFEntryType {
char type;
};
-#define NDF 16
+#define NDF 17
#define SCOUNT 0
#define FCOUNT 1
#define SINE 2
@@ -23,7 +23,8 @@ struct DFEntryType {
#define COS 4
#define TIME 5
#define HASNANS 6
-#define EXTRA 7
+#define STRIDX 7
+#define EXTRA 8
struct DFEntryType df[NDF] = {
{"scount", 1, -1, 'f'},
@@ -33,6 +34,7 @@ struct DFEntryType df[NDF] = {
{"cos", 20, -1, 'f'},
{"time", 20, -1, 'd'},
{"hasnans", 20, -1, 'f'},
+ {"stridx", 1, -1, 'u'},
{"E0", 20, -1, 'f'},
{"E1", 20, -1, 'f'},
{"E2", 20, -1, 'f'},
@@ -51,6 +53,7 @@ int main() {
int i, count = 0;
int j;
float x;
+ unsigned short idx;
double dx;
struct timeval tv;
@@ -92,8 +95,17 @@ int main() {
"META cos metaS STRING Test_String\n");
fprintf(fpf, "cos/units STRING ^o\ncos/quantity STRING Angle\n");
+
+ // SARRAY type
+ fprintf(fpf, "namearray SARRAY ");
+ for (i=0; i<20; i++) {
+ fprintf(fpf, " LABEL%02d", i);
+ }
+ fprintf(fpf, "\n");
fclose(fpf);
+ // SINDIR type
+ fprintf(fpf, "label SINDIR stridx namearray\n");
printf("starting loop\n");
while (1) {
@@ -162,8 +174,16 @@ int main() {
}
}
+ /* write 'stridx' */
+ idx = (count/10)%20;
+ nw = write(df[STRIDX].fp, &idx, sizeof(unsigned short));
+ if (nw<0) {
+ fprintf(stderr, "error writing stridx\n");
+ }
+
+
/* write extras */
- for (j=6; j<NDF; j++) {
+ for (j=EXTRA; j<NDF; j++) {
for (i=0; i<df[j].spf; i++) {
x = (double)rand()/(double)RAND_MAX;
nw = write(df[j].fp, &x, sizeof(float));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic