From deanne@teal.csn.org (Deanne Pecora)
Newsgroups: misc.invest.technical
Subject: Info on TC2000 data format [partial answer]
Date: Tue, 19 Apr 1994 12:52:37 GMT

A few days ago someone posted a message asking about the TeleChart data 
format.  I figured out part of it a while ago.  

Each record in the file consists of six 32-bit words.  

The first record is 24 characters containing the name of the stock or
fund, possibly including the exchange.  The 24'th character is a * if
the item is on the "hot list".  

I have not been able to make any sense out of the next six-word record. 
I have tried looking at the data as fixed, float, short integer, etc. 
If anyone knows what they mean, please post or e-mail me.  

All of the remaining records are data--date, high, low, close, volume,
open.

The program following this message reads and prints the title, header,
and first ten data records of a TeleChart file.  I have not been able
to find information in the file (in the mysterious second record?) as
to the number of data records.  To modify the program to read an entire
data file, you need to modify the "for loop" to check for end-of-file.
The program was written for MicroSoft C 5.0.

                                        Deanne Pecora

------------------------------ CUT HERE ------------------------------

/* Reads TeleChart data file.  */
/* Compile and link with   cl /Zl readtc.c /link em slibfp slibc libh */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#define FIELDS 6

int main( argc,	argv )
    int argc;
    char *argv[];
{
    FILE *file_in;
    int stat, nrec, i;
    float ftemp[FIELDS], mstemp[FIELDS];
    char title[24];
    
    if ( argc < 2 )
    	{
	printf( "Usage:  readtc <file>" );
	exit(1);
	}

    if( (file_in = fopen(argv[1], "r+b")) == NULL)
        {
        printf("\n\nError opening file %s\n", argv[1]);
        exit(1);
        }

    /* Read the first 6 words (24 chars) of title data */        
    stat = fread(title, sizeof(char), 24, file_in);
    printf("\n\nTitle record \"%24s\"", title);

    /* Read the next 6 words -- what are they?? */
    /* Word 8 seems to be a data value; words 10 and 11 always 0.0 */

    stat = fread(mstemp, sizeof(float), FIELDS, file_in);
    stat = fmsbintoieee(&mstemp[0], &ftemp[0]);
    stat += fmsbintoieee(&mstemp[1], &ftemp[1]);
    stat += fmsbintoieee(&mstemp[2], &ftemp[2]);
    stat += fmsbintoieee(&mstemp[3], &ftemp[3]);
    stat += fmsbintoieee(&mstemp[4], &ftemp[4]);
    stat += fmsbintoieee(&mstemp[5], &ftemp[5]);

    if(stat)
        printf("\nError in record %d", i);
    else     
        printf("\n\nHeader record\n   %.0f  %.3f  %.1f  %.2f  %.2f  %.1f\n",
           ftemp[0], ftemp[1], ftemp[2], ftemp[3], ftemp[4], ftemp[5]);

    /* Now start reading the data records (6 fields per record) */
    /* Data is  Date, High, Low, Close, Volume, Open */
    
    for(i=1; i<=10; i++)
        {
        stat = fread(mstemp, sizeof(float), FIELDS, file_in);
        stat = fmsbintoieee(&mstemp[0], &ftemp[0]);
        stat += fmsbintoieee(&mstemp[1], &ftemp[1]);
        stat += fmsbintoieee(&mstemp[2], &ftemp[2]);
        stat += fmsbintoieee(&mstemp[3], &ftemp[3]);
        stat += fmsbintoieee(&mstemp[4], &ftemp[4]);
        stat += fmsbintoieee(&mstemp[5], &ftemp[5]);

        if(stat)
	    printf("\nError in record %d", i);
	else     
            printf("\nRec %d:  %.0f  %9.3f  %9.3f  %9.3f  %7.0f  %9.3f",
               i, ftemp[0], ftemp[1], ftemp[2], ftemp[3], ftemp[4], ftemp[5]);
        }

    if(fclose(file_in)==EOF)
        printf("\n\nError closing file");
    else  
        printf("\n\nFile closed OK\n\n");

    exit(0);    
    }


