void PHolderListMgr::ReadPHolderListDES( char *newfile ) { FILE *fp; fp = fopen( newfile, "r" ); char temp[255]; fgets( temp, 255, fp ); Stringc line = temp; int nparm = line.convert_to_integer(); if( nparm > 0 ) { pHolderListMgrPtr->DelAllPHolders(); vector< Geom* > gVec = aircraftPtr->getGeomVec(); gVec.push_back( aircraftPtr->getUserGeom() ); for ( int i = 0 ; i < nparm ; i++ ) { fgets( temp, 255, fp ); line = temp; int istart = 0; int iend = line.search_for_substring(':'); int id = line.get_range( istart, iend-1 ).convert_to_integer(); istart = iend + 1; iend = line.search_for_substring( istart, ':' ); istart = iend + 1; iend = line.search_for_substring( istart, ':' ); Stringc group = line.get_range( istart, iend-1 ); istart = iend + 1; iend = line.search_for_substring( istart, ':' ); Stringc parm = line.get_range( istart, iend-1 ); istart = iend + 1; iend = line.get_length(); double val = line.get_range( istart, iend-1 ).convert_to_double(); Parm* p = parmMgrPtr->FindParm( gVec, id, group, parm ); if ( p ) { p->set_from_link( val ); p->get_geom()->parm_changed( p ); ParmHolder* ph = new ParmHolder(); ph->setParm( p ); m_PHolderVec.push_back( ph ); m_CurrPHolderIndex = (int)m_PHolderVec.size() - 1; } } } fclose( fp ); }
//===== Read AF File =====// int FuselageXSec::read_xsec_file( Stringc file_name ) { int i; Stringc line; char buff[255]; //==== Open file ====// FILE* file_id = fopen(file_name, "r"); if (file_id == (FILE *)NULL) return(0); fgets(buff, 80, file_id); line = buff; if (line.search_for_substring("FUSE XSEC FILE") < 0) return 0; char name[255]; int num_pnts; float y, z; fscanf(file_id, "%s", name); fgets(buff, 80, file_id); fileName = name; fscanf(file_id, "%d", &num_pnts); fgets(buff, 80, file_id); file_crv.init( num_pnts ); for ( i = 0 ; i < num_pnts ; i++ ) { fscanf(file_id, "%f %f", &y, &z); fgets(buff, 80, file_id); file_crv.load_pnt( i, vec3d( 0.0, y, z )); } //==== Find Height & Width ====// vec3d p0 = file_crv.get_pnt( 0 ); vec3d pn = file_crv.get_pnt( num_pnts-1 ); height = fabs(p0.z() - pn.z()); double max_y = 0; for ( i = 0 ; i < num_pnts ; i++ ) { double y = file_crv.get_pnt( i ).y(); if ( fabs(y) > max_y ) max_y = fabs(y); } width = (2.0*max_y); //==== Scale Point By Height & Width ====// for ( i = 0 ; i < num_pnts ; i++ ) { double y = 2.0*file_crv.get_pnt( i ).y()/width(); double z = 2.0*file_crv.get_pnt( i ).z()/height(); file_crv.load_pnt( i, vec3d( 0.0, y, z )); } file_crv.comp_tans(); vec3d top_tan = vec3d( 0.0, 1.0, 0.0 ); double tan_mag = (file_crv).get_tan(0).mag(); file_crv.load_tan( 0, top_tan*tan_mag ); int last_id = file_crv.get_num_pnts() - 1; vec3d bot_tan = vec3d( 0.0, -1.0, 0.0 ); tan_mag = file_crv.get_tan( last_id ).mag(); file_crv.load_tan( last_id, bot_tan*tan_mag ); fclose(file_id); return 1; }
//==== Read Airfoil File ====// void Af::read(FILE* file_id) { int i; Stringc line; char buff[255]; int temp_type; int version = geom_ptr->get_aircraft_ptr()->get_version(); fgets(buff, 80, file_id); fgets(buff, 80, file_id); line = buff; if (line.search_for_substring("Num") >= 0) { sscanf(buff, "%d", &num_pnts); if (version >= 5) { fscanf(file_id, "%d", &inverted_flag); fgets(buff, 80, file_id); } camber.read(file_id); camber_loc.read(file_id); thickness.read(file_id); temp_type = NACA_4_SERIES; } else { sscanf(buff, "%d", &temp_type); if (version >= 5) { fscanf(file_id, "%d", &inverted_flag); fgets(buff, 80, file_id); } camber.read(file_id); camber_loc.read(file_id); thickness.read(file_id); thickness_loc.read(file_id); radius_le.read(file_id); radius_te.read(file_id); if ( temp_type == NACA_6_SERIES ) { fscanf( file_id, "%d", &sixser ); fgets(buff, 80, file_id); ideal_cl.read(file_id); a.read(file_id); } if ( temp_type == AIRFOIL_FILE ) { fgets(buff, 80, file_id); name = buff; name.remove_trailing_blanks(); name.remove_all_substrings('\n'); vec3d pnt; float x, z; int num_upper, num_lower; fscanf(file_id, "%f",&orig_af_thickness); fgets(buff, 80, file_id); fscanf(file_id, "%f",&radius_le_correction_factor); fgets(buff, 80, file_id); fscanf(file_id, "%f",&radius_te_correction_factor); fgets(buff, 80, file_id); fscanf(file_id, "%d",&num_upper); fgets(buff, 80, file_id); upper_curve.init(num_upper); for ( i = 0 ; i < num_upper ; i++) { fscanf(file_id, "%f %f",&x, &z); pnt = vec3d(x, 0.0, z); upper_curve.load_pnt( i, pnt ); } fgets(buff, 80, file_id); fscanf(file_id, "%d",&num_lower); fgets(buff, 80, file_id); lower_curve.init(num_lower); for ( i = 0 ; i < num_lower ; i++) { fscanf(file_id, "%f %f",&x, &z); pnt = vec3d(x, 0.0, z); lower_curve.load_pnt( i, pnt ); } fgets(buff, 80, file_id); } } set_type(temp_type); }
int Af::readVspAirfoil( FILE* file_id, int *thickness_read_flag, int *radius_le_read_flag, int *radius_te_read_flag ) { int i; Stringc line; char buff[256]; fgets(buff, 255, file_id); name = buff; name.remove_trailing_blanks(); name.remove_all_substrings('\n'); int sym_flag; int num_pnts_upper, num_pnts_lower; float x, z; fscanf(file_id, "%d", &sym_flag); fgets(buff, 255, file_id); fscanf(file_id, "%d", &num_pnts_upper); fgets(buff, 255, file_id); upper_curve.init(num_pnts_upper); if (sym_flag) { num_pnts_lower = num_pnts_upper; lower_curve.init(num_pnts_lower); } else { fscanf(file_id, "%d", &num_pnts_lower); fgets(buff, 255, file_id); lower_curve.init(num_pnts_lower); } for (i = 0 ; i < num_pnts_upper ; i++) { fscanf(file_id, "%f %f", &x, &z); fgets(buff, 255, file_id); upper_curve.load_pnt( i, vec3d(x, 0.0, z)); if ( sym_flag ) { lower_curve.load_pnt( i, vec3d(x, 0.0, -z) ); } } fgets(buff, 255, file_id); if ( !sym_flag ) { for ( i = 0 ; i < num_pnts_lower ; i++) { fscanf(file_id, "%f %f", &x, &z); fgets(buff, 255, file_id); lower_curve.load_pnt( i, vec3d(x, 0.0, z) ); } fgets(buff, 255, file_id); } //==== Close Trailing Edge - Set Last Points ====// vec3d last_pnt = upper_curve.get_pnt(num_pnts_upper-1) + lower_curve.get_pnt(num_pnts_lower-1); upper_curve.load_pnt(num_pnts_upper-1, last_pnt*0.5); lower_curve.load_pnt(num_pnts_lower-1, last_pnt*0.5); float fdum; int more_data_flag = 1; while (more_data_flag) { more_data_flag = 0; if ( fgets(buff, 255, file_id) ) { more_data_flag = 1; line = buff; } else { line = " "; } if (line.search_for_substring("Radius") >= 0) { sscanf(buff, "%f", &fdum); if (line.search_for_substring("Trailing") >= 0) { radius_te = fdum; *radius_te_read_flag = 1; } else { radius_le = fdum; *radius_le_read_flag = 1; } } if (line.search_for_substring("Thick") >= 0) { sscanf(buff, "%f", &fdum); if (line.search_for_substring("Location") >= 0) { thickness_loc = fdum; } else { *thickness_read_flag = 1; thickness = fdum; } } if (line.search_for_substring("Camber") >= 0) { sscanf(buff, "%f", &fdum); if (line.search_for_substring("Location") >= 0) { camber_loc = fdum; } else { camber = fdum; } } if (line.search_for_substring("Delta") >= 0) { sscanf(buff, "%f", &fdum); delta_y_le = fdum; } } fclose(file_id); return 1; }
//===== Read AF File =====// int Af::read_af_file( Stringc file_name ) { Stringc line; char buff[255]; int thickness_read_flag = 0; int radius_le_read_flag = 0; int radius_te_read_flag = 0; /* --- Open file --- */ FILE* file_id = fopen(file_name, "r"); if (file_id == (FILE *)NULL) return(0); fgets(buff, 255, file_id); line = buff; int ok = 0; if (line.search_for_substring("AIRFOIL FILE") < 0) { ok = readSeligAirfoil( file_id ); if ( ok ) { name = buff; name.remove_trailing_blanks(); name.remove_all_substrings('\n'); name.remove_all_substrings('\r'); } else { ok = readLednicerAirfoil( file_id ); } } else { ok = readVspAirfoil( file_id, &thickness_read_flag, &radius_le_read_flag, &radius_te_read_flag ); } fclose( file_id ); if ( !ok ) return 0; //==== Set Type and Deactivate Parameters ====// set_type( AIRFOIL_FILE ); //==== Check if Thickness was in File - Compute if not ====// if ( !thickness_read_flag ) thickness = compute_thickness_af_curves(); //==== Set Base Thickness Value ====// orig_af_thickness = (float)thickness(); //==== Check if Radius LE was in File - Compute if not ====// if ( !radius_le_read_flag ) { radius_le = compute_radius_le_af_curves(); radius_le_correction_factor = 1.0; } else { radius_le_correction_factor = (float)(radius_le()/compute_radius_le_af_curves()); } //==== Check if Radius TE was in File - Compute if not ====// if ( !radius_te_read_flag ) { radius_te = 0.0; } upper_curve.comp_tans(); lower_curve.comp_tans(); vec3d leading_edge_tan = vec3d(0.0, 0.0, 1.0); double tan_mag = upper_curve.get_tan(0).mag(); upper_curve.load_tan( 0, leading_edge_tan*tan_mag); tan_mag = -(lower_curve.get_tan(0).mag()); lower_curve.load_tan( 0, leading_edge_tan*tan_mag); generate_from_file_curve(); return(1); }
void PHolderListMgr::ReadPHolderListXDDM( char *newfile ) { pHolderListMgrPtr->DelAllPHolders(); //==== Read Xml File ====// xmlDocPtr doc; xmlNodePtr node; LIBXML_TEST_VERSION xmlKeepBlanksDefault(0); //==== Build an XML tree from a the file ====// doc = xmlParseFile(newfile); // if (doc == NULL) return 0; xmlNodePtr root = xmlDocGetRootElement(doc); if (root == NULL) { fprintf(stderr,"empty document\n"); xmlFreeDoc(doc); // return 0; } vector< Geom* > gVec = aircraftPtr->getGeomVec(); gVec.push_back( aircraftPtr->getUserGeom() ); vector< xmlNodePtr > vlist; int num_v = xmlGetNumNames( root, "Variable" ); for ( int i = 0 ; i < num_v ; i++ ) { xmlNodePtr var_node = xmlGetNode( root, "Variable", i ); vlist.push_back( var_node ); } int num_c = xmlGetNumNames( root, "Constant" ); for ( int i = 0 ; i < num_c ; i++ ) { xmlNodePtr cst_node = xmlGetNode( root, "Constant", i ); vlist.push_back( cst_node ); } int num_tot = num_v + num_c; for ( int i = 0 ; i < num_tot ; i++ ) { xmlNodePtr var_node = vlist[i]; if ( var_node ) { Stringc varname = Stringc( xmlFindPropString( var_node, "VSPVarName", " " ) ); int istart = 0; int iend = varname.search_for_substring(':'); int id = varname.get_range( istart, iend-1 ).convert_to_integer(); istart = iend + 1; iend = varname.search_for_substring( istart, ':' ); istart = iend + 1; iend = varname.search_for_substring( istart, ':' ); Stringc group = varname.get_range( istart, iend-1 ); istart = iend + 1; iend = varname.get_length(); Stringc parm = varname.get_range( istart, iend-1 ); Parm* p = parmMgrPtr->FindParm( gVec, id, group, parm ); if ( p ) { double val = xmlFindPropDouble( var_node, "Value", p->get() ); p->set_from_link( val ); p->get_geom()->parm_changed( p ); ParmHolder* ph = new ParmHolder(); ph->setParm( p ); const xmlChar* varstr = (xmlChar*) "Variable"; if( !xmlStrcmp(var_node->name, varstr ) ) ph->setDesType( XDDM_VAR ); else ph->setDesType( XDDM_CONST ); m_PHolderVec.push_back( ph ); m_CurrPHolderIndex = (int)m_PHolderVec.size() - 1; } } } //===== Free Doc =====// xmlFreeDoc( doc ); // return 1; }