#!/usr/bin/perl

use MicModule;

$choice=@ARGV[0];

if ( $choice ne '' ) { @ctyps =($choice);
		       print @ctyps;}
else {@ctyps=('surfobs','lidar','create','retro','inca_work','aerocom','aerocom_work','synthesis');}

for ($c=0;$c<@ctyps; $c++) {

$ctyp=$ctyps[$c];



## switch to activate other web servers with other 
## directories
$machine="dataipsl";
$dirunixbase = '/bipbip/AEROCOM/';
if ( $machine ne 'dataipsl' ) {
    print $ctyp,'- not on dataipsl ',"\n";
    $dirunixbase = '/home/aerocom0/';
}

if ( $ctyp =~ /aerocom/ ) {$dirunix=$dirunixbase;}
else {$dirunix=$dirunixbase.uc($ctyp).'/';}

$t='dummy';
$pf='constructlist';


@arguments=($ctyp,$t,$r,$dirunix,$t,$t,$t,$t,$t,$t,$pf);
@rlist = ::MicModule::psr(@arguments);
print @rlist,"\n";


for ($r=0;$r<@rlist; $r++) {


    @arguments=($ctyp,$t,$rlist[$r],$dirunix,$t,$t,$t,$t,$t,$t,$pf);

    @typlist = ::MicModule::pst(@arguments);
    @slist = ::MicModule::pss(@arguments);
    @plist = ::MicModule::psp(@arguments);
    @stlist = ::MicModule::psst(@arguments);
    @ylist = ::MicModule::psy(@arguments);
    @mlist = ::MicModule::psm(@arguments);


    $name=$dirunix.$rlist[$r].'/list.txt';
    $outfile = ">".$name;
    open (OUT , $outfile); print OUT "";
    $outfile2 = ">>".$name;
    open (OUT , $outfile2);
    
    if (@typlist == 0){ @typlist=('du')} 
    for($i=0; $i<@typlist; $i++) {
	print OUT $typlist[$i];
	if ($i < @typlist-1) {print OUT ","};
    }
    
    print OUT "\n";
    
    if (@slist == 0){ @slist=('du')} 
    for($i=0; $i<@slist; $i++) {
	print OUT $slist[$i];
	if ($i < @slist-1) {print OUT ","};
    }
    
    print OUT "\n";
    if (@plist == 0){ @plist=('du')} 
    for($i=0; $i<@plist; $i++) {
	print OUT $plist[$i];
	if ($i < @plist-1) {print OUT ","};
    }
    
    print OUT "\n";
    if (@ylist == 0){ @ylist=('du')} 
    for($i=0; $i<@ylist; $i++) {
	print OUT $ylist[$i];
	if ($i < @ylist-1) {print OUT ","};
    }

    print OUT "\n";
    if (@mlist == 0){ @mlist=('du')} 
    for($i=0; $i<@mlist; $i++) {
	print OUT $mlist[$i];
	if ($i < @mlist-1) {print OUT ","};
    }
    print OUT "\n";

    if (@stlist == 0){ @stlist=('du')} 
    for($i=0; $i<@stlist; $i++) {
	print OUT $stlist[$i];
	if ($i < @stlist-1) {print OUT ","};
    }
    print OUT "\n";
    close (OUT); 	
    
}
}    
exit;

