function execute($parUserId)
 {
     // Arrays
     require "arrays.php";
     //Verify item status
     if ($this->status != 'B' and $this->status != 'Q') {
         return 1;
     }
     // Flags
     $inproduction = true;
     // Searching Scene
     $sql = "SELECT * FROM Scene WHERE SceneId='" . $this->sceneId . "'";
     $this->bd->query($sql) or die("<br> Error on execution/result sql = {$sql} <br>");
     $itens = $this->bd->numRows();
     if ($itens == 0) {
         die("Erro nas Cenas");
     }
     $row = $this->bd->fetchRow();
     $this->bd->freeResult($results);
     // Scene data
     $res = explode(".", $row["SceneId"]);
     $sufix = $res[1];
     $satCod = $row["Satellite"];
     $sensor = $row["Sensor"];
     if ($satCod == "P6" and ($sensor == "LIS3" or $sensor == "AWIF")) {
         $date_IRS = $row["Date"];
         $path_IRS = $row["Path"];
         $row_IRS = $row["Row"];
     }
     for ($i = 0; $i < $matSatCod[0]; $i++) {
         if ($satCod == $matSatCod[$i]) {
             break;
         }
     }
     $satName = $matSatName[$i];
     $taName = $satName . "Scene";
     if ($GLOBALS["stationDebug"]) {
         echo "\n RequestClass - Satelite = " . $satName . " TabName = " . $taName . " UserName = "******"\n";
     }
     //Finding Gralha/Fred
     $sql = "SELECT * FROM {$taName} WHERE SceneId='" . $this->sceneId . "'";
     if ($GLOBALS["stationDebug"]) {
         echo "RequestClass - Sql Command: " . $sql . "\n";
     }
     $this->bd->query($sql);
     $row = $this->bd->fetchRow() or die("<br> Error on execution/result sql = {$sql} <br>");
     $file = $row["Gralha"];
     $this->bd->freeResult();
     if ($GLOBALS["stationDebug"]) {
         echo "RequestClass - File = " . $file . "\n";
     }
     // Creating p2u argument
     $argument = $parUserId . ";" . $this->reqId . ";" . $this->sceneId . ";" . $file . ";" . $this->numItem . ";" . $this->restoration;
     $procPar = 0;
     if ($GLOBALS["stationDebug"]) {
         echo "RequestClass - Argument = " . $argument . "\n";
     }
     // Instantiating P2 class
     searchMedia($this->bd, $objMedia, $this->media);
     $execClass = $objMedia[0]->getExecClass();
     if ($GLOBALS["stationDebug"]) {
         echo "1 - RequestClass - starting P2U or P2C = " . $execClass . "\n";
     }
     if ($satCod == "P6" and ($sensor == "LIS3" or $sensor == "AWIF")) {
         include_once "listFiles.php";
         if ($sensor == "LIS3") {
             $sensor = "LISS3";
         } else {
             $sensor = "AWIFS";
         }
         $dir_path = getTiffDir($satCod);
         $res = explode("-", $date_IRS);
         $date_dir = $res[0] . "_" . $res[1];
         $date_aux = $res[0] . $res[1] . $res[2];
         $tiff_dir = $dir_path . "{$date_dir}/{$satCod}" . "_{$sensor}" . "_{$date_aux}/{$path_IRS}" . "_{$row_IRS}";
         //       $tiffs = listFiles2($tiff_dir,"");
         //       $cmd = "ls -1 $tiff_dir";
         //       $res = shell_exec($cmd);
         //			 $tiffs = explode("\n",$res);
         $aux_tiffs = glob($tiff_dir . "/*");
         $index = 0;
         foreach ($aux_tiffs as $file) {
             $tiffs[$index] = basename($file);
             $index++;
         }
         print_r($tiffs);
         $argument = $parUserId . ";" . $this->reqId . ";" . $this->sceneId . ";" . $tiff_dir . ";" . $this->numItem . ";" . $satCod;
         if ($GLOBALS["stationDebug"]) {
             echo "RequestClass ====> starting P2U for P6 products - Argument = {$argument} \n";
         }
         if ($GLOBALS["stationDebug"]) {
             echo "\n RequestClass =====> tifdir = {$tiff_dir} \n";
         }
         $p2u = new p2u($argument);
     } else {
         // GLS
         // ===
         if ($sufix == "GLS") {
             $sql = "SELECT Gralha FROM LandsatScene WHERE SceneId='" . $this->sceneId . "'";
             $this->bd->query($sql) or die("<br> Error on execution/result sql = {$sql} <br>");
             $itens = $this->bd->numRows();
             if ($itens == 0) {
                 die("Erro nas Cenas");
             }
             $row = $this->bd->fetchRow();
             $this->bd->freeResult($results);
             $gralha = $row["Gralha"];
             decodeGralha($gralha, $satellite, $number, $instrument, $channel_gralha, $type, $date, $path, $row);
             if ($number == 5) {
                 $sat_prefix = "LT5";
             } else {
                 $sat_prefix = "LE7";
             }
             $year = substr($date, 0, 4);
             $timestamp = strtotime($date);
             $julian_date = strftime('%j', $timestamp);
             $sql = "SELECT Dataset FROM Scene WHERE SceneId='" . $this->sceneId . "'";
             if ($GLOBALS["stationDebug"]) {
                 echo "\n =====> RequestClass - Sql Command: " . $sql . "\n";
             }
             $this->bd->query($sql);
             $row_result = $this->bd->fetchRow() or die("\n =====> Request.Class - execute ====> Error on execution/result sql = {$sql} \n");
             $dataset = $row_result["Dataset"];
             $this->bd->freeResult();
             if ($dataset == "GLS2000") {
                 $target_tiffs = "*" . $path . "*" . $row . "*" . $date . "*.tar.gz";
             } else {
                 $target_tiffs = "*" . $path . "*" . $row . "*" . $year . $julian_date . "*.tar.gz";
             }
             $dir_path = getTiffDir($sufix);
             $tiff_dir = $dir_path . $satellite . $number;
             $cmd = "find {$tiff_dir} -name {$target_tiffs}";
             $cmd = addslashes($cmd);
             echo "\n =====> Request.Class - execute ====> com = {$cmd} \n";
             $output = shell_exec($cmd);
             $output = substr($output, 0, strlen($output) - 1);
             if ($output == "") {
                 die("\n =====> Request.Class - execute ====> No files : {$target_tiffs} !");
             }
             $tiffs = explode("\n", $output);
             sort($tiffs);
             echo "\ntiffs = \n";
             print_r($tiffs);
             echo "\n";
             $argument = $parUserId . ";" . $this->reqId . ";" . $this->sceneId . ";" . $tiffs[0] . ";" . $this->numItem . ";" . $sufix;
             echo "\nargument = \n";
             print_r($argument);
             echo "\n";
             $p2u = new p2u($argument);
             //      echo "\n<br> argument = $argument";
         } else {
             $p2u = new $execClass($argument);
             $tiffs = $p2u->getTiffs();
         }
     }
     //      print_r($tiffs);
     // For generation of a product
     if ($sensor == "CCD") {
         $bands_all = array(0 => "5", 1 => "BAND1", 2 => "BAND2", 3 => "BAND3", 4 => "BAND4", 5 => "BAND5");
         $bands_lacking = 0;
         foreach ($tiffs as $tiff_found) {
             $one_tiff = basename($tiff_found);
             for ($i = 1; $i <= $bands_all[0]; $i++) {
                 $found = strstr($one_tiff, $bands_all[$i]);
                 if ($found) {
                     $bands_all[$i] = 1;
                     $bands_lacking += 1;
                 }
             }
         }
         for ($i = 1; $i < 6; $i++) {
             if ($bands_all[$i] != 1) {
                 $bands_lacking += 1;
             }
         }
     }
     if ($sensor != "CCD") {
         $factor = 1;
     } else {
         if ($bands_lacking > 0) {
             $factor = 6;
         } else {
             $factor = 5;
         }
     }
     // We could have two repeated bands 3 (CCD1XS and CCD2XS), plus bands 1,2 and 4, and no PAN, and we would have 5 bands on directory!
     //      if(trim($this->productId)== "" and count($tiffs) < $factor)
     if (count($tiffs) < $factor) {
         // Tiff does not exist in disk, lets build it from gralha
         if ($GLOBALS["stationDebug"]) {
             echo "RequestClass - Tiff not found, looking for {$file}\n";
         }
         $gralhas = findSimilarGralhainDisk($file);
         $count_gralhas = count($gralhas);
         if ($count_gralhas > 0 or count($tiffs) > 0) {
             $gralhas_files = array(0 => "CCD1XS", 1 => "CCD2XS", 2 => "CCD2PAN");
             foreach ($gralhas as $filedir) {
                 if ($GLOBALS["stationDebug"]) {
                     echo "<br> \n RequestClass - {$filedir} found <br> \n";
                 }
                 if ($sensor == "CCD") {
                     decodeGralha(basename($filedir), $satellite, $number, $instrument, $channel, $type, $date, $path, $row);
                     $this_gralha_tiffs = findTiffinDiskFromGralha(basename($filedir), $this->restoration, $channel);
                     // look for specific (Channel) Tiff data
                     switch ($type) {
                         case "XS":
                             if ($channel == 1) {
                                 $gralhas_files[0] = "1";
                             } else {
                                 $gralhas_files[1] = "1";
                             }
                             // Gralha CCD2XS present
                             break;
                         case "PAN":
                             $gralhas_files[2] = "1";
                             // Gralha CCD2PAN present
                     }
                     if (count($this_gralha_tiffs) == 0) {
                         $procPar = $this->g2tStart($filedir, $procPar, $satCod);
                     }
                 } else {
                     if ($sensor == "ETM") {
                         $filepan = str_replace("XS", "PAN", $filedir);
                         $procPar = $this->g2tStart($filepan, $procPar, $satCod);
                     }
                     $procPar = $this->g2tStart($filedir, $procPar, $satCod);
                 }
             }
             if ($sensor == "CCD") {
                 for ($i = 0; $i < 3; $i++) {
                     if ($gralhas_files[$i] != "1") {
                         $gralha_name = str_replace("CCD1XS", $gralhas_files[$i], $file);
                         // CCD1XS is the reference for Gralha in CbersScene
                         decodeGralha($gralha_name, $satellite, $number, $instrument, $channel, $type, $date, $path, $row);
                         $tiffs_found = findTiffinDiskFromGralha($gralha_name, $this->restoration, $channel);
                         // look for specific (Channel) Tiff data
                         if (count($tiffs_found) == 0) {
                             $status = findDRDfromSceneId($this->sceneId, $drds, $tapeid, $tapepath, $skip);
                             if ($status == 0) {
                                 if ($gralhas_files[$i] == "CCD1XS") {
                                     $index = 0;
                                 } else {
                                     $index = 1;
                                 }
                                 // Corresponds to DRD[1] (CCD2XS and CCD2PAN)
                                 $fulldrd = findDRDinDisk($drds[$index]);
                                 if (strlen($fulldrd) > 1) {
                                     $d2g = new d2g($drds[$index]);
                                     $d2g->createWorkOrder();
                                     $d2g->start($procPar);
                                     $procPar = $this->g2tStart($gralha_name, $d2g->id(), $satCod);
                                     $gralhas_files[$i] = "1";
                                 } else {
                                     $inproduction = false;
                                 }
                             } else {
                                 $inproduction = false;
                             }
                         } else {
                             $gralhas_files[$i] = "1";
                         }
                         // Gralha not present but Tiffs are !!! That's what matters !!!
                     }
                 }
             }
         } else {
             if ($GLOBALS["stationDebug"]) {
                 echo "<br> RequestClass - Gralhas not found, looking for DRD\n";
             }
             $status = findDRDfromSceneId($this->sceneId, $drds, $tapeid, $tapepath, $skip);
             if ($GLOBALS["stationDebug"]) {
                 echo "<br> RequestClass - Nome DRD = {$drds['0']} <br> \n";
             }
             if ($status == 0) {
                 if ($sensor == "CCD") {
                     $limit = 2;
                 } else {
                     $limit = 1;
                 }
                 // Just one DRD to process
                 if ($GLOBALS["stationDebug"]) {
                     echo "<br> RequestClass - drd = {$drds} \n";
                 }
                 for ($i = 0; $i < $limit; $i++) {
                     $fulldrd = findDRDinDisk($drds[$i]);
                     if (strlen($fulldrd) > 1) {
                         if ($GLOBALS["stationDebug"]) {
                             echo "<br> RequestClass - drd = {$drds} full = {$fulldrd} \n";
                         }
                         if ($satCod == "T1" or $satCod == "A1") {
                             $d2g = new c2h($fulldrd);
                         } else {
                             $d2g = new d2g($drds[$i]);
                             $d2g->createWorkOrder();
                         }
                         $d2g->start($procPar);
                         if ($GLOBALS["stationDebug"]) {
                             echo "<br> RequestClass - After D2G, creating g2t para " . $gralha . "\n";
                         }
                         if ($satCod == "T1" or $satCod == "A1") {
                             decodeDRD($drds[$i], $satellite, $number, $instrument, $year, $month, $day, $hour, $minute, $second, $channel);
                             $datedir = $year . "_" . $month;
                             $datepath = getGralhaDir($satellite . $number) . $datedir;
                             $result = explode("_", $file);
                             $hdfName = $result[0] . "." . "hdf";
                             $hdfFullName = $datepath . "/" . $drds[$i] . "/" . $hdfName;
                             $arg = $hdfFullName;
                         } else {
                             $arg = $file;
                         }
                         if ($i == 1) {
                             $arg = str_replace("CCD1XS", "CCD2XS", $file);
                             $procPar = $this->g2tStart($arg, $d2g->id(), $satCod);
                             $arg = str_replace("CCD1XS", "CCD2PAN", $file);
                             $procPar = $this->g2tStart($arg, $procPar, $satCod);
                         } else {
                             $procPar = $this->g2tStart($arg, $d2g->id(), $satCod);
                         }
                     } else {
                         /*
                         #
                         # Old code segment - proceedings have been improved.
                         #
                         							if ($GLOBALS["stationDebug"]) echo "<br> RequestClass - DRD not found, looking for DRD on tape\n";
                         $targument = $tapeid.";".$tapepath.";;".$skip; // IMPORTANT
                         if ($GLOBALS["stationDebug"]) echo "<br> RequestClass - Argument = " . $targument . "\n";
                         $m2d = new m2d ($targument);
                         $m2d->setStatus ("OPERATOR");
                         if ($GLOBALS["stationDebug"]) echo "<br> RequestClass - Bd = Man " . $m2d->dbman . " Cat = " . $m2d->dbcat . "\n";
                         if ($GLOBALS["stationDebug"]) echo "<br> RequestClass - Bd = Man " . $GLOBALS["dbmanager"] . " Cat = " . $GLOBALS["dbcatalog"] . "\n";
                         $m2d->start ();
                         if ($GLOBALS["stationDebug"]) echo "<br> RequestClass - After M2D, creating d2g para " . $drds . "\n";
                         $d2g = new d2g ($drds[$i]);
                         $d2g->createWorkOrder();
                         $d2g->start ($m2d->id());
                         $procPar = $this->g2tStart($file, $d2g->id(),$satCod);
                         #
                         #
                         #
                         */
                         echo "<br> RequestClass - DRD data ({$drds[$i]}) not found ! <br>\n";
                         if ($sensor == "CCD") {
                             if ($i > 0) {
                                 $arg = str_replace("CCD1XS", "CCD2XS", $argument);
                             }
                             $m2d_warning = new m2d("{$arg}");
                             $m2d_warning->setStatus("OPERATOR");
                             $m2d_warning->start(0, "<font color=#FF0000>WARNING ====> </font> DRD data ({$drds[$i]}) not found on proper directory ! ");
                         } else {
                             $inproduction = false;
                         }
                     }
                 }
             } else {
                 $inproduction = false;
             }
         }
     }
     // Setting up status
     if ($sensor == "CCD" and $inproduction == false) {
         if ($gralhas_files[0] != "1") {
             $arg = str_replace("CCD2XS", "CCD1XS", $argument);
             $msg = "Can\\'t Generate GRALHA CCD1XS Data !";
             $p2u_warning = new p2u($arg);
             $p2u_warning->setStatus("OPERATOR");
             $p2u_warning->start(0, "<font color=#FF0000>WARNING ====>  </font>" . $msg);
         }
         if ($gralhas_files[1] != "1") {
             // Let's first check if CCD2XS Band 3 (that might be repeated due to CCD1XS) is the one that's lacking; if so, NO PROBLEMS !
             if ($bands_all[1] != "1" or $bands_all[3] != "1") {
                 $arg = str_replace("CCD1XS", "CCD2XS", $argument);
                 $msg = "Can\\'t Generate GRALHA CCD2XS Data !";
                 $p2u_warning = new p2u($arg);
                 $p2u_warning->setStatus("OPERATOR");
                 $p2u_warning->start(0, "<font color=#FF0000>WARNING ====>  </font>" . $msg);
             }
         }
         if ($gralhas_files[2] != "1") {
             $msg = "Can\\'t Generate GRALHA CCD2PAN Data !";
             $arg = str_replace("CCD1XS", "CCD2PAN", $argument);
             $p2u_warning = new p2u($arg);
             $p2u_warning->setStatus("OPERATOR");
             $p2u_warning->start(0, "<font color=#FF0000>WARNING ====>  </font>" . $msg);
         }
         $inproduction = true;
         // We previously know that we have at least one CCD - otherwise we would have been directed to the m2d operation above !!!
     }
     if ($this->status != 'Q') {
         $this->updateStatus($inproduction ? 'C' : 'Y');
     }
     if ($inproduction == true) {
         if ($GLOBALS["stationDebug"]) {
             echo "RequestClass - Everything OK - let's start p2u with this dependence " . $procPar . "\n";
         }
         if (trim($execClass) != "p2u") {
             if ($this->status != 'Q') {
                 // This clause has been added to provide a previous execution of a "p2c" request for allowing Control Quality
                 // assesment, before mailing product to user.
                 // Comment this statement if this policy be changed.
                 $p2u->setStatus("OPERATOR");
             }
         }
         $p2u->start($procPar);
     } else {
         $p2u->sendErrorMail($file);
         $p2u->sendFirstMail();
         $p2u->setStatus("OPERATOR");
         switch ($satCod) {
             case "P6":
                 $msg = "Tiff files no found !";
                 break;
             case "L5":
             case "L7":
                 if ($sufix == "GLS") {
                     $msg = "Tiff files no found !";
                 } else {
                     $msg = "DRD data not found !";
                 }
                 break;
             default:
                 $msg = "DRD data not found !";
         }
         $p2u->start(0, $msg);
     }
 }
function findTiffinDiskFromGralha($gralha, $restoration, $bands = "")
{
    if ($GLOBALS["stationDebug"]) {
        echo "\n ====> ** teste TiffFunctions:findTiffinDiskFromGralha =====> gralha = {$gralha} \n";
    }
    if ($restoration == "P6" or $restoration == "GLS" or $restoration == "UKDMC") {
        $fullname = array();
        if ($restoration == "GLS") {
            $fullname[0] = $gralha;
            print_r($fullname);
            return $fullname;
        }
        $result = explode('_', strtoupper($gralha));
        $satellite = $result[0];
        if ($satellite == "AQUA" or $satellite == "TERRA") {
            $numero = $result[1];
            $sensor = $result[2];
            $data = $result[3];
            $hora = $result[4];
            if ($GLOBALS["stationDebug"]) {
                echo "\n É AQUA OU TERRA \n\n";
                print_r($result);
                echo "\n\n";
            }
            $fullname = array();
            $fullname[0] = $gralha;
            print_r($fullname);
            return $fullname;
        }
        include_once "listFiles.php";
        $tiffs = listFiles($gralha, "0");
        //	 print_r ($tiffs);
        $fullname = array();
        $index = 0;
        foreach ($tiffs as $file) {
            $fullname[$index] = "{$gralha}/{$file}";
            $index++;
        }
        return $fullname;
    }
    //decodeGralha($gralha,$satellite,$number,$instrument,$channel_gralha,$type,$date,$path,$row);
    decodeGralha2($gralha, $satellite, $number, $instrument, $channel_gralha, $type, $date, $path, $row, $hora);
    #
    # Gralha CCD1XS provides Band-2, Band-3 and Band-4 Tiffs
    # Gralha CCD2XS provides Band-1, Band-3 Tiffs
    # Gralha CCD2PAN provides Band-5 (Pan) Tiff
    #
    if ($type == "PAN") {
        $gralha = str_replace("CCD2PAN", "CCD1XS", $gralha);
    } else {
        if ($channel_gralha == "2") {
            $gralha = str_replace("CCD2XS", "CCD1XS", $gralha);
        }
    }
    if ($GLOBALS["stationDebug"]) {
        echo "\n ====> TiffFunctions:findTiffinDiskFromGralha - Gralha = {$gralha} Satellite = {$satellite} Number = {$number} Instrument = {$instrument} Channel_gralha = {$channel_gralha} Type = {$type} Date = {$date} Path = {$path} Row = {$row}  \n";
    }
    $dbcat = $GLOBALS["dbcatalog"];
    switch ($satellite) {
        case "CBERS":
            $sat_prefix = "Cbers";
            break;
        case "AQUA":
            $sat_prefix = "Modis";
            break;
        case "TERRA":
            $sat_prefix = "Modis";
            break;
        case "LANDSAT":
            $sat_prefix = "Landsat";
            break;
        case "NPP":
        case "SNPP":
        case "S-NPP":
            $sat_prefix = "Npp";
    }
    if ($sat_prefix != "Landsat") {
        if ($GLOBALS["stationDebug"]) {
            echo "BBB -> findTiffinDiskfromGralha - Antes do Teste 9999 <br>\n";
        }
        if ($sat_prefix != "Modis" and $sat_prefix != "Npp" and strlen($gralha) >= 30) {
            if ($GLOBALS["stationDebug"]) {
                echo "BBB -> findTiffinDiskfromGralha - Depois do Teste 9999 -- AQUA e TERRA Antigo <br>\n";
            }
            $sql = "SELECT DRD FROM {$sat_prefix}" . "Scene WHERE GRALHA = '{$gralha}'";
            if ($GLOBALS["stationDebug"]) {
                echo "QQQQQ -> findTiffinDiskfromGralha - sql = {$sql} <br>\n";
            }
            $dbcat->query($sql) or $dbcat->error($sql);
            $row_array = $dbcat->fetchRow();
            $drdName = $row_array[DRD];
            decodeDRD($drdName, $satellite, $number, $instrument, $year, $month, $day, $hour, $minute, $second, $channel);
            if ($GLOBALS["stationDebug"]) {
                echo "\n ====> MMMM TiffFunctions:findTiffinDiskFromGralha - DRDname = {$drdName} Satellite = {$satellite} Number = {$number} Instrument = {$instrument} Year = {$year} Month = {$month} Day = {$day} Hour = {$hour} Minute = {$minute} Second = {$second} Channel = {$channel}  \n";
            }
            $date = sprintf("%4d%02d%02d.%02d%02d%02d", $year, $month, $day, $hour, $minute, $second);
        }
    }
    $dname = substr("{$date}", 0, 4) . "_" . substr("{$date}", 4, 2);
    $dir = getTiffDir($satellite . $number) . $dname;
    if ($sat_prefix == "Landsat") {
        $date = $date . "*";
    }
    $dir = $dir . "/" . $satellite . $number . "_" . $instrument . "_" . $date . "/";
    if ($restoration == 1) {
        $restor = "_rest";
    }
    if ($sat_prefix !== "Modis") {
        $dir = $dir . $path . "_{$row}" . "_0" . $restor . "/";
    }
    // Modis PATH and ROW have formats not due to
    // other satellites formats
    // (e.g. LANDSAT, CBERS : path = nnn and row = nnn
    // MODIS : path = vn or vnn and row = hn or hnn
    // where "v" and "h" are tags for vetical (path)
    if ($GLOBALS["stationDebug"]) {
        echo "\n****************** <br>\n";
    }
    if ($GLOBALS["stationDebug"]) {
        echo "WWW** -> findTiffinDiskfromGralha - dir = {$dir} <br>\n";
    }
    //	echo "\n ==============> dir = $dir \n";
    // Lets find the generic name for similar CCD gralhas (CCD1XS,CCD2XS,CCD2PAN) CBERS_2_CCD1XS_20040130_153_126.h5
    $target = $gralha;
    //	echo " target = $gralha \n ";
    if ($instrument == "CCD") {
        $pieces = explode("_", $gralha);
        if (isset($bands) and is_numeric($bands)) {
            $channel_gralha = $bands;
        } else {
            $channel_gralha = "*";
            $type = "*";
        }
        $target = $pieces[0] . "_" . $pieces[1] . "_CCD" . $channel_gralha . $type . "_" . $pieces[3] . "_" . $pieces[4] . "_" . $pieces[5];
    } else {
        if ($instrument == "ETM") {
            $target = str_replace("ETMXS_", "ETM*_", $target);
        }
    }
    // For Landsat-7 ETM : just to include the PAN band (ETMPAN)
    //echo " p0 = $pieces[0] p1 = $pieces[1] p3 = $pieces[3] p4 = $pieces[4] p5 = $pieces[5] \n";
    if ($sat_prefix == "Modis") {
        $tiff = basename($target, ".h5") . "*.tif.zip";
    } else {
        $tiff = basename($target, ".h5") . "_L?_BAND*.tif.zip";
    }
    // Added : 1) Level indicator (L2, by default)	                                                           //         2) Suffix ".zip"
    if ($GLOBALS["stationDebug"]) {
        echo "\n\nSatellite : {$satellite}";
    }
    if ($GLOBALS["stationDebug"]) {
        echo "\nInstrument : {$instrument}";
    }
    if ($GLOBALS["stationDebug"]) {
        echo "\ntiff : {$tiff} \n\n";
    }
    $com = "find {$dir} -name {$tiff}";
    if ($GLOBALS["stationDebug"]) {
        echo "\n\nAQUA e TERRA Normal";
        echo "\nsat_prefix =  {$sat_prefix}\n";
        echo "\ndir =  {$dir}\n";
        echo "\niff =  {$tiff}\n";
        echo "\ncom =  {$com}\n\n";
    }
    // AQUA e TERRA
    // ============
    if (($satellite == "AQUA" or $satellite == "TERRA") and strtoupper($instrument) == "MODIS" and (strlen($gralha) == 28 or strlen($gralha) == 29)) {
        //$com= "find $dir -name $tiff";
        $ano = substr($date, 0, 4);
        $mes = substr($date, 4, 2);
        $dia = substr($date, 6, 2);
        $hra = substr($hora, 0, 2);
        $min = substr($hora, 2, 2);
        $seg = substr($hora, 4, 2);
        $dir_base = '/Level-2/';
        $dir_satelite = "{$satellite}{$number}";
        $dir_periodo = "{$ano}" . '_' . "{$mes}";
        $dir_arquivo = "{$satellite}" . '_' . "{$instrument}" . '.' . "{$ano}" . '_' . "{$mes}" . '_' . "{$dia}" . '.' . "{$hra}" . '_' . "{$min}" . '_' . "{$seg}";
        $aqua_file = 'AQUA.MYDcrefl_TrueColor.' . $ano . '_' . $mes . '_' . $dia . '.' . $hra . '_' . $min . '_' . $seg . '.tif.zip';
        $terra_file = 'TERRA.MODcrefl_TrueColor.' . $ano . '_' . $mes . '_' . $dia . '.' . $hra . '_' . $min . '_' . $seg . '.tif.zip';
        $dir = $dir_base . $dir_satelite . '/' . $dir_periodo . '/' . $dir_arquivo . '/';
        if ($GLOBALS["stationDebug"]) {
            echo "\n\nAQUA e TERRA novos";
            echo "\nData : {$ano}  {$mes}  {$dia}   -   Horario : {$hra}  {$min}  {$seg}";
            echo "\naqua_file =  {$aqua_file}\n";
            echo "\nterra_file =  {$terra_file}\n";
            echo "\ndir =  {$dir}\n\n";
        }
        if ($satellite == "AQUA") {
            $tiff = $aqua_file;
        } else {
            $tiff = $terra_file;
        }
        $com = "find {$dir} -name {$tiff}";
    }
    // FIM AQUA e TERRA
    // ================
    if ($GLOBALS["stationDebug"]) {
        echo "\nsatellite : {$satellite}";
        echo "\ninstrument =  {$instrument}\n\n";
    }
    // S-NPP
    // ============
    if (($satellite == "NPP" or $satellite == "SNPP" or $satellite == "S-NPP") and strtoupper($instrument) == "VIIRS") {
        //$com= "find $dir -name $tiff";
        if ($GLOBALS["stationDebug"]) {
            echo "\n\nDentro de NPP SNPP";
        }
        $ano = substr($date, 0, 4);
        $mes = substr($date, 4, 2);
        $dia = substr($date, 6, 2);
        $hra = substr($hora, 0, 2);
        $min = substr($hora, 2, 2);
        $seg = substr($hora, 4, 2);
        $data_amd = "{$ano}-{$mes}-{$dia}";
        $comando = "echo \$(date +'%j' -d {$data_amd})";
        $ano_juliano = substr($ano, 2, 2);
        $dia_juliano = shell_exec($comando);
        $dia_juliano = substr($dia_juliano, 0, strlen($dia_juliano) - 1);
        $dia_juliano = rtrim($dia_juliano);
        $dir_base = '/L2_NPP/';
        $dir_periodo = "{$ano}" . '_' . "{$mes}";
        $dir_arquivo = "{$satellite}" . '_' . "{$instrument}" . '.' . "{$ano}" . '_' . "{$mes}" . '_' . "{$dia}" . '.' . "{$hra}" . '_' . "{$min}" . '_' . "{$seg}";
        $npp_file = 'NPP_TCOLOR_SDR.' . "{$ano_juliano}" . "{$dia_juliano}" . "{$hra}" . "{$min}" . "{$seg}" . '.tif.zip';
        $dir = $dir_base . $dir_periodo . '/' . $dir_arquivo . '/';
        $tiff = "{$npp_file}";
        $com = "find {$dir} -name {$tiff}";
        if ($GLOBALS["stationDebug"]) {
            echo "\n\nData : {$ano}  {$mes}  {$dia}   -   Horario : {$hra}  {$min}  {$seg}";
            echo "\nnpp_file =  {$npp_file}\n";
            echo "\ndir =  {$dir}\n\n";
            echo "\ncom =  {$com}\n\n";
        }
    }
    // FIM S-NPP
    // ================
    if ($GLOBALS["stationDebug"]) {
        echo "findTiffinDiskFromGralha - command = {$com} <br>\n";
    }
    $output = shell_exec($com);
    $output = substr($output, 0, strlen($output) - 1);
    $fullname = explode("\n", $output);
    // No file was found
    if (strlen($output) <= 1) {
        if ($GLOBALS["stationDebug"]) {
            echo "findTiffinDiskFromGralha - No file found <br>\n";
        }
        $fullname = array();
        return $fullname;
    }
    if ($instrument == "CCD" and is_numeric($bands)) {
        // i.e. the number of Tiff bands found for this Gralha is less than 3 (2 in case of CCD2XS or 1 in case of CCD2PAN), we have to produce all Tiffs band from this Grallha again !!!
        if ($bands == 1) {
            $limit = 3;
        } else {
            if ($type == "PAN") {
                $limit = 1;
            } else {
                $limit = 2;
            }
        }
        if (count($fullname) < $limit) {
            if ($GLOBALS["stationDebug"]) {
                echo "findTiffinDiskFromGralha - Not all Tiff bands found <br>\n";
            }
            $fullname = array();
            return $fullname;
        }
    }
    // Tiffs were found
    if ($GLOBALS["stationDebug"]) {
        echo "findTiffinDiskFromGralha - Files found : " . count($fullname) . " (" . strlen($output) . ")<br>\n";
        print_r($fullname);
        foreach ($fullname as $file) {
            echo "{$file} <br>\n";
        }
    }
    return $fullname;
}