cdds_in is called to initialize an input dictionary. A temporary dictionary name is returned, along with any dictionaries specified by the user/default. It provides the title and a copy of the bootstrap dictionaries (par:). The resulting dictionaries are left in "scan" mode.
This is normally followed by a call to cdds_open to open the binary stream associated with the dictionary.
in_dict = cdds_in("in", "stdin:", title); in_bin = cdds_open(in_dict, "in_format", "in_data", "r"); if (in_bin < 0) { cdds_prterr("Unable to open input data\n"); } cdds_scanf("size.axis(1)", "%d", &ns);
Another example is to open a velocity file with no default.
vel_dict = cdds_in("vel", " ", title); vel_bin = cdds_open(vel_dict, "vel_format", "vel_data", "r");
A dataset may not be in a host-dependent format with which a program can work. So an internal buffer binary must be defined and opened. This is done creating a temporary internal buffer dictionary and defining the desired fields in a host-dependent format (typically "asp" and then opening the binary stream. You can write modification definitions to the "override:" internal dictionary via the "MOD_FIELD" definition. (See Process Data to see how to map the input buffer to this internal buffer.)
/* "override:" overrides any existing definitions. */ cdds_dict("override:", "print"); cdds_printf("MOD_FIELD", "*+ int StaCor;\n"); cdds_printf(" ", "*+ float SrcX;\n"); cdds_printf(" ", "*+ SAMPLE_TYPE Samples[axis_size(1)];\n"); cdds_printf("fmt:*:asp.SAMPLE_TYPE", "typedef float SAMPLE_TYPE;\n");
The application can open binary data using this internal "asp" format. The open mode is "m" (memory), because external I/O to a stream is not required. The data will only reside within buffers provided by the application (buf) or by cdds_write.
int buf_bin; const char *buf_dict; ... /* Initialize "buf_dict" dictionary */ buf_dict = cdds_out(" ", " ", in_dict); cdds_printf("buf_format", " asp\n"); /* Open "buf" binary (see "override:") */ buf_bin = cdds_open(buf_dict, "buf_format", " ", "m"); /* close out the override: dictionary */ cdds_dict("override:", "reset");
There are several ways to access fields within the internal buffer.
int tag, sxindex, smpindex; float srcx, *buf; ... tag = cdds_member(buf_bin, 0, "SrcX"); sxindex = cdds_index(buf_bin, tag, DDS_FLOAT); tag = cdds_member(buf_bin, 0, "Samples"); smpindex = cdds_index(buf_bin, tag, DDS_FLOAT); ... srcx = buf[sxindex]; process(buf[smpindex), ...); ... buf[sxindex] = srcx;
stacortag = cdds_member(buf_bin, 0, "StaCor"); ... cdds_geti(buf_bin, stacortag, buf, 0, stacor, 1);