=head2 mdi_dpcstr - translate MDI data product codes into English

=for usage

  $str = mdi_dpcstr($dpc);

=for ref

Convert MDI DPC's into data product names and other strings

This is a straightforward translation of the Rock Bush rules in MDI
Tech Note 133 (http://soi.stanford.edu/general/TechNotes/96.133.html).
You insert an MDI data product code and you get back a string identifying
what the thing is claiming to be.

Because the routine uses control-flow (C<if> statements) to assemble the 
string, you can't thread it.  Only one DPC at a time, please.

AUTHOR

Craig DeForest, 2000 

=cut

sub mdi_dpcstr {
  my($dpc) = shift()  + 0; # force conversion to int
  my($str) = '';

  
  $str .= ['flight ','ground ']->[($dpc & 0x80000000) >> 31];
  $str .= ['5k ','160k ']->[($dpc & 0x40000000) >> 30];

  my($type) = ($dpc & 0x30000000) >> 28;
  $str .= ['std-science ','limb-figure-science ','IP-engineering ', 'misc. '] ->[$type];
  
  # Science & Limb Figure interpretation
  if($type < 2) {
    # Observing mode
    $str .= ['60s ','30s ','time-weighted avg ','other ']->[($dpc & 0x00c00000) >> 22];
        
    # Observable type
    my($obs) = ($dpc & 0x0f000000) >> 24;
    $str .= ['filtergram ','FD filtergram (sum) ', 'FD dopplergram (raw) ','FD dopplergram (bad->0) ',
	     'HR line depth ', 'FD line depth w/FF ', 'FD continuum ','FD continuum w/FF ',
	     'FD magnetogram ', 'FD magnetogram (sum) ','HR dopplergram ', 'HR magnetogram ', 
	     'FD line depth', 'HR continuum ', 'UNKNOWN (E) ', 'UNKNOWN (F) ']
		-> [$obs];
    
    if( $obs <= 1) { # special filtergram cases
      
      $str .= '('. ['Unk. filt. subtype','simple','TAP burst','TAP cont',
		    'Ice-hunt dark','Ice FD CAL','Ice HR CAL','comp. test',
		    'HR continuum','Intermediate Sd','Intermediate Si','FD continuum',
		    'hi cadence HR','FD CAL detune','FD OBS detune','focus',
		    'HR light xfer','dark','full dark','phase diversity HR',
		    'FD light xfer'] 
		      -> [($dpc & 0x001f0000) >> 16]
			. ') ';

    } else {
      $str .= sprintf('(vers. 0x%2.2x) ',($dpc & 0x000f00000) >> 16);
    }
  } 

  # IP engineering data and such
  elsif($type == 2) {
    my($dumptype) = ($dpc & 0x0f000000)>>24;
    $str .= ['IP register dump','IP table dump','IP bin list dump','IP limb figure list dump',
	     'IP memory dump','future 5','future 6','future 7',
	     'future 8','future 9','ISS high rate sample data','future B',
	     'future C','future D','IP error dump','future F'
	     ]->[$dumptype].' ';
    
    if($dumptype == 1) {
      my $a = ($dpc & 0x0000f000)>>12;
      $str .= '('.
	(([0, 'reciprocal table','vel. table','sqrt table']->[$a]) || "unknown $a")
	  .') ';
    } 
  }

  # Figure out if it's a standard product, in which case sa format indicator is in order.
  my($prod) = ($dpc & 0xf0000000)>>28;
  if([1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0]->[$prod]) {
    my $format = 
       ['cropped linear image','cropped sqrt imagex100','NxM extract','NxM sqrt extract',
		  'NxM binned','rect weighted binned','vector weighted binned','irregular weighted binned',
		  'arbitrary weighted binned','circular buffer','cropped sqrt imagex64','full 1040x1033 image',
		  'multiple sqrt extractx100','future D','future E','future F'
		  ]->[($dpc & 0x0000f000)>>12] ;
    $str .= '['. $format;

    
    if($format =~ m/crop/) {
      $str .= sprintf(', radius: %g',($dpc & 0x0000007f)/8.0);
    } else {
      
      $str .= ', '. ($instruments::soho::mdi::size_table->{$dpc & 0x0000ffff} || "unknown no. of") . ' pixels';
    }

    $str .= ']'
  }
  $str;
}

BEGIN {
$instruments::soho::mdi::size_table = {
	0x2000=>'1024x1024',
	0x2201=>'1024x128',
	0x2202=>'128x1024',
	0x2400=>'256x256',
	0x2100=>'300x300',
	0x2300=>'350x350',
	0x2500=>'400x400',
	0x2700=>'450x450',
	0x2900=>'550x550',
	0x2a00=>'1024x600',
	0x2b00=>'1024x640',
	0x2b01=>'640x1024',
	0x2c00=>'128x128',
	0x2d00=>'1024x500',
	0x2d01=>'500x1024',
	0x2e00=>'1024x800',
	0x2f00=>'1024x850',
	0x2040=>'1024x750',
	0x2140=>'1024x700',
	0x3000=>'1024x1024',
	0x4400=>'256x256',
	0x4800=>'512x512',
	0x4c00=>'128x128',
	0x5001=>'12453',
	0x6001=>'180',
	0x7001=>'180',
	0x9001=>'220800',
	0xafb0=>'17878',
	0xafc0=>'1024x1024',
	0xb000=>'1040x1033',
	0xc001=>'245760',
	0xcf58=>'20624'
	};
}

  
		    

