/
CCtfFindMain.cpp
82 lines (76 loc) · 1.96 KB
/
CCtfFindMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "CMainInc.h"
#include <Mrcfile/CMrcFileInc.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
#include <string.h>
using namespace GCTFFind;
bool mCheckSame(void);
bool mCheckSave(char* pcMrcFile);
bool mCheckGPU(int iGpuID);
int main(int argc, char* argv[])
{
CInput* pInput = CInput::GetInstance();
if(argc == 1)
{ printf("Use GCtfFind --help to get more information.\n");
return 0;
}
else if(strstr(argv[1], "--help"))
{ pInput->ShowTags();
return 0;
}
else if(strstr(argv[1], "--version"))
{ printf("GCtfFind version 1.0.5, Oct 04, 2023\n");
return 0;
}
//------------------------
pInput->Parse(argc, argv);
bool bSame = mCheckSame();
if(bSame) return 1;
//---------------------------------------------
bool bSave = mCheckSave(pInput->m_acOutMrcFile);
bool bGpu = mCheckGPU(pInput->m_iGpuID);
if(!bSave || !bGpu) return 1;
//---------------------------
CProcessMain aProcessMain;
aProcessMain.DoIt();
return 0;
}
bool mCheckSame(void)
{
CInput* pInput = CInput::GetInstance();
int iSame1, iSame2;
iSame1 = strcasecmp(pInput->m_acInMrcFile, pInput->m_acOutMrcFile);
iSame2 = strcasecmp(pInput->m_acInMrcFile, pInput->m_acOutCtfFile);
if(iSame1 == 0 || iSame2 == 0)
{ fprintf(stderr, "Error: input and output files have the"
"same name,\n\n");
return true;
}
return false;
}
bool mCheckSave(char* pcMrcFile)
{
Mrc::CSaveMrc aSaveMrc;
bool bSave = aSaveMrc.OpenFile(pcMrcFile);
remove(pcMrcFile);
if(bSave) return true;
//--------------------
printf("Error: Unable to open output MRC file.\n");
printf("......%s\n\n", pcMrcFile);
return false;
}
bool mCheckGPU(int iGpuID)
{
cudaError_t tErr = cudaSetDevice(iGpuID);
cudaDeviceReset();
if(tErr == cudaSuccess) return true;
//----------------------------------
if(tErr == cudaErrorInvalidDevice)
{ printf("Error: Invalid GPU (%d)\n\n", iGpuID);
}
else if(tErr == cudaErrorDeviceAlreadyInUse)
{ printf("Error: GPU (%d) already in use\n\n", iGpuID);
}
return false;
}