showspikes.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/perl
  2. # this script parses lines like this from a parameter.xml file
  3. #<Para SimTag="TEST418" StimContrast="1.050000" InputStrength="0.200000" ExExStrength="0.180000" ExExRange="0.030000" ExInhStrength="1.250000" ExInhRange="0.080000" />
  4. $FileName="parameter.xml";
  5. my $RefParaNames = ReadParaNames($FileName);
  6. my @ParaNames=@$RefParaNames;
  7. print "ParaNames=$#ParaNames\n";
  8. my $NParas = MinAB($#ARGV, $#ParaNames) + 1;
  9. print "ARGV[0]= $ARGV[0] \n";
  10. # generate regular expressions for each parameter
  11. for (my $i=0; $i<$NParas; ++$i) {
  12. $RegExpList[$#RegExpList+1] = "$ParaNames[$i]=\"$ARGV[$i]";
  13. print $RegExpList[$#RegExpList]."\n";
  14. }
  15. open(FILE, "<$FileName");
  16. while(<FILE>) {
  17. my $NoHitCount=0;
  18. foreach $RegExp (@RegExpList) {
  19. if (!/$RegExp/i) {
  20. $NoHitCount++;
  21. }
  22. }
  23. if ($NoHitCount == 0) {
  24. print $_;
  25. }
  26. }
  27. close FILE;
  28. sub Usage()
  29. {
  30. print "usage:\n";
  31. print "showspikes.pl ";
  32. foreach $Name (@ParaNames) {
  33. print " <$Name>";
  34. }
  35. print "\n";
  36. }
  37. # read parameter names from xml file
  38. sub ReadParaNames(*)
  39. {
  40. my $FileName = shift;
  41. open(FILE, "<$FileName");
  42. my @ParaNames;
  43. while(<FILE>) {
  44. if (/<Para SimTag=\"[a-z0-9]+\"(.*=\".*)$/i) {
  45. $_=$1;
  46. # print $_;
  47. while(/ ([a-z0-9]+)=\"[^\"]+\"(.*)/i) {
  48. # print $1."\n";
  49. $ParaNames[$#ParaNames+1] = $1;
  50. $_=$2;
  51. }
  52. last;
  53. }
  54. }
  55. close FILe;
  56. return \@ParaNames;
  57. }
  58. ##############
  59. sub MaxAB(**)
  60. {
  61. my $a=shift;
  62. my $b=shift;
  63. return ($a>$b) ? $a : $b;
  64. }
  65. sub MinAB(**)
  66. {
  67. my $a=shift;
  68. my $b=shift;
  69. return ($a<$b) ? $a : $b;
  70. }