#pragma rtGlobals=3 // Use modern global access method and strict wave access. Menu "Load Waves" "Load One RND File...", LoadOneRNDFile("", "") "Load All RND Files...", LoadAllRNDFiles("") End static StrConstant kFileNameExtension = ".txt" Function/S GetColumnInfoStr(fileName) String fileName String baseName = ParseFilePath(3, fileName, ":", 0, 0) // File name with extension removed if (IgorVersion() < 8.00) // In Igor Pro 7 and before, wave names were limited to 31 characters baseName = baseName[0,13] endif String columnInfoStr = " " columnInfoStr += "N=" + "'" + baseName + "_" + "depth_for_growth" + "';" // 1 columnInfoStr += "N=" + "'" + baseName + "_" + "growthp_3" + "';" // 2 columnInfoStr += "N='_skip_';" // 3 growthp_17 columnInfoStr += "N=" + "'" + baseName + "_" + "growthp_50" + "';" // 4 columnInfoStr += "N='_skip_';" // 5 growthp_83 columnInfoStr += "N=" + "'" + baseName + "_" + "growthp_97" + "';" // 6 columnInfoStr += "N=" + "'" + baseName + "_" + "age_for_rate" + "';" // 7 columnInfoStr += "N='_skip_';" // 8 ratep_3 columnInfoStr += "N='_skip_';" // 9 ratep_17 columnInfoStr += "N=" + "'" + baseName + "_" + "ratep_50" + "';" // 10 columnInfoStr += "N='_skip_';" // 11 ratep_83 columnInfoStr += "N='_skip_';" // 12 ratep_97 columnInfoStr += "N=" + "'" + baseName + "_" + "age_for_age_err" + "';" // 13 columnInfoStr += "N=" + "'" + baseName + "_" + "AgeMinusErr" + "';" // 14 columnInfoStr += "N='_skip_';" // 15 AgeMinusErr1SE columnInfoStr += "N='_skip_';" // 16 AgePlusErr1SE columnInfoStr += "N=" + "'" + baseName + "_" + "AgePlusErr" + "';" // 17 return columnInfoStr End // LoadOneRNDFile(pathName, fileName) Function LoadOneRNDFile(pathName, fileName) String pathName // Name of an Igor symbolic path or "" for dialog String fileName // Name of file or full path to file or "" for dialog // First get a valid reference to a file. if ((strlen(pathName)==0) || (strlen(fileName)==0)) // Display dialog looking for file. Variable refNum Open/D/R/F=kFileNameExtension/P=$pathName refNum as fileName fileName = S_fileName // S_fileName is set by Open/D if (strlen(fileName) == 0) // User cancelled? return -1 endif endif String columnInfoStr = GetColumnInfoStr(fileName) LoadWave /G /O /D /K=0 /A /B=columnInfoStr /Q /P=$pathName fileName Variable numWavesLoaded = V_flag // V_flag is set by LoadWave Variable numWavesToBeLoaded = 9 if (numWavesLoaded != numWavesToBeLoaded) Printf "Error loading file: Expected %d waves, found %d waves\r" return -1 endif return 0 // Success End // LoadAllRNDFiles(pathName) // Loads all files in specified folder with extension specified by kFileNameExtension. // The output waves are: DateTimeW, CH4_dry, CO2_dry // All loaded waves are concatenated, creating the output waves in the current data folder. // If the output waves already exist in the current data folder, this routine appends to them. Function LoadAllRNDFiles(pathName) String pathName // Name of symbolic path or "" to get dialog String fileName Variable index=0 if (strlen(pathName)==0) // If no path specified, create one NewPath/O TemporaryPath // This will put up a dialog if (V_flag != 0) return -1 // User cancelled endif pathName = "TemporaryPath" endif Variable result do // Loop through each file in folder fileName = IndexedFile($pathName, index, kFileNameExtension) if (strlen(fileName) == 0) // No more files? break // Break out of loop endif result = LoadOneRNDFile(pathName, fileName) if (result != 0) String message sprintf message, "An error occurred while loading the file \"%s\". Aborting the load.\r", fileName Print message DoAlert 0, message break endif Printf "Loaded file %d: \"%s\"\r", index, fileName index += 1 while (1) if (Exists("TemporaryPath")) // Kill temp path if it exists KillPath TemporaryPath endif return 0 // Signifies success End