270 Keysight Signal Generators Programming Guide
Creating and Downloading Waveform Files 
Programming Examples 
    // spreadsheet to help spot any problems.
    FILE *outfile = fopen(ofile, “w”);
    if (outfile==NULL) perror (“Error opening file to write”);
    for(index=0; index<numsamples; index++)
    {
        fprintf(outfile, “%d, %d\n”, idata[index], qdata[index]);
    }
    fclose(outfile);
    // Little endian order data, use the character array and for loop. 
// If big endian order, comment out this character array and for loop, 
// and use the next loop (Big Endian order data).
  // We need a buffer to interleave the I and Q data.  
// 4 bytes to account for 2 I bytes and 2 Q bytes.
char iqbuffer[NUMSAMPLES*4];
// Interleave I and Q, and swap bytes from little
    // endian order to big endian order.
    for(index=0; index<numsamples; index++)
    {
        int ivalue = idata[index]; 
        int qvalue = qdata[index]; 
        iqbuffer[index*4]   = (ivalue >> 8) & 0xFF; // high byte of i
        iqbuffer[index*4+1] = ivalue & 0xFF;        // low byte of i    
        iqbuffer[index*4+2] = (qvalue >> 8) & 0xFF; // high byte of q
        iqbuffer[index*4+3] = qvalue & 0xFF;        // low byte of q
    }
    // Big Endian order data, uncomment the following lines of code.
    // Interleave the I and Q data.  
    // short iqbuffer[NUMSAMPLES*2];            // Big endian order, uncomment this line
    // for(index=0; index<numsamples; index++)  // Big endian order, uncomment this line
    // {                                        // Big endian order, uncomment this line
    //     iqbuffer[index*2]   = idata[index];  // Big endian order, uncomment this line
    //     iqbuffer[index*2+1] = qdata[index];  // Big endian order, uncomment this line
    // }                                        // Big endian order, uncomment this line
 
    // Open a connection to write to the instrument
    INST id=iopen(instOpenString);
    if (!id)