-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwodtodepthmatrix_FINAL.c
1547 lines (1043 loc) · 41 KB
/
wodtodepthmatrix_FINAL.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/***********************************************************
DEFINED CONSTANTS
MAXTAX: MAXIMUM NUMBER OF TAXA DELIMITORS IN A TAXA SET
MAXSEC: MAXIMUM NUMBER OF SECONDARY HEADERS
MAXBIO MAXIMUM NUMBER OF BIOLOGICAL HEADERS
MAXPARM: MAXIMUM NUMBER OF MEASURED AND/OR CALCULATED VARIABLES
MAXSECP: MAXIMUM NUMBER OF VARIABLE SPECIFIC SECONDARY HEADERS
IDIM: LONGITUDE DIMENSIONS
JDIM: LATITUDE DIMENSIONS
KDIM: STANDARD DEPTH LEVELS
************************************************************/
#define maxtax 30
#define maxsec 100
#define maxbio 50
#define maxparm 100
#define maxpsec 25 * maxparm
#define idim 360
#define jdim 180
#define kdim 102
#define kdimax 137
#define maxchoice 8
/**********************************************************
*FP - WOD DATA FILE TO BE OPENED FOR READING
*FPOUT - FILE TO BE OPENED FOR WRITING OUTPUT
*FPLIST - FILE WITH LIST OF WOA FILES TO READ
*FPWOA - WOA FILES TO READ IN
***********************************************************/
FILE *fp,*fpout,*fplist, *fpwoa;
/**********************************************************
HEADER INFORMATION FOR EACH CAST
CC - COUNTRY CODE OF COUNTRY RESPONSIBLE FOR TAKING DATA AT CAST
ICRUISE - NODC/WOD ASSIGNED CRUISE NUMBER (UNIQUE WITH COUNTRY CODE)
OCAST - WOD UNIQUE CAST NUMBER
YEAR, MONTH, DAY, HOUR - TIME AND DATA OF CAST
LATITUDE, LONGITUDE - POSITION OF CAST
LEVELS - NUMBER OF DEPTH LEVELS MEASURED AT CAST
ISOOR - SET TO ZERO FOR OBSERVED LEVEL DATA, ONE FOR STANDARD LEVEL
IP2 - VARIABLE CODES FOR VARIABLES MEASURED AT CAST
IPERROR - ERROR FLAGS FOR EACH VARIABLE MEASURED AT CAST
HTOTFIG - TOTAL NUMBER OF FIGURES FOR 1: HOUR, 2: LATITUDE, 3: LONGITUDE
HSIGFIG - NUMBER SIGNIFICANT FIGURES FOR 1: HOUR, 2: LATITUDE, 3: LONGITUDE
HTOTFIG - NUMBER OF FIGURES TO THE RIGHT OF THE DECIMAL FOR
1: HOUR, 2: LATITUDE, 3: LONGITUDE
**************************************************************/
char cc[2];
int icruise=0, ostation=0, year=0, month=0, day=0;
int hour,longitude,latitude;
int levels,isoor,nparm,ip2[maxparm],iperror[maxparm];
int htotfig[3],hsigfig[3],hrightfig[3];
/*************************************************************
CHARACTER AND PRIMARY INVESTIGATOR DATA
ORIGCFIG - NUMBER OF CHARACTERS IN ORIGINATORS CRUISE CODE
(ZERO IF NOT GIVEN)
ORIGC - ORIGINATORS CRUISE CODE
ORIGSFIG - NUMBER OF CHARACTERS IN ORIGINATORS STATION CODE
(ZERO IF NOT GIVEN)
ORIGS - ORIGINATORS STATION CODE
NPI - NUMBER OF PRIMARY INVESTIGATORS
IPIP - VARIABLE FOR PRIMARY INVESTIGATOR
IPI - PRIMARY INVESTIGATORY
*****************************************************************/
int origcfig,origsfig;
char origc[30],origs[30];
int ipip[maxparm],ipi[maxparm],npi;
/*************************************************************
SECONDARY HEADER INFORMATION
NSEC - NUMBER OF SECONDARY HEADERS
STOTFIG - TOTAL FIGURES FOR EACH SECONDARY HEADER
SSIGFIG - NUMBER OF SIGNIFICANT FIGURES FOR EACH SECONDARY HEADER
SRIGHTFIG - NUMBER OF FIGURES RIGHT OF DECIMAL FOR EACH SECONDARY HEADER
SECCODE - SECONDARY HEADER CODE
SECVAL - SECONDARY HEADER VALUE
**************************************************************/
int nsec;
int stotfig[maxsec],ssigfig[maxsec],srightfig[maxsec];
int seccode[maxsec],secval[maxsec];
/*************************************************************
VARIABLE SPECIFIC SECONDARY HEADER INFORMATION
NPSEC - NUMBER OF VARIABLE SPECIFIC SECONDARY HEADERS
PSTOTFIG - TOTAL FIGURES FOR EACH VARIABLE SPECIFIC SECONDARY HEADER
PSSIGFIG - NUMBER OF SIGNIFICANT FIGURES FOR EACH VARIABLE
SPECIFIC SECONDARY HEADER
PSRIGHTFIG - NUMBER OF FIGURES RIGHT OF DECIMAL FOR EACH VARIABLE
SPECIFIC SECONDARY HEADER
PSECPARM - VALUE OF VARIABLE SPECIFIC SECONDARY HEADER
PSECCODE - VARIABLE SPECIFIC SECONDARY HEADER CODE
PSECVAL - VARIABLE SPECIFIC SECONDARY HEADER VALUE
**************************************************************/
int npsec;
int pstotfig[maxpsec],pssigfig[maxpsec],psrightfig[maxpsec];
int psecparm[maxpsec],pseccode[maxpsec],psecval[maxpsec];
/*************************************************************
BIOLOGICAL HEADER INFORMATION
NBIO - NUMBER OF BIOLOGICAL HEADERS
BTOTFIG - TOTAL FIGURES FOR EACH BIOLOGICAL HEADER
BSIGFIG - NUMBER OF SIGNIFICANT FIGURES FOR EACH BIOLOGICAL HEADER
BRIGHTFIG - NUMBER OF FIGURES RIGHT OF DECIMAL FOR EACH BIOLOGICAL HEADER
BIOCODE - BIOLOGICAL HEADER CODE
BIOVAL - BIOLOGICAL HEADER VALUE
**************************************************************/
int nbio;
int btotfig[maxbio],bsigfig[maxbio],brightfig[maxbio];
int biocode[maxbio],bioval[maxbio];
/*************************************************************
TAXA SET INFORMATION
NTSETS - NUMBER OF TAXA SETS AT CAST
NTLOC - NUMBER OF DELIMITORS FOR EACH TAXA SET
NTCODE - TAXA CODE FOR EACH TAXA VARIABLE
NTVAL - VALUE FOR EACH TAXA CODE
NTERR - ERROR FLAG FOR EACH TAXA VALUE
NTOERR - ORIGINATORS FLAG FOR EACH TAXA VALUE
NTTOTFIG - TOTAL FIGURES FOR EACH TAXA VALUE
NTSIGFIG - NUMBER OF SIGNIFICANT FIGURES FOR EACH TAXA VALUE
NTRIGHTFIG - NUMBER OF FIGURES RIGHT OF THE DECIMAL FOR EACH TAXA VALUE
***************************************************************/
int ntsets;
int *ntloc,*ntcode,*ntval,*nterr,*ntoerr,*nttotfig,*ntsigfig,*ntrightfig;
/*************************************************************
DEPTH INFORMATION
DEPTH - DEPTH AT EACH DEPTH LEVEL
ZERR - DEPTH ERROR FLAG
ZOERR - DEPTH ORIGINATORS FLAG
ZTOTFIG - TOTAL FIGURES FOR EACH DEPTH VALUE
ZSIGFIG - NUMBER OF SIGNIFICANT FIGURES FOR EACH DEPTH
ZRIGHTFIG - NUMBER OF FIGURES RIGHT OF THE DECIMAL FOR EACH DEPTH
***************************************************************/
int *depth,*zerr,*zoerr,*ztotfig,*zsigfig,*zrightfig;
/*************************************************************
MEASURED VARIABLE INFORMATION
NVARS - MAXIMUM NUMBER OF VARIABLES
DVAL - DATA VALUE AT EACH DEPTH LEVEL
DERR - ERROR FLAG FOR EACH VARIABLE AT EACH LEVEL
DOERR - ORIGINATORS FLAG FOR EACH VARIABLE AT EACH LEVEL
DTOTFIG - TOTAL FIGURES FOR EACH DATA VALUE
DSIGFIG - NUMBER OF SIGNIFICANT FIGURES FOR EACH DATA VALUE
DRIGHTFIG - NUMBER OF FIGURES RIGHT OF THE DECIMAL FOR EACH DATA VALUE
***************************************************************/
int nvars=43;
int *dataval,*derr,*doerr,*dtotfig,*dsigfig,*drightfig;
/*************************************************************
SIZE DELIMITORS
ISIZE - PRESENT ARRAY SIZE NEEDED TO FIT ALL MEASURED VARIABLES
ZSIZE - PRESENT ARRAY SIZE NEEDED TO FIT ALL DEPTHS
NTSETSMAX - MAXIMUM NUMBER OF TAXA SETS
ISIZEMAX - MAXIMUM ARRAY SIZE YET ENCOUNTERED FOR MEASURED VARIABLES
ZSIZEMAX - MAXIMUM ARRAY SIZE YET ENCOUNTERED FOR DEPTHS
/*************************************************************/
int isize,zsize;
int ntsetsmax=0, isizemax=0,zsizemax=0;
/*************************************************************
USER SET VARIABLES
XCHOICE - CHOICE OF DEPTH SLICES
XINTERV1,XINTERV2 - SHALLOWEST/DEEPEST DEPTHS REQUESTED
*************************************************************/
char xchoice[2];
float xinterv1,xinterv2;
/*************************************************************
INTERNAL ARRAYS
TENP - POWERS OF TEN
SDEPTH - STANDARD DEPTH LEVELS
*************************************************************/
double tenp[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000 };
int sdepth[] = { 0, 5 , 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70,
75, 80, 85, 90, 95, 100, 125, 150, 175, 200, 225, 250,
275, 300, 325, 350, 375, 400,425, 450, 475, 500, 550,
600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100,
1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 1550, 1600,
1650, 1700, 1750, 1800, 1850, 1900, 1950, 2000, 2100,
2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100,
3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000,
4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900,
5000, 5100, 5200, 5300, 5400, 5500, 5600, 5700, 5800, 5900,
6000, 6100, 6200, 6300, 6400, 6500, 6600, 6700, 6800, 6900,
7000, 7100, 7200, 7300, 7400, 7500, 7600, 7700, 7800, 7900,
8000, 8100, 8200, 8300, 8400, 8500, 8600, 8700, 8800, 8900,
9000 };
char *namevar[] = { "Temp","Sal","Oxy","Phos","dum5","Sil","dum7",
"NO3","pH","dum10","Chl","dum12","dum13","dum14",
"dum15","dum16","Alk","dum18","dum19","pCO2",
"DIC","dum22","dum23","BAC","dum25","dum26",
"dum27","dum28","dum29","dum30","dum31","dum32",
"Trit","He","dHE3","dC14","dC13","Arg","Neo","CFC11",
"CFC12","CFC113","O18" };
main(int argc, char **argv)
{
char filename[80];
int i=0, j, k, s, jchoice, iend=0;
int ncast=0,dchoice;
// printf(" Enter input file name\n");
// scanf("%s",filename);
strcpy(filename, argv[1]);
if ((fp = fopen(filename,"rb+\0")) == NULL)
printf("UNABLE TO OPEN FILE\n");
else {
// printf( "Which variable would you like to see:\n");
// printf( " 0 - All\n");
// printf( " 1 - Temperature\n");
// printf( " 2 - Salinity\n");
// printf( " 3 - Oxygen\n");
// printf( " 4 - Phosphate\n");
// printf( " 6 - Silicate\n");
// printf( " 8 - Nitrate\n");
// printf( "11 - Chlorophyll\n");
// printf( "17 - Alkalinity\n");
// printf( "20 - pCO2\n");
// printf( "21 - tCO2\n");
// printf( "24 - BAC\n");
// printf( "33 - Tritium\n");
// printf( "34 - Helium\n");
// printf( "35 - deltaHE3\n");
// printf( "36 - deltaC14\n");
// printf( "37 - deltaC13\n");
// printf( "38 - Argon\n");
// printf( "39 - Neon\n");
// printf( "40 - CFC11\n");
// printf( "41 - CFC12\n");
// printf( "42 - CFC113\n");
// printf( "43 - Oxy18\n");
// scanf("%d",&jchoice);
jchoice = 0;
// printf( "Which depths would you like output:\n");
// printf( " A - All\n");
// printf( " S - Surface [Shallowest measurement only]\n");
// printf( " B - Bottom [Deepest measurement only]\n");
// printf( " I - Interval [measurements only between min/max depth]\n");
// scanf("%s",xchoice);
strcpy(xchoice, "A");
if ( *xchoice == 'I' ) {
printf("Enter shallowest depth\n");
scanf("%f",&xinterv1);
printf("Enter deepest depth\n");
scanf("%f",&xinterv2);
}
/********************************************************
INITIALIZE DYNAMIC ARRAYS
*********************************************************/
spacer(1);
/* GET USER INFORMATION (NUMBER OF CASTS, OUTPUT FILE NAME) */
// printf(" Enter output file name\n");
// scanf("%s",filename);
strcat(filename,".csv");
if ((fpout = fopen(filename,"w\0")) == NULL) {
printf("UNABLE TO OPEN FILE\n");
}
// printf(" ENTER NUMBER OF CASTS TO VIEW");
// printf (" (0 FOR ALL CASTS IN FILE)\n");
// if ( (s = scanf("%d",&ncast)) == 0 ) ncast=0;
ncast = 0;
if ( ncast == 0 ) ncast=100000000;
printheader(jchoice);
while ( !feof(fp) && iend != -1 && (i++) < ncast ) {
/********************************************************
READ IN CAST
**********************************************************/
if ( ( iend = oclread() ) == -1 ) printf(" END OF FILE REACHED\n");
else printstation(i,jchoice);
}
i = fclose(fp);
i = fclose(fpout);
printf("iii %d\n",i);
}
}
oclread()
{
int i,j;
char wodform;
int totfig=0, sigfig=0, rightfig=0;
int nbytet,ntypec,nbytec,nbytes,nbyteb;
int ninfc,ntoff, doff;
int missing=-9999;
int npinfs=0,npinfe=0,npinf;
int iend=0;
/**********************************************************
READ IN WOD FORMAT CODE: 'C' FOR WOD13 FORMAT
'B' FOR WOD05/WOD09 FORMAT
'A' FOR WOD01 FORMAT
***********************************************************/
totfig= 1;
if ( (iend = extractc(0,&totfig,&wodform)) == -1 ) return iend;
if ( wodform != 'C' ) {
printf("file is not in WOD13 format\n");
printf("csvfromwod cannot translate data\n");
return -1;
}
/**********************************************************
READ IN NUMBER OF BYTES IN ASCII CAST
***********************************************************/
if ( ( iend = extracti(0,&totfig,&sigfig,&rightfig,&nbytet,missing))
== -1 ) return iend;
/**********************************************************
READ IN WOD CAST NUMBER
***********************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&ostation,missing))
== -1 ) return iend;
/*********************************************************
READ IN NODC COUNTRY CODE
**********************************************************/
totfig= 2;
if ( (iend = extractc(0,&totfig,cc)) == -1 ) return iend;
/**********************************************************
READ IN CRUISE NUMBER
***********************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&icruise,
missing)) == -1) return iend;
/**********************************************************
READ IN YEAR, MONTH, DAY, TIME
***********************************************************/
totfig=4;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&year,missing))
== -1) return iend;
totfig=2;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&month,missing))
== -1) return iend;
totfig=2;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&day,missing))
== -1) return iend;
if ( (iend = extracti(1,htotfig,hsigfig,hrightfig,
&hour, 9999)) == -1) return iend;
/**********************************************************
READ IN LATITUDE AND LONGITUDE
***********************************************************/
if ( (iend = extracti(1,(htotfig+1),(hsigfig+1),(hrightfig+1),
&latitude, -9999)) == -1) return iend;
if ( (iend = extracti(1,(htotfig+2),(hsigfig+2),(hrightfig+2),
&longitude, -99999)) == -1) return iend;
/**********************************************************
READ IN NUMBER OF LEVELS
***********************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&levels,
missing)) == -1) return iend;
/**********************************************************
READ IN OBSERVED (0) OR STANDARD (1) LEVELS
***********************************************************/
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&isoor,missing))
== -1) return iend;
/**********************************************************
READ IN NUMBER OF VARIABLES AT THIS CAST (NOT INCLUDING
BIOLOGY)
***********************************************************/
totfig=2;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&nparm,missing))
== -1) return iend;
/**********************************************************
READ IN EACH VARIABLE CODE AND PROFILE ERROR CODE
***********************************************************/
for ( i =0; i< nparm; i++ ) {
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(ip2+i),
missing)) == -1) return iend;
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(iperror+i),
missing)) == -1) return iend;
/*******************************************************************
READ NUMBER OF VARIABLE SPECIFIC SECOND HEADER VARIABLES
********************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&npinf,missing))
== -1 ) return iend;
npinfe += npinf;
/*******************************************************************
READ IN EACH VARIABLE SPECIFIC SECOND HEADER VARIABLE
********************************************************************/
for ( j = npinfs; j < npinfe; j++ ) {
*(psecparm+j) = *(ip2+i);
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(pseccode+j),
missing)) == -1) return iend;
if ( (iend = extracti(1,(pstotfig+j),(pssigfig+j),(psrightfig+j),
(psecval+j), missing)) == -1) return iend;
}
npinfs += npinf;
}
npsec = npinfe;
/***************************************************************
READ IN NUMBER OF BYTES IN CHARACTER AND PRIMARY INVESTIGATOR FIELDS
****************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&nbytec,
missing)) == -1) return iend;
/**********************************************************
READ IN NUMBER OF INFORMATION TYPES (MAX 3: FOR CRUISE CODE,
STATION CODE AND PI INFORMATION)
***********************************************************/
origcfig= 0;
origsfig= 0;
npi= 0;
if ( nbytec > 0 ) {
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&ninfc,missing))
== -1) return iend;
/**********************************************************
READ IN TYPE OF INFORMATION : 1= CRUISE CODE,
2=STATION CODE AND 3=PI INFORMATION)
***********************************************************/
for ( i= 0; i < ninfc; i++) {
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&ntypec,missing))
== -1) return iend;
/***********************************************************
READ IN ORIGINATORS CRUISE CODE
************************************************************/
if ( ntypec == 1) {
totfig=2;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&origcfig,
missing)) == -1) return iend;
if ( (iend = extractc(0,&origcfig,origc)) == -1 ) return iend;
}
/***********************************************************
READ IN ORIGINATORS STATION CODE
************************************************************/
else if ( ntypec == 2 ) {
totfig=2;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&origsfig,
missing)) == -1) return iend;
if ( (iend = extractc(0,&origsfig,origs)) == -1 ) return iend;
}
/***********************************************************
READ IN PRIMARY INVESTIGATOR INFORMATION
************************************************************/
else if ( ntypec == 3 ) {
/**********************************************************
READ IN NUMBER OF PRIMARY INVESTIGATORS FOR THIS CAST
***********************************************************/
totfig=2;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,&npi,missing))
== -1) return iend;
/**********************************************************
READ IN EACH VARIABLE CODE AND PRIMARY INVESTIGATOR CODE
FOR THAT VARIABLE
***********************************************************/
for ( j =0; j< npi; j++ ) {
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(ipip+j),
missing)) == -1) return iend;
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(ipi+j),
missing)) == -1) return iend;
}
}
}
}
/***************************************************************
READ IN NUMBER OF BYTES IN SECONDARY HEADER FIELDS
****************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&nbytes,
missing)) == -1) return iend;
nsec = 0;
if ( nbytes > 0 ) {
/**************************************************************
READ IN NUMBER OF SECONDARY HEADER VARIABLES
***************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&nsec,
missing)) == -1) return iend;
/**********************************************************
READ IN EACH SECONDARY HEADER VARIABLE CODE AND VALUE
***********************************************************/
for ( i =0; i< nsec; i++ ) {
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(seccode+i),
missing)) == -1) return iend;
if ( (iend = extracti(1,(stotfig+i),(ssigfig+i),(srightfig+i),
(secval+i), missing)) == -1) return iend;
}
}
/***************************************************************
READ IN NUMBER OF BYTES IN BIOLOGY HEADER AND TAXA SET FIELDS
****************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&nbyteb,
missing)) == -1) return iend;
nbio= 0;
ntsets= 0;
if ( nbyteb > 0 ) {
/**************************************************************
READ IN NUMBER OF BIOLOGY HEADER VARIABLES
***************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&nbio,
missing)) == -1) return iend;
/**********************************************************
READ IN EACH BIOLOGY HEADER VARIABLE CODE AND VALUE
***********************************************************/
for ( i =0; i< nbio; i++ ) {
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(biocode+i),
missing)) == -1) return iend;
if ( (iend = extracti(1,(btotfig+i),(bsigfig+i),(brightfig+i),
(bioval+i), missing)) == -1) return iend;
}
/***************************************************************
READ IN NUMBER OF TAXA SETS
****************************************************************/
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,&ntsets,
missing)) == -1) return iend;
/***************************************************************
IF NUMBER OF TAXA SETS IS GREATER THAN THE PREVIOUS MAXIMUM,
REALLOCATE SPACE ACCORDINGLY
****************************************************************/
if ( ntsets > ntsetsmax ) {
ntsetsmax= ntsets;
spacer(2);
}
if ( ntsets > 0 ) {
/**************************************************************
READ IN NUMBER OF ENTRIES FOR THIS TAXA SET, CALCULATE OFFSET
FOR READING IN DATA
***************************************************************/
for ( j = 0; j < ntsets; j++) {
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(ntloc+j),
missing)) == -1) return iend;
ntoff= maxtax * j;
/**********************************************************
READ IN EACH TAXA SET VARIABLE CODE AND VALUE,
ERROR FLAG AND ORIGINATORS FLAG
***********************************************************/
for ( i =0; i< *(ntloc+j); i++ ) {
if ( (iend = extracti(0,&totfig,&sigfig,&rightfig,(ntcode+ntoff+i),
missing)) == -1) return iend;
if ( (iend = extracti(1,(nttotfig+ntoff+i),(ntsigfig+ntoff+i),
(ntrightfig+ntoff+i), (ntval+ntoff+i), missing))
== -1) return iend;
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(nterr+ntoff+i),
missing)) == -1) return iend;
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(ntoerr+ntoff+i),
missing)) == -1) return iend;
}
}
}
}
/***************************************************************
IF NUMBER OF DEPTHS IS GREATER THAN THE PREVIOUS MAXIMUM,
REALLOCATE SPACE ACCORDINGLY
****************************************************************/
zsize= levels;
if ( zsize > zsizemax ) {
zsizemax=zsize;
spacer(3);
}
/***************************************************************
IF NUMBER OF DEPTHS MULTIPLIED BY NUMBER OF VARIABLES IS
GREATER THAN THE PREVIOUS MAXIMUM, REALLOCATE SPACE ACCORDINGLY
****************************************************************/
isize= nparm * levels;
if ( isize > isizemax ) {
isizemax=isize;
spacer(4);
}
/**********************************************************
READ IN EACH DEPTH VALUE, ERROR FLAG, AND ORIGINATORS FLAG
***********************************************************/
for ( j = 0; j < levels; j++ ) {
if ( isoor == 0 || wodform == 'C' ) {
if ( (iend = extracti(1,(ztotfig+j),(zsigfig+j),
(zrightfig+j), (depth+j), missing))
== -1) return iend;
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(zerr+j),
missing)) == -1) return iend;
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(zoerr+j),
missing)) == -1) return iend;
}
/**********************************************************
READ IN EACH DATA VALUE
***********************************************************/
for ( i =0; i< nparm; i++ ) {
doff= i * levels;
if ( (iend = extracti(1,(dtotfig+doff+j),(dsigfig+doff+j),
(drightfig+doff+j), (dataval+doff+j), missing))
== -1) return iend;
if ( *(dtotfig+doff+j) > 0 ) {
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(derr+doff+j),
missing)) == -1) return iend;
totfig=1;
if ( (iend = extracti(2,&totfig,&sigfig,&rightfig,(doerr+doff+j),
missing)) == -1) return iend;
}
else {
*(derr+doff+j)=0;
*(doerr+doff+j)=0;
*(drightfig+doff+j)=2;
}
}
}
/***********************************************************
READ TO END OF CAST
************************************************************/
while ( ( i = fgetc(fp)) != '\n' && !feof(fp) );
return iend;
}
/***************************************************************
FUNCTION PRINTHEAD
PRINTHEAD PRINTS OUT FILE HEADER
***************************************************************/
printheader( int jchoice )
{
int k;
fprintf(fpout,"ISO_country,Cruise_ID,Latitude,Longitude,Year,Month,Day,");
fprintf(fpout,"Time,WOD_unique,depth(m),qc_flag");
if ( jchoice != 0 )
fprintf(fpout,",%s,qc_flag\n",namevar[jchoice-1]);
else
{
for ( k = 0; k < nvars; k++ ) {
fprintf(fpout,",%s,qc_flag",namevar[k]);
}
fprintf(fpout,"\n");
}
}
/***************************************************************
FUNCTION PRINTSTATION
PRINTSTATION PRINTS CAST TO THE SCREEN
***************************************************************/
printstation(int i, int jchoice)
{
int ii, ij, j, k, k0, offs,hastmp, yright,yall,zright;
int lat,lon,itseas, ixa, inbp;
int iwritten=0, k2,loopvars,j0;
int xright[maxparm],xall[maxparm];
float x[maxparm];
int ichoice[maxchoice],ilevelwrite;
int kblock= idim * jdim, iblock= kdim * kblock;
float xlon, xlat, xhour, y, z, xa, spaced=1.+1.E-07;
ichoice[0]=1;
ichoice[1]=2;
ichoice[2]=3;
ichoice[3]=4;
ichoice[4]=6;
ichoice[5]=8;
ichoice[6]=9;
ichoice[7]=17;
/***************************************************************
PRINT OUT HEADER
****************************************************************/
xhour= (hour/ tenp[ *(hrightfig) ]);
xlat= (latitude/ tenp[ *(hrightfig+1) ]);
xlon= (longitude/ tenp[ *(hrightfig+2) ]);
lat= ((xlat + 90.)/spaced)+1.;
if ( xlon < 0. ) lon=((xlon+360.)/spaced)+1.;
else lon=(xlon/spaced)+1.;
itseas=((month-1)/3)+13;
if ( levels > 0 ) {
if ( jchoice > 0 ) {
hastmp=-1;
loopvars=0;
for ( j = 0; j < nparm; j++ ) {
if ( *(ip2+ j) == jchoice ) hastmp=j;
}
}
else {
hastmp=0;
loopvars=nvars-1;
}
if ( hastmp > -1 ) {
ilevelwrite=0;
for ( k0 = 0; k0 < levels; k0++ ) {
k=k0;
if ( *xchoice == 'B' ) k= (levels - k0 - 1 );
iwritten=1;
if ( jchoice > 0 ) {
iwritten=0;
offs=hastmp * levels;
if ( *(dsigfig+offs+k) > 0 ) iwritten=1;
}
zright = *(zrightfig+k);