I have a text file containing data like this:
Date Hour Data
2014/01/01 00 5
2014/01/01 01 10
2014/01/01 02 7
2014/01/01 03 6
.
.
.
2014/01/01 23 4
2014/01/02 00 6
2014/01/02 01 9
2014/01/02 02 2
.
.
.
I want to plot the file in gnuplot with "Data" on y axis and "Hour" on x axis which I know how to do that. I also want that when "Hour" value is "00" (or at the changing of dates) the related "Date" appears on the x axis instead of "Hour". any idea?
Related
In COBOL I need to replace each char within random alphanumeric string of 149 char with numbers.
1 needs to be replaced with 4,
2 with 7 etc...
The complexity comes with few char needs to be replaced by digit in tens:
'A' needs to be replaced with 19,
'B' needs to be replaced with 21 etc...
Could someone please help? The following code not quite works. I am not sure how to resolve problem with positions.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG211.
**************************************************
* DEFINE FILES TO BE BE USED
**************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO INFILE
FILE STATUS IS WS-IN-STATUS.
SELECT TOTALS-FILE ASSIGN TO OUTTOT
FILE STATUS IS WS-TOTALS-STATUS.
DATA DIVISION.
**************************************************
* DEFINE FILE LAYOUTS
**************************************************
FILE SECTION.
FD IN-FILE RECORDING MODE IS F.
01 IN-REC.
03 IN-BODY PIC X(149).
03 IN-CRLF PIC XX.
FD TOTALS-FILE RECORDING MODE IS F.
*** TOTALS-REC TWICE THE SIZE IN CASE CONVERTING ALL TO TENS DIGITS ***
01 TOTALS-REC.
03 TOTALS-BODY PIC X(298).
03 TOTALS-CRLF PIC XX.
WORKING-STORAGE SECTION.
01 WS-IN-STATUS PIC XX.
88 IN-OK VALUE '00'.
88 IN-EOF VALUE '10'.
88 IN-VALID VALUE '00', '10'.
01 WS-TOTALS-STATUS PIC XX.
88 TOTALS-OK VALUE '00'.
01 WS-POS-IN PIC 999.
01 WS-POS-TOT PIC 999.
01 WS-CHARACTERS.
04 BF PIC X(24) VALUE '0123456789EFGHIKMNPQTUVZ'.
04 AF PIC X(24) VALUE '534916820717906256478310'.
PROCEDURE DIVISION.
MAIN-PROCESS SECTION.
PERFORM A-100-INIT
PERFORM B-100-PROCESS UNTIL IN-EOF
PERFORM C-100-TERM
DISPLAY 'PROGRAM FINISHED'
STOP RUN
.
***************************************************
* INITIAL PROCESSING - OPEN FILES
***************************************************
A-100-INIT SECTION.
OPEN INPUT IN-FILE
OUTPUT TOTALS-FILE
IF IN-OK AND TOTALS-OK
CONTINUE
ELSE
DISPLAY 'COULD NOT OPEN FILES'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
PERFORM Y-100-READ-IN
IF IN-EOF
DISPLAY 'IN FILE IS EMPTY'
END-IF
.
A-100-INIT-RETURN.
EXIT.
***************************************************
* PROCESS EACH RECORD
***************************************************
B-100-PROCESS SECTION.
INSPECT IN-REC
CONVERTING BF
TO AF
MOVE IN-REC TO TOTALS-BODY
MOVE 0 TO WS-POS-IN
MOVE 0 TO WS-POS-TOT
PERFORM VARYING WS-POS-IN FROM 1 BY 1 UNTIL WS-POS-IN > 149
EVALUATE IN-BODY (WS-POS-IN: )
WHEN 'A'
MOVE 21 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'B'
MOVE 17 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'C'
MOVE 13 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'D'
MOVE 15 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'J'
MOVE 11 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'L'
MOVE 31 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'O'
MOVE 23 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'R'
MOVE 19 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'S'
MOVE 10 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'W'
MOVE 16 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'X'
MOVE 18 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'Y'
MOVE 20 TO TOTALS-BODY (WS-POS-TOT: )
END-EVALUATE
END-PERFORM
MOVE X'0D0A' TO TOTALS-CRLF
PERFORM Y-200-WRITE-TOTALS
PERFORM Y-100-READ-MOO
.
B-100-PROCESS-RETURN.
EXIT.
***************************************************
* TERMINATION PROCESSING - CLOSE FILES
***************************************************
C-100-TERM SECTION.
CLOSE IN-FILE
TOTALS-FILE
IF IN-OK AND TOTALS-OK
CONTINUE
ELSE
DISPLAY 'COULD NOT CLOSE FILES'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
.
C-100-TERM-RETURN.
EXIT.
***************************************************
* READ RECORD
***************************************************
Y-100-READ-IN SECTION.
READ IN-FILE
IF NOT IN-VALID
DISPLAY 'COULD NOT READ IN RECORD'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
.
Y-100-READ-IN-RETURN.
EXIT.
***************************************************
* WRITE IN RECORD
***************************************************
Y-200-WRITE-TOTALS SECTION.
WRITE TOTALS-REC
IF NOT TOTALS-OK
DISPLAY 'COULD NOT WRITE TOTALS RECORD'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
.
Y-200-WRITE-TOTALS-RETURN.
EXIT.
***************************************************
* UNEXPECTED ERROR SECTION
***************************************************
Z-100-UNEXPECTED-ERROR SECTION.
DISPLAY 'IN STATUS IS ' WS-IN-STATUS
DISPLAY 'TOTALS STATUS IS ' WS-TOTALS-STATUS
STOP RUN
.
Z-100-TERM-RETURN.
EXIT.
I chose to use a common technique to place the one and two character translations into the output. To that end, I created a table defining all the translations in one place, used SEARCH to locate the specific translation, and INSTRING to place the translation into the output.
To test the code, I reduced the size of the fields to 9 and 18 positions.
I used lower-case for all significant changes included in this minimal working example (MWE).
WORKING-STORAGE SECTION.
01 IN-REC.
03 IN-BODY PIC X(9).
88 test-1 value "012345678".
88 test-2 value "9ABCDEFGH".
88 test-3 value "IJKLMNOPQ".
88 test-4 value "RSTUVWXYZ".
*** TOTALS-REC TWICE THE SIZE IN CASE CONVERTING ALL TO TENS DIGITS ***
01 TOTALS-REC.
03 TOTALS-BODY PIC X(18).
01 WS-POS-IN PIC 999.
01 WS-POS-TOT PIC 999.
01 WS-CHARACTERS.
03 translations-defined.
05 pic x value "0". 05 pic xx value "5 ".
05 pic x value "1". 05 pic xx value "3 ".
05 pic x value "2". 05 pic xx value "4 ".
05 pic x value "3". 05 pic xx value "9 ".
05 pic x value "4". 05 pic xx value "1 ".
05 pic x value "5". 05 pic xx value "6 ".
05 pic x value "6". 05 pic xx value "8 ".
05 pic x value "7". 05 pic xx value "2 ".
05 pic x value "8". 05 pic xx value "0 ".
05 pic x value "9". 05 pic xx value "7 ".
05 pic x value "A". 05 pic xx value "21".
05 pic x value "B". 05 pic xx value "17".
05 pic x value "C". 05 pic xx value "13".
05 pic x value "D". 05 pic xx value "15".
05 pic x value "E". 05 pic xx value "1 ".
05 pic x value "F". 05 pic xx value "7 ".
05 pic x value "G". 05 pic xx value "9 ".
05 pic x value "H". 05 pic xx value "0 ".
05 pic x value "I". 05 pic xx value "6 ".
05 pic x value "J". 05 pic xx value "11".
05 pic x value "K". 05 pic xx value "2 ".
05 pic x value "L". 05 pic xx value "31".
05 pic x value "M". 05 pic xx value "5 ".
05 pic x value "N". 05 pic xx value "6 ".
05 pic x value "O". 05 pic xx value "23".
05 pic x value "P". 05 pic xx value "4 ".
05 pic x value "Q". 05 pic xx value "7 ".
05 pic x value "R". 05 pic xx value "19".
05 pic x value "S". 05 pic xx value "10".
05 pic x value "T". 05 pic xx value "8 ".
05 pic x value "U". 05 pic xx value "3 ".
05 pic x value "V". 05 pic xx value "1 ".
05 pic x value "W". 05 pic xx value "16".
05 pic x value "X". 05 pic xx value "18".
05 pic x value "Y". 05 pic xx value "20".
05 pic x value "Z". 05 pic xx value "0 ".
03 redefines translations-defined.
05 translate-entry occurs 36 indexed by search-pos.
07 search-char pic x.
07 translate-char pic xx.
01 character-count comp pic 9(4).
procedure division.
begin.
set test-1 to true
perform translate-test
set test-2 to true
perform translate-test
set test-3 to true
perform translate-test
set test-4 to true
perform translate-test
stop run
.
translate-test.
display IN-BODY
perform B-100-PROCESS
display TOTALS-BODY
display space
.
***************************************************
* PROCESS EACH RECORD
***************************************************
B-100-PROCESS SECTION.
move 1 to WS-POS-TOT
move space to TOTALS-BODY
PERFORM VARYING WS-POS-IN FROM 1 BY 1 UNTIL WS-POS-IN > 9
set search-pos to 1
search translate-entry varying search-pos
when IN-BODY (WS-POS-IN:1) = search-char (search-pos)
unstring translate-char (search-pos)
delimited space
into TOTALS-BODY (WS-POS-TOT:2)
count in character-count
add character-count to WS-POS-TOT
END-PERFORM
.
Output:
012345678
534916820
9ABCDEFGH
7211713151790
IJKLMNOPQ
611231562347
RSTUVWXYZ
19108311618200
Continue from: EMV Reading PAN Code
I'm working in C, so I havn't Java tools and all the functions that parse automatically the response of APDU command.
I want to read all types of smart cards.
I have to parse the response of an GET PROCESSING OPTIONS and get the AFL (Access File Locator) of every card.
I have three cards with three different situation:
A) HelloBank: 77 12 82 2 38 0 94 c 10 2 4 1 18 1 1 0 20 1 1 0 90
B) PayPal: 77 12 82 2 39 0 94 c 18 1 1 0 20 1 1 0 28 1 3 1 90
C) PostePay: 80 a 1c 0 8 1 1 0 18 1 2 0 90
Case A)
I've got three different AFL: 10 2 4 1, 18 1 1 0, 20 1 1 0
So I send 00 B2 SFI P2 00 where SFI was 10>>3 (10 was first byte of first AFL) and P2 was SFI<<3|4 and this way I got the correct PAN Code of my card.
Case B)
I've got three different AFL: 18 1 1 0, 20 1 1 0, 28 1 3 1.
So I send 00 B2 SFI P2 00 builded in the same way as Case A, but I got the response 6A 83 for every AFL.
Case C)
I've got two different AFL: 8 1 1 0, 18 1 2 0 but I cannot parse those automatically because there isn't the same TAG of previous response.
If I use those AFL it worked and I can get the PAN Code of the card.
How can I make an universal way to read the correct AFL and how can I make the correct command with those AFL?
Here is the decoding of AFL:
You will get the AFL in multiple of 4 Bytes normally. Divide your complete AFL in a chunk of 4 Bytes. Lets take an example of 1 Chunk:
AABBCCDD
AA -> SFI (Decoding is described below)
BB -> First Record under this SFI
CC -> Last Record under this SFI
DD -> Record involved for Offline Data Authentication (Not for your use for the moment)
Taking your example 10 02 04 01 18 01 01 00 20 01 10 00
Chunks are 10 02 04 01, 18 01 01 00, 20 01 10 00
10 02 04 01 -->
Taking 1st Byte 10 : 00010000 Take initial 5 bits from MSB --> 00010 means 2 : Means SFI 2
Taking 2nd Byte 02 : First Record under SFI 2 is 02
Taking 3rd Byte 04 : Last Record under SFI 2 is 04
Excluding 4 Byte explanation since no use
Summary : SFI 2 contains record 2 to 4
How Read Record command will form :
APDU structure : CLA INS P1 P2 LE
CLA 00
INS B2
P1 (Rec No)02 (SInce in this SFI 2 inital record is 02)
P2 (SFI) SFI 02 : Represent the SFI in 5 binay digit 00010 and then append 100 in the end : 00010100 : In Hex 14
So P2 is 14
LE 00
APDU to Read SFI 2 Rec 2 : 00 B2 02 14 00
APDU to Read SFI 2 Rec 3 : 00 B2 03 14 00
APDU to Read SFI 2 Rec 4 : 00 B2 04 14 00
Now if you will try to Read Rec 5, Since this Rec is not present you will get SW 6A83 in this case.
Use the same procedure for all chunk to identify the available Records and SFIs
BY this mechanisam you can write the function to parse the AFL
I have a Dataframe with a column contains bytes objects b'\x00' to b'\x08'. I would like to replace them with the corresponding string '00' to '08'.
The bytes objects from b'\x01' to b'\x08' can be easily replaced by using a dict in dataframe.replace.
However the job on b'\x00' doesn't work. Here is my test.
My python version is
'3.6.3 |Anaconda custom (64-bit)| (default, Nov 8 2017, 15:10:56) [MSC v.1900 64 bit (AMD64)]'. Pandas is pre-installed.
bytes_list=[b'\x00',b'\x01',b'\x02',b'\x03',b'\x04',b'\x05',b'\x06',b'\x07',b'\x08']
bytes_df=pd.DataFrame({"bytes":bytes_list})
replacements = {b'\x00': '00',b'\x01': '01',b'\x02': '02',b'\x03': '03',b'\x04': '04'
,b'\x05': '05',b'\x06': '06',b'\x07': '07',b'\x08': '08'}
bytes_df.replace(replacements,inplace=True)
print(bytes_df)
Output:
bytes
0 b'\x00'
1 01
2 02
3 03
4 04
5 05
6 06
7 07
8 08
So you can see the bytes object b'\x00' isn't replaced.
Later I use applymap with a lambda func get what I need.
bytes_df.applymap(lambda x: x[0] if type(x) is bytes else x)
But I was still wondering if there is any other easy and pythonic way can do the same. And I was also wondering if this is a bug.
Could anyone explain?
You could circumvent the problem:
import pandas as pd
bytes_list=[b'\x00',b'\x01',b'\x02',b'\x03',b'\x04',b'\x05',b'\x06',b'\x07',b'\x08']
bytes_df=pd.DataFrame({ "bytes": ['0'+str(ord(x)) for x in bytes_list] })
print(bytes_df)
Output:
bytes
0 00
1 01
2 02
3 03
4 04
5 05
6 06
7 07
8 08
I have data something like this:
# c1 c2 c3
23 b 323
23 g 54
23 a 11
23 c 1
23 d 0
23 e 397
23 f 40
24 b 23
24 g 24
24 a 113
24 c 12
24 d 10
24 e 7
24 f 50
I need to plot with c1 on x-axis (23,24), c3 on y-axis for different values of c2 i.e, multiple graphs with different colors for each value of c2.
In general, you must do the filtering outside of gnuplot, in order to have lines connecting the filtered points.
If you know all values which can appear in the second column, you can use the solution given in Plotting multiple graphs depending on column value with gnuplot.
If you don't know the possible values, you can extract them with
c2s = system("awk '!/^#/ { print $2 }' test.dat | sort | uniq")
and then plot them with
plot for [c2 in c2s] sprintf('< grep ''\b%s\b'' test.dat', c2) using 1:3 with lines title c2
I have a list of times which i want to add to a string
0900 1730
0900 1730
1000 1700
0930 1700
i need to break these up to hours and minutes like so
09 00 17 30
09 00 17 30
10 00 17 00
09 30 17 00
to do this i am using the MID() function to get the first two characters from the cell and then the last two. But when i do this for numbers that start with 0 of have 00 it drops the first 0 like so
0930 = ",MID(B2,1,2),",",MID(B2,3,2)," output - 93 0 what i want = 09 30
0900 = ",MID(B2,1,2),",",MID(B2,3,2)," output - 90 0 what i want = 09 00
1000 = ",MID(B2,1,2),",",MID(B2,3,2)," output - 10 0 what i want = 10 00
is there a way to solve this?
You can use a mid of a pre-formatted block:
=MID(RIGHT("0000"&B2,4),1,2) =MID(RIGHT("0000"&B2,4),3,2)
This should give you two strings like 09 & 30.
If you want two numeric values you can add a value function:
=VALUE(MID(RIGHT("0000"&B2,4),1,2))
One way is place Single Quote(') before the 0 then it will store the 0930 as text in cell
and your formula will also work, No need to change in the formula.
So the value 0930 will be '0930