Main Page   Data Structures   File List   Data Fields   Globals  

disk2chain.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "sadie.h"
00003 #include "chain.h"
00004 
00005 
00006 void DISK2CHAIN (
00007 char *filename,              /* Filename for reading chain code */
00008 CHAIN **chainmap             /* Address of pointer to chain structure */
00009 ) {
00010     unsigned int *startCoord;
00011     unsigned char *code_valid;
00012     LIST_NODE *newLnode, **prevLnode;
00013     CHAIN_NODE *newCnode, **prevCnode;
00014     FILE *fp;
00015 
00016     fp = fopen(filename, "r");
00017     if (fp == NULL) {
00018         MESSAGE('E'," Can't open chain code file.");
00019         goto the_end;
00020     }
00021 
00022     /* Allocate memory for chain structure */
00023     (*chainmap) = (CHAIN *)malloc(sizeof(CHAIN));
00024     startCoord = (unsigned int *)calloc(2, sizeof(unsigned int));
00025     code_valid = (unsigned char *)calloc(2, sizeof(unsigned char));
00026     
00027     /* Read header from file */
00028     fread((char *)&((*chainmap)->nlin), CHAIN_HEADER_SIZE, 1, fp);
00029     (*chainmap)->list = NULL;
00030     prevLnode = (LIST_NODE **)&((*chainmap)->list);
00031 
00032     /* Read chain code from file into chain structure */
00033     while (fread(startCoord, sizeof(unsigned int), 2, fp) == 2) {
00034         newLnode = (LIST_NODE *)malloc(sizeof(LIST_NODE));
00035         newLnode->startj = startCoord[0];
00036         newLnode->startk = startCoord[1];
00037         fread((char *)&(newLnode->ring_type), sizeof(unsigned char), 1, fp);
00038         fread((char *)&(newLnode->ring_id), sizeof(int), 1, fp);
00039         newLnode->chain = NULL;
00040         newLnode->next = NULL;
00041         (*prevLnode) = newLnode;
00042         prevLnode = (LIST_NODE **)&(newLnode->next);
00043         prevCnode = (CHAIN_NODE **)&(newLnode->chain);
00044         fread(code_valid, sizeof(unsigned char), 2, fp);
00045         while (code_valid[0] != TERM_CODE) {
00046             newCnode = (CHAIN_NODE *)malloc(sizeof(CHAIN_NODE));
00047             newCnode->code = code_valid[0];
00048             newCnode->valid = code_valid[1];
00049             newCnode->next = NULL;
00050             (*prevCnode) = newCnode;
00051             prevCnode = (CHAIN_NODE **)&(newCnode->next);
00052             fread(code_valid, sizeof(unsigned char), 2, fp);
00053         }
00054     }
00055     fclose(fp);
00056     
00057  the_end:
00058 }
00059 
00060 
00061 
00062 
00063 

Generated on Wed Apr 9 08:56:05 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002