#!/usr/bin/perl

use CGI qw/:standard/;
use MicModule;
$dirbase = "/ipsl/nansen/data/AEROCOM/SURFOBS/" ;
$ctyp='surfobs';
$t1='ALL';
@arguments=($ctyp,$t1,$r[$pid],$dirbase,$p[$pid],$s[$pid],$y[$pid],$m[$pid],$st[$pid],$typ[$pid]);
my @rlist = ::MicModule::psr(@arguments);
print @rlist;

#my @rlist = ( 'AER_MS06');

# loop over directory list
for($r=0; $r<@rlist; $r++) {
    chdir  $dirbase . $rlist[$r] . "/plots" ;
    print  $dirbase . $rlist[$r] . "/plots \n" ;

# surfobs: OD550D_AER_an2000_m01_AbracosHill_SERIES.ps.png
    $argv1  = 9;  
    $argv2  = 9;
    $argp   = 0; # parameter
    $args   = 1; # species
    $argy   = 2; # year
    $argm   = 3; # period,month
    $argst  = 4; # station,region
    $argtyp = 5; # graph type

    my @flist = ();
    my @flist = glob("SCONCD_*.ps.png");
    
# loop over file list
    for($i=0; $i<@flist; $i++) {
	
	my @a = split /[\_\.]/, $flist[$i];
#	my $flistnew =$a[$argp].'_'.$a[$args].'_'.$a[$argy].'_'.$a[$argm].'_'.
#	    $a[$argst].'_'.$a[$argtyp].'.ps.png';
	my $flistnew ='SCONC_'.$a[$args].'_'.$a[$argy].'_'.$a[$argm].'_'.
	    $a[$argst].'_'.$a[$argtyp].'.ps.png';

# rename file # attention not reversible
	rename($flist[$i],$flistnew);
	
    }
}



