#!/bin/perl -w # # program to read steady-state field plots created by xfdtd (*.cef or *.bfd) # and redirect data into an easy to use data file # # Created by: Chad Pendley Feb 2001 $#fin_vals = -1; ( `uncompress *cef.Z` ); ( `uncompress *bfd.Z` ); system 'clear'; print "\n The purpose of this program is to read in Magnetic Field Plots (*.bfd) and/or\n"; print " Electric Field Plots (*.cef) created by the software XFDTD and organize the\n"; print " Data into a more easily used format. Data files will be created for x-, y-, \n"; print " and z-directed fields as well as magnitude plots.\n\n"; print " Created by: Chad Pendley\n at: Utah State University\n\n"; opendir (DIR, '.'); @my_files = grep (/(cef|bfd)$/, readdir(DIR)); closedir DIR; if ( $#my_files < 0 ) { print "\n\n *******************************************************************"; print "\n ********************* WARNING!! ***********************************"; print "\n *******************************************************************"; print "\n * There were no *.cef or *.bfd files located in this directory! *"; print "\n * *"; print "\n * Make sure that files are in working directory before *"; print "\n * Trying again. *"; print "\n * *"; print "\n *******************************************************************\n\n"; exit; } @file_cef = grep (/cef$/, @my_files); @file_bfd = grep (/bfd$/, @my_files); print "\nFrom this directory, the following file(s) were found:\n"; print "===================================================="; while ( 1 ) { print "\n\n Magnetic Field Plots Electric Field Plots\n"; print "[S] -------------------- [S] --------------------\n"; foreach $num ( 0..$#file_bfd) { print ( $choices{ $num } ? ' *' : ' ' ); print ' ' x( 2 - length( $num ) ) , "$num) $file_bfd[ $num ]"; if ( $#file_cef >= $num ) { print ' ' x( 37 - length( $file_bfd[ $num ] ) - length( $num + $#file_bfd + 1) ); print ( $choices{ ( $num + $#file_bfd + 1 ) } ? ' *' : ' ' ); print ' ' x( 2 ) , ( $num + $#file_bfd + 1) , ") $file_cef[ $num ]\n"; } else { print "\n"; } } if ( $#file_cef > $#file_bfd ) { $start = ( ( $#file_bfd >= 0 ) ? ( $#file_bfd + 1 ) : 0 ); foreach $num ( $start..$#file_cef ) { print ' ' x42 ; print ( $choices{ ( $num + $start ) } ? ' *' : ' ' ); print ' ' x( 3 - length( $num + $start ) ), ( $num + $start ) , ") $file_cef[ $num ]\n"; } } print "\n\n You may select (or de-select) any file by entering in the corresponding number.\n"; print " Select multiple files by use of a ',' or SPACE or '-' (e.g. 1,2,4 6 7-10)\n"; print "\n Select desired file(s) or press RETURN to continue: "; $choice = ; chomp( $choice ); ( length( $choice) > 0 ) || last; $max = $#file_bfd + $#file_cef + 1; $#fin_vals = -1; @fin_vals = SELECTION( $choice , $max ); foreach $vals ( @fin_vals ) { $choices{ $vals } = ( $choices{ $vals } + 1 ) % 2; } system 'clear'; } print "\n\n Creating file(s):\n\n"; foreach $sel ( sort { $a <=> $b } keys( %choices ) ) { if ( $choices{ $sel } ) { if ( $sel <= $#file_bfd ) { $file = $file_bfd[ $sel]; DISECT(); } else { $file = $file_cef[ ( $sel - $#file_bfd - 1 ) ]; DISECT(); } } } print "\n << Any Data files are located in directory: ./Field_Output_Dat_File >>\n\n"; print " *!* Remember to periodically delete un-needed files from this directory\n"; print " As they will take up memory.\n\n"; sub DECISION { local $choice = undef; while (1) { $choice = ; ( $choice =~ /^y/i ) && return 1; ( $choice =~ /^n/i ) && return undef; print "\n\nSORRY!! This requires a yes/no answer, please try again. >"; } } sub SELECTION( $choice, $max ) { $choice =~ s/[^\d-]/ /g; @choice1 = split( /\s+/ , $choice ); foreach ( @choice1 ) { if ( index( $_ , '-' ) >= 0 ) { ( $begin , $end ) = /^(\d+)\s*-\s*(\d+)$/; ( $begin >= 0 ) || ( $begin = 0 ); ( $end <= $max ) || ( $end = $max ); } else { $end = $begin = $_; } if (( $end >= 0 ) && ( $begin <= $max )) { CHECK_LOOP: foreach $num ( $begin..$end ) { foreach $vals ( @fin_vals ) { ( $vals == $num ) && next CHECK_LOOP; } push( @fin_vals , $num ); } } } @fin_vals = sort { $a <=> $b } @fin_vals; } sub DISECT { open( FILEIN , "$file" ); for ( $i = 1 ; $i <= 4 ; $i++ ) { $_ = ; } chomp; ( $NX , $NY , $NZ ) = /(\d+)\s*(\d+)\s*(\d+)/; $_ = ; chomp; ( $switch , $slice ) = $file =~ /\.(\D+)?(\d+)\.(cef|bfd)$/; ((( $switch cmp 'xy' ) == 0 ) && (( $J_END = $NY ),( $I_END = $NX ))) || ((( $switch cmp 'yz' ) == 0 ) && (( $J_END = $NZ ),( $I_END = $NY ))) || ((( $switch cmp 'xz' ) == 0 ) && (( $J_END = $NZ ),( $I_END = $NX ))) || return undef; foreach $j ( 0..( $J_END - 1 ) ) { foreach $i ( 0..( $I_END - 1 ) ) { $_ = ; ( $FX[ $i ][ $j ] , $FY[ $i ][ $j ] , $FZ[ $i ][ $j ] , $FT[ $i ][ $j ] ) = /(\S+)\s*(\S+)\s*(\S+)\s*(\S+)/; } } close FILEIN; ( $file =~ /cef$/ ) && ( $header = 'E' ) || ( $header = 'H' ); chop $file; chop $file; chop $file; chop $file; $file =~ s/\./_/g; unless ( -e 'Field_Output_Dat_File' ) { ( `mkdir Field_Output_Dat_File` ); } open( FILEOUTM , ">Field_Output_Dat_File/$file" . '_' . $header . 'MAG.dat' ); open( FILEOUTX , ">Field_Output_Dat_File/$file" . '_' . $header . 'X.dat' ); open( FILEOUTY , ">Field_Output_Dat_File/$file" . '_' . $header . 'Y.dat' ); open( FILEOUTZ , ">Field_Output_Dat_File/$file" . '_' . $header . 'Z.dat' ); foreach $j ( 0..( $J_END - 1 ) ) { foreach $i ( 0..( $I_END - 1 ) ) { print FILEOUTM " $FT[ $i ][ $j ]"; print FILEOUTX " $FX[ $i ][ $j ]"; print FILEOUTY " $FY[ $i ][ $j ]"; print FILEOUTZ " $FZ[ $i ][ $j ]"; } print FILEOUTM "\n"; print FILEOUTX "\n"; print FILEOUTY "\n"; print FILEOUTZ "\n"; } close FILEOUTM; close FILEOUTX; close FILEOUTY; close FILEOUTZ; print " $file" . '_' . "$header" . '.' . "m\n"; open( FILEOUT , ">$file" . '_' .$header . '.m' ); print FILEOUT "function [] = $file" . '_' . $header . "\n\n"; print FILEOUT "% This function was created automatically by the 'cf' program to view data\n"; print FILEOUT "% from xfdtd steady-state files. Running this m-file will produce graphs of\n"; print FILEOUT "% Field magnitudes for specific models.\n%\n% For any comments or questions see: Chad Pendley\n\n"; print FILEOUT "% Load in data files for minipulation\n"; print FILEOUT '%' x60 . "\n"; print FILEOUT "load 'Field_Output_Dat_File/" . $file . '_' . $header . "MAG.dat' % Field Magnitude data\n"; print FILEOUT "load 'Field_Output_Dat_File/" . $file . '_' . $header . "X.dat' % X-directed Field data\n"; print FILEOUT "load 'Field_Output_Dat_File/" . $file . '_' . $header . "Y.dat' % Y-directed Field data\n"; print FILEOUT "load 'Field_Output_Dat_File/" . $file . '_' . $header . "Z.dat' % Z-directed Field data\n\n"; foreach $tail ( 'MAG','X','Y','Z' ) { print FILEOUT "% Plotting data for " . $header . $tail . " Fields at slice $slice \n"; print FILEOUT '%' x60 . "\n\n"; print FILEOUT "% Plotting color map of data\n"; print FILEOUT "figure\n"; print FILEOUT "subplot(2,2,1), pcolor( $file" . '_' . $header . "$tail )\n"; print FILEOUT "title('$header-$tail fields along the $switch plane at slice $slice','Fontsize',12)\n"; print FILEOUT "ylabel '" , $switch =~ /\w(\w)/ , "-axis'\nxlabel '" , $switch =~ /(\w)\w/ , "-axis'\n"; print FILEOUT "% Plotting color map of normalized logrythmic values\n"; print FILEOUT "subplot(2,2,2), pcolor(log10(($file" . '_' . $header . "$tail )/max(max( $file" . '_' . $header . "$tail )))) \n"; print FILEOUT "title('Normalized Log plots of $header-$tail fields','Fontsize',12)\n"; print FILEOUT "ylabel '" , $switch =~ /\w(\w)/ , "-axis'\nxlabel '" , $switch =~ /(\w)\w/ , "-axis'\n"; print FILEOUT "% Plotting 3-D plot for actual data\n"; print FILEOUT "subplot(2,2,3), surf( $file" . '_' . $header . "$tail ) , axis([0 $I_END 0 $J_END 0 max(max( $file" . '_' . $header . "$tail ))])\n"; print FILEOUT "ylabel '" , $switch =~ /\w(\w)/ , "-axis'\nxlabel '" , $switch =~ /(\w)\w/ , "-axis'\nzlabel 'Magnitude'\n"; print FILEOUT "% Plotting Normalized Logrythmic values in a 3-D format\n"; print FILEOUT "subplot(2,2,4), surf(log10(($file" . '_' . $header . "$tail )/max(max( $file" . '_' . $header . "$tail )))) , axis([0 $I_END 0 $J_END min(min(log10(($file" . '_' . $header . "$tail )/max(max( $file" . '_' . $header . "$tail ))))) 0 ])\n"; print FILEOUT "ylabel '" , $switch =~ /\w(\w)/ , "-axis'\nxlabel '" , $switch =~ /(\w)\w/ , "-axis'\nzlabel 'Normalized Magnitude'\n\n"; } close FILEOUT; }