| 1 | |
|---|
| 2 | |
|---|
| 3 | use DBI; |
|---|
| 4 | use XML::XPath; |
|---|
| 5 | use XML::XPath::XMLParser; |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | my $dbh = DBI->connect ("dbi:Pg:dbname=matdl","el_oso", "hyfeguu") |
|---|
| 10 | || die "Can't connect: $DBI::errstr"; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | my $xmlfile = shift @ARGV; |
|---|
| 17 | my $xpath = XML::XPath->new( filename => $xmlfile ); |
|---|
| 18 | |
|---|
| 19 | sub xpath{ |
|---|
| 20 | |
|---|
| 21 | my ($query) = @_; |
|---|
| 22 | my $nodeset = $xpath->find( $query ); |
|---|
| 23 | my $results; |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | foreach my $node ( $nodeset->get_nodelist ) { |
|---|
| 27 | $results .= XML::XPath::XMLParser::as_string( $node ); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | return $results; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | sub formunit{ |
|---|
| 34 | |
|---|
| 35 | my ($propid) = @_; |
|---|
| 36 | my ($units, $powers); |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | $units = &xpath("//PropertyDetails[\@id='$propid']/Units/\@name"); |
|---|
| 46 | chop $units; |
|---|
| 47 | ($trash, $units) = split/\"/,$units; |
|---|
| 48 | $formedunit = $units; |
|---|
| 49 | |
|---|
| 50 | return $formedunit; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | my $matname = &xpath( "//BulkDetails/Name/text()"); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | $str = $dbh->prepare("insert into Materials values (DEFAULT,'$xmlfile','$matname')"); |
|---|
| 62 | $str->execute; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | $str = $dbh->prepare("select matid from Materials where matname='$matname'"); |
|---|
| 67 | $str->execute; |
|---|
| 68 | $matid = $str->fetchrow_array; |
|---|
| 69 | |
|---|
| 70 | my $properties = &xpath("//PropertyDetails/\@id"); |
|---|
| 71 | chop $properties; |
|---|
| 72 | @props = split / id=\"/,$properties; |
|---|
| 73 | @props = split /\" /,"@props"; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | $propname_last = ""; |
|---|
| 77 | |
|---|
| 78 | foreach (@props){ |
|---|
| 79 | |
|---|
| 80 | $propid = $_; |
|---|
| 81 | $propid =~ s/ //g; #Remove blank spaces |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | $propname = &xpath("//PropertyDetails[\@id='$propid']/Name/text()"); |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | if($propname eq $propname_last){ |
|---|
| 88 | break;} |
|---|
| 89 | |
|---|
| 90 | $value = &xpath("//PropertyData[\@property='$propid'][1]/Data/text()"); |
|---|
| 91 | $format = &xpath("//PropertyData[\@property='$propid'][1]/Data/\@format"); |
|---|
| 92 | chop $format; |
|---|
| 93 | ($trash,$format) = split /\"/,$format; |
|---|
| 94 | $units = &formunit($propid); |
|---|
| 95 | |
|---|
| 96 | $propname =~ s/\'/\\\'/g; |
|---|
| 97 | |
|---|
| 98 | print "insert into Properties values('$matid','$propid','$propname','$value','$format','$units')\n"; |
|---|
| 99 | $str = $dbh->prepare("insert into Properties values('$matid','$propid','$propname','$value','$format','$units')"); |
|---|
| 100 | $str->execute; |
|---|
| 101 | |
|---|
| 102 | $propname_last = $propname; |
|---|
| 103 | |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | $str = $dbh->prepare("update properties set value=cast(cast(value as numeric)/145.03774 as text),units='MPa' where units='psi'"); |
|---|
| 117 | $str->execute; |
|---|
| 118 | |
|---|
| 119 | $str = $dbh->prepare("update properties set value=cast(cast(value as numeric)*6.8947573 as text),units='MPa' where units='ksi'"); |
|---|
| 120 | $str->execute; |
|---|
| 121 | |
|---|
| 122 | $str = $dbh->prepare("update properties set value=cast(cast(value as numeric)*1000 as text),units='MPa' where units='GPa'"); |
|---|
| 123 | $str->execute; |
|---|
| 124 | |
|---|
| 125 | $str = $dbh->prepare("update properties set value=cast(cast(value as numeric)*27.6799047102 as text),units='g/cc' where units='lb/cu in.'; |
|---|
| 126 | "); |
|---|
| 127 | $str->execute; |
|---|
| 128 | |
|---|
| 129 | $str = $dbh->prepare("update properties set value=cast(cast(value as numeric)*4.1868 as text),units='' where units='Btu/lb./°F'"); |
|---|
| 130 | $str->execute; |
|---|
| 131 | |
|---|
| 132 | $str = $dbh->prepare("update properties set value=cast(cast(value as numeric)*.144227888864 as text),units='W/m-K' where units='Btu-in/ft squared/hr/°F'; |
|---|
| 133 | "); |
|---|
| 134 | $str->execute; |
|---|