#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>

#include <GetNbox.h>

#include <..\OriginLab\NetCDFManager.h>
#include <..\originlab\file_utils.h>
#include <..\originlab\fu_utils.h>	///---Sim 09-11-2006 SUPPORT_MULTI_FILES_INXF
#include <sys_utils.h> ///---Sim 09-13-2006 SUPPORT_MULTI_FILES_INXF
///---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
#include <oErrMsg.h>
#include <ocu.h>
///---END HANDLE_ERR_MESSAGE_USE_DLL

///////////////////////////////////////////////////////////////////////
//////// modification log
/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
/// Hong 03/29/07 FIX_ERROR_IMPORT_1_D_DATA
/// Hong 04/10/07 v8.0597b FIX_FAIL_WHEN_FROM_SCRIPT_NO_SHOW_DIALOG
/// Hong 04/10/07 v8.0597b IGNORE_FNAME$_WHEN_FROM_MENU
/// Hong 04/13/07 v8.0600 FIX_X_COLUMN_NOT_IMPORTED
/// Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
/// Sim 06-25-2007 UPDATE_ORGANIZER
/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
/// Hong 01/13/09 v8.0995d FIX_D&D_MATRIX_ONLY_FILE_RUNTIME_IF_FILTER_USE_WKS_AS_TARGET_PAGE
/// Sophy 7/22/2009 STOP_IMPORTING_WHEN_FAIL_TO_CREATE_MORE_LAYER_FOR_IMPORT_DATA
/// Sophy 9/3/2009 QA80-13130-P5 FAIL_TO_IMPORT_1D_DATA_WHEN_DIM_NAME_IS_SAME_AS_VAR_NAME
///	Sophy 9/11/2009 QA80-13128 NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
///////////////////////////////////////////////////////////////////////

//put your own support static functions here

///---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
/*
enum {    // need move all error codes later
	ERR_NETCDF_NO_VARIABLE_FOUND, 
};
*/
///---END HANDLE_ERR_MESSAGE_USE_DLL

#define TREENODE_DATA_SELECTION "DataSelection" ///---Sim 01-18-2007 SHOW_FILE_INFO

///---Sim 11-16-2006 RELIABLE_OK_ENABLE
static bool s_bFileValid = true;
#define OK_SURE(_OK_ENABLE) _OK_ENABLE = s_bFileValid; //also can be _OK_ENABLE = s_bFileValid && s_bSetting
///---END RELIABLE_OK_ENABLE

static void _counstruct_branch(TreeNode& trGUI, TreeNode& trVar, string& strTagName, bool bOpen)
{
	TreeNode trVarNode;
	trVarNode = trGUI.AddNode(strTagName, TRGP_BRANCH);
	trVarNode.SetAttribute(STR_LABEL_ATTRIB, strTagName);
	///---Sim 01-17-2007 ADD_CHECK_ALL_UNCHECK_ALL_OPTION
	int nBranchStyle = GETNBRANCH_CHECK_CONTROL | GETNBRANCH_CHECK_CONTROL_ONE_EVENT; 
	if(bOpen)			//expand the hightest dimension
		//trVarNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
		nBranchStyle |= GETNBRANCH_OPEN;
	trVarNode.SetAttribute(STR_ATTRIB_BRANCH, nBranchStyle);		
	///---END ADD_CHECK_ALL_UNCHECK_ALL_OPTION
	
	foreach(TreeNode trStr in trVar.Children)		//make label and tip
	{	
		string strTip, strLabel;
		strLabel = trStr.tagName;
		TreeNode trStrNode = trVarNode.AddNumericNode(1, strLabel, TRGP_CHECK);
		
		foreach(TreeNode trTip in trStr.Children)
		{
			string strTipName;
			strTipName = trTip.tagName;
			if(strTipName.CompareNoCase(STR_OC_TYPE) == 0)
			{
				strLabel += " (";
				strLabel += trTip.strVal;
				strLabel += ") ";
			}
			
			if((strTipName.CompareNoCase(STR_LONGNAME_ATTRIB) == 0) && (strTipName.CompareNoCase(trStr.tagName) != 0))
			{
				strLabel += trTip.strVal;
			}
			
			strTipName += " = ";
			strTipName += trTip.strVal;
			strTip += strTipName;
			strTip += ", ";
		}
		
		if(strLabel.GetLength() > 60)			//cut to 60 char if strTip is too long
		{
			strLabel = strLabel.Left(57);
			strLabel += "...";
		}
		
		trStrNode.SetAttribute(STR_LABEL_ATTRIB, strLabel);
		trStrNode.SetAttribute(STR_TIPS_ATTRIB, strTip);
		//trStrNode.SetAttribute(STR_ATTRIB_DISPFMT, DISPLAY_EDITOR_CHECK_ON_LEFT); // Hong 03/13/07 AVOID_LABEL_TRUNCATED
		/// Hong 12/26/06 ADD_1_D_DATA_TO_WKS
		///Sophy 9/3/2009 QA80-13130-P5 FAIL_TO_IMPORT_1D_DATA_WHEN_DIM_NAME_IS_SAME_AS_VAR_NAME
		//if( 0 == trVar.tagName.Compare("Var1D") )
		//{
			//string strVarName, strDimName;
			//strVarName = trStr.tagName;
			//strDimName = trStr.Dims.strVal;
			//strDimName.Delete(0);
			//strDimName.Delete(strDimName.GetLength() - 1);
			//if( strVarName == strDimName )
				///// Hong 04/13/07 v8.0600 FIX_X_COLUMN_NOT_IMPORTED
				////continue;
				//trStrNode.Show = 0;
				///// end FIX_X_COLUMN_NOT_IMPORTED
		//}
		///end FAIL_TO_IMPORT_1D_DATA_WHEN_DIM_NAME_IS_SAME_AS_VAR_NAME
		/// end ADD_1_D_DATA_TO_WKS
		
	}
}

static bool _construct_GUI_tree(TreeNode& trGUI, TreeNode& trInfo)
{
	string strTagName;
	bool bOpen = true; 			//branch to expand or not
	
	/// Hong 12/26/06 ADD_1_D_DATA_TO_WKS
	//for(int nn=4; nn>1; nn--)	//suppose tagName to be Var%dD, %d = 1,2,3,4
	for(int nn=4; nn>0; nn--)	//suppose tagName to be Var%dD, %d = 1,2,3,4
	/// end ADD_1_D_DATA_TO_WKS
	{
		TreeNode trVar;
		strTagName.Format("Var%dD", nn);
		trVar = trInfo.GetNode(strTagName, false);
		if(trVar.IsValid())
		{
			_counstruct_branch(trGUI, trVar, strTagName, bOpen);	
			bOpen = false;
		}
	}
	
	if(trGUI.IsEmpty())
		return false;
	///---Sim 01-17-2007 ADD_CHECK_ALL_UNCHECK_ALL_OPTION
	trGUI.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);//Hong 11/1/06 AUTO_EXPAND_BRANCH_NODE	
	//trGUI.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_CHECK_CONTROL | GETNBRANCH_OPEN);	
	///---END ADD_CHECK_ALL_UNCHECK_ALL_OPTION
	return true;
}

///---Sim 01-18-2007 SHOW_FILE_INFO
static BOOL construct_tree_FileInfo(string strFileName, TreeNode& trInfo)
{
		if ( !strFileName.IsFile() )
			return false;
		string strInfo;
		strInfo.Format("File Size: %s ", GetFileSize(strFileName));
		trInfo.strVal = strInfo;
		trInfo.Enable = 0;
		return true;
}
///---END SHOW_FILE_INFO

///---Sim 11-13-2006 CONSTRUCT_SETTING_FUNCTIOIN
static bool construct_tree_setting(StringArray& vsFileNames, TreeNode& trNode)
{
	Tree trFileVarInfo;
	//TreeNode trGUI;///---Sim 01-18-2007 SHOW_FILE_INFO remove
	TreeNode trFile; ///---Sim 01-18-2007 SHOW_FILE_INFO
	string strFileName;
	string strTag; ///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
	
	trNode.RemoveChildrenWithPrefix();
	///---Sim 09-12-2006 USE_STRING_SEPARATE_FOR_STR_DELIM
	//int nSize = strFileName.GetTokens(vs);
	int nSize = vsFileNames.GetSize(); 
	///---END USE_STRING_SEPARATE_FOR_STR_DELIM
	for(int index = 0; index < nSize; index++)
	{
		strFileName = GetFileName(vsFileNames[index], true);
		///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		strTag.Format("file%d", index+1);
		///---END FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		///---Sim 09-12-2006 FOR_CORRECT_VAR_TREE_NODE_SETTING
		//trGUI = trNode.AddNode("");
		//trGUI.SetAttribute(STR_LABEL_ATTRIB, vs[index]);
		///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		//trGUI = trNode.AddNode(strTempFileName);
		trFile = trNode.AddNode(strTag); ///---Sim 01-18-2007 SHOW_FILE_INFO
		///---END FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		trFile.SetAttribute(STR_LABEL_ATTRIB, strFileName); ///---Sim 01-18-2007 SHOW_FILE_INFO
		///---END FOR_CORRECT_VAR_TREE_NODE_SETTING
		//GETN_USE(trGUI)
		
		///---Sim 01-18-2007 SHOW_FILE_INFO
		// Load File Info
		TreeNode trFileInfo;
		trFileInfo = trFile.AddNode("FileInfo");
		trFileInfo.SetAttribute(STR_LABEL_ATTRIB, STR_FILE_INFO);	///Sophy 9/21/2009 SET_LABEL_ON_GUI_FOR_TRANSLATION
		if ( !construct_tree_FileInfo(vsFileNames[index], trFileInfo) )
			return false;
		///---END SHOW_FILE_INFO
		
		//if ( 0 > netcdf_open(vsFileNames[index]) )
		//{
			//return false;
		//}
		//trFileVarInfo.Reset(); ///---Sim 09-13-2006 FIX_MULTI_FILE_VAR_INFO_LOADING
		//netcdf_get_vars_info(&trFileVarInfo);
		//netcdf_close(); ///---Sim 09-12-2006 NEED_CLOSE_FILE_FOR_NEXT_OPEN
		NetCDF netCDF;
		if ( netCDF.Open(vsFileNames[index]) == NC_FAIL )
			return false;
		trFileVarInfo.Reset();
		netCDF.GetVarsInfo(&trFileVarInfo);
		netCDF.Close();
		
		TreeNode trGUI = trFile.AddNode(TREENODE_DATA_SELECTION); ///---Sim 01-18-2007 SHOW_FILE_INFO
		trGUI.SetAttribute(STR_LABEL_ATTRIB, STR_DATA_SELECTION);	///Sophy 9/21/2009 SET_LABEL_ON_GUI_FOR_TRANSLATION
		if(!_construct_GUI_tree(trGUI, trFileVarInfo))
		{
			return false;
		}
	}
	trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);	
	return true;
}
///---END CONSTRUCT_SETTING_FUNCTIOIN

///---Sim 11-20-2006 SUPPORT_DND_OPEN_DIALOG
static bool file_name_event(TreeNode& trGetN, string& strErrMsg)
{
	string strFileName = trGetN.fname.strVal;
	TreeNode trNode = trGetN.trfiles;
	
	// clean the trFiles on GUI
	trNode.RemoveChildrenWithPrefix();
	
	if ( !check_imported_file_name(strFileName, strErrMsg) )
		return false;
	
	StringArray vsFileNames;
	separate_multiline_files(strFileName, vsFileNames);
	if ( !construct_tree_setting(vsFileNames, trNode) )
	{
		// clean the trFiles on GUI
		trNode.RemoveChildrenWithPrefix();
		strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
		return false;
	}
	
	return true;
}
///---END SUPPORT_DND_OPEN_DIALOG

class netCDFFile : public BinFile
{
public:
	netCDFFile(LPCSTR lpcszFileName, BOOL bImport = true) 
	:BinFile(bImport)
	{
		m_strFileName = lpcszFileName;
	}
	~netCDFFile()
	{
		//netcdf_close();
		m_netCDF.Close();
	}
public:
	int Import(MatrixPage& mp, TreeNode& trFileInfo, TreeNode& trSetting)
	{
		int nRet; 
		if ( nRet = ReadHeader(trFileInfo ) )
			return nRet;
		/*
		// GUI codes may need be improved
		GETN_TREE(trGUI)
		if(!_construct_GUI_tree(trGUI, trFileInfo))
		{
			///---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
			///need handle err message by using dll
			//MessageBox(NULL, "No variables with at least 2D found in " + m_strFileName);
			XF_THROW_EX(IMPERR_NETCDF_NO_VARIABLE_FOUND, m_strFileName);
			return IMPERR_NETCDF_NO_VARIABLE_FOUND;  
			///---END HANDLE_ERR_MESSAGE_USE_DLL
		}
		
		string 	strTitle;
		strTitle = GetFileName(m_strFileName);

		if(!GetNBox(trGUI, strTitle, strTitle, NULL, NULL))
		{
			return XFERR_UI_USER_CANCEL;
		}
		return ReadData(mp, trGUI, trFileInfo);
		*/
		///---Sim 09-19-2006 CHECK_TREE_SETTING
		//return ReadData(mp, trSetting, trFileInfo);
		Tree trUsingSetting;
		if ( trSetting && trSetting.IsValid() )
			trUsingSetting = trSetting;
		return ReadData(mp, trUsingSetting, trFileInfo);
		///---END CHECK_TREE_SETTING
	}
	
private:
	NetCDF	m_netCDF;
private:
	int ReadHeader(TreeNode& trFileInfo)
	{
		//if ( 0 > netcdf_open(m_strFileName) )
			//return IMPERR_FAILED_OPEN; ///---Sim 11-07-2006 HANDLE_ERR_MESSAGE_USE_DLL
		//
		//netcdf_get_vars_info(&trFileInfo);
		if ( m_netCDF.Open(m_strFileName) == NC_FAIL )
			return IMPERR_FAILED_OPEN;
		
		m_netCDF.GetVarsInfo(&trFileInfo);
		
		return CER_NO_ERROR; ///---Sim 11-07-2006 HANDLE_ERR_MESSAGE_USE_DLL
	}
	int ReadData(MatrixPage& mp, TreeNode& trGUI, TreeNode& trFileInfo)
	{
		vector<int> vnDim(NC_MAX_VAR_DIMS);
		vnDim = 0;
		int ii, nVarDims, nIndex = 0, nMat = 0;
		string strVar, str;
		int nLayers = mp.Layers.Count();
		MatrixLayer matLayer;
		int nType;
		//byte mv[9];
		bool bHasMissing;
		double dMissingValue;
		
		foreach(TreeNode trVar in trGUI.Children)
		{
			/// Hong 12/26/06 ADD_1_D_DATA_TO_WKS
			WorksheetPage wp;
			Worksheet wks;
			int nCol = 0;
			string strTemp = trVar.tagName;
			if( 0 == strTemp.Compare("Var1D") )
			{
				int nYNum = 0; /// Hong 07/30/07 v8.0670 FIX_X_ALWAYS_IMPORTED
				foreach(TreeNode tn in trVar.Children)
				{
					if(1 == tn.nVal)
					{
						nCol++;
						/// Hong 07/30/07 v8.0670 FIX_X_ALWAYS_IMPORTED
						if ( tn.Show != 0 )
							nYNum++;
						/// end FIX_X_ALWAYS_IMPORTED
					}
				}
				if ( nYNum > 0 ) /// Hong 07/30/07 v8.0670 FIX_X_ALWAYS_IMPORTED
				{
					if( nCol > 0 )
					{
						wp.Create("origin");
						wks = wp.Layers();
						wks.SetSize(-1, nCol);
						/// Hong 09/01/07 v8.0693 ADD_DATARANGE_INFO_INTO_ORGANIZER
						m_orng.Add(wks, 0, STR_RANGE_STR, nCol - 1); 
						wp.SetName(m_strFileName, OCD_KEEP_SN | OCD_LONG_NAME | OCD_ENUM_NEXT);
						wp.TitleShow = WIN_TITLE_SHOW_BOTH;
						/// end /// Hong 09/01/07 v8.0693 ADD_DATARANGE_INFO_INTO_ORGANIZER
					}
				}
			}
			nCol = 0;
			/// end ADD_1_D_DATA_TO_WKS
			foreach(TreeNode trStr in trVar.Children)
			{
				if(1 == trStr.nVal)
				{
					strVar = trStr.tagName;
					//nVarDims = netcdf_get_var_info(strVar, vnDim, &nType, NULL, NULL, NULL, mv);
					nVarDims = m_netCDF.GetOneVarInfo(strVar, vnDim, &nType, NULL, NULL, NULL, &bHasMissing, &dMissingValue);
					if(nVarDims < 0)
					{
						///---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
						//printf("%d: %s is not a valid variable\n", nIndex, strVar);
						warning_msg_box(IMPERR_NETCDF_NOT_VALID_VARIABLE, nIndex, strVar, false);
						///---END HANDLE_ERR_MESSAGE_USE_DLL
						continue;
					}
					nIndex++;
					if ( nVarDims > 1 && vnDim[0] == 1 ) // if highest dim has only one value, then we should lower the dim size by one
						nVarDims--;
					
					// 1D should read into worksheet
					/// Hong 12/26/06 ADD_1_D_DATA_TO_WKS
					if( wks )
					{
						//netcdf_1d_col(strVar, wks, nCol++);
						m_netCDF.ImportOneDCol(strVar, wks, nCol++);
						wks.SetName(strVar, OCD_ENUM_NEXT);
					}
					/// end ADD_1_D_DATA_TO_WKS
					/// Hong 01/18/07 QA80-9256 FIX_WARNNING_MESSAGE_IMPORT_1_D_DATA
					//if( nVarDims >= 2 )
					if( nVarDims >= 1 )
					{
						switch(nVarDims)
						{
						case 1:
							// add other special code for 1 D data here
							break;
					/// end FIX_WARNNING_MESSAGE_IMPORT_1_D_DATA
						case 2:
						case 3:
						case 4:	///Sophy 9/11/2009 QA80-13128 NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
							// Create layer with var name
							if(nMat >= nLayers)
								mp.AddLayer("");
								
							matLayer = mp.Layers(nMat++);
							///Sophy 7/22/2009 STOP_IMPORTING_WHEN_FAIL_TO_CREATE_MORE_LAYER_FOR_IMPORT_DATA
							if ( !matLayer )
							{
								///Sophy 9/11/2009 QA80-13128 NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
								//return CER_INVALID_MATRIX;
								//if layer number exceed limitation, create new page
								MatrixPage mpMore;
								mpMore.Create("Origin");
								if ( mpMore )
								{
									nLayers = mpMore.Layers.Count();
									nMat = 0;
									if ( nMat >= nLayers )
										mpMore.AddLayer("");
									
									mp = mpMore; //set as current page
									matLayer = mp.Layers(nMat++);
								}
								if ( !matLayer )
									return CER_INVALID_MATRIX;
								///end NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
							}
							///end STOP_IMPORTING_WHEN_FAIL_TO_CREATE_MORE_LAYER_FOR_IMPORT_DATA
							//netcdf_xd_mat(strVar, matLayer);
							///Sophy 9/11/2009 QA80-13128 NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
							//m_netCDF.ImportXDMat(strVar, matLayer);
							m_netCDF.ImportXDMatEx(strVar, matLayer);
							///end NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
							matLayer.SetViewImage();
							matLayer.SetName(strVar, OCD_ENUM_NEXT);
							m_orng.Add(matLayer, 0, STR_RANGE_STR); /// Hong 09/01/07 v8.0693 ADD_DATARANGE_INFO_INTO_ORGANIZER
							break;
						///Sophy 9/11/2009 QA80-13128 NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
						/*
						case 4:
							// create layer with var name and index in the 4rd dimension				
							for( ii = 0; ii < vnDim[0]; ii++ )
							{
								if(nMat >= nLayers)
									mp.AddLayer("");
								matLayer = mp.Layers(nMat++);
								///Sophy 7/22/2009 STOP_IMPORTING_WHEN_FAIL_TO_CREATE_MORE_LAYER_FOR_IMPORT_DATA
								if ( !matLayer )
								{
									return CER_INVALID_MATRIX;
								}
								///end STOP_IMPORTING_WHEN_FAIL_TO_CREATE_MORE_LAYER_FOR_IMPORT_DATA
								//netcdf_xd_mat(strVar, matLayer, ii);
								m_netCDF.ImportXDMat(strVar, matLayer, ii);
								matLayer.SetViewImage();
								str.Format("%s-%d", strVar, ii+1);
								matLayer.SetName(str, OCD_ENUM_NEXT);
								m_orng.Add(matLayer, 0, STR_RANGE_STR); /// Hong 09/01/07 v8.0693 ADD_DATARANGE_INFO_INTO_ORGANIZER
							}
							break;
						*/
						///end NC_SUPPORT_IMPORT_MULTIPLE_DIMS_AS_SINGLE_SHEET_WITH_MULTIPLE_OBJS
						default:
							///---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
							//out_str("please contact Sim or Andrew to to why come here"); 
							warning_msg_box(IMPERR_NETCDF_UNKNOW_VAR_DIM, strVar, false);
							///---END HANDLE_ERR_MESSAGE_USE_DLL
							continue;
						}
						/// Hong 03/29/07 FIX_ERROR_IMPORT_1_D_DATA
						//if ( mv[0] )
						if ( bHasMissing && nVarDims >= 2 )
						/// end FIX_ERROR_IMPORT_1_D_DATA
							matLayer.SetMissingValue(nType, &dMissingValue);	
					}
					///---Sim 08-16-2006 TO_NETCDF_WORK
					/// AW 07/23/08 MORE_ON_NETCDF_FOR_EZCHROM
					// nVarDims == 0
					//else
					else if (nVarDims < 0) 
					/// END MORE_ON_NETCDF_FOR_EZCHROM
					{
						// handle error message
						///---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
						warning_msg_box(IMPERR_NETCDF_UNKNOW_VAR_DIM, strVar, false);
						///---END HANDLE_ERR_MESSAGE_USE_DLL
					}
					///---END TO_NETCDF_WORK
				}
			}
		}
		mp.SetName(m_strFileName, OCD_KEEP_SN | OCD_LONG_NAME | OCD_ENUM_NEXT);
		mp.TitleShow = WIN_TITLE_SHOW_BOTH;
		return CER_NO_ERROR; ///---Sim 11-07-2006 HANDLE_ERR_MESSAGE_USE_DLL
	}
};

void impNetCDF(const string& fname, const TreeNode& trfiles, Range& orng, TreeNode& trheader, const TreeNode& trFilter)
{
	int nRet = 0; 
	
	///---Sim 09-19-2006 MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE	
	/*
	Tree trInfo;
	if ( finfo )
		trInfo = finfo;
	*/
	Tree trBaseInfo; 
	/// Hong 01/10/06 FINFO_IS_ONLY_OUTPUT
	//if ( finfo )
		//trBaseInfo = finfo;
	/// end FINFO_IS_ONLY_OUTPUT
	///---END MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE	
	
	///---Sim 09-12-2006 SUPPPORT_DEFAULT_FILTER_IS_EMPTY
	Tree tnUsingFilter; /// Hong 06/13/07 v8.0640c TEMP_ADD_FILTER_INFO_FOR_MAKE_FILTER
	int nVer;
	if ( fuGetDouble(trFilter, IDE_DISP_IMP_ORIGINVER, nVer) )
		tnUsingFilter = trFilter;
	///---END SUPPPORT_DEFAULT_FILTER_IS_EMPTY
	
	/// Hong 06/13/07 v8.0640c TEMP_ADD_FILTER_INFO_FOR_MAKE_FILTER
	if ( tnUsingFilter.GetNodeCount() <= 0 )
	{
		fuPrepareDefault(tnUsingFilter, FILTER_TYPE_XFUNC);
		fuSetTargetPage(tnUsingFilter, EXIST_MATRIX);
		tree_set_attribute_to_all_nodes(tnUsingFilter, "Show", "0");		
		/// Hong 09/14/07 v8.0702 FIX_DEFAULT_IMPORT_MODE_ERROR
		fuSet1stImportMode(tnUsingFilter, ASCIMP_MODE_NEW_BOOKS);
		fuSetImportMode(tnUsingFilter, ASCIMP_MODE_NEW_BOOKS);
		/// end FIX_DEFAULT_IMPORT_MODE_ERROR
	}
	
	fuSetXFunctionName(tnUsingFilter, "impNetCDF");
	/// end TEMP_ADD_FILTER_INFO_FOR_MAKE_FILTER
	/// Hong 01/13/09 v8.0995d FIX_D&D_MATRIX_ONLY_FILE_RUNTIME_IF_FILTER_USE_WKS_AS_TARGET_PAGE
	// design refer to /// AW 02/28/07 8/0272c ADD_NEW_MATRIX_PAGE_WHEN_ACTIVE_WINDOW_IS_WKS
	if ( EXIST_WKS == fuGetTargetPage(tnUsingFilter) )
		fuSetTargetPage(tnUsingFilter, EXIST_MATRIX);
	/// end FIX_D&D_MATRIX_ONLY_FILE_RUNTIME_IF_FILTER_USE_WKS_AS_TARGET_PAGE
	
	//	int r1,r2,c1,c2; 
	//	orng.GetRange(0, r1, c1, r2, c2, ws);  // used to get wkspg
	
	///---Sim 09-11-2006 SUPPORT_MULTI_FILES_INXF
	/*
	netCDFFile netcdfFile(fname);
	
	// mp is temp codes, need wait datarange for matrix layer
	MatrixPage mp = Project.Pages();     
	if ( !mp )
	{
		mp.Create("Origin");
	}
	
	if ( nRet = netcdfFile.Import(mp, trInfo, trSetting) )
	{
		XF_THROW(nRet);
	}
	else if( !trFilter )
	{
		//impinfo_AddFile(ws, fname, trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC); wait organizer for Matrixpage
		///Have saved in page by import function
		//impinfo_AddFile(pg.Layers(), fname, trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, trFilter);
	}
	*/
	int c1,c2; 
	Datasheet lyTarget;
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//orng.GetRange(lyTarget, c1, c2);
	MatrixPage mpgTarget;
	if ( !GetRangeInfo(orng, lyTarget, mpgTarget, c1, c2) )
		XF_THROW(XFERR_INVALID_RANGE);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	MatrixLayer mlTarget(lyTarget);
	if(!mlTarget.IsValid())
	/// AW 02/28/07 8/0272c ADD_NEW_MATRIX_PAGE_WHEN_ACTIVE_WINDOW_IS_WKS
	//	XF_THROW(CER_INVALID_MATRIX); ///---Sim 11-07-2006 HANDLE_ERR_MESSAGE_USE_DLL
	{
		MatrixPage MatPg;
		MatPg.Create("Origin");
		mlTarget = MatPg.Layers(0);
		
		///---Sim 03-07-2007 FIX_IMPORT_RANGE_ERROR
		if ( orng.IsValid() )
		{
			orng.Reset();
			orng.Add(mlTarget, 0);
		}
		///---END FIX_IMPORT_RANGE_ERROR
	}
	/// END ADD_NEW_MATRIX_PAGE_WHEN_ACTIVE_WINDOW_IS_WKS
	
	///---Sim 09-13-2006 CREATE_PAGE_FOR_EACH_FILE
	//Page pgTarget;
	//MatrixPage mpgTarget; /// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	mlTarget.GetParent(mpgTarget);
	///---END CREATE_PAGE_FOR_EACH_FILE
	StringArray vsFileNames;
	separate_multiline_files(fname, vsFileNames); 
	
	/// Hong 04/10/07 v8.0597b FIX_FAIL_WHEN_FROM_SCRIPT_NO_SHOW_DIALOG
	if ( trfiles.IsEmpty() && !fname.IsEmpty() )
	{
		if ( !construct_tree_setting(vsFileNames, trfiles) )
		{
			XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
			return ;
		}
	}
	
	if( trfiles.IsEmpty())//trSetting was constructed by file
		XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
	/// end FIX_FAIL_WHEN_FROM_SCRIPT_NO_SHOW_DIALOG
	
	string strFileName;
	int nFileCount = vsFileNames.GetSize();
	///---Sim 09-28-2006 CHECK_VALID_FILE_NAME
	if ( nFileCount <= 0 )
		XF_THROW(CER_INVALID_FILENAME); ///---Sim 11-07-2006 HANDLE_ERR_MESSAGE_USE_DLL
	///---END CHECK_VALID_FILE_NAME
	int nIndexLayer = mpgTarget.Layers.Count() - 1;
	///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
	//for ( int ii = 0; ii < nFileCount; ii++ )
	int nFileIndex = 0;
	foreach(TreeNode trFileNode in trfiles.Children )
	///---END FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
	{
		strFileName = vsFileNames[nFileIndex]; ///---Sim 11-06-2006 SINGLE_FILE_NAME
		///---Sim 09-11-2006 CHARACTER_COLON_SHOULD_NOT_IN_FILE_NAME
		//vsFileNames[ii].Remove('\"'); ///---Sim 11-06-2006 NO_NEED
		///---END CHARACTER_COLON_SHOULD_NOT_IN_FILE_NAME
		///---Sim 11-06-2006 SINGLE_FILE_NAME
		//netCDFFile netcdfFile(vsFileNames[ii]);
		netCDFFile netcdfFile(strFileName);
		///---END SINGLE_FILE_NAME
		///---Sim 09-19-2006 SUPPORT_DATA_RANGE
		/*
		///---Sim 09-13-2006 CREATE_PAGE_FOR_EACH_FILE
		//mlTarget = GetTargetLayer(pgTarget, nIndexLayer, ii, tnUsingFilter); ///---Sim 09-06-2006 FIX_EXCESSIVE_EMPTY_SHEET
		if ( 1 != mpgTarget.Layers.Count() || !is_sheet_empty(mpgTarget.Layers()) )
		{
			mpgTarget.Create("Origin");
			mlTarget = mpgTarget.Layers();
		}
		///---END CREATE_PAGE_FOR_EACH_FILE
		*/
		//---Sim 11-06-2006 FILE_INDEX
		//mlTarget = GetTargetLayer(mpgTarget, nIndexLayer, ii, tnUsingFilter, true, orng, ASCIMP_MODE_NEW_BOOKS);
		///---Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		/*
		if ( 0 == nFileIndex )
		{
			int nImportMode = get_first_file_import_mode(FILE_TYPE_NETCDF);
			TreeNode trInValid;
			
			mlTarget = GetTargetLayer(mpgTarget, nIndexLayer, nFileIndex, trInValid, true, orng, nImportMode);
		}
		else
		*/
		//{
		mlTarget = GetTargetLayer(mpgTarget, nIndexLayer, nFileIndex, tnUsingFilter, true, orng, ASCIMP_MODE_NEW_BOOKS);
		//}
		///---END TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		//---END FILE_INDEX
		///---END SUPPORT_DATA_RANGE
		//strFileName = GetFileName(vsFileNames[ii], true); ///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER remove
		///---Sim 09-19-2006 MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE
		/// Hong 01/10/06 FINFO_IS_ONLY_OUTPUT
		//Tree trInfo;
		//trInfo.Replace(trBaseInfo);
		string strFile;
		strFile.Format("File%d", nFileIndex + 1); // file index to be 1
		TreeNode trInfo = trBaseInfo.AddNode(strFile);
		/// end FINFO_IS_ONLY_OUTPUT
		///---END MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE
		///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		//if ( nRet = netcdfFile.Import(mpgTarget, trInfo, trSetting.GetNode(strFileName)) )
		///---Sim 01-18-2007 GET_TREENODE_FILE_DATA_SELECTION
		TreeNode trFileSetting = trFileNode.GetNode(TREENODE_DATA_SELECTION);
		//if ( nRet = netcdfFile.Import(mpgTarget, trInfo, trFileNode) )
		if ( nRet = netcdfFile.Import(mpgTarget, trInfo, trFileSetting) )
		///---END GET_TREENODE_FILE_DATA_SELECTION
		///---END FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		{
			XF_THROW_EX(nRet, GetFileName(strFileName, false)); ///---Sim 11-07-2006 HANDLE_ERR_MESSAGE_USE_DLL
		}
		else //if( !trFilter )   ///---Sim 08/11/06 MORE_ON_TRINFO CAN"T SEE any reason need trFilter be invalid here  
		{
			///---Sim 11-06-2006 SINGLE_FILE_NAME
			//impinfo_AddFile(mlTarget, vsFileNames[ii], trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter);
			/// Hong 09/01/07 v8.0693 ADD_DATARANGE_INFO_INTO_ORGANIZER
			//impinfo_AddFile(mlTarget, strFileName, trInfo, ASCIMP_MODE_NEW_BOOKS, FILTER_TYPE_XFUNC, tnUsingFilter);
			
			DataRange drImported;
			drImported = netcdfFile.GetDataRange();
			Tree trDataRange;		
			getRangeInfo(trDataRange, drImported);
			impinfo_AddFile(mlTarget, strFileName, trInfo, ASCIMP_MODE_NEW_BOOKS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange);
			/// end ADD_DATARANGE_INFO_INTO_ORGANIZER
			///---END SINGLE_FILE_NAME
		}
		///---Sim 09-06-2006 FIX_EXCESSIVE_EMPTY_SHEET
		//if ( ii < nFileCount - 1 ) 
			//mlTarget = GetTargetLayer(pgTarget, nIndexLayer, ii, trFilter);
		///---END FIX_EXCESSIVE_EMPTY_SHEET
		nFileIndex++;	///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
	}
	///---END SUPPORT_MULTI_FILES_INXF	
	//refresh_organizer_gui(mpgTarget); ///---Sim 06-25-2007 UPDATE_ORGANIZER
	if( trheader )
		trheader.Replace(trBaseInfo.Clone(), true, true);/// Hong 01/10/06 FINFO_IS_ONLY_OUTPUT
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int impNetCDF_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return impNetCDF_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	
	OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
	//trVarNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
	
	///---Sim 11-20-2006 SUPPORT_DND_OPEN_DIALOG
	if ( GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID )
	{
		s_bFileValid = file_name_event(trGetN, strErrMsg);
		OK_SURE(bOKEnable);
		
		return true;
	}
	///---END SUPPORT_DND_OPEN_DIALOG
	
	/// AW 08/15/06 NEW_DLG_OF_IMPORT
	if ( 0 == lstrcmp(lpcszNodeName, "fname") )
	{
		///---Sim 11-20-2006 SUPPORT_DND_OPEN_DIALOG
		s_bFileValid = file_name_event(trGetN, strErrMsg);
		OK_SURE(bOKEnable);
		return true;
		//s_bFileValid = true; ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
		//OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
	//
		//TreeNode trFName =  tree_get_node_by_tagname(trGetN, "fname", true, false, false);
		////Tree trFileInfo; ///---Sim 11-13-2006 NO_NEED
		//string strFileName = trFName.strVal;
		//
		///// AW 08/29/06 SUPPORT_MULTI_FILES_INXF
		///*
		//if ( !trFName.IsValid() || 0 > netcdf_open(trFName.strVal) )
		//{
			//XF_THROW( IMPERR_FILE_OPEN);
			//return true;
		//}
	//
		//netcdf_get_vars_info(&trFileInfo);
		//*/
		/////---Sim 11-13-2006 NO_NEED
		////TreeNode trNode, trGUI;
		////vector<string> vs;
		////string strTempFileName;
		////trNode = trGetN.trSetting;
		 /////---END NO_NEED
		///// Hong 11/1/06 RESET_WILL_CLEAR_TREENODE_ATTRIBUTE
		////trNode.Reset();
		////trNode.RemoveChildrenWithPrefix();  ///---Sim 11-13-2006 NO_NEED
		///// end RESET_WILL_CLEAR_TREENODE_ATTRIBUTE
		///// Hong 11/1/06 ERROR_MESSAGE
		//int nErrCode = CER_NO_ERROR;
		//int nInvalidFileIdx = 0;
		//if( strFileName.IsEmpty ())
		//{
			//nErrCode = CER_EMPTY_FILENAME;
		//}
		//else if( !is_valid_filename(strFileName, nInvalidFileIdx) )
		//{
			//nErrCode = CER_INVALID_FILENAME_INDEX;
		//}
		//if(CER_NO_ERROR != nErrCode)
		//{
			//strErrMsg = nErrCode;
			//
			//if ( CER_INVALID_FILENAME_INDEX == nErrCode )
			//{
				//strErrMsg += ":";
				//strErrMsg += nInvalidFileIdx;
			//}
		//
			//s_bFileValid = false; ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			//OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
	//
			////clear trSetting
			//trGetN.trSetting.RemoveChildrenWithPrefix();
			//return true;
		//}
		///// end ERROR_MESSAGE
		/////---Sim 11-13-2006 CONSTRUCT_SETTING_FUNCTION
		///*
		//string strTag; ///---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
		/////---Sim 09-12-2006 USE_STRING_SEPARATE_FOR_STR_DELIM
		////int nSize = strFileName.GetTokens(vs);
		//int nSize = separate_multiline_files(strFileName, vs); 
		/////---END USE_STRING_SEPARATE_FOR_STR_DELIM
		//for(int index = 0; index < nSize; index++)
		//{
			/////---Sim 09-11-2006 CHARACTER_COLON_SHOULD_NOT_IN_FILE_NAME
			//vs[index].Remove('\"');
			/////---END CHARACTER_COLON_SHOULD_NOT_IN_FILE_NAME
			//strTempFileName = GetFileName(vs[index], true);
			/////---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
			//strTag.Format("file%d", index+1);
			/////---END FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
			/////---Sim 09-12-2006 FOR_CORRECT_VAR_TREE_NODE_SETTING
			////trGUI = trNode.AddNode("");
			////trGUI.SetAttribute(STR_LABEL_ATTRIB, vs[index]);
			/////---Sim 11-06-2006 FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
			////trGUI = trNode.AddNode(strTempFileName);
			//trGUI = trNode.AddNode(strTag);
			/////---END FIX_BUG_FOR_FIRST_CHAR_IS_NOT_LETTER
			//trGUI.SetAttribute(STR_LABEL_ATTRIB, strTempFileName);
			/////---END FOR_CORRECT_VAR_TREE_NODE_SETTING
			//GETN_USE(trGUI)
			//if ( 0 > netcdf_open(vs[index]) )
			//{
				/////---Sim 11-06-2006 HANDLE_ERROR_MESSAGE
				////XF_THROW( IMPERR_FILE_OPEN);
				//strErrMsg = IMPERR_FILE_OPEN;
				//bOKEnable = false;
				//
				////clear trSetting
				//trGetN.trSetting.RemoveChildrenWithPrefix();
				/////---END HANDLE_ERROR_MESSAGE
				//return true;	
			//}
			//trFileInfo.Reset(); ///---Sim 09-13-2006 FIX_MULTI_FILE_VAR_INFO_LOADING
			//netcdf_get_vars_info(&trFileInfo);
			//netcdf_close(); ///---Sim 09-12-2006 NEED_CLOSE_FILE_FOR_NEXT_OPEN
			//if(!_construct_GUI_tree(trGUI, trFileInfo))
			//{
				/////---Sim 08-18-2006 HANDLE_ERR_MESSAGE_USE_DLL
				////MessageBox(NULL, "No variables with at least 2D found in " + strFileName);
				////XF_THROW( ERR_NETCDF_NO_VARIABLE_FOUND)
				/////---Sim 11-06-2006 HANDLE_ERROR_MESSAGE
				////XF_THROW_EX(IMPERR_NETCDF_NO_VARIABLE_FOUND, strTempFileName);
				//strErrMsg = IMPERR_NETCDF_NO_VARIABLE_FOUND;
				//strErrMsg += ":";
				//strErrMsg += strTempFileName;
				//bOKEnable = false;
				//
				////clear trSetting
				//trGetN.trSetting.RemoveChildrenWithPrefix();
				/////---END HANDLE_ERROR_MESSAGE
				//return true;
				/////---END HANDLE_ERR_MESSAGE_USE_DLL
			//}
		//}
		//trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);	
		//*/
		//StringArray vsFileNames;
		//TreeNode trInfo = trGetN.trSetting;
		//separate_multiline_files(trGetN.fname.strVal, vsFileNames);
		//if ( !construct_tree_setting(vsFileNames, trInfo) )
		//{
			/////---Sim 10-30-2006 ERROR_MESSAGE
			//// clean the trFiles on GUI
			//trInfo.RemoveChildrenWithPrefix();
			//
			////XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
			////return false;
			//strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
			//s_bFileValid = false; ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			//OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			//
			//return true;
			/////---END ERROR_MESSAGE
		//}
		/////---Sim 11-13-2006 CONSTRUCT_SETTING_FUNCTION
		//return true; ///---Sim 11-06-2006 UPDATE_GUI
		///---END SUPPORT_DND_OPEN_DIALOG
	}
	
	/// END NEW_DLG_OF_IMPORT	
	
	return false;	

}

int impNetCDF_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void impNetCDF_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	if(nGetNDialog > 0)
	{
		trGetN.AutoUpdate.Show = 0;
		trGetN.trheader.Show = 0;			/// AW 08/15/06 NEW_DLG_OF_IMPORT 
		trGetN.trFilter.Show = 0;
	}
	/// Hong 12/22/06 CHECK_FNAME_EMPTY_UNASSIGNED
	if(nGetNDialog > -1)
	{
		string strFileName = trGetN.fname.strVal;
		
		/// Hong 04/10/07 v8.0597b IGNORE_FNAME$_WHEN_FROM_MENU
		if ( LTXF_FROM_GUI_MENU & dwCntrl ) // if from menu, ignore default value fname$
			strFileName = "";
		/// end IGNORE_FNAME$_WHEN_FROM_MENU
		
		if(is_empty_or_unassigned(strFileName))
		{			
			/// Hong 05/31/07 v8.0630 MORE_ON_ACCESS_TO_FDLOG
			//int nFilesRet = get_open_box_by_file_group(strFileName, "NetCDF", "NetCDF", true);
			int nFilesRet;
			if ( 0 != nGetNDialog )
			{
				int nShowOptionsDlg = 1;
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_open_box_by_file_group(strFileName, "NetCDF", _L("NetCDF"),
				//	OPENBOX_FLAG_MULTIFILES, NULL, NULL, _L("Show Options Dialog"), &nShowOptionsDlg);
				nFilesRet = get_open_box_by_file_group(strFileName, "NetCDF", NULL,
					OPENBOX_FLAG_MULTIFILES, NULL, NULL, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				nRet = (nShowOptionsDlg ? XFEVT_PROCEED : XFEVT_PROCEED_NO_DLG);
			}
			else
			{
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_open_box_by_file_group(strFileName, "NetCDF", _L("NetCDF"), true);
				nFilesRet = get_open_box_by_file_group(strFileName, "NetCDF", NULL, true);
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
			}
			/// end MORE_ON_ACCESS_TO_FDLOG
			/// end THEME_FILENAME_WORKBOOK_AND_WORKSHEET
			if ( 0 == nFilesRet )
			{
				nRet = XFEVT_ABORT;
				//warning_msg_box(XFERR_UI_USER_CANCEL, false);
				return;
			}
			///---END HANDLE_USER_CANCEL_OPEN_FILE_BOX
			trGetN.fname.strVal = strFileName;
			string strErrMsg;
			if( !file_name_event(trGetN, strErrMsg) )
			{
				/// Hong 03/21/07 v8.0586 FIX_FAIL_DUMP_CORRECT_ERROR_STRING
				//nRet = XFEVT_ABORT;
				//warning_msg_box(strErrMsg, false);
				int nErrMsg = atoi(strErrMsg);
				nRet = XFEVT_ABORT;
				warning_msg_box(nErrMsg, false, 'E'); // should pass an int ///---Sim 06-19-2007 IMPROVE_WARNING_MESSAGE_POST_FUNCTION
				/// end FIX_FAIL_DUMP_CORRECT_ERROR_STRING
				return;
			}
		}
	}
	/// end CHECK_FNAME_EMPTY_UNASSIGNED
}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int impNetCDF_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
