@@ -1,548 +1,549 | |||||
1 | # Needed for the FilesStuff class |
|
1 | # Needed for the FilesStuff class | |
2 | import os |
|
2 | import os | |
3 | import numpy as np |
|
3 | import numpy as np | |
4 | # Needed for the TCPComm class |
|
4 | # Needed for the TCPComm class | |
5 | import socket |
|
5 | import socket | |
6 |
|
6 | |||
7 | class TCPComm: |
|
7 | class TCPComm: | |
8 |
|
8 | |||
9 | __HEADER = "JRO" |
|
9 | __HEADER = "JRO" | |
10 | __TYPE = "ABS" |
|
10 | __TYPE = "ABS" | |
11 |
|
11 | |||
12 | def __init__(self, ipSource, iDSource, ipDestino, iDDestino, portDestino, asServer=False): |
|
12 | def __init__(self, ipSource, iDSource, ipDestino, iDDestino, portDestino, asServer=False): | |
13 |
|
13 | |||
14 | self.ipSource = ipSource |
|
14 | self.ipSource = ipSource | |
15 | self.iDSource = iDSource |
|
15 | self.iDSource = iDSource | |
16 | self.ipDestino = ipDestino |
|
16 | self.ipDestino = ipDestino | |
17 | self.iDDestino = iDDestino |
|
17 | self.iDDestino = iDDestino | |
18 | self.portDestino = portDestino |
|
18 | self.portDestino = portDestino | |
19 | self.addr = (ipDestino,portDestino) |
|
19 | self.addr = (ipDestino,portDestino) | |
20 |
|
20 | |||
21 | self.sc = "none" |
|
21 | self.sc = "none" | |
22 | self.answer = "none" #test |
|
22 | self.answer = "none" #test | |
23 | self.asServer = False |
|
23 | self.asServer = False | |
24 | self.len = "000000" |
|
24 | self.len = "000000" | |
25 | self.crc = "0" |
|
25 | self.crc = "0" | |
26 |
|
26 | |||
27 | self.openSocket(asServer) |
|
27 | self.openSocket(asServer) | |
28 |
|
28 | |||
29 | def openSocket(self, asServer): |
|
29 | def openSocket(self, asServer): | |
30 |
|
30 | |||
31 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) |
|
31 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |
32 | # self.socket_c = socket.socket() |
|
32 | # self.socket_c = socket.socket() | |
33 | # self.socket_c.connect((self.ipDestino, self.portDestino)) |
|
33 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |
34 |
|
34 | |||
35 | if asServer: |
|
35 | if asServer: | |
36 | self.socket_c = socket.socket() |
|
36 | self.socket_c = socket.socket() | |
37 | # self.configAsServer() |
|
37 | # self.configAsServer() | |
38 | self.socket_c.bind(self.addr) |
|
38 | self.socket_c.bind(self.addr) | |
39 | self.asServer = True |
|
39 | self.asServer = True | |
40 | else: |
|
40 | else: | |
41 | # self.configAsClient() |
|
41 | # self.configAsClient() | |
42 | self.asServer = False #Socket is opened at the sendData function |
|
42 | self.asServer = False #Socket is opened at the sendData function | |
43 |
|
43 | |||
44 | # def configAsClient(self): |
|
44 | # def configAsClient(self): | |
45 | #Buscar broadcast TCP |
|
45 | #Buscar broadcast TCP | |
46 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) |
|
46 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
47 | # self.socket_c.connect(self.addr) |
|
47 | # self.socket_c.connect(self.addr) | |
48 | # pass |
|
48 | # pass | |
49 |
|
49 | |||
50 | # def configAsServer(self): |
|
50 | # def configAsServer(self): | |
51 | # |
|
51 | # | |
52 | # self.socket_c.bind(self.addr) |
|
52 | # self.socket_c.bind(self.addr) | |
53 |
|
53 | |||
54 | def waitData(self): |
|
54 | def waitData(self): | |
55 | if self.asServer == True: |
|
55 | if self.asServer == True: | |
56 | trama_rx, l = self.waitAsServer() |
|
56 | trama_rx, l = self.waitAsServer() | |
57 | else: |
|
57 | else: | |
58 | trama_rx, l = self.waitAsClient() |
|
58 | trama_rx, l = self.waitAsClient() | |
59 |
|
59 | |||
60 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx, l) |
|
60 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx, l) | |
61 |
|
61 | |||
62 | return ipSource, ipDestino, cmd, data |
|
62 | return ipSource, ipDestino, cmd, data | |
63 |
|
63 | |||
64 | def waitAsClient2(self, nbytes = 1024): |
|
64 | def waitAsClient2(self, nbytes = 1024): | |
65 | print "\nWaiting the server." |
|
65 | print "\nWaiting the server." | |
66 | # Short data through ethernet |
|
66 | # Short data through ethernet | |
67 | trama_rx = self.socket_c.recv(nbytes) |
|
67 | trama_rx = self.socket_c.recv(nbytes) | |
68 | print "\nThis socket has received this data: " + str(trama_rx) |
|
68 | print "\nThis socket has received this data: " + str(trama_rx) | |
69 |
|
69 | |||
70 | return trama_rx |
|
70 | return trama_rx | |
71 |
|
71 | |||
72 | def waitAsServer2(self, nbytes = 1024): |
|
72 | def waitAsServer2(self, nbytes = 1024): | |
73 | print "\nWaiting some client." |
|
73 | print "\nWaiting some client." | |
74 | self.socket_c.listen(1) |
|
74 | self.socket_c.listen(1) | |
75 | sc, addr = self.socket_c.accept() |
|
75 | sc, addr = self.socket_c.accept() | |
76 | self.sc = sc |
|
76 | self.sc = sc | |
77 | self.answer = addr |
|
77 | self.answer = addr | |
78 | # Big data through ethernet |
|
78 | # Big data through ethernet | |
79 | trama_rx = "" |
|
79 | trama_rx = "" | |
80 | while True: |
|
80 | while True: | |
81 | tmp = self.sc.recv(nbytes) |
|
81 | tmp = self.sc.recv(nbytes) | |
82 | trama_rx = trama_rx + tmp |
|
82 | trama_rx = trama_rx + tmp | |
83 | if trama_rx[-4:] == "quit": |
|
83 | if trama_rx[-4:] == "quit": | |
84 | break |
|
84 | break | |
85 |
|
85 | |||
86 | print "\nThis socket has received some data from: " + str(self.answer) |
|
86 | print "\nThis socket has received some data from: " + str(self.answer) | |
87 |
|
87 | |||
88 | return trama_rx |
|
88 | return trama_rx | |
89 |
|
89 | |||
90 | def waitAsServer(self, nbytes = 1024): |
|
90 | def waitAsServer(self, nbytes = 1024): | |
91 | print "\nWaiting some client." |
|
91 | print "\nWaiting some client." | |
92 | self.socket_c.listen(1) |
|
92 | self.socket_c.listen(1) | |
93 | sc, addr = self.socket_c.accept() |
|
93 | sc, addr = self.socket_c.accept() | |
94 | self.sc = sc |
|
94 | self.sc = sc | |
95 | self.answer = addr |
|
95 | self.answer = addr | |
96 | # Big data through ethernet |
|
96 | # Big data through ethernet | |
97 | cnt = 0; |
|
97 | cnt = 0; | |
98 | first = 0; |
|
98 | first = 0; | |
99 | trama_rx = "" |
|
99 | trama_rx = "" | |
100 | while True: |
|
100 | while True: | |
101 | tmp = self.sc.recv(nbytes) |
|
101 | tmp = self.sc.recv(nbytes) | |
102 | trama_rx = trama_rx + tmp |
|
102 | trama_rx = trama_rx + tmp | |
103 | cnt = len(trama_rx) |
|
103 | cnt = len(trama_rx) | |
104 | if first == 0: |
|
104 | if first == 0: | |
105 | first = 1 |
|
105 | first = 1 | |
106 | lng = int(trama_rx[20:26]) |
|
106 | lng = int(trama_rx[20:26]) | |
107 | frm_lng= lng + 31 # 31 bytes are fixed and added to the data size to get the frame size |
|
107 | frm_lng= lng + 31 # 31 bytes are fixed and added to the data size to get the frame size | |
108 | if cnt == frm_lng: |
|
108 | if cnt == frm_lng: | |
109 | break |
|
109 | break | |
110 |
|
110 | |||
111 | print "\nThis socket has received some data from: " + str(self.answer) |
|
111 | print "\nThis socket has received some data from: " + str(self.answer) | |
|
112 | print trama_rx | |||
112 |
|
113 | |||
113 | return trama_rx, lng |
|
114 | return trama_rx, lng | |
114 |
|
115 | |||
115 | def waitAsClient(self, nbytes = 2048): |
|
116 | def waitAsClient(self, nbytes = 2048): | |
116 | print "\nWaiting the server." |
|
117 | print "\nWaiting the server." | |
117 | # Short data through ethernet |
|
118 | # Short data through ethernet | |
118 | try: |
|
119 | try: | |
119 | trama_rx = self.socket_c.recv(nbytes) |
|
120 | trama_rx = self.socket_c.recv(nbytes) | |
120 | lng = int(trama_rx[20:26]) |
|
121 | lng = int(trama_rx[20:26]) | |
121 | except: |
|
122 | except: | |
122 | print "Waiting error" |
|
123 | print "Waiting error" | |
123 | trama_rx = "Error" |
|
124 | trama_rx = "Error" | |
124 | lng = 0 |
|
125 | lng = 0 | |
125 | else: |
|
126 | else: | |
126 | print "\nThis socket has received this data: " + str(trama_rx) |
|
127 | print "\nThis socket has received this data: " + str(trama_rx) | |
127 |
|
128 | |||
128 | return trama_rx, lng |
|
129 | return trama_rx, lng | |
129 |
|
130 | |||
130 | def sendData2(self, cmd, data, ipDestino): |
|
131 | def sendData2(self, cmd, data, ipDestino): | |
131 |
|
132 | |||
132 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ |
|
133 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ | |
133 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" |
|
134 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" | |
134 |
|
135 | |||
135 | if self.asServer == True: |
|
136 | if self.asServer == True: | |
136 | self.SendAsServer(trama_tx) |
|
137 | self.SendAsServer(trama_tx) | |
137 | else: |
|
138 | else: | |
138 | self.SendAsClient(ipDestino, trama_tx) |
|
139 | self.SendAsClient(ipDestino, trama_tx) | |
139 |
|
140 | |||
140 | def sendData(self, cmd, data, ipDestino): |
|
141 | def sendData(self, cmd, data, ipDestino): | |
141 |
|
142 | |||
142 | trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ |
|
143 | trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ | |
143 | self.iDDestino + self.len + str(cmd) + str(data) + self.crc |
|
144 | self.iDDestino + self.len + str(cmd) + str(data) + self.crc | |
144 |
|
145 | |||
145 | self.len = self.int2str(len(data)) |
|
146 | self.len = self.int2str(len(data)) | |
146 |
|
147 | |||
147 | trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ |
|
148 | trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ | |
148 | self.iDDestino + self.len + str(cmd) + str(data) + self.crc |
|
149 | self.iDDestino + self.len + str(cmd) + str(data) + self.crc | |
149 |
|
150 | |||
150 | if self.asServer == True: |
|
151 | if self.asServer == True: | |
151 | self.SendAsServer(trama_tx) |
|
152 | self.SendAsServer(trama_tx) | |
152 | else: |
|
153 | else: | |
153 | self.SendAsClient(ipDestino, trama_tx) |
|
154 | self.SendAsClient(ipDestino, trama_tx) | |
154 |
|
155 | |||
155 | def SendAsServer(self, trama_tx): |
|
156 | def SendAsServer(self, trama_tx): | |
156 |
|
157 | |||
157 | self.sc.send(trama_tx) |
|
158 | self.sc.send(trama_tx) | |
158 | print "Sending message:[" + trama_tx + "] to: " + str(self.answer) |
|
159 | print "Sending message:[" + trama_tx + "] to: " + str(self.answer) | |
159 |
|
160 | |||
160 |
|
161 | |||
161 | def SendAsClient(self, ipDestino, trama_tx): |
|
162 | def SendAsClient(self, ipDestino, trama_tx): | |
162 |
|
163 | |||
163 | try: |
|
164 | try: | |
164 | self.socket_c.connect((ipDestino, self.portDestino)) |
|
165 | self.socket_c.connect((ipDestino, self.portDestino)) | |
165 | except: |
|
166 | except: | |
166 | print "Connection error with:" + ipDestino |
|
167 | print "Connection error with:" + ipDestino | |
167 | else: |
|
168 | else: | |
168 | self.socket_c.send(trama_tx) |
|
169 | self.socket_c.send(trama_tx) | |
169 | print "Sending message:[" + trama_tx + "] to: " + ipDestino |
|
170 | print "Sending message:[" + trama_tx + "] to: " + ipDestino | |
170 |
|
171 | |||
171 | def __getTrama2(self, trama): |
|
172 | def __getTrama2(self, trama): | |
172 |
|
173 | |||
173 | FrameList = trama.split(':') |
|
174 | FrameList = trama.split(':') | |
174 |
|
175 | |||
175 | header = FrameList[0] |
|
176 | header = FrameList[0] | |
176 | TypeOfInstrument = FrameList[1] |
|
177 | TypeOfInstrument = FrameList[1] | |
177 | ipSource = FrameList[2] |
|
178 | ipSource = FrameList[2] | |
178 | ipDestino = FrameList[3] |
|
179 | ipDestino = FrameList[3] | |
179 | len = FrameList[4] |
|
180 | len = FrameList[4] | |
180 | cmd = FrameList[5] |
|
181 | cmd = FrameList[5] | |
181 | data = FrameList[6] |
|
182 | data = FrameList[6] | |
182 | crc = FrameList[7] |
|
183 | crc = FrameList[7] | |
183 | trash = FrameList[8] |
|
184 | trash = FrameList[8] | |
184 |
|
185 | |||
185 | return ipSource, ipDestino, cmd, data |
|
186 | return ipSource, ipDestino, cmd, data | |
186 |
|
187 | |||
187 | def __getTrama(self, trama, l): |
|
188 | def __getTrama(self, trama, l): | |
188 |
|
189 | |||
189 | header = trama[0:3] |
|
190 | header = trama[0:3] | |
190 | TypeOfInstrument = trama[3:6] |
|
191 | TypeOfInstrument = trama[3:6] | |
191 | ipSource = trama[6:13] |
|
192 | ipSource = trama[6:13] | |
192 | ipDestino = trama[13:20] |
|
193 | ipDestino = trama[13:20] | |
193 | len = trama[20:26] |
|
194 | len = trama[20:26] | |
194 | cmd = trama[26:30] |
|
195 | cmd = trama[26:30] | |
195 | data = trama[30:30+int(l)] |
|
196 | data = trama[30:30+int(l)] | |
196 | crc = trama[30+ int(l):] |
|
197 | crc = trama[30+ int(l):] | |
197 |
|
198 | |||
198 | return ipSource, ipDestino, cmd, data |
|
199 | return ipSource, ipDestino, cmd, data | |
199 |
|
200 | |||
200 | def close_socket(self): |
|
201 | def close_socket(self): | |
201 | self.socket_c.close() |
|
202 | self.socket_c.close() | |
202 |
|
203 | |||
203 | def open_socket(self): |
|
204 | def open_socket(self): | |
204 | self.socket_c = socket.socket() |
|
205 | self.socket_c = socket.socket() | |
205 |
|
206 | |||
206 | def int2str(self, n): |
|
207 | def int2str(self, n): | |
207 |
|
208 | |||
208 | str_n = str(n) |
|
209 | str_n = str(n) | |
209 | l_n = len(str_n) |
|
210 | l_n = len(str_n) | |
210 | if l_n == 1: |
|
211 | if l_n == 1: | |
211 | str_n = "00000" + str_n |
|
212 | str_n = "00000" + str_n | |
212 | elif l_n == 2: |
|
213 | elif l_n == 2: | |
213 | str_n = "0000" + str_n |
|
214 | str_n = "0000" + str_n | |
214 | elif l_n == 3: |
|
215 | elif l_n == 3: | |
215 | str_n = "000" + str_n |
|
216 | str_n = "000" + str_n | |
216 | elif l_n == 4: |
|
217 | elif l_n == 4: | |
217 | str_n = "00" + str_n |
|
218 | str_n = "00" + str_n | |
218 | elif l_n == 5: |
|
219 | elif l_n == 5: | |
219 | str_n = "0" + str_n |
|
220 | str_n = "0" + str_n | |
220 | return str_n |
|
221 | return str_n | |
221 |
|
222 | |||
222 | class FilesStuff(): |
|
223 | class FilesStuff(): | |
223 |
|
224 | |||
224 | def lst2string(self, lst): |
|
225 | def lst2string(self, lst): | |
225 | string='' |
|
226 | string='' | |
226 | for i in lst: |
|
227 | for i in lst: | |
227 | string=string+i |
|
228 | string=string+i | |
228 | return string |
|
229 | return string | |
229 |
|
230 | |||
230 | def string2lst(self, string): |
|
231 | def string2lst(self, string): | |
231 | lst = [] |
|
232 | lst = [] | |
232 | for i in string: |
|
233 | for i in string: | |
233 | lst.append(i) |
|
234 | lst.append(i) | |
234 | return lst |
|
235 | return lst | |
235 |
|
236 | |||
236 |
|
237 | |||
237 | def file1(self, filename, type): |
|
238 | def file1(self, filename, type): | |
238 | lst = self.string2lst(filename) |
|
239 | lst = self.string2lst(filename) | |
239 | fin = -1 |
|
240 | fin = -1 | |
240 | t = len(lst) |
|
241 | t = len(lst) | |
241 | for i in np.arange(-1,-t,-1): |
|
242 | for i in np.arange(-1,-t,-1): | |
242 | if lst[i]=='/': |
|
243 | if lst[i]=='/': | |
243 | fin=i |
|
244 | fin=i | |
244 | break |
|
245 | break | |
245 | if type == '1': |
|
246 | if type == '1': | |
246 | nombre2 = lst[fin+1:] |
|
247 | nombre2 = lst[fin+1:] | |
247 | nombre2[-1]='s' |
|
248 | nombre2[-1]='s' | |
248 | nombre2 = self.lst2string(nombre2) |
|
249 | nombre2 = self.lst2string(nombre2) | |
249 | return nombre2 |
|
250 | return nombre2 | |
250 | if type == '2': |
|
251 | if type == '2': | |
251 | nombre2 = lst[fin+1:] |
|
252 | nombre2 = lst[fin+1:] | |
252 | nombre2[-1]='1' |
|
253 | nombre2[-1]='1' | |
253 | nombre2 = self.lst2string(nombre2) |
|
254 | nombre2 = self.lst2string(nombre2) | |
254 | return nombre2 |
|
255 | return nombre2 | |
255 |
|
256 | |||
256 |
|
257 | |||
257 | def EliminaSaltoDeLinea(self,cadena): |
|
258 | def EliminaSaltoDeLinea(self,cadena): | |
258 | i = 0 |
|
259 | i = 0 | |
259 | for elemento in cadena: |
|
260 | for elemento in cadena: | |
260 | if elemento =='\n' or elemento =='\r': |
|
261 | if elemento =='\n' or elemento =='\r': | |
261 | pass |
|
262 | pass | |
262 | else: |
|
263 | else: | |
263 | i=i+1 |
|
264 | i=i+1 | |
264 | return cadena [:i] |
|
265 | return cadena [:i] | |
265 |
|
266 | |||
266 | def NumeroDeExperimentos(self, path): |
|
267 | def NumeroDeExperimentos(self, path): | |
267 | fichero1=open(path,'r') |
|
268 | fichero1=open(path,'r') | |
268 | cont=0 |
|
269 | cont=0 | |
269 | for cadena in fichero1: |
|
270 | for cadena in fichero1: | |
270 | cont=cont+1 |
|
271 | cont=cont+1 | |
271 | if cont==3: |
|
272 | if cont==3: | |
272 | nexp='' |
|
273 | nexp='' | |
273 | pos=0 |
|
274 | pos=0 | |
274 | for elemento in cadena: |
|
275 | for elemento in cadena: | |
275 | pos=pos+1 |
|
276 | pos=pos+1 | |
276 | if elemento=='=': |
|
277 | if elemento=='=': | |
277 | nexp=int(cadena[pos:]) |
|
278 | nexp=int(cadena[pos:]) | |
278 | return nexp |
|
279 | return nexp | |
279 | fichero1.close() |
|
280 | fichero1.close() | |
280 |
|
281 | |||
281 | def Paridad(self, numero): |
|
282 | def Paridad(self, numero): | |
282 | if numero%2==0: return 'par' |
|
283 | if numero%2==0: return 'par' | |
283 | elif numero%2==1: return 'impar' |
|
284 | elif numero%2==1: return 'impar' | |
284 |
|
285 | |||
285 | def EvaluaCadena(self,cadena): |
|
286 | def EvaluaCadena(self,cadena): | |
286 | if len(cadena)>35: |
|
287 | if len(cadena)>35: | |
287 | if cadena[-1]=='$': |
|
288 | if cadena[-1]=='$': | |
288 | return cadena[-35:-2] |
|
289 | return cadena[-35:-2] | |
289 | elif cadena[-1]==']': |
|
290 | elif cadena[-1]==']': | |
290 | return cadena[-34:-1] |
|
291 | return cadena[-34:-1] | |
291 | else: |
|
292 | else: | |
292 | return None |
|
293 | return None | |
293 |
|
294 | |||
294 | def GuardaEnLista(self,path): |
|
295 | def GuardaEnLista(self,path): | |
295 | fichero=open(path,'r') |
|
296 | fichero=open(path,'r') | |
296 | lista=[] |
|
297 | lista=[] | |
297 | for cadena in fichero: |
|
298 | for cadena in fichero: | |
298 | cadena = self.EliminaSaltoDeLinea(cadena) |
|
299 | cadena = self.EliminaSaltoDeLinea(cadena) | |
299 | cadena = self.EvaluaCadena(cadena) |
|
300 | cadena = self.EvaluaCadena(cadena) | |
300 | if cadena != None: |
|
301 | if cadena != None: | |
301 | lista.append(cadena) |
|
302 | lista.append(cadena) | |
302 | fichero.close() |
|
303 | fichero.close() | |
303 | return lista |
|
304 | return lista | |
304 |
|
305 | |||
305 | def CreaFicherosPrevios(self, path, archivo): |
|
306 | def CreaFicherosPrevios(self, path, archivo): | |
306 | vector = self.GuardaEnLista(archivo) |
|
307 | vector = self.GuardaEnLista(archivo) | |
307 | for i in range(1,self.NumeroDeExperimentos(archivo)+1): |
|
308 | for i in range(1,self.NumeroDeExperimentos(archivo)+1): | |
308 | fichero =open(path + str(i)+ '.txt','w') |
|
309 | fichero =open(path + str(i)+ '.txt','w') | |
309 | for j in range(0,16): |
|
310 | for j in range(0,16): | |
310 | fichero.write(vector[j+16*(i-1)]+'\n') |
|
311 | fichero.write(vector[j+16*(i-1)]+'\n') | |
311 | fichero.close() |
|
312 | fichero.close() | |
312 |
|
313 | |||
313 | def CapturaValoresEnArchivo(self, path, polarizacion='up'): |
|
314 | def CapturaValoresEnArchivo(self, path, polarizacion='up'): | |
314 | # |
|
315 | # | |
315 | # N01 N02 N03 N04 E01 E02 E03 E04 M01 M02 M03 M04 M05 M06 M07 M08 |
|
316 | # N01 N02 N03 N04 E01 E02 E03 E04 M01 M02 M03 M04 M05 M06 M07 M08 | |
316 | # N05 N06 N07 N08 E05 E06 E07 E08 M09 M10 M11 M12 M13 M14 M15 M16 |
|
317 | # N05 N06 N07 N08 E05 E06 E07 E08 M09 M10 M11 M12 M13 M14 M15 M16 | |
317 | # N09 N10 N11 N12 E09 E10 E11 E12 M17 M18 M19 M20 M21 M22 M23 M24 |
|
318 | # N09 N10 N11 N12 E09 E10 E11 E12 M17 M18 M19 M20 M21 M22 M23 M24 | |
318 | # N13 N14 N15 N16 E13 E14 E15 E16 M25 M26 M27 M28 M29 M30 M31 M32 |
|
319 | # N13 N14 N15 N16 E13 E14 E15 E16 M25 M26 M27 M28 M29 M30 M31 M32 | |
319 | # |
|
320 | # | |
320 | # W01 W02 W03 W04 S01 S02 S03 S04 M33 M34 M35 M36 M37 M38 M39 M40 |
|
321 | # W01 W02 W03 W04 S01 S02 S03 S04 M33 M34 M35 M36 M37 M38 M39 M40 | |
321 | # W05 W06 W07 W08 S05 S06 S07 S08 M41 M42 M43 M44 M45 M46 M47 M48 |
|
322 | # W05 W06 W07 W08 S05 S06 S07 S08 M41 M42 M43 M44 M45 M46 M47 M48 | |
322 | # W09 W10 W11 W12 S09 S10 S11 S12 M49 M50 M51 M52 M53 M54 M55 M56 |
|
323 | # W09 W10 W11 W12 S09 S10 S11 S12 M49 M50 M51 M52 M53 M54 M55 M56 | |
323 | # W13 W14 W15 W16 S13 S14 S15 S16 M57 M58 M59 M60 M61 M62 M63 M64 |
|
324 | # W13 W14 W15 W16 S13 S14 S15 S16 M57 M58 M59 M60 M61 M62 M63 M64 | |
324 | # |
|
325 | # | |
325 | fichero =open(path,'r') |
|
326 | fichero =open(path,'r') | |
326 | cnt=0 |
|
327 | cnt=0 | |
327 | lstup=[] |
|
328 | lstup=[] | |
328 | lstdw=[] |
|
329 | lstdw=[] | |
329 | for cadena in fichero: |
|
330 | for cadena in fichero: | |
330 | cnt=cnt+1 |
|
331 | cnt=cnt+1 | |
331 | if cnt==1: |
|
332 | if cnt==1: | |
332 | nu01=cadena[1:4] |
|
333 | nu01=cadena[1:4] | |
333 | nu02=cadena[5:8] |
|
334 | nu02=cadena[5:8] | |
334 | nu03=cadena[9:12] |
|
335 | nu03=cadena[9:12] | |
335 | nu04=cadena[13:16] |
|
336 | nu04=cadena[13:16] | |
336 | eu01=cadena[17:20] |
|
337 | eu01=cadena[17:20] | |
337 | eu02=cadena[21:24] |
|
338 | eu02=cadena[21:24] | |
338 | eu03=cadena[25:28] |
|
339 | eu03=cadena[25:28] | |
339 | eu04=cadena[29:32] |
|
340 | eu04=cadena[29:32] | |
340 | if cnt==2: |
|
341 | if cnt==2: | |
341 | nu05=cadena[1:4] |
|
342 | nu05=cadena[1:4] | |
342 | nu06=cadena[5:8] |
|
343 | nu06=cadena[5:8] | |
343 | nu07=cadena[9:12] |
|
344 | nu07=cadena[9:12] | |
344 | nu08=cadena[13:16] |
|
345 | nu08=cadena[13:16] | |
345 | eu05=cadena[17:20] |
|
346 | eu05=cadena[17:20] | |
346 | eu06=cadena[21:24] |
|
347 | eu06=cadena[21:24] | |
347 | eu07=cadena[25:28] |
|
348 | eu07=cadena[25:28] | |
348 | eu08=cadena[29:32] |
|
349 | eu08=cadena[29:32] | |
349 | if cnt==3: |
|
350 | if cnt==3: | |
350 | nu09=cadena[1:4] |
|
351 | nu09=cadena[1:4] | |
351 | nu10=cadena[5:8] |
|
352 | nu10=cadena[5:8] | |
352 | nu11=cadena[9:12] |
|
353 | nu11=cadena[9:12] | |
353 | nu12=cadena[13:16] |
|
354 | nu12=cadena[13:16] | |
354 | eu09=cadena[17:20] |
|
355 | eu09=cadena[17:20] | |
355 | eu10=cadena[21:24] |
|
356 | eu10=cadena[21:24] | |
356 | eu11=cadena[25:28] |
|
357 | eu11=cadena[25:28] | |
357 | eu12=cadena[29:32] |
|
358 | eu12=cadena[29:32] | |
358 | if cnt==4: |
|
359 | if cnt==4: | |
359 | nu13=cadena[1:4] |
|
360 | nu13=cadena[1:4] | |
360 | nu14=cadena[5:8] |
|
361 | nu14=cadena[5:8] | |
361 | nu15=cadena[9:12] |
|
362 | nu15=cadena[9:12] | |
362 | nu16=cadena[13:16] |
|
363 | nu16=cadena[13:16] | |
363 | eu13=cadena[17:20] |
|
364 | eu13=cadena[17:20] | |
364 | eu14=cadena[21:24] |
|
365 | eu14=cadena[21:24] | |
365 | eu15=cadena[25:28] |
|
366 | eu15=cadena[25:28] | |
366 | eu16=cadena[29:32] |
|
367 | eu16=cadena[29:32] | |
367 | if cnt==5: |
|
368 | if cnt==5: | |
368 | wu01=cadena[1:4] |
|
369 | wu01=cadena[1:4] | |
369 | wu02=cadena[5:8] |
|
370 | wu02=cadena[5:8] | |
370 | wu03=cadena[9:12] |
|
371 | wu03=cadena[9:12] | |
371 | wu04=cadena[13:16] |
|
372 | wu04=cadena[13:16] | |
372 | su01=cadena[17:20] |
|
373 | su01=cadena[17:20] | |
373 | su02=cadena[21:24] |
|
374 | su02=cadena[21:24] | |
374 | su03=cadena[25:28] |
|
375 | su03=cadena[25:28] | |
375 | su04=cadena[29:32] |
|
376 | su04=cadena[29:32] | |
376 | if cnt==6: |
|
377 | if cnt==6: | |
377 | wu05=cadena[1:4] |
|
378 | wu05=cadena[1:4] | |
378 | wu06=cadena[5:8] |
|
379 | wu06=cadena[5:8] | |
379 | wu07=cadena[9:12] |
|
380 | wu07=cadena[9:12] | |
380 | wu08=cadena[13:16] |
|
381 | wu08=cadena[13:16] | |
381 | su05=cadena[17:20] |
|
382 | su05=cadena[17:20] | |
382 | su06=cadena[21:24] |
|
383 | su06=cadena[21:24] | |
383 | su07=cadena[25:28] |
|
384 | su07=cadena[25:28] | |
384 | su08=cadena[29:32] |
|
385 | su08=cadena[29:32] | |
385 | if cnt==7: |
|
386 | if cnt==7: | |
386 | wu09=cadena[1:4] |
|
387 | wu09=cadena[1:4] | |
387 | wu10=cadena[5:8] |
|
388 | wu10=cadena[5:8] | |
388 | wu11=cadena[9:12] |
|
389 | wu11=cadena[9:12] | |
389 | wu12=cadena[13:16] |
|
390 | wu12=cadena[13:16] | |
390 | su09=cadena[17:20] |
|
391 | su09=cadena[17:20] | |
391 | su10=cadena[21:24] |
|
392 | su10=cadena[21:24] | |
392 | su11=cadena[25:28] |
|
393 | su11=cadena[25:28] | |
393 | su12=cadena[29:32] |
|
394 | su12=cadena[29:32] | |
394 | if cnt==8: |
|
395 | if cnt==8: | |
395 | wu13=cadena[1:4] |
|
396 | wu13=cadena[1:4] | |
396 | wu14=cadena[5:8] |
|
397 | wu14=cadena[5:8] | |
397 | wu15=cadena[9:12] |
|
398 | wu15=cadena[9:12] | |
398 | wu16=cadena[13:16] |
|
399 | wu16=cadena[13:16] | |
399 | su13=cadena[17:20] |
|
400 | su13=cadena[17:20] | |
400 | su14=cadena[21:24] |
|
401 | su14=cadena[21:24] | |
401 | su15=cadena[25:28] |
|
402 | su15=cadena[25:28] | |
402 | su16=cadena[29:32] |
|
403 | su16=cadena[29:32] | |
403 | if cnt==9: |
|
404 | if cnt==9: | |
404 | nd01=cadena[1:4] |
|
405 | nd01=cadena[1:4] | |
405 | nd02=cadena[5:8] |
|
406 | nd02=cadena[5:8] | |
406 | nd03=cadena[9:12] |
|
407 | nd03=cadena[9:12] | |
407 | nd04=cadena[13:16] |
|
408 | nd04=cadena[13:16] | |
408 | ed01=cadena[17:20] |
|
409 | ed01=cadena[17:20] | |
409 | ed02=cadena[21:24] |
|
410 | ed02=cadena[21:24] | |
410 | ed03=cadena[25:28] |
|
411 | ed03=cadena[25:28] | |
411 | ed04=cadena[29:32] |
|
412 | ed04=cadena[29:32] | |
412 | if cnt==10: |
|
413 | if cnt==10: | |
413 | nd05=cadena[1:4] |
|
414 | nd05=cadena[1:4] | |
414 | nd06=cadena[5:8] |
|
415 | nd06=cadena[5:8] | |
415 | nd07=cadena[9:12] |
|
416 | nd07=cadena[9:12] | |
416 | nd08=cadena[13:16] |
|
417 | nd08=cadena[13:16] | |
417 | ed05=cadena[17:20] |
|
418 | ed05=cadena[17:20] | |
418 | ed06=cadena[21:24] |
|
419 | ed06=cadena[21:24] | |
419 | ed07=cadena[25:28] |
|
420 | ed07=cadena[25:28] | |
420 | ed08=cadena[29:32] |
|
421 | ed08=cadena[29:32] | |
421 | if cnt==11: |
|
422 | if cnt==11: | |
422 | nd09=cadena[1:4] |
|
423 | nd09=cadena[1:4] | |
423 | nd10=cadena[5:8] |
|
424 | nd10=cadena[5:8] | |
424 | nd11=cadena[9:12] |
|
425 | nd11=cadena[9:12] | |
425 | nd12=cadena[13:16] |
|
426 | nd12=cadena[13:16] | |
426 | ed09=cadena[17:20] |
|
427 | ed09=cadena[17:20] | |
427 | ed10=cadena[21:24] |
|
428 | ed10=cadena[21:24] | |
428 | ed11=cadena[25:28] |
|
429 | ed11=cadena[25:28] | |
429 | ed12=cadena[29:32] |
|
430 | ed12=cadena[29:32] | |
430 | if cnt==12: |
|
431 | if cnt==12: | |
431 | nd13=cadena[1:4] |
|
432 | nd13=cadena[1:4] | |
432 | nd14=cadena[5:8] |
|
433 | nd14=cadena[5:8] | |
433 | nd15=cadena[9:12] |
|
434 | nd15=cadena[9:12] | |
434 | nd16=cadena[13:16] |
|
435 | nd16=cadena[13:16] | |
435 | ed13=cadena[17:20] |
|
436 | ed13=cadena[17:20] | |
436 | ed14=cadena[21:24] |
|
437 | ed14=cadena[21:24] | |
437 | ed15=cadena[25:28] |
|
438 | ed15=cadena[25:28] | |
438 | ed16=cadena[29:32] |
|
439 | ed16=cadena[29:32] | |
439 | if cnt==13: |
|
440 | if cnt==13: | |
440 | wd01=cadena[1:4] |
|
441 | wd01=cadena[1:4] | |
441 | wd02=cadena[5:8] |
|
442 | wd02=cadena[5:8] | |
442 | wd03=cadena[9:12] |
|
443 | wd03=cadena[9:12] | |
443 | wd04=cadena[13:16] |
|
444 | wd04=cadena[13:16] | |
444 | sd01=cadena[17:20] |
|
445 | sd01=cadena[17:20] | |
445 | sd02=cadena[21:24] |
|
446 | sd02=cadena[21:24] | |
446 | sd03=cadena[25:28] |
|
447 | sd03=cadena[25:28] | |
447 | sd04=cadena[29:32] |
|
448 | sd04=cadena[29:32] | |
448 | if cnt==14: |
|
449 | if cnt==14: | |
449 | wd05=cadena[1:4] |
|
450 | wd05=cadena[1:4] | |
450 | wd06=cadena[5:8] |
|
451 | wd06=cadena[5:8] | |
451 | wd07=cadena[9:12] |
|
452 | wd07=cadena[9:12] | |
452 | wd08=cadena[13:16] |
|
453 | wd08=cadena[13:16] | |
453 | sd05=cadena[17:20] |
|
454 | sd05=cadena[17:20] | |
454 | sd06=cadena[21:24] |
|
455 | sd06=cadena[21:24] | |
455 | sd07=cadena[25:28] |
|
456 | sd07=cadena[25:28] | |
456 | sd08=cadena[29:32] |
|
457 | sd08=cadena[29:32] | |
457 | if cnt==15: |
|
458 | if cnt==15: | |
458 | wd09=cadena[1:4] |
|
459 | wd09=cadena[1:4] | |
459 | wd10=cadena[5:8] |
|
460 | wd10=cadena[5:8] | |
460 | wd11=cadena[9:12] |
|
461 | wd11=cadena[9:12] | |
461 | wd12=cadena[13:16] |
|
462 | wd12=cadena[13:16] | |
462 | sd09=cadena[17:20] |
|
463 | sd09=cadena[17:20] | |
463 | sd10=cadena[21:24] |
|
464 | sd10=cadena[21:24] | |
464 | sd11=cadena[25:28] |
|
465 | sd11=cadena[25:28] | |
465 | sd12=cadena[29:32] |
|
466 | sd12=cadena[29:32] | |
466 | if cnt==16: |
|
467 | if cnt==16: | |
467 | wd13=cadena[1:4] |
|
468 | wd13=cadena[1:4] | |
468 | wd14=cadena[5:8] |
|
469 | wd14=cadena[5:8] | |
469 | wd15=cadena[9:12] |
|
470 | wd15=cadena[9:12] | |
470 | wd16=cadena[13:16] |
|
471 | wd16=cadena[13:16] | |
471 | sd13=cadena[17:20] |
|
472 | sd13=cadena[17:20] | |
472 | sd14=cadena[21:24] |
|
473 | sd14=cadena[21:24] | |
473 | sd15=cadena[25:28] |
|
474 | sd15=cadena[25:28] | |
474 | sd16=cadena[29:32] |
|
475 | sd16=cadena[29:32] | |
475 | blck_1_up = [nu01,nu02,nu03,nu04,eu01,eu02,eu03,eu04,nu05,nu06,nu07,nu08,eu05,eu06,eu07,eu08] |
|
476 | blck_1_up = [nu01,nu02,nu03,nu04,eu01,eu02,eu03,eu04,nu05,nu06,nu07,nu08,eu05,eu06,eu07,eu08] | |
476 | blck_1_dw = [nd01,nd02,nd03,nd04,ed01,ed02,ed03,ed04,nd05,nd06,nd07,nd08,ed05,ed06,ed07,ed08] |
|
477 | blck_1_dw = [nd01,nd02,nd03,nd04,ed01,ed02,ed03,ed04,nd05,nd06,nd07,nd08,ed05,ed06,ed07,ed08] | |
477 | blck_2_up = [nu09,nu10,nu11,nu12,eu09,eu10,eu11,eu12,nu13,nu14,nu15,nu16,eu13,eu14,eu15,eu16] |
|
478 | blck_2_up = [nu09,nu10,nu11,nu12,eu09,eu10,eu11,eu12,nu13,nu14,nu15,nu16,eu13,eu14,eu15,eu16] | |
478 | blck_2_dw = [nd09,nd10,nd11,nd12,ed09,ed10,ed11,ed12,nd13,nd14,nd15,nd16,ed13,ed14,ed15,ed16] |
|
479 | blck_2_dw = [nd09,nd10,nd11,nd12,ed09,ed10,ed11,ed12,nd13,nd14,nd15,nd16,ed13,ed14,ed15,ed16] | |
479 | blck_3_up = [wu01,wu02,wu03,wu04,su01,su02,su03,su04,wu05,wu06,wu07,wu08,su05,su06,su07,su08] |
|
480 | blck_3_up = [wu01,wu02,wu03,wu04,su01,su02,su03,su04,wu05,wu06,wu07,wu08,su05,su06,su07,su08] | |
480 | blck_3_dw = [wd01,wd02,wd03,wd04,sd01,sd02,sd03,sd04,wd05,wd06,wd07,wd08,sd05,sd06,sd07,sd08] |
|
481 | blck_3_dw = [wd01,wd02,wd03,wd04,sd01,sd02,sd03,sd04,wd05,wd06,wd07,wd08,sd05,sd06,sd07,sd08] | |
481 | blck_4_up = [wu09,wu10,wu11,wu12,su09,su10,su11,su12,wu13,wu14,wu15,wu16,su13,su14,su15,su16] |
|
482 | blck_4_up = [wu09,wu10,wu11,wu12,su09,su10,su11,su12,wu13,wu14,wu15,wu16,su13,su14,su15,su16] | |
482 | blck_4_dw = [wd09,wd10,wd11,wd12,sd09,sd10,sd11,sd12,wd13,wd14,wd15,wd16,sd13,sd14,sd15,sd16] |
|
483 | blck_4_dw = [wd09,wd10,wd11,wd12,sd09,sd10,sd11,sd12,wd13,wd14,wd15,wd16,sd13,sd14,sd15,sd16] | |
483 |
|
484 | |||
484 | lstup = blck_1_up + blck_2_up + blck_3_up + blck_4_up |
|
485 | lstup = blck_1_up + blck_2_up + blck_3_up + blck_4_up | |
485 | lstdw = blck_1_dw + blck_2_dw + blck_3_dw + blck_4_dw |
|
486 | lstdw = blck_1_dw + blck_2_dw + blck_3_dw + blck_4_dw | |
486 |
|
487 | |||
487 | if polarizacion=='up': |
|
488 | if polarizacion=='up': | |
488 | return lstup |
|
489 | return lstup | |
489 | elif polarizacion=='dw': |
|
490 | elif polarizacion=='dw': | |
490 | return lstdw |
|
491 | return lstdw | |
491 | fichero.close() |
|
492 | fichero.close() | |
492 |
|
493 | |||
493 | def CreaFormatoFinal(self, path, filename): |
|
494 | def CreaFormatoFinal(self, path, filename): | |
494 | ne=self.NumeroDeExperimentos(filename) |
|
495 | ne=self.NumeroDeExperimentos(filename) | |
495 |
|
496 | |||
496 | #nombre01 = file1(archivo,'1') |
|
497 | #nombre01 = file1(archivo,'1') | |
497 | nombre02 = self.file1(filename,'2') |
|
498 | nombre02 = self.file1(filename,'2') | |
498 | fichero=open(path + 'CentralControlFormat.txt','w') |
|
499 | fichero=open(path + 'CentralControlFormat.txt','w') | |
499 | fichero.write(nombre02+'\n') |
|
500 | fichero.write(nombre02+'\n') | |
500 | fichero.write(str(ne)+'\n') |
|
501 | fichero.write(str(ne)+'\n') | |
501 |
|
502 | |||
502 | for i in range(1,65): |
|
503 | for i in range(1,65): | |
503 |
|
504 | |||
504 | if i<10: |
|
505 | if i<10: | |
505 | nmod = '0'+str(i) |
|
506 | nmod = '0'+str(i) | |
506 | else: nmod = str(i) |
|
507 | else: nmod = str(i) | |
507 |
|
508 | |||
508 | fichero.write("ABS_" + nmod+'\n') |
|
509 | fichero.write("ABS_" + nmod+'\n') | |
509 |
|
510 | |||
510 | for j in range(1,ne+1): |
|
511 | for j in range(1,ne+1): | |
511 | ruta=path+str(j)+'.txt' |
|
512 | ruta=path+str(j)+'.txt' | |
512 | lu=self.CapturaValoresEnArchivo(ruta,polarizacion='up') |
|
513 | lu=self.CapturaValoresEnArchivo(ruta,polarizacion='up') | |
513 | ld=self.CapturaValoresEnArchivo(ruta,polarizacion='dw') |
|
514 | ld=self.CapturaValoresEnArchivo(ruta,polarizacion='dw') | |
514 | part1='' |
|
515 | part1='' | |
515 | part2='' |
|
516 | part2='' | |
516 | if lu[i-1]=='1.0': part1='000' |
|
517 | if lu[i-1]=='1.0': part1='000' | |
517 | if lu[i-1]=='2.0': part1='001' |
|
518 | if lu[i-1]=='2.0': part1='001' | |
518 | if lu[i-1]=='3.0': part1='010' |
|
519 | if lu[i-1]=='3.0': part1='010' | |
519 | if lu[i-1]=='0.0': part1='011' |
|
520 | if lu[i-1]=='0.0': part1='011' | |
520 | if lu[i-1]=='0.5': part1='100' |
|
521 | if lu[i-1]=='0.5': part1='100' | |
521 | if lu[i-1]=='1.5': part1='101' |
|
522 | if lu[i-1]=='1.5': part1='101' | |
522 | if lu[i-1]=='2.5': part1='110' |
|
523 | if lu[i-1]=='2.5': part1='110' | |
523 | if lu[i-1]=='3.5': part1='111' |
|
524 | if lu[i-1]=='3.5': part1='111' | |
524 | if ld[i-1]=='1.0': part2='000' |
|
525 | if ld[i-1]=='1.0': part2='000' | |
525 | if ld[i-1]=='2.0': part2='001' |
|
526 | if ld[i-1]=='2.0': part2='001' | |
526 | if ld[i-1]=='3.0': part2='010' |
|
527 | if ld[i-1]=='3.0': part2='010' | |
527 | if ld[i-1]=='0.0': part2='011' |
|
528 | if ld[i-1]=='0.0': part2='011' | |
528 | if ld[i-1]=='0.5': part2='100' |
|
529 | if ld[i-1]=='0.5': part2='100' | |
529 | if ld[i-1]=='1.5': part2='101' |
|
530 | if ld[i-1]=='1.5': part2='101' | |
530 | if ld[i-1]=='2.5': part2='110' |
|
531 | if ld[i-1]=='2.5': part2='110' | |
531 | if ld[i-1]=='3.5': part2='111' |
|
532 | if ld[i-1]=='3.5': part2='111' | |
532 | fichero.write(part1+part2+'\n') |
|
533 | fichero.write(part1+part2+'\n') | |
533 | fichero.write('------'+'\n') |
|
534 | fichero.write('------'+'\n') | |
534 | fichero.close() |
|
535 | fichero.close() | |
535 |
|
536 | |||
536 | def EliminaArchivosEnLaCarpeta(self, path, filename): |
|
537 | def EliminaArchivosEnLaCarpeta(self, path, filename): | |
537 | ne=self.NumeroDeExperimentos(filename) |
|
538 | ne=self.NumeroDeExperimentos(filename) | |
538 | for i in range(1,ne+1): |
|
539 | for i in range(1,ne+1): | |
539 | os.remove(path + str(i)+'.txt') |
|
540 | os.remove(path + str(i)+'.txt') | |
540 |
|
541 | |||
541 |
|
542 | |||
542 | def toCentralControlFormat(self, filename): |
|
543 | def toCentralControlFormat(self, filename): | |
543 | """ Funcion que genera un archivo para el control central""" |
|
544 | """ Funcion que genera un archivo para el control central""" | |
544 |
|
545 | |||
545 | path = os.getcwd() + '/' |
|
546 | path = os.getcwd() + '/' | |
546 | self.CreaFicherosPrevios(path, filename) |
|
547 | self.CreaFicherosPrevios(path, filename) | |
547 | self.CreaFormatoFinal(path, filename) |
|
548 | self.CreaFormatoFinal(path, filename) | |
548 | self.EliminaArchivosEnLaCarpeta(path, filename) |
|
549 | self.EliminaArchivosEnLaCarpeta(path, filename) |
General Comments 0
You need to be logged in to leave comments.
Login now