// SARCalibrationTool.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "SARCalibration.h"
#include "SARBaseTool.h"
#include <iostream>
#include <string>
#include <memory>



int SiglePolarCalibration(int argc, char* argv[]) {
    qDebug() << "mode  : 1 "<< "\n";
    QString in_tiff_path = "";
    QString out_path = "";
    double calibration = 0;
	// params prase
    for (int i = 0; i < argc; i++) {
		if (string(argv[i]) == "-in")
        { 
            in_tiff_path = argv[i + 1]; 
            qDebug() << "in file : " << in_tiff_path << "\n";
        }
		else if (string(argv[i]) == "-out") {
			out_path = argv[i + 1];
            qDebug() << "out file : " << in_tiff_path << "\n";
		}
        else if (string(argv[i]) == "-calibrationConst") {
            calibration = strtod(argv[i + 1], NULL);
            qDebug() << "calibrationConst  : " << calibration << "\n";
        }
        else {}
    }
    // excute tool
    return CalibrationComplex(out_path, in_tiff_path, calibration);
}


int RasterComplex2dB(int argc, char* argv[]) {
    qDebug() << "mode  : 1 " << "\n";
    QString in_tiff_path = "";
    QString out_path = "";
    // params prase
    for (int i = 0; i < argc; i++) {
        if (string(argv[i]) == "-in")
        {
            in_tiff_path = argv[i + 1];
            qDebug() << "in file : " << in_tiff_path << "\n";
        }
        else if (string(argv[i]) == "-out") {
            out_path = argv[i + 1];
            qDebug() << "out file : " << in_tiff_path << "\n";
        }
        else {}
    }
    // excute tool
    return Complex2dB(in_tiff_path, out_path);
}


int Test_SARCalibrationTool(int argc, char* argv[])
{
    qDebug() << "calibration tool " << "\n";
    qDebug() << "sigle polsar Amg:  SARCalibrationTool.exe 1 -in filepath -out filepath -calibrationConst 43" << "\n";
    qDebug() << "complex 2 dB :  SARCalibrationTool.exe 1 -in filepath -out filepath" << "\n";
    if (argc == 1) {
    qDebug() << "the number of params should be than 2" << "\n";
    return 2;
    }
    try {
        int mode = atoi(argv[1]);
        if (mode == 1) {
           return  SiglePolarCalibration(argc, argv);
        }
        else if (mode == 2) {
            return  RasterComplex2dB(argc, argv);
        }
        else {}
    }
    catch (std::exception ex) {
        std::wcerr << ex.what() << "\n";
    }

    qDebug() << "Hello World!\n";
    return 0;
}

