📄 msdat.cpp
字号:
// $masm\msdat.cpp 1.5 milbo$ routines for handling the ms.dat data log file// Warning: this is raw research code -- expect it to be quite messy.// milbo durban may 05//-----------------------------------------------------------------------------// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// A copy of the GNU General Public License is available at// http://www.r-project.org/Licenses///-----------------------------------------------------------------------------#include "all.hpp"static FILE *pgDatFile; // the data file (use -fd flag im ms.exe to append detailed results to this file)static int igRun; // run number for pgDatFile (one more than last run number in data file)//-----------------------------------------------------------------------------// open the global variable pgDatFile and write a headervoid OpenDatFile (const char sRefShapeFile[], const char sModel[]){if (sRefShapeFile[0] == 0) Err("You can't use the -s flag without the -r flag"); // need a reference file if you use -dpgDatFile = fopen(CONF_sMsDatFilename, "r"); // existing file:? check by opening for readingif (pgDatFile) { // existing file: get global run numbers igRun_* (1 + highest run number in the file for this sModel) char s[1000+1]; int iRun_Lev0 = -1, iRun_Prof0 = -1; while (Fgets(s, 1000, pgDatFile)) { int iRun = -1; char sModel[SLEN], sTag[SLEN]; if (sscanf(s, "%d %s %s", &iRun, sModel, sTag) == 3 && strcmp(sModel, sModel) == 0) { ASSERT(iRun >= 0 && iRun < 100); if (strcmp(sTag, "aLev0") == 0) iRun_Lev0 = iRun+1; if (strcmp(sTag, "aProf0") == 0) iRun_Prof0 = iRun+1; } } if (iRun_Lev0 < 0 || iRun_Prof0 < 0) { iRun_Lev0 = 1; // can't find for this model, start at iRun=1 iRun_Prof0 = 1; } if (iRun_Lev0 < 0 || iRun_Prof0 < 0) SysErr("Bad file %s: can't find Lev0 or Prof0", CONF_sMsDatFilename); if (iRun_Lev0 != iRun_Prof0) SysErr("Bad file %s: Lev0 Run=%d but Prof0 Run =%d", CONF_sMsDatFilename, iRun_Lev0, iRun_Prof0); igRun = iRun_Lev0; fclose(pgDatFile); lprintf("Appending to %s (run %d)\n", CONF_sMsDatFilename, igRun); pgDatFile = Fopen(CONF_sMsDatFilename, "a"); // reopen for appending, will exit with an error msg if can't }else { // new file: set global run number igRun to 1 and write header igRun = 1; lprintf("Opening %s (run %d)\n", CONF_sMsDatFilename, igRun); pgDatFile = Fopen(CONF_sMsDatFilename, "w"); // open for writing, will exit with an error msg if can't Fprintf(pgDatFile, "Run Model Tag File Time "); for (int iPoint = 0; iPoint < CONF_nPointsInDatFile; iPoint++) Fprintf(pgDatFile, "p%d ", iPoint); Fprintf(pgDatFile, "\n"); }}//-----------------------------------------------------------------------------void CloseDatFile (void){if (pgDatFile) fclose(pgDatFile);}//-----------------------------------------------------------------------------// Tags (at the time I wrote this) (now incorrect? TODO)//// aLev search results shape// bProf suggested profile model// cStart start shape// dRef reference shape conformed to model//// The saved distances are the distances from the above shapes to the reference shape.//// If iLev >= 0 then we append it to the tag name.the level number.//// The a,c,c, etc prefixes are so that the tags appear in this order// in alphabetically sorted tag lists.void AppendDistancesToDatFile (int iLev, const SHAPE &Shape, const SHAPE &RefShape, const double NormDist, const char sImageBase[], const char sModel[], const char sTag[], double Time){if (!pgDatFile) return; // data file not openchar sTag1[SLEN];if (iLev < 0) sprintf(sTag1, "%s%", sTag);else sprintf(sTag1, "%s%d", sTag, iLev);Fprintf(pgDatFile, "%-3d %-10s %-20s %-12s %.3f ", igRun, sModel, sTag1, sImageBase, Time);double InterEyeDist = NormDist;DASSERT(Shape.nrows() < CONF_nPointsInDatFile);double TotalDist = 0;int nPoints = 0;for (int iRow = 0; iRow < CONF_nPointsInDatFile; iRow++) { if (iRow < Shape.nrows() && iRow < RefShape.nrows() && fPointUsed(RefShape, iRow)) { double Dist = PointDist(Shape, RefShape, iRow) / InterEyeDist; Fprintf(pgDatFile, "%.5f ", Dist); TotalDist += Dist; nPoints++; } else Fprintf(pgDatFile, "NA "); }Fprintf(pgDatFile, "\n");}//-----------------------------------------------------------------------------// is ms.dat open?bool fDatFile (void){return pgDatFile != NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -