Commit 2b5aff50939361e7b0646a61b842cfb7454194ec

Authored by Elena.Budnik
1 parent 41c930bc
Exists in master

stereo added

Bin.py/makeRequest.py
@@ -64,9 +64,9 @@ def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtL @@ -64,9 +64,9 @@ def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtL
64 xml.write('\t<START>'+startTime+'</START>\n') 64 xml.write('\t<START>'+startTime+'</START>\n')
65 xml.write('\t<STOP>'+stopTime+'</STOP>\n') 65 xml.write('\t<STOP>'+stopTime+'</STOP>\n')
66 xml.write('\t<PLASMA_VI>'+plasmaVI+'</PLASMA_VI>\n') 66 xml.write('\t<PLASMA_VI>'+plasmaVI+'</PLASMA_VI>\n')
67 - xml.write('\t<SOURCE_VI>earth_orb_all</SOURCE_VI>\n')  
68 - xml.write('\t<SOURCE_R_PARAM>R</SOURCE_R_PARAM>\n')  
69 - xml.write('\t<SOURCE_LON_PARAM>LON_HCI</SOURCE_LON_PARAM>\n') 67 + xml.write('\t<SOURCE_VI>'+srcVI+'</SOURCE_VI>\n')
  68 + xml.write('\t<SOURCE_R_PARAM>'+srcRParam+'</SOURCE_R_PARAM>\n')
  69 + xml.write('\t<SOURCE_LON_PARAM>'+srcLonParam+'</SOURCE_LON_PARAM>\n')
70 xml.write('\t<TARGET_VI>'+tgtVI+'</TARGET_VI>\n') 70 xml.write('\t<TARGET_VI>'+tgtVI+'</TARGET_VI>\n')
71 xml.write('\t<TARGET_R_PARAM>'+tgtRParam+'</TARGET_R_PARAM>\n') 71 xml.write('\t<TARGET_R_PARAM>'+tgtRParam+'</TARGET_R_PARAM>\n')
72 xml.write('\t<TARGET_LON_PARAM>'+tgtLonParam+'</TARGET_LON_PARAM>\n') 72 xml.write('\t<TARGET_LON_PARAM>'+tgtLonParam+'</TARGET_LON_PARAM>\n')
@@ -75,12 +75,18 @@ def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtL @@ -75,12 +75,18 @@ def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtL
75 75
76 76
77 # In[8]: 77 # In[8]:
78 -  
79 -tgtRParam = 'R_HCI'  
80 -if tgtVI == 'p67_orb_all':  
81 - tgtRParam = 'R' 78 +if plasmaVI == 'sta_l2_pla' :
  79 + srcVI = 'sta_l2_orb'
  80 +elif plasmaVI == 'stb_l2_pla' :
  81 + srcVI = 'stb_l2_orb'
  82 +else :
  83 + srcVI = 'earth_orb_all'
82 84
  85 +srcRParam = 'R_HCI'
  86 +srcLonParam = 'LON_HCI'
  87 +tgtRParam = 'R_HCI'
83 tgtLonParam = 'LON_HCI' 88 tgtLonParam = 'LON_HCI'
  89 +
84 newMissionStart = missionStopTime 90 newMissionStart = missionStopTime
85 newMissionStop = omniStopTime 91 newMissionStop = omniStopTime
86 print "New mission start : " + newMissionStart.isoformat() 92 print "New mission start : " + newMissionStart.isoformat()
@@ -93,7 +99,7 @@ else: @@ -93,7 +99,7 @@ else:
93 print "Database has to be updated" 99 print "Database has to be updated"
94 100
95 if newMissionStart.year != newMissionStop.year and plasmaVI != 'ace_swepam_real': 101 if newMissionStart.year != newMissionStop.year and plasmaVI != 'ace_swepam_real':
96 - print "2 files will be producted" 102 + print "2 files will be produced"
97 newMissionxml1Start = datetime(newMissionStart.year,1,1,0,0) 103 newMissionxml1Start = datetime(newMissionStart.year,1,1,0,0)
98 newMissionxml1Stop = datetime(newMissionStop.year,1,1,0,0) 104 newMissionxml1Stop = datetime(newMissionStop.year,1,1,0,0)
99 newMissionxml2Start = datetime(newMissionStop.year,1,1,0,0) 105 newMissionxml2Start = datetime(newMissionStop.year,1,1,0,0)
@@ -102,12 +108,12 @@ if newMissionStart.year != newMissionStop.year and plasmaVI != &#39;ace_swepam_real&#39; @@ -102,12 +108,12 @@ if newMissionStart.year != newMissionStop.year and plasmaVI != &#39;ace_swepam_real&#39;
102 print 'XML 1 Stop : ' + newMissionxml1Stop.isoformat() 108 print 'XML 1 Stop : ' + newMissionxml1Stop.isoformat()
103 print 'XML 2 Start : ' + newMissionxml2Start.isoformat() 109 print 'XML 2 Start : ' + newMissionxml2Start.isoformat()
104 print 'XML 2 Stop : ' + newMissionxml2Stop.isoformat() 110 print 'XML 2 Stop : ' + newMissionxml2Stop.isoformat()
105 - XMLfilename = prefix+'_'+str(newMissionxml1Start.year)+'.xml' 111 + XMLfilename = prefix + '_' + str(newMissionxml1Start.year) + '.xml'
106 writeXMLMission(XMLfilename,newMissionxml1Start.isoformat(),newMissionxml1Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam) 112 writeXMLMission(XMLfilename,newMissionxml1Start.isoformat(),newMissionxml1Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)
107 - XMLfilename = prefix+'_'+str(newMissionxml2Start.year)+'.xml' 113 + XMLfilename = prefix + '_' + str(newMissionxml2Start.year) + '.xml'
108 writeXMLMission(XMLfilename,newMissionxml2Start.isoformat(),newMissionxml2Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam) 114 writeXMLMission(XMLfilename,newMissionxml2Start.isoformat(),newMissionxml2Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)
109 else: 115 else:
110 - print "1 file will be producted" 116 + print "1 file will be produced"
111 if plasmaVI == "ace_swepam_real": 117 if plasmaVI == "ace_swepam_real":
112 newMissionxmlStart = datetime(newMissionStart.year,newMissionStart.month,newMissionStart.day,0,0) 118 newMissionxmlStart = datetime(newMissionStart.year,newMissionStart.month,newMissionStart.day,0,0)
113 # Future !!! 119 # Future !!!
@@ -119,5 +125,5 @@ else: @@ -119,5 +125,5 @@ else:
119 125
120 print 'XML Start : ' + newMissionxmlStart.isoformat() 126 print 'XML Start : ' + newMissionxmlStart.isoformat()
121 print 'XML Stop : ' + newMissionxmlStop.isoformat() 127 print 'XML Stop : ' + newMissionxmlStop.isoformat()
122 - XMLfilename = prefix+'_'+str(newMissionxmlStart.year)+'.xml' 128 + XMLfilename = prefix + '_' + str(newMissionxmlStart.year) + '.xml'
123 writeXMLMission(XMLfilename,newMissionxmlStart.isoformat(),newMissionxmlStop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam) 129 writeXMLMission(XMLfilename,newMissionxmlStart.isoformat(),newMissionxmlStop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)
@@ -74,6 +74,8 @@ def main(): @@ -74,6 +74,8 @@ def main():
74 # if run run.py 'alone' - for previous years 74 # if run run.py 'alone' - for previous years
75 #plasmaStop = shiftedDate(stop, days=marginPlasma) 75 #plasmaStop = shiftedDate(stop, days=marginPlasma)
76 #plasmaStop = shiftedDate(swStop) 76 #plasmaStop = shiftedDate(swStop)
  77 + print plasmaStop
  78 +
77 plasmaDDStop = time2ddtime(plasmaStop) 79 plasmaDDStop = time2ddtime(plasmaStop)
78 ddTimeDeltaPlasma = DDTimeDelta(plasmaStart, plasmaStop) 80 ddTimeDeltaPlasma = DDTimeDelta(plasmaStart, plasmaStop)
79 81
@@ -85,10 +87,16 @@ def main(): @@ -85,10 +87,16 @@ def main():
85 87
86 # GET DATA FROM DD BASE DEPENDING ON SW INPUT 88 # GET DATA FROM DD BASE DEPENDING ON SW INPUT
87 if plasmaVi == 'omni_hour_all': 89 if plasmaVi == 'omni_hour_all':
88 - plasmaCmd = ['get_OMNI_1H',MYDIR+'/plasma.csv',plasmaDDStart,ddTimeDeltaPlasma] 90 + plasmaCmd = ['get_OMNI_1H',MYDIR + '/plasma.csv',plasmaDDStart,ddTimeDeltaPlasma]
89 elif plasmaVi == 'ace_swepam_real': 91 elif plasmaVi == 'ace_swepam_real':
90 - plasmaCmd = ['get_ACE_RT',MYDIR+'/plasma.csv',MYDIR+'/mag.csv',plasmaDDStart,ddTimeDeltaPlasma]  
91 - 92 + plasmaCmd = ['get_ACE_RT',MYDIR + '/plasma.csv',MYDIR + '/mag.csv',plasmaDDStart,ddTimeDeltaPlasma]
  93 + elif plasmaVi == 'sta_l2_pla':
  94 + plasmaCmd = ['get_STEREO','a',MYDIR + '/plasma.csv',MYDIR + '/mag.csv',plasmaDDStart,ddTimeDeltaPlasma]
  95 + elif plasmaVi == 'stb_l2_pla':
  96 + plasmaCmd = ['get_STEREO','b',MYDIR + '/plasma.csv',MYDIR + '/mag.csv',plasmaDDStart,ddTimeDeltaPlasma]
  97 + elif plasmaVi == 'dsc_fc_1m':
  98 + plasmaCmd = ['get_DSCOVR', MYDIR + '/plasma.csv',MYDIR + '/mag.csv',plasmaDDStart,ddTimeDeltaPlasma]
  99 +
92 print plasmaCmd 100 print plasmaCmd
93 srcCmd = ['get_R_LON_HCI',MYDIR+'/source.csv',srcVi,srcR,srcLon,orbitsDDStart,ddTimeDeltaOrbit] 101 srcCmd = ['get_R_LON_HCI',MYDIR+'/source.csv',srcVi,srcR,srcLon,orbitsDDStart,ddTimeDeltaOrbit]
94 tgtCmd = ['get_R_LON_HCI',MYDIR+'/target.csv',tgtVi,tgtR,tgtLon,orbitsDDStart,ddTimeDeltaOrbit] 102 tgtCmd = ['get_R_LON_HCI',MYDIR+'/target.csv',tgtVi,tgtR,tgtLon,orbitsDDStart,ddTimeDeltaOrbit]
@@ -108,7 +116,7 @@ def main(): @@ -108,7 +116,7 @@ def main():
108 116
109 # PLASMA DATAFRAME 117 # PLASMA DATAFRAME
110 if plasmaVi == 'omni_hour_all': 118 if plasmaVi == 'omni_hour_all':
111 - plasma = pd.read_csv(MYDIR+'/plasma.csv', dtype='S16,f4,f4,f4,f4,f4,f4,f4,f4') 119 + plasma = pd.read_csv(MYDIR + '/plasma.csv', dtype='S16,f4,f4,f4,f4,f4,f4,f4,f4')
112 elif plasmaVi == 'ace_swepam_real': 120 elif plasmaVi == 'ace_swepam_real':
113 if os.path.getsize(MYDIR+'/mag.csv') == 0: 121 if os.path.getsize(MYDIR+'/mag.csv') == 0:
114 logger.error('Failed to load mag data') 122 logger.error('Failed to load mag data')
@@ -116,11 +124,17 @@ def main(): @@ -116,11 +124,17 @@ def main():
116 sw = pd.read_csv(MYDIR+'/plasma.csv', dtype='S16,f4,f4,f4') 124 sw = pd.read_csv(MYDIR+'/plasma.csv', dtype='S16,f4,f4,f4')
117 mag = pd.read_csv(MYDIR+'/mag.csv', dtype='S16,f4,f4,f4') 125 mag = pd.read_csv(MYDIR+'/mag.csv', dtype='S16,f4,f4,f4')
118 plasma = sw.merge(mag, on='Time') 126 plasma = sw.merge(mag, on='Time')
  127 + elif plasmaVi == 'sta_l2_pla' or plasmaVi == 'stb_l2_pla' or plasmaVi == 'dsc_fc_1m':
  128 + if os.path.getsize(MYDIR+'/mag.csv') == 0:
  129 + logger.error('Failed to load mag data')
  130 + sys.exit(2)
  131 + sw = pd.read_csv(MYDIR+'/plasma.csv', dtype='S16,f4,f4,f4,f4,f4')
  132 + mag = pd.read_csv(MYDIR+'/mag.csv', dtype='S16,f4,f4,f4')
  133 + plasma = sw.merge(mag, on='Time')
119 134
120 plasma['Time'] = ddTime2Datetime(plasma['Time']) 135 plasma['Time'] = ddTime2Datetime(plasma['Time'])
121 plasma = plasma.set_index('Time') 136 plasma = plasma.set_index('Time')
122 -  
123 - 137 +
124 logger.info('Number of NaNs for plasma data before cleaning : %d' % plasma.isnull().sum().sum()) 138 logger.info('Number of NaNs for plasma data before cleaning : %d' % plasma.isnull().sum().sum())
125 plasma = plasma.interpolate().fillna(method='bfill') 139 plasma = plasma.interpolate().fillna(method='bfill')
126 logger.info('Number of NaNs for plasma data after cleaning : %d' % plasma.isnull().sum().sum()) 140 logger.info('Number of NaNs for plasma data after cleaning : %d' % plasma.isnull().sum().sum())
@@ -157,18 +171,31 @@ def main(): @@ -157,18 +171,31 @@ def main():
157 target = pd.DataFrame(data=targetData,columns=targetColumns) 171 target = pd.DataFrame(data=targetData,columns=targetColumns)
158 target = target.set_index('Time') 172 target = target.set_index('Time')
159 173
160 -  
161 - # SPHERICAL TO CARTESIAN COORDS  
162 - if plasmaVi == 'omni_hour_all':  
163 - vlon = np.radians(plasma['Vlon'])  
164 - vlat = np.radians(plasma['Vlat'])  
165 - elif plasmaVi == 'ace_swepam_real':  
166 - vlon = np.radians(-2.0)  
167 - vlat = np.radians(1.0) 174 + # TAO frame : RTN with t=-t
  175 + if plasmaVi == 'sta_l2_pla' or plasmaVi == 'stb_l2_pla' :
  176 + vx = plasma['Vr']
  177 + vy = -plasma['Vt']
  178 + vz = plasma['Vn']
  179 + temperature = plasma['Vth']*plasma['Vth']*60.6 # v=sqrt(2kT/m)
  180 + elif plasmaVi == 'dsc_fc_1m':
  181 + vx = -plasma['Vx']
  182 + vy = -plasma['Vy']
  183 + vz = plasma['Vz']
  184 + temperature = plasma.Temperature
  185 + else :
  186 + # SPHERICAL TO CARTESIAN COORDS
  187 + if plasmaVi == 'omni_hour_all':
  188 + vlon = np.radians(plasma['Vlon'])
  189 + vlat = np.radians(plasma['Vlat'])
  190 + elif plasmaVi == 'ace_swepam_real':
  191 + vlon = np.radians(-2.0)
  192 + vlat = np.radians(1.0)
  193 +
  194 + vx = plasma['V']*np.cos(vlat)*np.cos(vlon)
  195 + vy = -plasma['V']*np.cos(vlat)*np.sin(vlon)
  196 + vz = plasma['V']*np.sin(vlat)
168 197
169 - vx = plasma['V']*np.cos(vlat)*np.cos(vlon)  
170 - vy = -plasma['V']*np.cos(vlat)*np.sin(vlon)  
171 - vz = plasma['V']*np.sin(vlat) 198 + temperature = plasma.Temperature
172 199
173 # ROTATION 200 # ROTATION
174 bx = -np.array(plasma['Bx']) 201 bx = -np.array(plasma['Bx'])
@@ -176,7 +203,7 @@ def main(): @@ -176,7 +203,7 @@ def main():
176 bz = np.array(plasma['Bz']) 203 bz = np.array(plasma['Bz'])
177 204
178 # FINAL PLASMA DATAFRAME 205 # FINAL PLASMA DATAFRAME
179 - plasmaData = np.array([plasma.index,plasma.Density,plasma.Temperature,vx,vy,vz,bx,by,bz]) 206 + plasmaData = np.array([plasma.index,plasma.Density,temperature,vx,vy,vz,bx,by,bz])
180 plasmaColumns = ['Time','Density','Temperature','Vx','Vy','Vz','Bx','By','Bz'] 207 plasmaColumns = ['Time','Density','Temperature','Vx','Vy','Vz','Bx','By','Bz']
181 plasma = pd.DataFrame(data=plasmaData.T,columns=plasmaColumns) 208 plasma = pd.DataFrame(data=plasmaData.T,columns=plasmaColumns)
182 plasma = plasma.set_index('Time') 209 plasma = plasma.set_index('Time')
Sources/Makefile
@@ -9,7 +9,7 @@ INCLUDE = -I${DD_DIR}/include/DDClientLibC -I${TINYDIR}/include @@ -9,7 +9,7 @@ INCLUDE = -I${DD_DIR}/include/DDClientLibC -I${TINYDIR}/include
9 LIB = -L${DD_DIR}/lib -L${TINYDIR}/lib 9 LIB = -L${DD_DIR}/lib -L${TINYDIR}/lib
10 LKLIBS = -lDDClientLibC -ltinyxml -lnetcdf -lm 10 LKLIBS = -lDDClientLibC -ltinyxml -lnetcdf -lm
11 LDFLAGS = -fPIC 11 LDFLAGS = -fPIC
12 -EXE = get_Orbit get_OMNI_1H get_ACE_RT get_R_LON_HCI 12 +EXE = get_Orbit get_OMNI_1H get_ACE_RT get_STEREO get_DSCOVR get_R_LON_HCI
13 # ********************* END OF COMPILER SETTINGS ***************************** 13 # ********************* END OF COMPILER SETTINGS *****************************
14 14
15 # ******************************** LINKING ********************************* 15 # ******************************** LINKING *********************************
@@ -26,6 +26,12 @@ get_OMNI_1H: get_OMNI_1H.o @@ -26,6 +26,12 @@ get_OMNI_1H: get_OMNI_1H.o
26 get_ACE_RT: get_ACE_RT.o 26 get_ACE_RT: get_ACE_RT.o
27 ${CXX} -o $@ $^ ${LDFLAGS} ${LIB} ${LKLIBS} 27 ${CXX} -o $@ $^ ${LDFLAGS} ${LIB} ${LKLIBS}
28 28
  29 +get_STEREO: get_STEREO.o
  30 + ${CXX} -o $@ $^ ${LDFLAGS} ${LIB} ${LKLIBS}
  31 +
  32 +get_DSCOVR: get_DSCOVR.o
  33 + ${CXX} -o $@ $^ ${LDFLAGS} ${LIB} ${LKLIBS}
  34 +
29 get_R_LON_HCI: get_R_LON_HCI.o 35 get_R_LON_HCI: get_R_LON_HCI.o
30 ${CXX} -o $@ $^ ${LDFLAGS} ${LIB} ${LKLIBS} 36 ${CXX} -o $@ $^ ${LDFLAGS} ${LIB} ${LKLIBS}
31 # ************************** END OF LINKING ********************************* 37 # ************************** END OF LINKING *********************************
@@ -38,8 +44,14 @@ get_OMNI_1H.o: get_OMNI_1H.cpp @@ -38,8 +44,14 @@ get_OMNI_1H.o: get_OMNI_1H.cpp
38 ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS} 44 ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS}
39 45
40 get_ACE_RT.o: get_ACE_RT.cpp 46 get_ACE_RT.o: get_ACE_RT.cpp
41 - ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS}  
42 - 47 + ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS}
  48 +
  49 +get_STEREO.o: get_STEREO.cpp
  50 + ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS}
  51 +
  52 +get_DSCOVR.o: get_DSCOVR.cpp
  53 + ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS}
  54 +
43 get_R_LON_HCI.o: get_R_LON_HCI.cpp 55 get_R_LON_HCI.o: get_R_LON_HCI.cpp
44 ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS} 56 ${CXX} -c $< -o $@ ${INCLUDE} ${CXXFLAGS}
45 # ************************* END OF COMPILING ******************************** 57 # ************************* END OF COMPILING ********************************
Sources/get_ACE_RT.cpp
@@ -15,12 +15,12 @@ @@ -15,12 +15,12 @@
15 /////////////// 15 ///////////////
16 using namespace std; 16 using namespace std;
17 17
18 -int main(int argc, char const *argv[]) 18 +int main (int argc, char const *argv[]) throw(std::string)
19 { 19 {
20 if (argc != 5) 20 if (argc != 5)
21 { 21 {
22 - cout << "[ERROR] Usage : ./get_ACE_RT (plasma filename) (mag filename) (ddStart) (ddInterval)" << endl;  
23 - exit(EXIT_FAILURE); 22 + cout << "[ERROR] Usage : ./get_ACE_RT (plasma filename) (mag filename) (ddStart) (ddInterval)" << endl;
  23 + exit(EXIT_FAILURE);
24 } 24 }
25 25
26 string dataFilename = argv[1]; 26 string dataFilename = argv[1];
@@ -50,14 +50,16 @@ int main(int argc, char const *argv[]) @@ -50,14 +50,16 @@ int main(int argc, char const *argv[])
50 if (error < 0) 50 if (error < 0)
51 { 51 {
52 std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime SW -> err value : " + error; 52 std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime SW -> err value : " + error;
53 - throw std::string(ddSetTimeErr); 53 + printf(" bad time pointer plasma %d %d\n", id_sw, error);
  54 + throw ddSetTimeErr;
54 } 55 }
55 error = DD_SetTime(id_mag, st); 56 error = DD_SetTime(id_mag, st);
56 57
57 if (error < 0) 58 if (error < 0)
58 { 59 {
59 std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime Mag -> err value : " + error; 60 std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime Mag -> err value : " + error;
60 - throw std::string(ddSetTimeErr); 61 + printf(" bad time pointer mag %d\n", error);
  62 + throw ddSetTimeErr;
61 } 63 }
62 // GET DATA 64 // GET DATA
63 char *params[4]; 65 char *params[4];
@@ -76,7 +78,7 @@ int main(int argc, char const *argv[]) @@ -76,7 +78,7 @@ int main(int argc, char const *argv[])
76 DD_data_t *data; 78 DD_data_t *data;
77 79
78 int status = 0; 80 int status = 0;
79 - 81 +
80 plasmaFile << "Time,Density,Temperature,V" << endl; 82 plasmaFile << "Time,Density,Temperature,V" << endl;
81 83
82 do { 84 do {
Sources/get_DSCOVR.cpp 0 โ†’ 100644
@@ -0,0 +1,155 @@ @@ -0,0 +1,155 @@
  1 +/////////////////
  2 +// CPP HEADERS //
  3 +/////////////////
  4 +#include <iostream>
  5 +#include <fstream>
  6 +#include <stdlib.h>
  7 +
  8 +////////////
  9 +/// DDLIB //
  10 +////////////
  11 +#include "DD.h"
  12 +
  13 +#define NAN (0.0/0.0)
  14 +////////////////
  15 +// NAMESPACES //
  16 +///////////////
  17 +using namespace std;
  18 +
  19 +int main (int argc, char const *argv[]) throw(std::string)
  20 +{
  21 + if (argc != 5)
  22 + {
  23 + cout << "[ERROR] Usage : ./get_DSCOVR (plasma filename) (mag filename) (ddStart) (ddInterval)" << endl;
  24 + exit(EXIT_FAILURE);
  25 + }
  26 +
  27 + string dataFilename = argv[1];
  28 + string dataFilename1 = argv[2];
  29 + string ddStart = argv[3];
  30 + string ddInterval = argv[4];
  31 + string plasmaVi = "dsc_fc_1m";
  32 + string timeParameter = "Time";
  33 + string DensParameter = "proton_density";
  34 + string TempParameter = "proton_temperature";
  35 + string VNormParameter = "vp_gse";
  36 + string magVi = "dsc_mag_1m";
  37 + string magParameter = "b_gse";
  38 +
  39 + ofstream plasmaFile(dataFilename.c_str(), ios::out);
  40 + ofstream magFile(dataFilename1.c_str(), ios::out);
  41 +
  42 + int id_sw = DD_SetVariable( const_cast<char*>( plasmaVi.c_str() ) );
  43 + int id_mag = DD_SetVariable( const_cast<char*>( magVi.c_str() ) );
  44 +
  45 + char *st = const_cast<char*>( ddStart.c_str() );
  46 +
  47 + int error = DD_SetTime(id_sw, st);
  48 +
  49 + if (error < 0)
  50 + {
  51 + std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime SW -> err value : " + error;
  52 + printf(" bad time pointer plasma %d %d\n", id_sw, error);
  53 + throw ddSetTimeErr;
  54 + }
  55 + error = DD_SetTime(id_mag, st);
  56 +
  57 + if (error < 0)
  58 + {
  59 + std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime Mag -> err value : " + error;
  60 + printf(" bad time pointer mag %d\n", error);
  61 + throw ddSetTimeErr;
  62 + }
  63 + // GET DATA
  64 + char *params[4];
  65 +
  66 + params[0] = const_cast<char*>( timeParameter.c_str() );
  67 + params[1] = const_cast<char*>( DensParameter.c_str() );
  68 + params[2] = const_cast<char*>( TempParameter.c_str() );
  69 + params[3] = const_cast<char*>( VNormParameter.c_str() );
  70 +
  71 + char *params_mag[2];
  72 + params_mag[0] = const_cast<char*>( timeParameter.c_str() );
  73 + params_mag[1] = const_cast<char*>( magParameter.c_str() );
  74 +
  75 + char *timeIntervall = const_cast<char*>( ddInterval.c_str() );
  76 +
  77 + DD_data_t *data;
  78 +
  79 + int status = 0;
  80 +
  81 + plasmaFile << "Time,Density,Temperature,Vx,Vy,Vz" << endl;
  82 +
  83 + do {
  84 +
  85 + status = DD_GetMultiData(id_sw, 4, static_cast<char**>(params), timeIntervall, &data, 1);
  86 +
  87 + if (status < 0)
  88 + {
  89 + std::string ddGetDataErr = "[ERROR] Failed to get SW data -> status : " + status;
  90 + throw std::string(ddGetDataErr);
  91 + }
  92 +
  93 + for (int j = 0; j < data->VarNumber; ++j)
  94 + {
  95 + float density = *(static_cast<float*>(data[1].Variables[j]));
  96 + if (density < -1000.) density = NAN;
  97 + float temperature = *(static_cast<float*>(data[2].Variables[j]));
  98 + if (temperature < -1000.) temperature = NAN;
  99 + float vx = static_cast<float*>(data[3].Variables[j])[0];
  100 + float vy = static_cast<float*>(data[3].Variables[j])[1];
  101 + float vz = static_cast<float*>(data[3].Variables[j])[2];
  102 + if (vx < -9000.) {
  103 + vx = NAN; vy = NAN; vz = NAN;
  104 + }
  105 + plasmaFile << static_cast<char*>(data[0].Variables[j]) << ","
  106 + << density << ","
  107 + << temperature << ","
  108 + << vx << ","
  109 + << vy << ","
  110 + << vz << endl;
  111 + }
  112 +
  113 + } while (status == MOREDATA);
  114 +
  115 + DD_Close(id_sw);
  116 +
  117 + status = 0;
  118 +
  119 + magFile << "Time,Bx,By,Bz" << endl;
  120 +
  121 + do {
  122 +
  123 + status = DD_GetMultiData(id_mag, 2, static_cast<char**>(params_mag), timeIntervall, &data, 1);
  124 +
  125 + if (status < 0)
  126 + {
  127 + std::string ddGetDataErr = "[ERROR] Failed to get MAG data -> status : " + status;
  128 + throw std::string(ddGetDataErr);
  129 + }
  130 +
  131 + for (int j = 0; j < data->VarNumber; ++j)
  132 + {
  133 + float bx = static_cast<float*>(data[1].Variables[j])[0];
  134 + float by = static_cast<float*>(data[1].Variables[j])[1];
  135 + float bz = static_cast<float*>(data[1].Variables[j])[2];
  136 + if (bx < -9000.) {
  137 + bx = NAN; by = NAN; bz = NAN;
  138 + }
  139 + magFile << static_cast<char*>(data[0].Variables[j]) << ","
  140 + << bx << ","
  141 + << by << ","
  142 + << bz << endl;
  143 + }
  144 +
  145 + } while (status == MOREDATA);
  146 +
  147 +
  148 + DD_Close(id_mag);
  149 +
  150 + plasmaFile.close();
  151 +
  152 + magFile.close();
  153 +
  154 + return 0;
  155 +}
0 \ No newline at end of file 156 \ No newline at end of file
Sources/get_STEREO.cpp 0 โ†’ 100644
@@ -0,0 +1,145 @@ @@ -0,0 +1,145 @@
  1 +/////////////////
  2 +// CPP HEADERS //
  3 +/////////////////
  4 +#include <iostream>
  5 +#include <fstream>
  6 +#include <stdlib.h>
  7 +#include <string.h>
  8 +
  9 +////////////
  10 +/// DDLIB //
  11 +////////////
  12 +#include "DD.h"
  13 +
  14 +////////////////
  15 +// NAMESPACES //
  16 +///////////////
  17 +using namespace std;
  18 +
  19 +int main (int argc, char const *argv[]) throw(std::string)
  20 +{
  21 + if (argc != 6)
  22 + {
  23 + cout << "[ERROR] Usage : ./get_STEREO [a,b] (plasma filename) (mag filename) (ddStart) (ddInterval)" << endl;
  24 + exit(EXIT_FAILURE);
  25 + }
  26 +
  27 + string stereo = argv[1];
  28 + string dataFilename = argv[2];
  29 + string dataFilename1 = argv[3];
  30 + string ddStart = argv[4];
  31 + string ddInterval = argv[5];
  32 +
  33 + string plasmaVi = "sta_l2_pla";
  34 + string timeParameter = "Time";
  35 + string DensParameter = "Np";
  36 + string TempParameter = "Vth";
  37 + string VNormParameter = "Vrtn";
  38 + string magVi = "sta_mag_mag";
  39 + string magParameter = "B";
  40 +
  41 + ofstream plasmaFile(dataFilename.c_str(), ios::out);
  42 + ofstream magFile(dataFilename1.c_str(), ios::out);
  43 +
  44 + memcpy(&(plasmaVi[2]),argv[1],1);
  45 + memcpy(&(magVi[2]),argv[1],1);
  46 +
  47 + printf("PlasmaVi %s\n", plasmaVi.c_str());
  48 + int id_sw = DD_SetVariable( const_cast<char*>( plasmaVi.c_str() ) );
  49 + int id_mag = DD_SetVariable( const_cast<char*>( magVi.c_str() ) );
  50 +
  51 + char *st = const_cast<char*>( ddStart.c_str() );
  52 +
  53 + int error = DD_SetTime(id_sw, st);
  54 +
  55 + if (error < 0)
  56 + {
  57 + std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime SW -> err value : " + error;
  58 + printf(" bad time pointer plasma %d %d\n", id_sw, error);
  59 + throw ddSetTimeErr;
  60 + }
  61 + error = DD_SetTime(id_mag, st);
  62 +
  63 + if (error < 0)
  64 + {
  65 + std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime Mag -> err value : " + error;
  66 + printf(" bad time pointer mag %d\n", error);
  67 + throw ddSetTimeErr;
  68 + }
  69 + // GET DATA
  70 + char *params[4];
  71 +
  72 + params[0] = const_cast<char*>( timeParameter.c_str() );
  73 + params[1] = const_cast<char*>( DensParameter.c_str() );
  74 + params[2] = const_cast<char*>( TempParameter.c_str() );
  75 + params[3] = const_cast<char*>( VNormParameter.c_str() );
  76 +
  77 + char *params_mag[2];
  78 + params_mag[0] = const_cast<char*>( timeParameter.c_str() );
  79 + params_mag[1] = const_cast<char*>( magParameter.c_str() );
  80 +
  81 + char *timeIntervall = const_cast<char*>( ddInterval.c_str() );
  82 +
  83 + DD_data_t *data;
  84 +
  85 + int status = 0;
  86 +
  87 + plasmaFile << "Time,Density,Vth,Vr,Vt,Vn" << endl;
  88 +
  89 + do {
  90 +
  91 + status = DD_GetMultiData(id_sw, 4, static_cast<char**>(params), timeIntervall, &data, 1);
  92 +
  93 + if (status < 0)
  94 + {
  95 + std::string ddGetDataErr = "[ERROR] Failed to get SW data -> status : " + status;
  96 + throw std::string(ddGetDataErr);
  97 + }
  98 +
  99 + for (int j = 0; j < data->VarNumber; ++j)
  100 + {
  101 + plasmaFile << static_cast<char*>(data[0].Variables[j]) << ","
  102 + << *(static_cast<float*>(data[1].Variables[j])) << ","
  103 + << *(static_cast<float*>(data[2].Variables[j])) << ","
  104 + << static_cast<float*>(data[3].Variables[j])[0] << ","
  105 + << static_cast<float*>(data[3].Variables[j])[1] << ","
  106 + << static_cast<float*>(data[3].Variables[j])[2] << endl;
  107 + }
  108 +
  109 + } while (status == MOREDATA);
  110 +
  111 + DD_Close(id_sw);
  112 +
  113 + status = 0;
  114 +
  115 + magFile << "Time,Bx,By,Bz" << endl;
  116 +
  117 + do {
  118 +
  119 + status = DD_GetMultiData(id_mag, 2, static_cast<char**>(params_mag), timeIntervall, &data, 1);
  120 +
  121 + if (status < 0)
  122 + {
  123 + std::string ddGetDataErr = "[ERROR] Failed to get MAG data -> status : " + status;
  124 + throw std::string(ddGetDataErr);
  125 + }
  126 +
  127 + for (int j = 0; j < data->VarNumber; ++j)
  128 + {
  129 + magFile << static_cast<char*>(data[0].Variables[j]) << ","
  130 + << static_cast<float*>(data[1].Variables[j])[0] << ","
  131 + << static_cast<float*>(data[1].Variables[j])[1] << ","
  132 + << static_cast<float*>(data[1].Variables[j])[2] << endl;
  133 + }
  134 +
  135 + } while (status == MOREDATA);
  136 +
  137 +
  138 + DD_Close(id_mag);
  139 +
  140 + plasmaFile.close();
  141 +
  142 + magFile.close();
  143 +
  144 + return 0;
  145 +}
0 \ No newline at end of file 146 \ No newline at end of file