import java.awt.*; import java.applet.*; public class tgas extends Frame { DataPanel dataPanel; ControlPanel controlPanel; InputList inlist=new InputList(this); gasState gas=new gasState(-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,1); String parmString; public tgas() { super("Thermodynamic Properties of Air"); dataPanel=new DataPanel(this); controlPanel=new ControlPanel(this); setLayout(new BorderLayout(0,0)); setBackground(Color.cyan); addNotify(); add("Center",dataPanel); add("South",controlPanel); } public boolean handleEvent(Event event) { if (event.id == Event.WINDOW_DESTROY) { hide(); return true; } return super.handleEvent(event); } void convert() { double val1,val2; int i,units; inlist.parse(dataPanel.intext.getText()); if(inlist.npts<1) return; units=controlPanel.choice2.getSelectedIndex()+1; gas.units=units; parmString="Pressure (Pa) \tEntropy (J/kg/K) \tDensity (kg/m3)\tEnergy (J/kg) \tSpeed (m/s) \tEnthalpy (J/kg) \tTemperature (K)\n"; if(units==2) parmString="Pressure(psi)\tEntropy(btu/lbm/R)\tDensity(lbm/ft3)\tEnergy(btu/lbm)\tSpeed(ft/s) \tEnthalpy(btu/lbm)\tTemperature (R)\n"; for(i=0;i0.0) sgn=1; else if(d<0.0) sgn=-1; else return("0.0000e+000"); buf=String.valueOf(d); if(buf.indexOf('#')>=0) { buf=buf+"? "; return(buf.substring(0,11)); //catches infinities } d=Math.abs(d); exp=(int)(Math.log(d*1.0000001)/Math.log(10)); if(d<1.0) exp--; mant=(int)Math.round(d*Math.pow(10.,(double)(sdigits-1-exp))); buf=String.valueOf(mant); out=buf.substring(0,1)+"."+buf.substring(1); //insert point if(sgn==-1) out="-"+out; else out=" "+out; if(exp>=0) out=out+"e+"; else out=out+"e-"; if(Math.abs(exp)>99) out=out+String.valueOf(Math.abs(exp)); else if(Math.abs(exp)>9) out=out+"0"+String.valueOf(Math.abs(exp)); else out=out+"00"+String.valueOf(Math.abs(exp)); return(out); } } class DataPanel extends Panel { tgas root; TextArea intext,outext; DataPanel(tgas target) { root=target; setLayout(new GridLayout(2,1,10,0)); intext=new TextArea("Type/paste in quantities to be converted here. Select quantities to be entered below."); intext.setFont(new Font("Dialog",Font.PLAIN,8)); add(intext); outext=new TextArea("Press compute and results will appear here. Copy/paste these into your application.\n\nVersion 1.1, 7/17/98, programmed by William Devenport (Java) and Bernard Grossman (Fortran)\nAOE Dept., Virginia Tech, based on 'Simplified Curve Fits for the Thermodynamic Properties\nof Equilibrium Air' by Srinivasan S, Tannehill J C and Weilmuenster K J, NASA RP1181, August 1987."); outext.setFont(new Font("Dialog",Font.PLAIN,8)); outext.setEditable(false); add(outext); } } class ControlPanel extends Panel { tgas root; Choice choice1,choice2; Button button1,button2,button3; help helpframe; ControlPanel(tgas target) { root=target; choice1= new Choice(); setLayout(new GridLayout(1,5,10,0)); choice1.setFont(new Font("Dialog",Font.PLAIN,10)); add(choice1); choice1.addItem("Pressure, Entropy"); choice1.addItem("Energy, Density"); choice1.addItem("Pressure, Density"); choice1.addItem("Entropy, Enthalpy"); choice1.addItem("Pressure, Temperature"); choice2= new Choice(); choice2.setFont(new Font("Dialog",Font.PLAIN,10)); add(choice2); choice2.addItem("SI Units"); choice2.addItem("British Units"); button1=new Button("Compute"); button2=new Button("Clear"); button3=new Button("Help"); add(button2); add(button1); add(button3); } public boolean handleEvent(Event event) { if (event.id == Event.ACTION_EVENT && event.target == button1) { root.convert(); return true; } if (event.id == Event.ACTION_EVENT && event.target == button2) { root.dataPanel.outext.setText(""); root.dataPanel.intext.setText(""); return true; } if (event.id == Event.ACTION_EVENT && event.target == button3) { if(helpframe==null) { helpframe=new help(root); helpframe.resize(300,500); helpframe.show(); return true;} else { helpframe.show(); return true; } } if (event.id == Event.ACTION_EVENT && (event.target == choice1 || event.target==choice2)) { if(helpframe==null) return true; else { helpframe.helptext.setText(helpframe.htext1+helpframe.htext2[choice1.getSelectedIndex()*2+choice2.getSelectedIndex()]+helpframe.htext3); return true; } } return super.handleEvent(event); } } class InputList { double xList[]=new double[1000]; double yList[]=new double[1000]; char[] delim={' ',',','\n','\t','\r','\f'}; String table,datas; Double DdataD = new Double(0.0); int npts=0; tgas root; InputList (tgas target) { root=target; } void parse(String nolist) { int i,j; table=new String(nolist); //Replace all delimiters by spaces for(i=1;i<6;i++) { table=table.replace(delim[i],' '); } for(j=0,npts=0;;) { //trim leading and trailing whitespaces table=table.trim(); if(table.length()==0) break; if(table.indexOf(' ')==-1) { datas=table;table=""; } else { datas=table.substring(0,table.indexOf(' ')); table=table.substring(table.indexOf(' ')); } try { DdataD=Double.valueOf(datas); } catch (NumberFormatException nFE) { perror("Number format error. Use only spaces, commas or carriage returns as delimeters"); return; } if(j%2==0) { xList[j/2]=DdataD.doubleValue(); j++; } else { yList[(j-1)/2]=DdataD.doubleValue(); j++; npts++; if(npts==1000) break; } } if(npts<1) perror("Less than two numbers entered. Enter at least 2"); } void perror(String msg) { try { root.dataPanel.intext.setText(msg); } catch (NullPointerException nPE) { } npts=0; } }