-
Notifications
You must be signed in to change notification settings - Fork 0
/
pw_elgin.c
6693 lines (5313 loc) · 144 KB
/
pw_elgin.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** pw_elgin -- a program to look up elgin watch data
**
** Copyright (C) 1999, 2000 Wayne Schlitt ([email protected])
** Version 1 05/24/00
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
static char *versionInfo = "1.0";
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
#include <getopt.h>
#include <time.h>
#include <stdarg.h>
#ifdef HAVE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif
/* default directory of the data files */
#ifndef LIBDIR
#define LIBDIR "./" /* change this to .../lib someday */
#endif
typedef unsigned char uchar;
#define TRUE 1
#define FALSE 0
#define array_elem( a ) (sizeof( a )/sizeof( a[0] ))
#define str_prefix( a, b ) (strncmp( a, b, strlen( b ) ) == 0)
double sqr( double a )
{
return a * a;
}
#define MAX_SN_RANGES 20000
#define MAX_GRADE 1000
#define GRADE_UNKNOWN -1
#define MAX_CLASS 136
#define CLASS_UNKNOWN 0
#define MAX_SIZE 85
#define MIN_SIZE -25
#define SIZE_UNKNOWN (MAX_SIZE+1)
#define NUM_SIZES (SIZE_UNKNOWN - MIN_SIZE + 1)
#define PLATE_FULL 0
#define PLATE_3_4 1
#define PLATE_UNKNOWN 2
#define STYLE_HC 1 /* hunter case */
#define STYLE_OF 2 /* open face */
#define STYLE_CVT 3 /* convertable */
#define STYLE_SS 4 /* sweep second */
#define STYLE_NONE 5 /* no second */
#define STYLE_UNKNOWN 6
#define NUM_STYLES 7
#define FINISH_GILDED 0 /* gold gilded movement */
#define FINISH_NICKEL 1 /* nickel damaskeening mvt */
#define FINISH_TWO_TONE 2 /* nickel damaskeening *and* gilded
* in a pattern. Common on other brands
* not in Elgin's */
#define FINISH_FLAT 3 /* flat nickel, no damaskeening */
#define FINISH_UNKNOWN 4
#define NUM_FINISHES 5
#define MIN_MODEL 1
#define MAX_MODEL 24
#define MODEL_UNKNOWN 0
#define NUM_MODELS 25
#define SETTING_KEY 0 /* key set, key wind */
#define SETTING_LEVER 1 /* lever set, pend wind */
#define SETTING_PEND 2 /* pendant set, pend wind */
#define SETTING_AUTO 3 /* pendant set, automatic wind */
#define SETTING_HACK 4 /* PS/PW w/hack setting (can stop sec hand) */
#define SETTING_UNKNOWN 5
#define NUM_SETTINGS 6
#define TRAIN_SLOW 0 /* slow train (4.5 bps) */
#define TRAIN_QUICK 1 /* quick train (5 bps) */
#define TRAIN_QS 2 /* both quick and slow for this model */
#define TRAIN_FAST 3 /* fast train (5.5 bps) */
#define TRAIN_VFAST 4 /* very fast train (6 bps) */
#define TRAIN_JBUG 5 /* jitter bug train (40 bps?) */
#define TRAIN_UNKNOWN 6
#define NUM_TRAINS 7
#define MAX_JEWELS 24
#define MIN_JEWELS 7
#define JEWELS_UNKNOWN 0
#define NUM_JEWELS 25
#define DEFAULT_WIND_HRS 40 /* is it really this long? */
#define REG_FREE 0 /* regulator can be freely moved */
#define REG_ELGIN 1 /* std Elgin micrometric regulator with */
/* "notched spool on a threaded rod" */
#define REG_RR_PAT 2 /* "Railroad Patent Regulator" */
/* like std Elgin, but a spring under */
/* the balance cock to force reg to */
/* one side of the notched spool. */
/* looks like an elgin from the top, */
/* but has a small pin near balance */
/* jewel end of the regulator */
#define REG_OLD_RR_PAT 3 /* "Old style Patent Regulator" */
/* this was used on some of the early */
/* elgin watches. Like the RR Patent, */
/* it had a spring under the balance */
/* cock, but it used a screw on the top */
/* of the cock to adjusted it. */
#define REG_BALL 4 /* The elgin "Ball Watch Co" style */
/* has a spring on top and a "jack */
/* screw" type rod that you turn with a */
/* pin on one side of the balance cock */
#define REG_HULBURD 5 /* hulburds were just weird. */
#define REG_DURABALANCE 6 /* the regulator is part of the balance */
#define REG_UNKNOWN 7
#define NUM_REGS 8
#define BARREL_GOING 0 /* "normal" mainspring barrel */
#define BARREL_MOTOR 1 /* barrel has shaft with 3 screws */
#define BARREL_JMOTOR 2 /* jeweled motor barrel */
#define BARREL_UNKNOWN 3
#define NUM_BARRELS 4
#define MAX_PAT_DIGITS 8
#define MAX_CHAR_PER_DIGIT (sizeof( "[0123456789]" ) - 1)
typedef struct
{
int num_digits;
char digit_set[ MAX_PAT_DIGITS ][ 10 ];
char digits_in_set[ MAX_PAT_DIGITS ];
int digit_val[ MAX_PAT_DIGITS ];
int min_val[ MAX_PAT_DIGITS ];
int max_val[ MAX_PAT_DIGITS ];
} num_pat_type;
#define N_NONE 0 /* no name printed on mvt */
#define N_ADVANCE 1
#define N_AGE 2
#define N_AVERY 3 /* Thomas M. Avery 2nd Prez */
#define N_CHIEF 4
#define N_CULVER 5 /* Howard Z. Culver On 1884 board */
#define N_DEXTER_ST 6
#define N_FATHER_TIME 7
#define N_FARGO 8 /* Charles (Chas) Fargo On 1884 board */
#define N_FARWELL 9 /* J.V. Farwell Chicago investor? */
#define N_FERRY 10 /* William H. Ferry Chicago investor? */
#define N_FRANCES_RUBIE 11 /* ??? */
#define N_GAIL_BORDEN 12 /* "of the condensed milk fame" */
#define N_LADY_ELGIN 13
#define N_LADY_RAYMOND 14
#define N_LAFLIN 15 /* Matthew (Mat) Laflin An original director */
#define N_LEADER 16
#define N_LORD_ELGIN 17 /* George P. Lord 1st Biz Manager */
/* see notes below about the Lord Elgin name */
#define N_OGDEN 18 /* M.D. Odgen Chicago investor? */
#define N_OVERLAND 19
#define N_RAYMOND 20 /* Benjamin W. Raymond 1st Prez */
#define N_RYERSON 21 /* Joseph T. Ryerson An original director */
#define N_TAYLOR 22 /* Henry H. Taylor An original director */
#define N_VERITAS 23
#define N_WHEELER 24 /* George M. Wheeler An original director */
#define N_STANDARD 25
#define N_INTER_OCEAN 26
#define N_N_W_CO 27
#define N_SUN_DIAL 28
#define N_ATLAS 29
#define N_ACME 30
#define N_SOLAR 31
#define N_149 32
#define N_150 33
#define N_270 34
#define N_274 35
#define N_280 36
#define N_333 37
#define N_348 38
#define N_349 39
#define N_HULBURD 40 /* Charles H. Hulburd 3rd Prez */
#define N_DELUXE 41
#define N_STRAND 42
#define N_SENIOR_17 43
#define N_LORD_ELGIN_SERIES 44
#define N_TRANSIT 45
#define MAX_NAME 46
#define N_DEFER MAX_NAME /* defer to the default */
#define N_UNKNOWN (MAX_NAME+1) /* don't know which name */
char *mvt_names[ MAX_NAME ] =
{ "", "ADV", "AGE", "AVR", "CHF", "HZC", "DEX",
"FT", "FGO", "FAR", "FRY", "FR", "GB",
"LDY", "LDR", "LAF", "LED", "LE", "OGD",
"OVR", "BWR", "RYR", "TAY", "VER", "GMW",
"STD", "NWC", "INT",
"SUN", "ATL", "ACM", "SOL",
"149", "150", "270", "274", "280", "333", "348", "349",
"HUL", "DLX",
"STR", "S17", "LES", "TRN"};
char *mvt_names_long[ MAX_NAME ] =
{ "None", "Advance", "Age", "Avery", "Chief", "Culver", "Dexter St",
"Father Time", "Fargo", "Farwell", "Ferry", "Frances Rubie", "Gail Borden",
"Lady Elgin", "Lady Raymond", "Laflin", "Leader", "Lord Elgin", "Ogden",
"Overland", "Raymond", "Ryerson", "Taylor", "Veritas", "Wheeler",
"Standard", "N W Co", "Inter-Ocean",
"Sun Dial", "Atlas", "Acme", "Solar",
"149", "150", "270", "274", "333", "348", "280", "349",
"Hulburd", "Deluxe",
"Strand", "Senior 17", "LE Series", "Transit" };
/*
* Notes on the "Lord Elgin" name:
*
* While Elgin did have a high muckity-muck with the last name of "Lord"
* who worked for them, it is not clear that the Lord Elgin line was named
* after him. G. P. Lord retired(?) in 1876, some 30 years before the first
* "Lord Elgin" watch was created. It is possible that they had even
* forgotten that they even had a "G. P. Lord" working for them. Also, Elgin
* seems to have switched to "made up" names like "Veritas" and "Father Time".
*
* On the other hand, the also resurected the "Frances Rubie" name and created
* the "Lady Raymond" name in this same general timeframe.
*
* Anyway, I find this "G.P. Lord" relationship interesting and amusing.
*/
#define MAX_ADJ_NAME 11
#define ADJ_UNKNOWN (MAX_ADJ_NAME-1)
char *adj_names[ MAX_ADJ_NAME ] = {"U", "A", "AT", "AP", "A1P", "A2P", "A3P", "A4P", "A5P", "A6P", "?"};
#define MAX_GRADE_NAME 8
typedef struct
{
int grade;
int class;
int dial_size;
int mvt_size;
int plate;
int bridge;
int style;
int finish;
int min_model;
int max_model;
int setting;
int train;
int min_jewels;
int max_jewels;
int min_adj;
int max_adj;
int wi_option; /* is a wind indicator available? */
int wind_hrs; /* how long watch stays wound */
int regulator; /* type of regulator adjustment */
int barrel;
int name[ MAX_GRADE_NAME ];
char *comments; /* comments about this grade */
char *comment_lines; /* comments following this line */
/* the following info is calculated based off of the sn data */
int first_snr;
int last_snr;
int min_cnt;
int max_cnt;
int total_cnt;
int num_runs;
int num_consecutive;
double avg_cnt;
double std_dev;
char sn_comments; /* sn range w/this grade has comments */
char sn_comment_lines; /* sn range w/this grade has comment lines */
char first_in_size;
char last_produced_in_size;
char last_grade_in_size;
char first_in_bridge;
char first_in_bridge_in_size;
char first_in_style;
char first_in_style_in_size;
char first_in_finish;
char first_in_finish_in_size;
char first_in_model_in_size;
char first_in_setting;
char first_in_setting_in_size;
char first_in_jewel;
char first_in_jewel_in_size;
char first_in_wi_option;
char first_in_wi_option_in_size;
char first_in_wind_hrs;
char first_in_regulator;
char first_in_regulator_in_size;
char first_in_barrel;
char first_in_barrel_in_size;
char first_in_name[ MAX_GRADE_NAME ];
char first_in_name_in_size[ MAX_GRADE_NAME ];
int flag_notes; /* print foot notes on this grade? */
} grade_type;
typedef struct
{
int sn;
uchar letter;
int cnt;
int grade;
int name;
int line;
char *comments; /* comments about this grade */
char *comment_lines; /* comments following this line */
int year;
int next_grade;
int next_size;
int next_bridge;
int next_bridge_in_size;
int next_style;
int next_style_in_size;
int next_finish;
int next_finish_in_size;
int next_model_in_size;
int next_setting;
int next_setting_in_size;
int next_jewel;
int next_jewel_in_size;
int next_wi_option;
int next_wi_option_in_size;
int next_wind_hrs;
int next_regulator;
int next_regulator_in_size;
int next_barrel;
int next_barrel_in_size;
int next_name[ MAX_GRADE_NAME ];
int next_name_in_size[ MAX_GRADE_NAME ];
} sn_range_type;
typedef struct
{
int grade[ MAX_GRADE ];
int size[ NUM_SIZES ];
int bridge;
int bridge_in_size[ NUM_SIZES ];
int style[ NUM_STYLES ];
int style_in_size[ NUM_SIZES ][ NUM_STYLES ];
int finish[ NUM_FINISHES ];
int finish_in_size[ NUM_SIZES ][ NUM_FINISHES ];
int model_in_size[ NUM_SIZES ][ NUM_MODELS ];
int setting[ NUM_SETTINGS ];
int setting_in_size[ NUM_SIZES ][ NUM_SETTINGS ];
int jewel[ NUM_JEWELS ];
int jewel_in_size[ NUM_SIZES ][ NUM_JEWELS ];
int wi_option;
int wi_option_in_size[ NUM_SIZES ];
int wind_hrs;
int regulator[ NUM_REGS ];
int regulator_in_size[ NUM_SIZES ][ NUM_REGS ];
int barrel[ NUM_BARRELS ];
int barrel_in_size[ NUM_SIZES ][ NUM_BARRELS ];
int name[ MAX_GRADE_NAME ];
int name_in_size[ NUM_SIZES ][ MAX_GRADE_NAME ];
} run_info_type;
typedef struct
{
run_info_type first;
run_info_type prev_tot_in_gr;
run_info_type prev_snr_idx;
} first_runs_type;
typedef struct
{
int year;
int sn;
} sn_year_type;
sn_year_type sn_year[] = {
{1867, 100},
{1868, 31000},
{1869, 71000},
{1870, 101000},
{1871, 126000},
{1872, 152000},
{1873, 176000},
{1874, 210000},
{1875, 310000},
{1876, 410000},
{1877, 510000},
{1878, 552000},
{1879, 601000},
{1880, 701000},
{1881, 801000},
{1882, 1000000},
{1883, 1440000},
{1884, 1650000},
{1885, 1850000},
{1886, 2000000},
{1887, 2550000},
{1888, 3000000},
{1889, 3550000},
{1890, 4000000},
{1891, 4400000},
{1892, 4890000},
{1893, 5000000},
{1894, 5500000},
{1895, 6000000},
{1896, 6550000}, /* Apr 6 1986 mtrl cat has sn up to 6944000 */
{1897, 7000000},
{1898, 7550000},
{1899, 8100000},
{1900, 9100000},
{1901, 9350000},
{1902, 9755000},
{1903, 10100000},
{1904, 11000000},
{1905, 12100000},
{1906, 12500000},
{1907, 13100000},
{1908, 13550000},
{1909, 14100000},
{1910, 15100000},
{1911, 16000000},
{1912, 17000000},
{1913, 17550000},
{1914, 18000000},
{1915, 18500000},
{1916, 19000000},
{1917, 20000000},
{1918, 21000000},
{1919, 22000000},
{1920, 23000000},
{1921, 24000000},
{1922, 25000000},
{1923, 26000000},
{1924, 27000000},
{1925, 28000000},
{1926, 29000000},
{1927, 30000000},
{1928, 32000000},
{1929, 33000000},
{1930, 33300000},
{1931, 33500000},
{1932, 33700000},
{1933, 34000000},
{1934, 35000000},
{1935, 35500000},
{1936, 36200000},
{1937, 37000000},
{1938, 37900000},
{1939, 38200000},
{1940, 39100000},
{1941, 40200000},
{1942, 41100000},
{1943, 42200000},
{1944, 42600000},
{1945, 43200000},
{1946, 44000000},
{1947, 45000000},
{1948, 46000000},
{1949, 47000000},
{1950, 48000000},
{1951, 50000000},
{1952, 52000000},
{1953, 53300000},
{1954, 54000000},
{1955, 54500000},
{1956, 55000000}
};
int cvt_sn_letter( uchar letter, int sn )
{
switch( letter )
{
case '_':
return 0;
case 'X': /* shugart doesn't say where this split is */
if( sn < 500000 )
return 38000000;
else
return 39000000;
#define SHUGART
#ifdef SHUGART
/* according to Shugart's, these four letters are represent the
* 42 million prefix. This contradicts what is shown in the
* 1950 MC, but it makes the production quantities make more sense.
*
* With all of these at 42 million, the yearly production output
* drops until 1941, and then shoots up in 1942 as would be expected
* when the US entered WWII. The production peaks in 1944, and then
* drops dramatically in 1945 after the war ends.
*
* With the prefixes determined by the 1950 MC, the production starts
* to rise in 1939, and actually drops to a low level in 1943-1944.
*
* Another way to "fix" this problem would be to adjust the sn_year[]
* values, but I have no idea what to adjust them too, and the various
* sources seem to agree for this time period.
*
* A further thing to ponder: The gold flashed movements are
* supposed to have been made during WWII "because nickel was
* a criticl metal". The non-lettered gold flashed watches
* are in the 41,000,000 range and the current sn_year[]
* ranges would place that in early 1942, which sounds about
* right. There are also gold flashed watches in the "Y"
* ranges, which also appear to be in the 1942-1944 range.
*/
case 'C':
case 'E':
case 'T':
case 'Y':
return 42000000;
#else
case 'C': /* shugart says 42,000,000 but elgin SN list
* shows C's ending at 40,000,000 */
return 39000000;
case 'E': /* shugart says 42,000,000 but elgin SN list
* shows E's between C's and T/Y's, so this
* is my guess. */
return 40000000;
case 'T': /* shugart says 42,000,000 and elgin SN list
* shows T's ending at 43,000,000, but there
* are also some before the Y's */
if( sn < 300000 )
return 41000000;
else
return 42000000;
case 'Y': /* shugart says 42,000,000 but elgin SN list
* shows Y's ending at 42,000,000 */
return 41000000;
#endif
case 'L':
return 43000000;
case 'U':
return 44000000;
case 'J':
return 45000000;
case 'V':
return 46000000;
case 'H':
return 47000000;
case 'N':
return 48000000;
case 'F':
return 49000000;
case 'S':
return 50000000;
case 'R':
return 51000000;
case 'P':
return 52000000;
case 'K':
return 53000000;
case 'I':
return 54000000;
break;
case '!': /* special case for "grades with no known ranges" */
return -2;
default:
return -1;
break;
}
}
int cvt_sn_grade( uchar letter, int sn, int grade )
{
switch( grade )
{
/* grades before about G=85 are too disorganized to figure out
* which are retro-grades and which arent. After all, the
* "first" watch made was a G=69, and G=1 wasn't made until ca
* 1879 */
case 95:
/* first sn is 2180001, but based on surounding ones, I would expect
* something around 1200001-1500001 */
return 0;
case 109:
/* first sn is 4212001, but based on surounding ones, I would expect
* something around 2850001-3010001 */
return 0;
/* 140? early first SN */
/* 141? early first SN */
/* 142? early first SN */
/* 145? <= 74? */
/* 147? looks suspicious, but I can't find anything which it might be */
/* 148? early first SN */
/* 167? early first SN */
/* 168? early first SN */
case 169:
/* looks like the first run of G=169 were really converted 142s */
/* later G=169's were converted to 228's */
/* need a check here */
return 0;
case 170:
/* looks like the first run of G=170 were really converted 146s */
/* need a check here */
return 0;
case 174:
/* looks like the first two runs of G=174 were really converted 112s */
if( letter == '_' && sn < 5396001 )
return 1500000;
return 0;
case 176:
/* looks like the first run of G=176 were really converted 122s */
if( letter == '_' && sn < 5411001 )
return 1400000;
return 0;
/* 185? early first SN */
case 186:
/* looks like the first two runs of G=186 were really converted 157s */
/* if( letter == '_' && sn < 5411001 )
return 700000; */
return 0;
/* 187? late first SN */
/* 220? early first SN */
case 224:
/* looks like the first 3 runs of G=224 were really converted 198s */
/* need a check here */
return 0;
case 226:
/* looks like all runs of G=226 were really converted 141s */
/* need a check here */
return 0;
case 227:
/* looks like all runs of G=227 were really converted 145s */
/* need a check here */
return 0;
case 228:
/* looks like all runs of G=228 were really converted 169s */
/* (G=169's were converted from 142's) */
/* need a check here */
return 0;
case 229:
/* looks like all runs of G=229 were really converted 170s */
/* (G=170's were converted from 146's) */
/* need a check here */
return 0;
case 230:
/* looks like the first run of G=230 were really converted 132s */
/* need a check here */
return 0;
case 231:
/* looks like all runs of G=231 were really converted 133s */
/* need a check here */
return 0;
/* 241? early first SN looks like this is from 154s*/
/* 242? late first SN */
/* 243? late first SN */
/* 244? early first SN looks like this is from 159 */
/* 246? late first SN */
/* 257? looks like this is from 220 */
/* 258? looks like this is from 221 */
/* 259? looks like this is from 233, maybe? */
/* 260? early first SN looks like this is from 235 */
/* 261? early first SN looks like this is from 217 */
/* 262? looks like this is from 218, maybe? */
/* 264? looks like this is from 204 */
case 265:
/* looks like all runs of G=265 were really converted 165s */
/* need a check here */
return 0;
case 266:
/* looks like all the runs of G=266 were really converted 166s */
/* need a check here */
return 0;
/* 271? early first SN */
/* 272? early first SN */
case 273:
/* looks like all the runs of G=273 were really converted 184s */
/* need a check here */
return 0;
/* 283? early first SN looks like it is related to G=148 */
/* 299? late first SN */
/* 309? early first SN looks like it is related to G=251 */
/* 316? early first SN looks like it is related to G=261 */
/* 319? first SN looks like it is half the final run of G=268 */
/* 320? early first SN */
/* 321? first SN looks like it is half the final run of G=275 */
/* 339? first SN looks like it is half the final run of G=305 */
/* 340? first SN looks like it is half the final run of G=306 */
/* 344? early first SN looks like it is related to G=302 */
/* 345? early first SN looks like it is related to G=304 */
/* 349? early first SN */
/* 379? looks like it is related to G=336 */
/* 382? early first SN looks like it is related to G=340 */
/* 383? early first SN looks like it is related to G=344 */
/* 384? looks like it is related to G=345 */
/* 412? early first SN */
/* 428? late first SN */
/* 429? late first SN */
/* 430? late first SN */
/* 431? late first SN */
/* 437? early first SN */
/* 496? late first SN */
/* 505? early first SN */
/* 522? early first SN */
/* 537? late first SN */
/* 538? late first SN */
/* 539? late first SN */
/* 581? early first SN */
}
return 0;
}
int elgin_prod_year( sn_range_type *s )
{
int i;
static int last_sn = 0;
static int last_i = 0;
int sn_offset;
int sn = s->sn;
if( (sn < 101 && s->letter == '_') || sn < 1 )
{
fprintf( stderr, "%s:%d invalid serial number: %d\n",
__FILE__, __LINE__, sn );
return 0;
}
sn_offset = cvt_sn_letter( s->letter, sn );
if( sn_offset < 0 )
{
if( sn_offset != -2 )
fprintf( stderr, "%s:%d invalid letter serial number: "
"'%c' (%02x)\n",
__FILE__, __LINE__, s->letter, s->letter );
return 0;
}
sn += sn_offset;
/* sn += cvt_sn_grade( s->letter, s->sn, s->grade ); */
if( sn < last_sn )
{
last_sn = 0;
last_i = 0;
}
for( i = last_i; i < array_elem( sn_year ); i++ )
if( sn <= sn_year[i].sn )
{
last_i = i;
last_sn = sn;
return sn_year[i].year - 1;
}
fprintf( stderr, "%s:%d invalid serial number: %d\n",
__FILE__, __LINE__, sn );
return 9999;
}
/*
*****************************************************************************
* WARNING!
*****************************************************************************
*
* These are nasty macros that have all sorts of really bad side effects.
* The alternative is to cut and paste a lot of code, which I think is worse.
*
*/
#define DEFUN_FIND_COUNT_VAR( var, subscript, check ) \
int find_count_in_##var( uchar letter, int sn, \
grade_type *g, sn_range_type *snr, \
first_runs_type *fr ) \
{ \
int tot_in_gr; \
int snr_idx; \
\
check;\
\
snr_idx = fr->prev_snr_idx.var subscript; \
tot_in_gr = fr->prev_tot_in_gr.var subscript; \
if( snr_idx == -1 \
|| snr[ snr_idx ].letter != letter \
|| snr[ snr_idx ].sn > sn \
) \
{ \
tot_in_gr = 0; \
snr_idx = fr->first.var subscript; \
} \
\
do \
{ \
if( snr[ snr_idx ].letter != letter \
|| sn > snr[ snr_idx ].sn + snr[ snr_idx ].cnt ) \
tot_in_gr += snr[ snr_idx ].cnt; \
else \
{ \
fr->prev_tot_in_gr.var subscript = tot_in_gr; \
fr->prev_snr_idx.var subscript = snr_idx; \
\
return tot_in_gr + sn - snr[ snr_idx ].sn + 1; \
} \
\
snr_idx = snr[ snr_idx ].next_##var; \
} \
while( snr_idx != -1 ); \
\
fprintf( stderr, "%s:%d could not find sn %d's count in " #var ".\n", \
__FILE__, __LINE__, sn ); \
\
return -1; \
}
#define DEFUN_FIND_COUNT_VAR_IN_SIZE( var, subscript, check ) \
int find_count_in_##var##_in_size( uchar letter, int sn, \
grade_type *g, sn_range_type *snr, \
first_runs_type *fr ) \
{ \
int tot_in_gr; \
int snr_idx; \
\
check; \
\
snr_idx = fr->prev_snr_idx.var##_in_size[ g->mvt_size - MIN_SIZE ]subscript; \
tot_in_gr = fr->prev_tot_in_gr.var##_in_size[ g->mvt_size - MIN_SIZE ]subscript; \
if( snr_idx == -1 \
|| snr[ snr_idx ].letter != letter \
|| snr[ snr_idx ].sn > sn \
) \
{ \
tot_in_gr = 0; \
snr_idx = fr->first.var##_in_size[ g->mvt_size - MIN_SIZE ]subscript; \
} \
\
do \
{ \
if( snr[ snr_idx ].letter != letter \
|| sn > snr[ snr_idx ].sn + snr[ snr_idx ].cnt ) \
tot_in_gr += snr[ snr_idx ].cnt; \
else \
{ \
fr->prev_tot_in_gr.var##_in_size[ g->mvt_size - MIN_SIZE ]subscript = tot_in_gr; \
fr->prev_snr_idx.var##_in_size[ g->mvt_size - MIN_SIZE ]subscript = snr_idx; \
\
return tot_in_gr + sn - snr[ snr_idx ].sn + 1; \
} \
\
snr_idx = snr[ snr_idx ].next_##var##_in_size; \
} \
while( snr_idx != -1 ); \
\
fprintf( stderr, "%s:%d could not find sn %d's count in " #var ".\n", \
__FILE__, __LINE__, sn ); \
\
return -1; \
}
#define SET_COUNT_VAR( var, subscript, cond ) \
if( fr->first.var subscript == -1 ) \
{ \
if( cond ) \
{ \
g->first_in_##var = TRUE; \
g->flag_notes = TRUE; \
} \
fr->first.var subscript = i; \
pr.first.var subscript = i; \
} else { \
snr[ pr.first.var subscript ].next_##var = i; \
pr.first.var subscript = i; \
}
#define SET_COUNT_VAR_IN_SIZE( var, subscript, cond ) \
if( fr->first.var##_in_size[ size_idx ] subscript == -1 ) \
{ \
if( cond ) \
{ \
g->first_in_##var##_in_size = TRUE; \
g->flag_notes = TRUE; \
} \
fr->first.var##_in_size[ size_idx ] subscript = i; \
pr.first.var##_in_size[ size_idx ] subscript = i; \
} else { \
snr[ pr.first.var##_in_size[ size_idx ] subscript ].next_##var##_in_size = i; \
pr.first.var##_in_size[ size_idx ] subscript = i; \
}
#define CHECK_COUNT_VAR( var, subscript, msg, limit ) \
cnt = find_count_in_##var( s->letter, out_np.min_val[ 0 ], \
g, snr, fr ); \
if( cnt < limit ) \
add_note( ¬e,"%d of %s" msg, cnt, var##_to_str( subscript ) ); \