« lib/App/SeismicUnixGui/sunix/NMO_Vel_Stk/sunmo.pm
↑ Summary
lib/App/SeismicUnixGui/developer/code/sunix/sudoc2pm_nameNnumber.pm »
| 1 | package App::SeismicUnixGui::developer::code::sunix::sudoc; | ||
| 2 | use Moose; | ||
| 3 | |||
| 4 | =head2 sunix_pl | ||
| 5 | |||
| 6 | shares many similar attributes to current | ||
| 7 | class in that files are examined for patterns | ||
| 8 | However, the current class uses sudoc files | ||
| 9 | rather than sunix perl scripts | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | extends 'App::SeismicUnixGui::misc::sunix_pl'; | ||
| 14 | |||
| 15 | =head2 hash of encapsuated variables | ||
| 16 | |||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | my $sudoc = { | ||
| 21 | _names => '', | ||
| 22 | _values => '', | ||
| 23 | }; | ||
| 24 | |||
| 25 | =head2 sub parse variable names | ||
| 26 | |||
| 27 | from among selected lines | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub parameters { | ||
| 32 | my ( $self, $hash_ref ) = @_; | ||
| 33 | my $line_num = 0; | ||
| 34 | my $op_line_num = 0; | ||
| 35 | my $line_text; | ||
| 36 | my ( @default_names, @default_values, @extraction ); | ||
| 37 | my $parse_names; | ||
| 38 | my $parse_names_ref = $hash_ref; | ||
| 39 | |||
| 40 | foreach ( @{ $parse_names_ref->{_line_contents} } ) { | ||
| 41 | |||
| 42 | # print ("line $line_num comprises: @{$parse_names_ref->{_line_contents}}[$i] "); | ||
| 43 | |||
| 44 | $line_text = @{ $parse_names_ref->{_line_contents} }[$line_num]; | ||
| 45 | |||
| 46 | # match regex (m//) to string ($line_text) | ||
| 47 | # and assign (=~) to array @fields | ||
| 48 | # look for any number of whitespaces (\s*) | ||
| 49 | # followed by one or more word characters (\w+) | ||
| 50 | # followed by '=' | ||
| 51 | # followed by any or no whitespaces (\s*) | ||
| 52 | # followed by one or more (+) non-whitespaces [^\s]+ | ||
| 53 | my @fields = $line_text =~ m/\s*(\w+)\s*=\s*([^\s]+)/; | ||
| 54 | my $length = scalar @fields; | ||
| 55 | |||
| 56 | # filtered results | ||
| 57 | # for (my $i=0; $i<$length; $i++) { | ||
| 58 | # print ("line:$line_num, field $i:----$fields[$i]----\n"); | ||
| 59 | # } | ||
| 60 | |||
| 61 | if ( $fields[0] ) { | ||
| 62 | |||
| 63 | $default_names[$op_line_num] = $fields[0]; | ||
| 64 | |||
| 65 | # print("sudoc, $line_num param_name: $default_names[$op_line_num]\n"); | ||
| 66 | # only allow to pass those fields that are default useful values of the program | ||
| 67 | # replace the following fields with blanks | ||
| 68 | # replace any character . | ||
| 69 | # greedy replacement * | ||
| 70 | |||
| 71 | $fields[1] =~ s/\w+//; | ||
| 72 | $fields[1] =~ s/\*\w+//; | ||
| 73 | $fields[1] =~ s/\.\w+//; | ||
| 74 | $fields[1] =~ s/\-\w+//; | ||
| 75 | $fields[1] =~ s/\/\w+//; | ||
| 76 | # $fields[1] =~ s/^\w+\-\w+$//; | ||
| 77 | # $fields[1] =~ s/^\w*\/\w*$//; | ||
| 78 | # $fields[1] =~ s/\w+\/\w+$//; | ||
| 79 | $fields[1] =~ s/;//; | ||
| 80 | $fields[1] =~ s/\*//; | ||
| 81 | $fields[1] =~ s/\s+\w+//; | ||
| 82 | $fields[1] =~ s/=//; | ||
| 83 | |||
| 84 | $fields[1] =~ s/0.0,\.\.\..*//; | ||
| 85 | $fields[1] =~ s/1,\.\.\..*//; | ||
| 86 | $fields[1] =~ s/1.0,\.\.\..*//; | ||
| 87 | $fields[1] =~ s/0.0,0.0,\.\.\..*//; | ||
| 88 | $fields[1] =~ s/\(.*//; | ||
| 89 | $fields[1] =~ s/clip//; | ||
| 90 | $fields[1] =~ s/\-clip//; | ||
| 91 | # $fields[1] =~ s/^\w+\*\w+//; | ||
| 92 | $fields[1] =~ s/fc.*//; | ||
| 93 | |||
| 94 | $fields[1] =~ s/all.*//; | ||
| 95 | $fields[1] =~ s/axeswidth.*//; | ||
| 96 | $fields[1] =~ s/curve.*//; | ||
| 97 | |||
| 98 | $fields[1] =~ s/if.*//; | ||
| 99 | |||
| 100 | $fields[1] =~ s/d3*//; | ||
| 101 | |||
| 102 | $fields[1] =~ s/file.*//; | ||
| 103 | $fields[1] =~ s/f2.*//; | ||
| 104 | |||
| 105 | $fields[1] =~ s/height.*//; | ||
| 106 | $fields[1] =~ s/lmin//; | ||
| 107 | $fields[1] =~ s/lmax//; | ||
| 108 | $fields[1] =~ s/lwidth//; | ||
| 109 | |||
| 110 | $fields[1] =~ s/maximum.*//; | ||
| 111 | $fields[1] =~ s/min.*//; | ||
| 112 | $fields[1] =~ s/minimum.*//; | ||
| 113 | $fields[1] =~ s/name.*//; | ||
| 114 | $fields[1] =~ s/nc.*//; | ||
| 115 | |||
| 116 | $fields[1] =~ s/npair1.*//; | ||
| 117 | $fields[1] =~ s/number//; | ||
| 118 | $fields[1] =~ s/offset.*//; | ||
| 119 | |||
| 120 | $fields[1] =~ s/\[optional.*//; | ||
| 121 | |||
| 122 | |||
| 123 | $fields[1] =~ s/or.*//; | ||
| 124 | |||
| 125 | $fields[1] =~ s/perc.*//; | ||
| 126 | $fields[1] =~ s/\-perc.*//; | ||
| 127 | $fields[1] =~ s/red,yellow,blue,\.\.\..*//; | ||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | $fields[1] =~ s/tr.*//; | ||
| 132 | $fields[1] =~ s/x-coordinate.*//; | ||
| 133 | |||
| 134 | $fields[1] =~ s/x1min.*//; | ||
| 135 | $fields[1] =~ s/x2min.*//; | ||
| 136 | $fields[1] =~ s/x3min.*//; | ||
| 137 | $fields[1] =~ s/x1max.*//; | ||
| 138 | $fields[1] =~ s/x2max.*//; | ||
| 139 | $fields[1] =~ s/x3max.*//; | ||
| 140 | |||
| 141 | $fields[1] =~ s/x1.*//; | ||
| 142 | $fields[1] =~ s/x2.*//; | ||
| 143 | $fields[1] =~ s/x3.*//; | ||
| 144 | |||
| 145 | $fields[1] =~ s/-wperc//; | ||
| 146 | $default_values[$op_line_num] = $fields[1]; | ||
| 147 | # print( | ||
| 148 | #"sudoc, $line_num default param_value: $default_values[$op_line_num]\n" | ||
| 149 | # ); | ||
| 150 | |||
| 151 | $op_line_num++; | ||
| 152 | } | ||
| 153 | |||
| 154 | $line_num++; | ||
| 155 | } | ||
| 156 | |||
| 157 | # before exporting the parameter names and their values | ||
| 158 | # sort the names alphabetically but keep corresponding values attached | ||
| 159 | # borrowed from web: AdrianHHH | ||
| 160 | my @key_names = @default_names; | ||
| 161 | my @values = @default_values; | ||
| 162 | |||
| 163 | my ( @export_names, @export_values ); | ||
| 164 | my ( %old_hash, %new_hash ); | ||
| 165 | |||
| 166 | # place names and their values into a hash key/value pairs | ||
| 167 | for ( my $i = 0 ; $i <= $#key_names ; $i++ ) { | ||
| 168 | $old_hash{ $key_names[$i] } = $values[$i]; | ||
| 169 | |||
| 170 | # print("key=$key_names[$i]; values=$old_hash{$key_names[$i]}\n"); | ||
| 171 | } | ||
| 172 | |||
| 173 | # remove duplicate names/keys and their attached values | ||
| 174 | my @unique_keys = sort keys %old_hash; | ||
| 175 | my $length_unique_keys = scalar @unique_keys; | ||
| 176 | |||
| 177 | # print ("#unique_keys=$length_unique_keys, alphabetical and unique_keys: @unique_keys,\n"); | ||
| 178 | |||
| 179 | my ( $key, $value ); | ||
| 180 | |||
| 181 | for ( my $i = 0 ; $i < $length_unique_keys ; $i++ ) { | ||
| 182 | |||
| 183 | $key = $unique_keys[$i]; | ||
| 184 | $value = $old_hash{$key}; | ||
| 185 | |||
| 186 | |||
| 187 | # "#=$i: unique and alphabetical key: $key, and its value: $value\n"; | ||
| 188 | |||
| 189 | $export_names[$i] = $unique_keys[$i]; | ||
| 190 | $export_values[$i] = $value; | ||
| 191 | } | ||
| 192 | |||
| 193 | $sudoc->{_names} = \@export_names; | ||
| 194 | $sudoc->{_values} = \@export_values; | ||
| 195 | return ($sudoc); | ||
| 196 | |||
| 197 | } | ||
| 198 | 1; |