/* * ====================================================================== * test_hashtable.c : Test functions in Hash Table. * * Copyright (C) 1994-96 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written by: Mark Austin February 1994 * ====================================================================== */ #include #include #include "hashtable.h" #include "miscellaneous.h" #include "aiscsection.h" enum { NameLength = 35 }; void printAiscSection( const AISCSECTION * ); int main( void ) { char *cpErrorMessage = safeMalloc( NameLength*sizeof(char) , __FILE__, __LINE__ ); char *cpNameOfSection = safeMalloc( NameLength*sizeof(char) , __FILE__, __LINE__ ); float fWeight, fArea, fDepth, fWidth; float fBf, fTf, fRt; float fIzz, fIyy, fIxx; AISCSECTION *spAisc; HASHNODE *spNode; FILE *FpIn; int ii; /* [a] : Open "aisc section" file */ FpIn = fopen("AiscSections", "r"); if( FpIn == NULL ) { sprintf( cpErrorMessage,"%s : Error in file %s on line %3i", "Can't open file \"AiscSections\"", __FILE__, __LINE__ ); fatalError( cpErrorMessage, NULL ); } /* [b] : Initialize hash table */ hashTableInit(); /* [c] : Skip over header lines in "AiscSections" file */ for(ii = 1; ii <= NoLinesInHeader; ii++) fgets( cpErrorMessage, NameLength , FpIn ); /* [d] : Read sections from "AiscSections" and install in hash table */ while((fscanf( FpIn, "%s\n %f %f %f %f %f %f %f %f %f %f\n", cpNameOfSection, &fWeight, &fArea, &fDepth, &fWidth, &fBf, &fTf, &fRt, &fIzz, &fIyy, &fIxx)) != EOF) { spNode = hashTableInstall( cpNameOfSection ); spNode->uNode.spAisc = (AISCSECTION *) safeMalloc( sizeof( AISCSECTION ), __FILE__, __LINE__ ); spNode->eType = AiscSection; spNode->uNode.spAisc->cpName = saveString(cpNameOfSection, __FILE__, __LINE__ ); spNode->uNode.spAisc->fWeight = fWeight; /* Weight of Section */ spNode->uNode.spAisc->fArea = fArea; /* Cross Section Area */ spNode->uNode.spAisc->fDepth = fDepth; /* Depth of Section */ spNode->uNode.spAisc->fWidth = fWidth; /* Width of Section */ spNode->uNode.spAisc->fTw = fBf; /* Thickness of Web */ spNode->uNode.spAisc->fTf = fTf; /* Thickness of Flange */ spNode->uNode.spAisc->fRt = fRt; /* Radius of Gyration */ spNode->uNode.spAisc->fIxx = fIxx; /* Inertia about x-x axis */ spNode->uNode.spAisc->fIyy = fIyy; /* Inertia about y-y axis */ spNode->uNode.spAisc->fIzz = fIzz; /* Inertia about z-z azis */ } /* [e] : Close "aisc section" file and tidy up */ fclose ( FpIn ); free( (char *) cpErrorMessage); free( (char *) cpNameOfSection); /* [f] : Print Contents of Hash Table */ hashTablePrint(); /* [g] : Test Lookup and Install facilities */ spNode = hashTableLookup( "W1200x1200" ); if( spNode != NULL ) printAiscSection( spNode->uNode.spAisc ); else printf("Cannot find Section W1200x1200\n"); spNode = hashTableLookup( "W36x260" ); if( spNode != NULL ) printAiscSection( spNode->uNode.spAisc ); else printf("Cannot find Section W36x260\n"); /* [h] : Try to install same section multiple times */ printf("\n"); printf("Install \"Dummy Section\" into Hash Table\n"); spNode = hashTableInstall( "Dummy Section" ); printf("Install \"Dummy Section\" into Hash Table\n"); spNode = hashTableInstall( "Dummy Section" ); printf("Install \"Dummy Section\" into Hash Table\n"); spNode = hashTableInstall( "Dummy Section" ); } /* * ============================================================= * Print components of AISC Section * * Input : const AISCSECTION *spAisc : pointer to AISC section * Output : void * ============================================================= */ void printAiscSection( const AISCSECTION *spAisc ) { printf("AISC Section : Name = \"%s\"\n", spAisc->cpName ); printf(" : Weight = %10.4f\n", spAisc->fWeight); printf(" : Depth = %10.4f\n", spAisc->fDepth ); printf(" : Ixx = %10.4f\n", spAisc->fIxx ); printf(" : Iyy = %10.4f\n", spAisc->fIyy ); printf(" : Izz = %10.4f\n", spAisc->fIzz ); }