Exemplo n.º 1
0
int execute_cmd_line()
{
#ifndef __READLINE_DEBUG
    printf("Note: Macro __READLINE_DEBUG is Undefined, thus InteractiveCmd is Unavailable!!!\n\n");
#else
//    printf("Note: Welcome to Interactive Command!\n");
//    printf("      Press 'Quit'/'Exit'/'End'/'Bye'/'Q'/'E'/'B' to quit!\n\n");
    InitReadLine();
    while(1)
    {
        char *pszCmdLine = ReadCmdLine();
        if(IsUserQuitCmd(pszCmdLine))
        {
			if(pszLineRead != NULL){
            	free(pszLineRead);
				pszLineRead = NULL;
			}
            break;
        }

        if (ExecCmd(pszCmdLine) < 0){
			printf("ERR: can't find command!\n");
		}
    }
#endif

    return 0;
}
Exemplo n.º 2
0
int ActingAsServer(int argc, char* argv[], bool dbg) {
    SerialCom comm;
    PipeShell shell;
    int nPort = 1;
    int nBaud = 9600;
    int nBits = 8;
    int nStop = 1;
    char cParity = 'N';
    char sIfName[32];
    char sLcdDev[32];
    int distance = 26000;
    int neg_mode = 0;
    bool trace_gws = dbg;
    bool trace_lcd = false;
    bool trace_neg = false;

    memset(sIfName, 0x00, 32);
    memset(sLcdDev, 0x00, 32);
    strcpy(sIfName, "wlan0");
    strcpy(sLcdDev, "/dev/ttyS0");

    if (svrInitInstance()) {
        InitParameters(true);
        BufInit(&local_gws_buff);
        ScInit(&comm, 0); //nonblock mode
        ReadFileConf(&comm, &nPort, &nBaud, &nBits, &nStop, &cParity,
                     sIfName,sLcdDev,&distance,&neg_mode,
                     &trace_gws,&trace_lcd,&trace_neg);
        ReadCmdLine(argc, argv, &nPort, &nBaud, &nBits, &nStop, &cParity,
                    &trace_lcd,&trace_neg);
        if (false == ScOpen(&comm, nPort, nBaud, nBits, nStop, cParity)) {
            ShowStatusBar("%s", "Can not open GWS radio port.\n");
        } else {
            ShowStatusBar("%s", "GWS port OK.\n");
        }
        PipeShellInit(&shell);
        svrInitCommandHandler(&comm,&shell,sIfName,trace_gws);
        ShowStatusBar("%s" VT100_RESET "\n", "gwsman server ready.\n");
        if (lcd_main(sLcdDev,distance,neg_mode,trace_lcd,trace_neg) < 0) {
            printf("\n\n");
            fflush(stdout);
            while (svrTestInstance(static_chp.m_semInstance)) usleep(100000);
        } else fflush(stdout);
        ScExit(&comm);
        BufExit(&local_gws_buff);
        svrExitCommandHandler();
    }
    svrExitInstance();
    return 1;
}
Exemplo n.º 3
0
BOOL CALLBACK EnumWindowsProc(_In_  HWND hwnd,_In_  LPARAM lParam)
{
	TCHAR textBuffer[1024];
	GetWindowText(hwnd,textBuffer,1024);

	if (wcsstr(textBuffer,L"Конфигуратор") && *textBuffer != (L'['))
	{

		DWORD pid;
		GetWindowThreadProcessId(hwnd,&pid);
		HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);

		PWSTR cmd = ReadCmdLine(proc);
		
		TCHAR * baseNamePtr = wcsstr(cmd,L"/IBName\"");
		baseNamePtr+=8;

		TCHAR * ptr = baseNamePtr;

		while(*ptr != L'\"')
		{
			ptr++;
		}

		*ptr = 0;

		TCHAR windowTitle[1024];

		wsprintf(windowTitle,L"[%s] - %s",baseNamePtr,textBuffer);
		SetWindowText(hwnd,windowTitle);


		free(cmd);
	}

	return true;
}
Exemplo n.º 4
0
int main() {
    int n, childPid;
    char buf[BUF_MAX_SIZE];
    char execPath[PATH_MAX_LEN];
    char execCmd[CMD_MAX_LEN];
    int cmdLen = 0;
    char* execArgv[BUF_MAX_SIZE];
    int argvNum = 0;
    struct ExecCmd execCmdQueue[CMD_MAX_NUM];
    int cmdNum = 0;

    chdir(WorkDir);

    if(remoteOption) CreateConnection();
    stdoutfd = dup(STDOUT_FILENO);
    stderrfd = dup(STDERR_FILENO);

    /*** a connection come ***/
    for(;;) {

        /*** accept ***/
        if(remoteOption) {
            clilen = sizeof(cli_addr);
            newsockfd = accept(sockfd, (struct sockaddr*)&cli_addr, &clilen);
            if(newsockfd < 0) {
                write(STDERR_FILENO, "accept error!\n", 14);
                exit(1);
            }
            //write(STDERR_FILENO, "accept\n", 7);
    
            /*** for remote client, stdout/stderr is client socket ***/
            if(remoteOption){ 
                dup2(newsockfd, STDOUT_FILENO);
                dup2(newsockfd, STDERR_FILENO);
            }
        }
        connectionOption = 1;
        //int line = 1;

        /*** shell start ***/
        while(connectionOption) {
            if(welcomeMsgOption) {
                welcomeMsgOption = WelcomeMsg();
            }
            //printf("%4d", line++);fflush(stdout);
            write(STDOUT_FILENO, "% ", 2);

            /*** clean & initialize variables ***/
            bzero(buf, BUF_MAX_SIZE);
            bzero(execPath, PATH_MAX_LEN);
            bzero(execCmd, CMD_MAX_LEN);
            bzero(execArgv, sizeof(execArgv));
            bzero(execCmdQueue, sizeof(execCmdQueue));
            cmdNum = 0;
            argvNum = 0;
            cmdLen = 0;

            if(remoteOption) ReadCmdLineFromRemote(buf, &n);
            else ReadCmdLine(buf, &n);

            /*** cut input ***/
            char buf2[BUF_MAX_SIZE];
            strncpy(buf2, buf, n);
            strtok(buf2, "\n");
            strtok(buf2, "\r");
            /*write(STDERR_FILENO, "parse cmd line: ", 16);
            write(STDERR_FILENO, buf2, strlen(buf2));
            write(STDERR_FILENO, "\n", 1);*/

            ParsePipe(buf2, execCmdQueue, &cmdNum);

            int i = 0;
            for(; i < cmdNum; ++i) {

                /*** clean & initialize variables ***/
                bzero(execPath, PATH_MAX_LEN);
                bzero(execCmd, CMD_MAX_LEN);
                bzero(execArgv, sizeof(execArgv));
                argvNum = 0;
                cmdLen = 0;

                if(ParseCmdAndArgv(execCmdQueue[i].execCmdLine, execCmd, execArgv, &cmdLen, &argvNum) == -1) {
                    break;
                }

                /*** select a function ***/
                if(!strcmp(execCmd, "setenv")) {
                    SetEnv(argvNum, execArgv);
                }
                else if(!strcmp(execCmd, "printenv")) {
                    PrintEnv();
                }
                else if(!strcmp(execCmd, "\n")) {
                    break;
                }
                else if(!strcmp(execCmd, "exit")) {
                    CloseAllPipe();
                    //ListAllPipe();
                    if(remoteOption) {
                        connectionOption = 0;
                        break;
                    }
                    else {
                        return 0;
                    }
                }
                else {
                    /*** prepare to execute cmd ***/

                    int refreshOption = 0;
                    int stdinOption = 0;
                    int stdoutOption = 0;
                    char* ptrNextCmdLine;
                    if(i+1 < cmdNum) {
                        ptrNextCmdLine = execCmdQueue[i+1].execCmdLine;
                    }

                    /*** | or ! or > pipe ***/
                    if(execCmdQueue[i].pipeType > 0) {
                        CreatePipe(&stdoutOption, &execCmdQueue[i].pipeType, ptrNextCmdLine);
                        
                        SetPipePriority(ptrNextCmdLine, &cmdNum, &refreshOption, &execCmdQueue[i].pipeType);
                        
                        //ListAllPipe();
                    }

                    /*** fork a process to execute the cmd (in child process) ***/
                    if( (childPid = fork()) == -1) {
                        write(STDERR_FILENO, "fork() error.\n", 14);
                    }
                    else if(childPid == 0) {
                        /*** child process ***/

                        if(remoteOption) close(sockfd);

                        SetStdin(&stdinOption);

                        SetStdoutAndStderr(&stdoutOption, &execCmdQueue[i].pipeType);

                        Execute(execCmd, execPath, execArgv, &cmdLen);

                        exit(0);
                    }
                    else {
                        /*** parent process ***/

                        wait();

                        /*** stdout check & close ***/
                        if(stdoutOption == 1) {
                            if(execCmdQueue[i].pipeType == 1 || execCmdQueue[i].pipeType == 2) {
                                //printf("close fd[1]: %d\n", pipesTail->pipefd[1]);fflush(stdout);
                                close(pipesTail->pipefd[1]);
                            }
                            else if(execCmdQueue[i].pipeType == 3 && filepipe != NULL) {
                                //printf("close file, fd: %d\n", pipesTail->pipefd[0]);fflush(stdout);
                                fclose(filepipe);
                                filepipe = NULL;
                                struct PipeStruct* tmpPtr = pipes;
                                struct PipeStruct* tmpPrePtr;
                                pipesTail->priority = 1;
                            }
                        }

                        /*** when stdin complete, close both the r/w pipe fd (that priority==1) ***/
                        struct PipeStruct* ptrPipeStruct = pipes;
                        struct PipeStruct* prePtr = NULL;
                        while(ptrPipeStruct != NULL) {
                            if(ptrPipeStruct->priority == 1) {
                                //printf("close fd[0]: %d\n", ptrPipeStruct->pipefd[0]);fflush(stdout);
                                close(ptrPipeStruct->pipefd[0]);
                                if(ptrPipeStruct == pipes) {
                                    /*** delete the first node ***/
   
                                    if(ptrPipeStruct == pipesTail) {
                                        /*** the first node is also the last node ***/
   
                                        free(ptrPipeStruct);
                                        pipes = NULL;
                                        pipesTail = NULL;
                                        break;
                                    }
                                    else {
                                        pipes = ptrPipeStruct->next;
                                        free(ptrPipeStruct);
                                        ptrPipeStruct = pipes;
                                    }
                                }
                                else if(ptrPipeStruct == pipesTail) {
                                    /*** delete the last node ***/

                                    prePtr->next = NULL;
                                    pipesTail = prePtr;
                                    free(ptrPipeStruct);
                                    break;
                                }
                                else {
                                    prePtr->next = ptrPipeStruct->next;
                                    free(ptrPipeStruct);
                                    ptrPipeStruct = prePtr->next;
                                }

                            }
                            else {
                                prePtr = ptrPipeStruct;
                                ptrPipeStruct = ptrPipeStruct->next;
                            }
                        }

                        /*** refresh the next pipe priority ***/
                        if(refreshOption) {
                            pipesTail->priority = pipesTail->priority - 1;
                        }

                        /*** handle > pipe, end this execCmdQueue ***/
                        if(execCmdQueue[i].pipeType == 3) {
                            break;
                        }
                    }
                }
            }
            RefreshPipe();
        }
        if(remoteOption){
            dup2(stdoutfd, STDOUT_FILENO);
            dup2(stderrfd, STDERR_FILENO);
            close(newsockfd);
        }
        welcomeMsgOption = 1;
        bzero(PATH, sizeof(PATH));
        strcpy(PATH[0], "bin");
        strcpy(PATH[1], ".");
        pathNum = 2;
    }
    if(remoteOption) close(sockfd);
    return 0;
}
Exemplo n.º 5
0
Param_t *GetParam(int argc, const char **argv)
/* 
!C******************************************************************************

!Description: 'GetParam' sets up the 'param' data structure and populate with user
 parameters, either from the command line or from a parameter file.
 
!Input Parameters:
 argc           number of command line arguments
 argv           command line argument list

!Output Parameters:
 (returns)      'param' data structure or NULL when an error occurs

!Team Unique Header:

 ! Design Notes:
   1. An error status is returned when:
       a. memory allocation is not successful
       b. an error is returned from the ReadCmdLine function
       c. certain required parameters are invalid or not entered:
            input file name, output file name, geolocation file name,
	    SDS name, output space projection number, 
	    output space pixel size, output space upper left corner, 
	    output space image size, either output space sphere or projection
	    parameter number 0
	    output space zone number not given for UTM
   2. Error of type 'a' are handled with the 'LOG_RETURN_ERROR' macro and 
      the others are handled by writting the error messages to 'stderr' and 
      then printing the usage information.
   3. 'FreeParam' should be called to deallocate memory used by the 
      'param' data structures.

!END****************************************************************************
*/
{
  Param_t *this;
  Input_t *input = NULL;
  int i, j, ip, jp;
  char tmp_sds_name[MAX_STR_LEN];
  char errstr[M_MSG_LEN+1];            /* error string for OpenInput */
  char msg[M_MSG_LEN+1];
  char *extptr;                        /* ptr to the output file extension */
  double tmp_pixel_size;
  Geo_coord_t ul_corner;
  Geo_coord_t lr_corner;
  int copy_dim[MYHDF_MAX_RANK];

  /* Create the Param data structure */
  this = (Param_t *)malloc(sizeof(Param_t));
  if (this == (Param_t *)NULL)
    LOG_RETURN_ERROR("allocating Input structure", "GetParam",
                          (Param_t *)NULL);

  /* set default parameters */
  this->multires = false;
  this->input_file_name = (char *)NULL;
  this->output_file_name = (char *)NULL;
  this->geoloc_file_name = (char *)NULL;
  this->input_space_type = SWATH_SPACE;   /* Default is input swath */
  this->output_file_format = HDF_FMT;     /* Default is HDF output */

  this->num_input_sds = 0;                /* Default is no SDSs specified */
  this->output_space_def.pixel_size = -1.0;
  for (ip = 0; ip < MAX_SDS_DIMS; ip++)
  {
    this->input_sds_nbands[ip] = 0;
    this->output_pixel_size[ip] = -1.0;
    this->output_img_size[ip].l = -1;
    this->output_img_size[ip].s = -1;
    this->output_dt_arr[ip] = -1;
    this->ires[ip] = -1;
    this->fill_value[ip] = -1.0;

    for (jp = 0; jp < MAX_VAR_DIMS; jp++)
      this->input_sds_bands[ip][jp] = 0; /* Default is no bands processed */

    this->create_output[ip] = true;
    this->rank[ip] = 2;
    for (jp = 0; jp < MYHDF_MAX_RANK; jp++)
      this->dim[ip][jp] = 0;
    this->dim[ip][0] = -1;
    this->dim[ip][1] = -2;
  }

  this->input_sds_name = (char *)NULL;
  this->output_sds_name = (char *)NULL;
  this->iband = -1;
  this->kernel_type = NN;

  this->output_space_def.proj_num = -1;
  for (ip = 0; ip < NPROJ_PARAM; ip++)
    this->output_space_def.proj_param[ip] = 0.0;
  for (ip = 0; ip < NPROJ_PARAM; ip++)
    this->output_space_def.orig_proj_param[ip] = 0.0;
  this->output_space_def.ul_corner.x = -1.0;
  this->output_space_def.ul_corner.y = -1.0;
  this->output_space_def.ul_corner_geo.lat = -1.0;
  this->output_space_def.ul_corner_geo.lon = -1.0;
  this->output_space_def.ul_corner_set = false;
  this->output_space_def.lr_corner.x = -1.0;
  this->output_space_def.lr_corner.y = -1.0;
  this->output_space_def.lr_corner_geo.lat = -1.0;
  this->output_space_def.lr_corner_geo.lon = -1.0;
  this->output_space_def.lr_corner_set = false;
  this->output_space_def.img_size.l = -1;
  this->output_space_def.img_size.s = -1;
  this->output_space_def.zone = 0;
  this->output_space_def.zone_set = false;
  this->output_space_def.sphere = -1;
  this->output_space_def.isin_type = SPACE_NOT_ISIN;
  this->output_spatial_subset_type = LAT_LONG;

  /* Input space is not really used, since the MRTSwath will not
     work with Grids (only swath) */
  this->input_space_def.proj_num = -1;
  for (ip = 0; ip < NPROJ_PARAM; ip++)
    this->input_space_def.proj_param[ip] = 0.0;
  this->input_space_def.pixel_size = -1.0;
  this->input_space_def.ul_corner.x = -1.0;
  this->input_space_def.ul_corner.y = -1.0;
  this->input_space_def.ul_corner_set = false;
  this->input_space_def.img_size.l = -1;
  this->input_space_def.img_size.s = -1;
  this->input_space_def.zone = 0;
  this->input_space_def.zone_set = false;
  this->input_space_def.sphere = -1;
  this->input_space_def.isin_type = SPACE_NOT_ISIN;

  this->output_data_type = -1;
  this->patches_file_name = "patches.tmp";        

  /* Read the command-line and parameter file parameters */
  if (!ReadCmdLine(argc, argv, this)) {
    FreeParam(this);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    return (Param_t *)NULL; 
  }

  /* Check to see that all of the parameters are entered */
  if ((this->input_file_name == (char *)NULL)  ||  
      (strlen(this->input_file_name) < 1)) {
    sprintf(msg, "resamp: input file name not given\n");
    LogInfomsg(msg);
    FreeParam(this);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    return (Param_t *)NULL; 
  }

  /* Check the output filename */
  if ((this->output_file_name == (char *)NULL)  ||  
      (strlen(this->output_file_name) < 1)) {
    sprintf(msg, "resamp: output file name not given\n");
    LogInfomsg(msg);
    FreeParam(this);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    return (Param_t *)NULL; 
  }

  /* Check to see if a .hdf, .hdr. or .tif extension was provided in the
     filename. If so, remove it since the output file format will specify
     the output extension. */
  extptr = strstr (this->output_file_name, ".hdf");
  if (extptr)
    extptr[0] = '\0';

  extptr = strstr (this->output_file_name, ".HDF");
  if (extptr)
    extptr[0] = '\0';

  extptr = strstr (this->output_file_name, ".hdr");
  if (extptr)
    extptr[0] = '\0';

  extptr = strstr (this->output_file_name, ".HDR");
  if (extptr)
    extptr[0] = '\0';

  extptr = strstr (this->output_file_name, ".tif");
  if (extptr)
    extptr[0] = '\0';

  extptr = strstr (this->output_file_name, ".TIF");
  if (extptr)
    extptr[0] = '\0';

  /* Check the output file format */
  if ((this->output_file_format != HDF_FMT) && 
      (this->output_file_format != GEOTIFF_FMT) &&
      (this->output_file_format != RB_FMT) &&
      (this->output_file_format != BOTH)) {
    sprintf(msg, "resamp: unsupported output file format\n");    
    LogInfomsg(msg);
    FreeParam(this);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    return (Param_t *)NULL; 
  }

  if ((this->input_space_type == SWATH_SPACE)  &&
      ((this->geoloc_file_name == (char *)NULL)  ||  
       (strlen(this->input_file_name) < 1))) {
    sprintf(msg, "resamp: geolocation file name not given\n");
    LogInfomsg(msg);
    FreeParam(this);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    return (Param_t *)NULL; 
  }

  /* If no SDS names were specified then process all of them in the file,
     otherwise fill in the rest of the SDS information. */
  if (this->num_input_sds == 0) {
    /* Process all the SDS names, by default */
#ifdef DEBUG
    printf ("Reading default SDSs\n");
#endif
    this->num_input_sds = ReadSDS(this);
    if (this->num_input_sds == 0) {
      sprintf(msg, "resamp: error reading default SDS names\n");
      LogInfomsg(msg);
      FreeParam(this);
      sprintf(msg, "%s\n", USAGE);
      LogInfomsg(msg);
      return (Param_t *)NULL; 
    }
  }
  else {
    /* Read the SDSs and determine the number of bands in each */
    if (!SDSInfo(this)) {
      sprintf(msg, "resamp: error reading SDS information\n");
      LogInfomsg(msg);
      FreeParam(this);
      sprintf(msg, "%s\n", USAGE);
      LogInfomsg(msg);
      return (Param_t *)NULL; 
    }
  }

  /* Check output space definition */
  if (this->output_space_def.proj_num < 0) {
    sprintf(msg, "resamp: output space projection number not given\n");
    LogInfomsg(msg);
    FreeParam(this);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    return (Param_t *)NULL; 
  }

  /* Loop through all the SDSs and determine their resolution */
  for (i = 0; i < this->num_input_sds; i++)
  {
    /* Loop through all the bands in the current SDS until we find one
       that will be processed. Use that band to get the resolution of the
       SDS, since all the bands in the SDS will be the same resolution. */
    for (j = 0; j < this->input_sds_nbands[i]; j++)
    {
      /* Is this band one that should be processed? */
      if (!this->input_sds_bands[i][j])
        continue;

      /* Create the input_sds_name which is "SDSname, band" */
      if (this->input_sds_nbands[i] == 1)
      {
        /* 2D product so the band number is not needed */
        sprintf(tmp_sds_name, "%s", this->input_sds_name_list[i]);
      }
      else
      {
        /* 3D product so the band number is required */
        sprintf(tmp_sds_name, "%s, %d", this->input_sds_name_list[i], j);
      }

      this->input_sds_name = strdup (tmp_sds_name);
      if (this->input_sds_name == NULL) {
        sprintf(msg, "resamp: error creating input SDS band name");
	LogInfomsg(msg);
        FreeParam(this);
        return (Param_t *)NULL;
      }

#ifdef DEBUG
      printf ("Getting param %s ...\n", this->input_sds_name);
#endif

      /* Update the system to process the current SDS and band */
      if (!update_sds_info(i, this)) {
        sprintf(msg, "resamp: error updating SDS information");
	LogInfomsg(msg);
        FreeParam(this);
        return (Param_t *)NULL;
      }

      /* Make a copy of the dim parameters, since they get modified */
      for (ip = 0; ip < MYHDF_MAX_RANK; ip++) {
        copy_dim[ip] = this->dim[i][ip];
      }

      /* Open input file for the specified SDS and band */
      input = OpenInput(this->input_file_name, this->input_sds_name,
                        this->iband, this->rank[i], copy_dim, errstr);
      if (input == (Input_t *)NULL) {
        /* This is an invalid SDS for our processing so skip to the next
           SDS. We will only process SDSs that are at the 1km, 500m, or
           250m resolution (i.e. a factor of 1, 2, or 4 compared to the
           1km geolocation lat/long data). We also only process CHAR8,
           INT8, UINT8, INT16, and UINT16 data types. */
#ifdef DEBUG
        printf("%s\n", errstr);
        printf("%s %ld: param, not processing SDS/band\n\n", (__FILE__),
          (long)(__LINE__));
#endif
        break;
      }

      /* Determine the resolution of each of the input SDSs */
      if (!DetermineResolution(&input->sds, &input->dim, &this->ires[i])) {
        sprintf(msg, "resamp: error determining input resolution\n");
	LogInfomsg(msg);
        CloseInput(input);
        FreeInput(input);
        FreeParam(this);
        return (Param_t *)NULL; 
      }

      /* Close input file */
      if (!CloseInput(input)) {
        sprintf(msg, "resamp: closing input file");
	LogInfomsg(msg);
        FreeInput(input);
        FreeParam(this);
        return (Param_t *)NULL; 
      }

      /* Free the input structure */
      if (!FreeInput(input)) {
        sprintf(msg, "resamp: freeing input file stucture");
	LogInfomsg(msg);
        FreeParam(this);
        return (Param_t *)NULL;
      }

      /* We only need one band in this SDS, so break out of the loop */
      break;
    }  /* for (j = 0; j < this->input_sds_nbands[i]; j++) */
  }  /* for (i = 0; i < this->num_input_sds; i++) */

  /* Verify that at least one output pixel size value is defined */
  if (this->output_pixel_size[0] < 0.0) {
    /* No pixel size was specified, so try to determine the resolution of
       the input SDSs and use that for the pixel size. It is assumed that
       the input swath product will have the same resolution for all SDSs. */
    if (!DeterminePixelSize(this->geoloc_file_name, this->num_input_sds,
      this->ires, this->output_space_def.proj_num,
      this->output_pixel_size)) {
      sprintf(msg, "resamp: error determining output pixel size. "
        "Therefore, in order to process this data, the output pixel size "
        "must be specified.\n");
      LogInfomsg(msg);
      FreeParam(this);
      sprintf(msg, "%s\n", USAGE);
      LogInfomsg(msg);
      return (Param_t *)NULL; 
    }

    /* Set multires to FALSE since the output product will have the same
       resolution for all SDSs */
    this->multires = false;
  }

  /* If not enough pixel sizes were provided, then fill the pixel sizes
     in with the very last valid pixel size */
  for (ip = 0; ip < this->num_input_sds; ip++) {
    if (this->output_pixel_size[ip] < 0.0) {
      /* This is the first undefined pixel size, so grab the previous
         pixel size since it was the last valid pixel size value */
      tmp_pixel_size = this->output_pixel_size[ip-1];
      break;
    }
  }

  /* Fill in the rest of the values with the saved pixel size value */
  for (; ip < this->num_input_sds; ip++) {
    this->output_pixel_size[ip] = tmp_pixel_size;
  }

  /* Check the user-specified pixel sizes to see if the output product
     is multiple resolutions */
  for (ip = 0; ip < this->num_input_sds; ip++) {
    if (this->output_pixel_size[ip] != this->output_pixel_size[0])
      this->multires = true;
  }

  /* If the UL or LR corner was not specified, then use the bounding coords */
  if (!this->output_space_def.ul_corner_set ||
      !this->output_space_def.lr_corner_set) {
    /* Read the BOUNDING coords, by default */
    if (!ReadBoundCoords(this->input_file_name, &ul_corner, &lr_corner)) {
      sprintf(msg, "resamp: error reading BOUNDING COORDS from metadata. "
        "Therefore, in order to process this data, the output spatial "
        "subsetting will need to be specified.\n");
      LogInfomsg(msg);
      sprintf(msg, "%s\n", USAGE);
      LogInfomsg(msg);
      FreeParam(this);
      return (Param_t *)NULL; 
    }
    else {
      /* Store all initial corner points in the x/y corner structure.
         The call to convert_corners will handle moving to the lat/long
         structure location. */
      this->output_space_def.ul_corner_set = true;
      this->output_space_def.lr_corner_set = true;
      this->output_space_def.ul_corner.x = ul_corner.lon;
      this->output_space_def.ul_corner.y = ul_corner.lat;
      this->output_space_def.lr_corner.x = lr_corner.lon;
      this->output_space_def.lr_corner.y = lr_corner.lat;
      this->output_spatial_subset_type = LAT_LONG;
    }
  }

  if ((this->output_space_def.proj_param[0] <= 0.0) && 
      (this->output_space_def.sphere < 0)) {
    sprintf(msg, "resamp: either output space sphere or projection "
            "parameter number 0 must be given\n");
    LogInfomsg(msg);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    FreeParam(this);
    return (Param_t *)NULL; 
  }

  if ((this->output_space_def.proj_num == 1)  &&  /* UTM => proj_num = 1 */
       !this->output_space_def.zone_set) { 
    sprintf(msg, "resamp: output space zone number not given for UTM\n");
    LogInfomsg(msg);
    sprintf(msg, "%s\n", USAGE);
    LogInfomsg(msg);
    FreeParam(this);
    return (Param_t *)NULL; 
  }

  if (this->output_space_def.proj_num == 31) /* ISINUS => proj_num = 31 */
    this->output_space_def.isin_type= SPACE_ISIN_NEST_1;

  /* Copy the projection parameters to orig_proj_param to use the decimal
     degree values later (GeoTiff output) */
  for (i = 0; i < NPROJ_PARAM; i++) {
    this->output_space_def.orig_proj_param[i] =
      this->output_space_def.proj_param[i];
  }

  /* Convert the output projection parameter lat/long values from decimal
     degrees to DMS */
  if (!Deg2DMS (this->output_space_def.proj_num,
                this->output_space_def.proj_param)) {
    sprintf(msg, "resamp: error converting projection parameters from"
            "decimal degrees to DMS\n");
    LogInfomsg(msg);
    FreeParam(this);
    return (Param_t *)NULL; 
  }

  /* Use the UL and LR corner points to get the UL corner in output
     space and the number of lines/samples in the output image. This must
     be done for each SDS, since the pixel size might be different. */
  if (!ConvertCorners (this)) {
    sprintf(msg, "resamp: error determining UL and lines/samples from "
            "the input UL and LR corners\n");
    LogInfomsg(msg);
    FreeParam(this);
    return (Param_t *)NULL; 
  }

  /* Make sure the lat/long values are between +-180 and +-90 */
  if (this->output_space_def.ul_corner_geo.lat < -90.0 ||
      this->output_space_def.ul_corner_geo.lat > 90.0  ||
      this->output_space_def.lr_corner_geo.lat < -90.0 ||
      this->output_space_def.lr_corner_geo.lat > 90.0  ||
      this->output_space_def.ul_corner_geo.lon < -180.0 ||
      this->output_space_def.ul_corner_geo.lon > 180.0  ||
      this->output_space_def.lr_corner_geo.lon < -180.0 ||
      this->output_space_def.lr_corner_geo.lon > 180.0) {
    sprintf(msg, "resamp: invalid output lat/lon corners\n");
    LogInfomsg(msg);
    FreeParam(this);
    return (Param_t *)NULL; 
  }

  /* MRTSwath will only process swath data */
  if (this->input_space_type != SWATH_SPACE) {
    sprintf(msg, "resamp: grid or point data detected. MRTSwath will "
            "only process swath data\n");
    LogInfomsg(msg);
    FreeParam(this);
    return (Param_t *)NULL; 
  }

  return this;
}