Пример #1
0
void getCommandLineParams(t_Params *ptParams,int argc,char *argv[])
{
  char *szTemp = NULL;
  char *pcError = NULL;

  /*get parameter file name*/
  ptParams->szDatFile  = extractParameter(argc,argv,DAT_FILE,ALWAYS);  
  if(ptParams->szDatFile == NULL)
    goto error;

  /*get output filestub*/
  ptParams->szTreeFile  = extractParameter(argc,argv,TREE_FILE, ALWAYS);  
  if(ptParams->szTreeFile == NULL)
    goto error;

  ptParams->szMapFile  = extractParameter(argc,argv,MAP_FILE, ALWAYS);  
  if(ptParams->szMapFile == NULL)
    goto error;

  szTemp = extractParameter(argc,argv,SPLIT,ALWAYS);
  if(szTemp != NULL){
    ptParams->nSplit = strtol(szTemp,&pcError,10);
    if(*pcError != '\0'){
      goto error;
    }
  }
  else{
    goto error;
  }

  szTemp = extractParameter(argc,argv,MIN_SIZE,ALWAYS);
  if(szTemp != NULL){
    ptParams->nMinSize = strtol(szTemp,&pcError,10);
    if(*pcError != '\0'){
      goto error;
    }
  }
  else{
    goto error;
  }

  return;

 error:
  writeUsage(stdout);
  exit(EXIT_FAILURE);

}
Пример #2
0
void getCommandLineParams(t_Params *ptParams,int argc,char *argv[])
{
  char *szTemp = NULL;
  char *cError = NULL;

  /*get parameter file name*/
  ptParams->szInputFile  = extractParameter(argc,argv, INPUT_FILE,ALWAYS);  
  if(ptParams->szInputFile == NULL)
    goto error;
  
  if(szTemp = extractParameter(argc,argv, LOOKUP_FILE_FLAG, OPTION)){
    ptParams->szLookUpFile = szTemp;
  }
  else{
    ptParams->szLookUpFile = getenv("SEQ_LOOKUP_FILE");
    if(ptParams->szLookUpFile == NULL){
        ptParams->szLookUpFile = LOOKUP_FILE;
    }  
  }


  /*identifiers*/
  szTemp = extractParameter(argc, argv, IDENT, OPTION);
  if(szTemp != NULL){
    ptParams->bIdent = TRUE;
  }
  else{
    ptParams->bIdent = FALSE;
  }

  szTemp = extractParameter(argc, argv, PHYLIP, OPTION);
  if(szTemp != NULL){
    ptParams->bPhylip = TRUE;
  }
  else{
    ptParams->bPhylip = FALSE;
  }

  return;

 error:
  writeUsage(stdout);
  exit(EXIT_FAILURE);
}
Пример #3
0
void getCommandLineParams(t_Params *ptParams,int argc,char *argv[])
{
  char *szTemp = NULL;
  char *cError = NULL;

  /*get parameter file name*/
  ptParams->szDataFile  = extractParameter(argc,argv, DATA_FILE, ALWAYS);  
  if(ptParams->szDataFile == NULL)
    goto error;

  if(extractParameter(argc,argv, NO_INDEX, OPTION)){
    ptParams->bNoIndex = TRUE;
  }
  else{
    ptParams->bNoIndex = FALSE;
  }

  if(szTemp = extractParameter(argc,argv, LOOKUP_FILE_FLAG, OPTION)){
    ptParams->szLookUpFile = szTemp;
  }
  else{
    ptParams->szLookUpFile = getenv("PYRO_LOOKUP_FILE");
    if(ptParams->szLookUpFile == NULL){
    	ptParams->szLookUpFile = LOOKUP_FILE;
    }	
  }


  ptParams->szOutFileStub  = extractParameter(argc,argv, OUT_FILE_STUB, ALWAYS);  
  if(ptParams->szOutFileStub == NULL)
    goto error;

  return;

 error:
  writeUsage(stdout);
  exit(EXIT_FAILURE);
}
Пример #4
0
 void ArgumentHelper::handle_error() const {
   writeUsage(std::cerr);
   //exit(1);
 }
Пример #5
0
   bool ArgumentHelper::process(int argc,  const char **argv){
     name_= argv[0];
     ++argv;
     --argc;
 
     current_unnamed_= unnamed_arguments_.begin();
     current_optional_unnamed_= optional_unnamed_arguments_.begin();
     
     for ( int i=0; i< argc; ++i){
       if (strcmp(argv[i], "--help") == 0){
         writeUsage(std::cout);
         exit(0);
       }
     }
 
     while (argc != 0){
 
       const char* cur_arg= argv[0];
       if (cur_arg[0]=='-' && !seen_end_named_){
         --argc; ++argv;
         if (cur_arg[1]=='-'){
           if (cur_arg[2] == '\0') {
             //std::cout << "Ending flags " << std::endl;
             seen_end_named_=true;
           } else {
             // long argument
             LMap::iterator f= long_names_.find(cur_arg+2);
             if ( f != long_names_.end()){
               if (!f->second->process(argc, argv)) {
                 handle_error();
				 return false;
               }
             } else {
               std::cerr<< "Invalid long argument "<< cur_arg << ".\n";
               handle_error();
				 return false;
             }
           }
         } else {
           if (cur_arg[1]=='\0') {
             std::cerr << "Invalid argument " << cur_arg << ".\n";
             handle_error();
				 return false;
           }
           SMap::iterator f= short_names_.find(cur_arg[1]);
           if ( f != short_names_.end()){
             if (!f->second->process(argc, argv)) {
               handle_error();
				 return false;
             }
           } else {
             std::cerr<< "Invalid short argument "<< cur_arg << ".\n";
             handle_error();
				 return false;
           }
         }
       } else {
         if (current_unnamed_ != unnamed_arguments_.end()){
           Argument_target *t= *current_unnamed_;
           t->process(argc, argv);
           ++current_unnamed_;
         } else if (current_optional_unnamed_ != optional_unnamed_arguments_.end()){
           Argument_target *t= *current_optional_unnamed_;
           t->process(argc, argv);
           ++current_optional_unnamed_;
         } else if (extra_arguments_!= NULL){
           extra_arguments_->push_back(cur_arg);
           --argc;
           ++argv;
         } else {
           std::cerr << "Invalid extra argument " << argv[0] << std::endl;
           handle_error();
		 return false;
         }
       }
     }
 
     if (current_unnamed_ != unnamed_arguments_.end()){
       std::cerr << "Missing required arguments:" << std::endl;
       for (; current_unnamed_ != unnamed_arguments_.end(); ++current_unnamed_){
         (*current_unnamed_)->write_name(std::cerr);
         std::cerr << std::endl;
       }
       std::cerr << std::endl;
       handle_error();
	   return false;
     }
 
     if (VERBOSE) verbose=true;
	 return true;
   }
Пример #6
0
/****************************************************************************
Desc:	Prints the web page for an SCACHEMGR struct
		(The URL for this page requires no parameters since there is only
		one SCACHE_MGR per copy of FLAIM.)
****************************************************************************/
RCODE F_SCacheMgrPage::display(
	FLMUINT			uiNumParams,
	const char ** 	ppszParams)
{
	RCODE			rc = FERR_OK;
	SCACHE_MGR	LocalSCacheMgr;
	FLMBOOL		bAutoRefresh;
#define NUM_CACHE_REQ_STRINGS			4
	char	*		pszSCacheRequestString[ NUM_CACHE_REQ_STRINGS];
	char			szOffsetTable[12][6];
	char			szAddressTable[2][20];
	FLMBOOL		bHighlight = FALSE;
	char *		pszTemp = NULL;
	FLMUINT		uiLoop;

	// Note: The SCacheBlock requests need the following params:
	// "BlockAddress", "File", "LowTransID" and "HighTransID"
	// ex:  <A href="SCacheBlock?BlockAddress=100?File=5?LowTransID=30?HighTransID=100"> pMRUCache </A>
	
	if( RC_BAD( rc = f_alloc( 200, &pszTemp)))
	{
		printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer");
		goto Exit;
	}

	// First thing that we need to do is grab a local copy of gv_FlmSysData.SCacheMgr,
	// and of the data for the three SCache blocks that it has pointers to...
	for (uiLoop = 0; uiLoop < NUM_CACHE_REQ_STRINGS; uiLoop++)
	{
		if( RC_BAD( rc = f_alloc( 150,
									&pszSCacheRequestString[ uiLoop])))
		{
			printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer");
			goto Exit;
		}
	}
	f_mutexLock( gv_FlmSysData.hShareMutex);
	f_memcpy (&LocalSCacheMgr, &gv_FlmSysData.SCacheMgr, sizeof (LocalSCacheMgr));
	flmBuildSCacheBlockString( pszSCacheRequestString[0], LocalSCacheMgr.pMRUCache);
	flmBuildSCacheBlockString( pszSCacheRequestString[1], LocalSCacheMgr.pLRUCache);
	flmBuildSCacheBlockString( pszSCacheRequestString[2], LocalSCacheMgr.pFirstFree);
	flmBuildSCacheBlockString( pszSCacheRequestString[3], LocalSCacheMgr.pLastFree);
	f_mutexUnlock( gv_FlmSysData.hShareMutex);

	bAutoRefresh = DetectParameter( uiNumParams, ppszParams, "Refresh");

	// Now - are we being asked to display the usage stats?  Or is this a regular page...
	if (DetectParameter( uiNumParams, ppszParams, "Usage"))
	{
		// There's a function to handle display the usage info (because both
		// RCacheMgr and SCacheMgr have usage stats).
		writeUsage( &LocalSCacheMgr.Usage, bAutoRefresh,
						"/SCacheMgr?Usage",
						"Usage Statistics for the SCache");
	}
	else // This is a regular SCacheMgr page...
	{
		// Determine if we are being requested to refresh this page or  not.

		stdHdr();

		fnPrintf( m_pHRequest, HTML_DOCTYPE "<HTML>\n");

		if (bAutoRefresh)
		{
			// Send back the page with a refresh command in the header

			fnPrintf( m_pHRequest, 
				"<HEAD>"
				"<META http-equiv=\"refresh\" content=\"5; url=%s/SCacheMgr?Refresh\">"
				"<TITLE>gv_FlmSysData.SCacheMgr</TITLE>\n", m_pszURLString);

			printStyle();
			popupFrame();  //Spits out a Javascript function that will open a new window..
	
			fnPrintf( m_pHRequest, "\n</HEAD>\n<body>\n");


			f_sprintf( (char *)pszTemp,
							"<A HREF=%s/SCacheMgr>Stop Auto-refresh</A>", m_pszURLString);
		}
		else  // bAutoRefresh == FALSE
		{
			// Send back a page without the refresh command
			fnPrintf( m_pHRequest, 
				"<HEAD>"
				"<TITLE>gv_FlmSysData.SCacheMgr</TITLE>\n");

			printStyle();
			popupFrame();  //Spits out a Javascript function that will open a new window..
	
			fnPrintf( m_pHRequest, "\n</HEAD>\n<body>\n");

			f_sprintf( (char *)pszTemp,
						"<A HREF=%s/SCacheMgr?Refresh>Start Auto-refresh (5 sec.)</A>",
						m_pszURLString);
		}

		// Write out the table headings
		printTableStart( "SCache Manager Structure", 4);

		printTableRowStart();
		printColumnHeading( "", JUSTIFY_LEFT, FLM_IMON_COLOR_PUTTY_1, 4, 1, FALSE);
		fnPrintf( m_pHRequest, "<A HREF=%s/SCacheMgr>Refresh</A>, %s\n", m_pszURLString, pszTemp);
		printColumnHeadingClose();
		printTableRowEnd();

		// Write out the table headings.
		printTableRowStart();
		printColumnHeading( "Byte Offset (hex)");
		printColumnHeading( "Field Name");
		printColumnHeading( "Field Type");
		printColumnHeading( "Value");
		printTableRowEnd();
	
		//Now - we have three rows in the table that may or may not have hyperlinks in them.  
		printTableRowStart( bHighlight = ~bHighlight);
		flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[0], "pMRUCache", &LocalSCacheMgr, &LocalSCacheMgr.pMRUCache);
		printTableRowStart( bHighlight = ~bHighlight);
		flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[1], "pLRUCache", &LocalSCacheMgr, &LocalSCacheMgr.pLRUCache);
		printTableRowStart( bHighlight = ~bHighlight);
		flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[2], "pFirstFree", &LocalSCacheMgr, &LocalSCacheMgr.pFirstFree);
		printTableRowStart( bHighlight = ~bHighlight);
		flmPrintCacheLine(m_pHRequest, pszSCacheRequestString[3], "pLastFree", &LocalSCacheMgr, &LocalSCacheMgr.pLastFree);

		//Format the strings that are displayed in the Offset column on of the table
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.ppHashTbl, szOffsetTable[0]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.Usage, szOffsetTable[1]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.bAutoCalcMaxDirty, szOffsetTable[2]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiMaxDirtyCache, szOffsetTable[3]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiLowDirtyCache, szOffsetTable[4]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiTotalUses, szOffsetTable[5]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiBlocksUsed, szOffsetTable[6]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiPendingReads, szOffsetTable[7]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiIoWaits, szOffsetTable[8]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiHashTblSize, szOffsetTable[9]);
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.uiHashTblBits, szOffsetTable[10]);
#ifdef FLM_DEBUG
		printOffset(&LocalSCacheMgr, &LocalSCacheMgr.bDebug, szOffsetTable[11]);
#endif


		printAddress( LocalSCacheMgr.ppHashTbl, szAddressTable[0]);
		printAddress( &LocalSCacheMgr.Usage, szAddressTable[1]);

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s
				"<td><A HREF=\"%s/SCacheHashTable?Start=0\">ppHashTbl</A></td>\n"
				"<td>SCACHE **</td>\n"
				"<td><A href=\"%s/SCacheHashTbl\">%s</A></td>\n",
				szOffsetTable[0], m_pszURLString, m_pszURLString, szAddressTable[0]);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s
			"<td><A href=\"javascript:openPopup('%s/SCacheMgr?Usage')\">Usage</A></td>\n"
			"<td>FLM_CACHE_USAGE</td>\n"
			"<td><A href=\"javascript:openPopup('%s/SCacheMgr?Usage')\">%s</A></td>\n",
			szOffsetTable[1], m_pszURLString, m_pszURLString, szAddressTable[1]);
		printTableRowEnd();

		// uiFreeCount
		printHTMLUint(
			(char *)"uiFreeCount",
			(char *)"FLMUINT",
			(void *)&LocalSCacheMgr,
			(void *)&LocalSCacheMgr.uiFreeCount,
			LocalSCacheMgr.uiFreeCount,
			(bHighlight = ~bHighlight));

		// uiFreeBytes
		printHTMLUint(
			(char *)"uiFreeBytes",
			(char *)"FLMUINT",
			(void *)&LocalSCacheMgr,
			(void *)&LocalSCacheMgr.uiFreeBytes,
			LocalSCacheMgr.uiFreeBytes,
			(bHighlight = ~bHighlight));

		// uiReplaceableCount
		printHTMLUint(
			(char *)"uiReplaceableCount",
			(char *)"FLMUINT",
			(void *)&LocalSCacheMgr,
			(void *)&LocalSCacheMgr.uiReplaceableCount,
			LocalSCacheMgr.uiReplaceableCount,
			(bHighlight = ~bHighlight));

		// uiReplaceableBytes
		printHTMLUint(
			(char *)"uiReplaceableBytes",
			(char *)"FLMUINT",
			(void *)&LocalSCacheMgr,
			(void *)&LocalSCacheMgr.uiReplaceableBytes,
			LocalSCacheMgr.uiReplaceableBytes,
			(bHighlight = ~bHighlight));

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>bAutoCalcMaxDirty</td>\n"
						"<td>FLMBOOL</td>\n" TD_i, szOffsetTable[2],
						LocalSCacheMgr.bAutoCalcMaxDirty);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiMaxDirtyCache</td>\n"
						"<td>FLMUINT</td>\n" TD_lu, szOffsetTable[3],
						LocalSCacheMgr.uiMaxDirtyCache);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiLowDirtyCache</td>\n"
						"<td>FLMUINT</td>\n" TD_lu, szOffsetTable[4],
						LocalSCacheMgr.uiLowDirtyCache);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiTotalUses</td>\n"
						"<td>FLMUINT</td>\n" TD_lu, szOffsetTable[5],
						LocalSCacheMgr.uiTotalUses);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiBlocksUsed</td> <td>FLMUINT</td>\n"
					TD_lu, szOffsetTable[6], LocalSCacheMgr.uiBlocksUsed);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiPendingReads</td>\n"
			"<td>FLMUINT</td>\n" TD_lu,  szOffsetTable[7],
			LocalSCacheMgr.uiPendingReads);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiIoWaits</td>\n <td>FLMUINT</td>\n" TD_lu,
						szOffsetTable[8], LocalSCacheMgr.uiIoWaits);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiHashTableSize</td>\n"
					"<td>FLMUINT</td>\n" TD_lu, szOffsetTable[9],
					LocalSCacheMgr.uiHashTblSize);
		printTableRowEnd();

		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>uiHashTableBits</td>\n"
					"<td>FLMUINT</td>\n" TD_lu, szOffsetTable[10],
					LocalSCacheMgr.uiHashTblBits);
		printTableRowEnd();

#ifdef FLM_DEBUG
		printTableRowStart( bHighlight = ~bHighlight);
		fnPrintf( m_pHRequest, TD_s "<td>bDebug</td>\n" "<td>FLMBOOL</td>\n"
					TD_i, szOffsetTable[11], LocalSCacheMgr.bDebug);
		printTableRowEnd();
#endif

		printTableEnd();
		
		fnPrintf( m_pHRequest, "</BODY></HTML>\n");

		fnEmit();

	}

Exit:

	if (pszTemp)
	{
		f_free( &pszTemp);
	}

	for (uiLoop = 0; uiLoop < NUM_CACHE_REQ_STRINGS; uiLoop++)
	{
		if( pszSCacheRequestString[uiLoop])
		{
			f_free( &pszSCacheRequestString[uiLoop]);
		}
	}

	return( rc);
}
Пример #7
0
int main(int argc, const char *argv[]) {
   double startTime = Util::clock();
   Util::setShowError(true);
   Util::setShowWarning(true);
   Util::setShowStatus(false);
   if(argc <= 1) {
      writeUsage();
      return 0;
   }
   // Retrieve setup
   std::vector<std::string> args;
   for(int i = 1; i < argc; i++) {
      args.push_back(std::string(argv[i]));
   }
   SetupTrain setup(args);

   File* forecast = setup.forecasts[0];
   File* observation = setup.observations[0];
   File* ogrid = observation;
   int nLat = ogrid->getNumLat();
   int nLon = ogrid->getNumLon();
   int nTime = ogrid->getNumTime();
   vec2 lats = ogrid->getLats();
   vec2 lons = ogrid->getLons();
   vec2 elevs = ogrid->getElevs();

   Variable::Type variable = setup.variable;
   std::vector<double> offsets = forecast->getTimes();
   int D = setup.forecasts.size();

   std::cout << "Number of obs files: " << setup.observations.size() << std::endl;
   std::cout << "Number of fcst files: " << setup.forecasts.size() << std::endl;
   std::cout << "Number of lats: " << nLat << std::endl;
   std::cout << "Number of lons: " << nLon << std::endl;
   std::cout << "Number of times: " << nTime << std::endl;
   std::cout << "Forecast reference times: ";
   for(int f = 0; f < setup.forecasts.size(); f++) {
      double timeF = setup.forecasts[f]->getReferenceTime();
      std::cout << " " << timeF;
   }
   std::cout << std::endl;
   std::cout << "Observation reference times: ";
   for(int f = 0; f < setup.observations.size(); f++) {
      double timeO = setup.observations[f]->getReferenceTime();
      std::cout << " " << timeO;
   }
   std::cout << std::endl;

   // figure out which files match
   std::vector<int> indexF;
   std::vector<int> indexO;
   for(int f = 0; f < setup.forecasts.size(); f++) {
      int io = Util::MV;
      double timeF = setup.forecasts[f]->getReferenceTime();
      for(int o = 0; o < setup.observations.size(); o++) {
         double timeO = setup.observations[o]->getReferenceTime();
         if(timeF == timeO) {
            io = o;
         }
      }
      if(Util::isValid(io)) {
         indexF.push_back(f);
         indexO.push_back(io);
      }
   }

   int validD = indexF.size();
   std::cout << "Number of valid days: " << validD << std::endl;
   if(validD == 0) {
      return -1;
   }

   // vec2Int Io2f, Jo2f;
   // Downscaler::getNearestNeighbour(*observation, *forecast, Io2f, Jo2f);
   vec2Int If2o, Jf2o;
   Downscaler::getNearestNeighbour(*forecast, *observation, If2o, Jf2o);
   std::cout << "Created nearest neighbour map" << std::endl;
   std::vector<double> ftimes = forecast->getTimes();
   std::vector<double> otimes = observation->getTimes();
   double freftime = forecast->getReferenceTime();
   double oreftime = observation->getReferenceTime();

   std::cout << "Forecast offsets:";
   for(int t = 0; t < ftimes.size(); t++) {
      std::cout << " " << ftimes[t] - freftime;
   }
   std::cout << std::endl;
   std::cout << "Observation offsets:";
   for(int t = 0; t < otimes.size(); t++) {
      std::cout << " " << otimes[t] - oreftime;
   }
   std::cout << std::endl;

   for(int t = 0; t < offsets.size(); t++) {
      double time0 = Util::clock();
      std::cout << "Forecast time index: " << t << std::endl;
      // If multiple available obstimes, then use the one with the lowest ftime
      double ftime = ftimes[t] - freftime;
      int fTimeIndex = t;
      int oTimeIndex = Util::MV;
      int fmaxDays = ftimes[ftimes.size()-1] / 86400;

      /*
      // Use the same leadtime in obs and forecast (probably not optimal obs for
      // leadtimes above 24h)
      for(int tt = 0; tt < otimes.size(); tt++) {
         double otime = otimes[tt] - oreftime;
         if(otime == ftime) {
            oTimeIndex = tt;
            break;
         }
      }
      */

      for(int d = 0; d < fmaxDays; d++) {
         // Find appropriate obs time
         for(int tt = 0; tt < otimes.size(); tt++) {
            double otime = otimes[tt] - oreftime + d * 86400;
            if(otime == ftime && (t == 0 || tt != 0)) {
               oTimeIndex = tt;
               break;
            }
         }
      }
      assert(Util::isValid(oTimeIndex));

      // Loop over all files
      std::vector<FieldPtr> ffields;
      std::vector<FieldPtr> ofields;
      for(int d = 0; d < setup.forecasts.size(); d++) {
         double ftime = setup.forecasts[d]->getTimes()[t];
         int fDateIndex = d;
         int oDateIndex = Util::MV;

         // Find corresponding observation file
         for(int dd = 0; dd < setup.observations.size(); dd++) {
            double otime = setup.observations[dd]->getTimes()[oTimeIndex];
            if(ftime == otime) {
               oDateIndex = dd;
               break;
            }
         }

         if(Util::isValid(fDateIndex) && Util::isValid(oDateIndex)) {
            std::cout << "   Found matching: (" << fDateIndex << "," << fTimeIndex << ") " 
                      << " (" << oDateIndex << "," << oTimeIndex << ")" << std::endl;
            assert(setup.forecasts.size() > fDateIndex);
            assert(setup.observations.size() > oDateIndex);
            ffields.push_back(setup.forecasts[fDateIndex]->getField(variable, fTimeIndex));
            ofields.push_back(setup.observations[oDateIndex]->getField(variable, oTimeIndex));
         }
      }
      if(ffields.size() == 0) {
         std::stringstream ss;
         ss << "Cannot find files with available data for timestep " << t << std::endl;
         Util::error(ss.str());
      }
      assert(ffields.size() > 0);

      ////////////////////////
      // Compute parameters
      if(setup.output->isLocationDependent()) {
         // Do this in parallel, inserting the values into a preallocated matrix
         std::vector<std::vector<std::vector<float> > > parameters;
         parameters.resize(nLat);
         for(int i = 0; i < nLat; i++) {
            parameters[i].resize(nLon);
         }
         #pragma omp parallel for
         for(int i = 0; i < nLat; i++) {
            for(int j = 0; j < nLon; j++) {
               // Arrange data
               std::vector<ObsEns> data;
               for(int d = 0; d < ffields.size(); d++){
                  // Downscaling (currently nearest neighbour)
                  // float obs = (*ofields[d])(Io2f[i][j],Jo2f[i][j],0);
                  // const Ens& ens = (*ffields[d])(i,j);
                  float obs = (*ofields[d])(i,j,0);
                  Ens ens   = (*ffields[d])(If2o[i][j],Jf2o[i][j]);
                  ObsEns obsens(obs, ens);
                  data.push_back(obsens);
               }

               Parameters par = setup.method->train(data);
               parameters[i][j] = par.getValues();
            }
         }

         // Then save values serially
         for(int i = 0; i < nLat; i++) {
            for(int j = 0; j < nLon; j++) {
               float lat = lats[i][j];
               float lon = lons[i][j];
               float elev = elevs[i][j];

               setup.output->setParameters(Parameters(parameters[i][j]), t, Location(lat, lon, elev));
            }
         }
      }
      else {
         std::cout << "Location independent estimation" << std::endl;
         // Arrange data
         std::vector<ObsEns> data;
         for(int i = 0; i < nLat; i++) {
            for(int j = 0; j < nLon; j++) {
               for(int d = 0; d < ffields.size(); d++){
                  // Downscaling (currently nearest neighbour)
                  // float obs = (*ofields[d])(Io2f[i][j],Jo2f[i][j],0);
                  // const Ens& ens = (*ffields[d])(i,j);
                  float obs = (*ofields[d])(i,j,0);
                  Ens ens   = (*ffields[d])(If2o[i][j],Jf2o[i][j]);
                  if(Util::isValid(obs) && Util::isValid(ens[0])) {
                     ObsEns obsens(obs, ens);
                     data.push_back(obsens);
                  }
               }
            }
         }
         std::cout << "Using " << data.size() << " data points" << std::endl;
         Parameters par = setup.method->train(data);
         setup.output->setParameters(par, t, Location(Util::MV, Util::MV, Util::MV));
      }

      // Clear the memory of the files
      // for(int f = 0; f < ofields.size(); f++) {
      //    ofields[f].reset();
      // }
      for(int f = 0; f < setup.forecasts.size(); f++) {
         setup.forecasts[f]->clear();
      }
      for(int f = 0; f < setup.observations.size(); f++) {
         setup.observations[f]->clear();
      }

      double time1 = Util::clock();
      std::cout << "   Time: " << time1 - time0 << " seconds" << std::endl;
   }
   std::cout << "Recomputing nearest neighbour tree" << std::endl;
   setup.output->recomputeTree();

   std::cout << "Writing to parameter file" << std::endl;
   setup.output->write();
   double endTime = Util::clock();
   std::cout << "Total time: " << endTime - startTime << std::endl;
}
Пример #8
0
void getCommandLineParams(t_Params *ptParams,int argc,char *argv[])
{
  char *szTemp = NULL;
  char *cError = NULL;

  /*get parameter file name*/
  ptParams->szSeqInputFile  = extractParameter(argc,argv, SEQ_INPUT_FILE,ALWAYS);  
  if(ptParams->szSeqInputFile == NULL)
    goto error;
  
  /*get parameter file name*/
  ptParams->szRefInputFile  = extractParameter(argc,argv, REF_INPUT_FILE,OPTION);  
  if(ptParams->szRefInputFile == NULL){
    ptParams->szRefInputFile = ptParams->szSeqInputFile;
  }

  szTemp  = extractParameter(argc,argv,SKEW,OPTION);  
  if(szTemp != NULL){
    ptParams->nSkew = strtol(szTemp,&cError,10);
    if(*cError!='\0'){
      goto error;
    }
  }
  else{
    ptParams->nSkew = DEFAULT_SKEW;
  }

  if(extractParameter(argc,argv,USE_BALANCE,OPTION)){  
    ptParams->bImbalance = FALSE;
  }
  else{
    ptParams->bImbalance = TRUE;
  }

  szTemp  = extractParameter(argc,argv,CLASSIFY,OPTION);  
  if(szTemp != NULL){
    char *szTok = strtok(szTemp, DELIM2);
    
    ptParams->dAlpha = strtod(szTok,&cError);
    if(*cError!='\0'){
      goto error;
    }

    szTok = strtok(NULL, DELIM2);
    
    ptParams->dBeta = strtod(szTok,&cError);
    if(*cError!='\0'){
      goto error;
    }
  }
  else{
    if(ptParams->bImbalance == FALSE){
      ptParams->dAlpha = DEFAULT_ALPHA_1;
      ptParams->dBeta  = DEFAULT_BETA_1;
    }
    else{
      ptParams->dAlpha = DEFAULT_ALPHA_2;
      ptParams->dBeta  = DEFAULT_BETA_2;
    }
  }

  if(extractParameter(argc,argv,OUTPUT_ALIGNMENTS,OPTION)){  
    ptParams->bOutputAlignments = TRUE;
  }
  else{
    ptParams->bOutputAlignments = FALSE;
  }

  if(szTemp = extractParameter(argc,argv, LOOKUP_FILE_FLAG, OPTION)){
    ptParams->szLookUpFile = szTemp;
  }
  else{
    ptParams->szLookUpFile = getenv("SEQ_LOOKUP_FILE");
    if(ptParams->szLookUpFile == NULL){
        ptParams->szLookUpFile = LOOKUP_FILE;
    }  
  }

  return;

 error:
  writeUsage(stdout);
  exit(EXIT_FAILURE);
}