/* dcwdecode.c This code was extracted from the unpack2.c routine to allow reading data from sequential blocked devices (i.e. tapes). It takes as input a 332-byte packed record and unpacks it. For more information see the header in unpack2.c R6000 Unpack2.c written by Minh Huynh Decode.c code extracted from the above by Greg Ushomirskiy This version of decode was modified by Dan Wilkinson to provide coded swapping routines since the Microsoft Visual C compiler and library didn't support Minh's system routines. To properly swap the NOAA data bytes open file dcwswap.h and follow the instructions for your machine before compiling. */ #include "dcwdecode.h" #include "dcwswap.h" #include #include #include /* #include not found on pc system */ void decode (struct input_rec in_p_,struct archive_rec *rec_) { long int temp; short int s_temp; int i=0, j=0; struct S { long int IHD[9]; float HEAD[23]; long int ISTAT[8]; float HOUS[15]; long int MEPI[2]; long int MEP[4][19]; long int IHEP[2][11]; float TED[4][18]; float TEDFX[4]; long int ISTAT_P[2]; long int Index_MEPI[2]; long int Index_MEP[4][19]; long int Index_IHEP[2][11]; long int Index_TED[4][18]; long int IOPEN; long int IEND; } r_; float c2[] ={ 1057.f, 1121.f, 1185.f, 1249.f, 1313.f, 1377.f, 1441.f, 1505.f, 1569.f, 1633.f, 1697.f, 1761.f, 1825.f, 1889.f, 1953.f, 2017.f, 2113.f, 2241.f, 2369.f, 2497.f, 2625.f, 2753.f, 2881.f, 3009.f, 3137.f, 3265.f, 3393.f, 3521.f, 3649.f, 3777.f, 3905.f, 4033.f, 4225.f, 4481.f, 4737.f, 4993.f, 5249.f, 5505.f, 5761.f, 6017.f, 6273.f, 6529.f, 6785.f, 7041.f, 7297.f, 7553.f, 7809.f, 8065.f, 8449.f, 8961.f, 9473.f, 9985.f, 10497.f, 11009.f, 11521.f, 12033.f, 12545.f, 13057.f, 13569.f, 14081.f, 14593.f, 15105.f, 15617.f, 16129.f, 16897.f, 17921.f, 18945.f, 19969.f, 20993.f, 22017.f, 23041.f, 24065.f, 25089.f, 26113.f, 27137.f, 28161.f, 29185.f, 30209.f, 31233.f, 32257.f, 33793.f, 35841.f, 37889.f, 39937.f, 41985.f, 44033.f, 46081.f, 48129.f, 50177.f, 52225.f, 54273.f, 56321.f, 58369.f, 60417.f, 62465.f, 64513.f, 67584.f, 71680.f, 75776.f, 79872.f, 83968.f, 88064.f, 92160.f, 96256.f, 4.25f, 4.75f, 5.25f, 5.75f, 6.25f, 6.75f, 7.25f, 7.75f, 135168.f,143360.f,151552.f,159744.f,167936.f,176128.f,184320.f,192512.f, 2.125f, 2.375f, 2.625f, 2.875f, 3.125f, 3.375f, 3.625f, 3.875f, 0.0625f, 0.1875f, 0.3125f, 0.4375f, 0.5625f, 0.6875f, 0.8125f, 0.9375f, 1.0625f, 1.1875f, 1.3125f, 1.4375f, 1.5625f, 1.6875f, 1.8125f, 1.9375f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 8.5f, 9.5f, 10.5f, 11.5f, 12.5f, 13.5f, 14.5f, 15.5f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f, 32.f, 34.f, 36.f, 38.f, 40.f, 42.f, 44.f, 46.f, 48.f, 50.f, 52.f, 54.f, 56.f, 58.f, 60.f, 62.f, 64.f, 67.f, 71.f, 75.f, 79.f, 83.f, 87.f, 91.f, 95.f, 99.f, 103.f, 107.f, 111.f, 115.f, 119.f, 123.f, 127.f, 133.f, 141.f, 149.f, 157.f, 165.f, 173.f, 181.f, 189.f, 197.f, 205.f, 213.f, 221.f, 229.f, 237.f, 245.f, 253.f, 265.f, 281.f, 297.f, 313.f, 329.f, 345.f, 361.f, 377.f, 393.f, 409.f, 425.f, 441.f, 457.f, 473.f, 489.f, 505.f, 529.f, 561.f, 593.f, 625.f, 657.f, 689.f, 721.f, 753.f, 785.f, 817.f, 849.f, 881.f, 913.f, 945.f, 977.f, 1009.f}; float ic[]= {1057.f, 1121.f, 1185.f, 1249.f, 1313.f, 1377.f, 1441.f, 1505.f, 1569.f, 1633.f, 1697.f, 1761.f, 1825.f, 1889.f, 1953.f, 2017.f, 2113.f, 2241.f, 2369.f, 2497.f, 2625.f, 2753.f, 2881.f, 3009.f, 3137.f, 3265.f, 3393.f, 3521.f, 3649.f, 3777.f, 3905.f, 4033.f, 4225.f, 4481.f, 4737.f, 4993.f, 5249.f, 5505.f, 5761.f, 6017.f, 6273.f, 6529.f, 6785.f, 7041.f, 7297.f, 7553.f, 7809.f, 8065.f, 8449.f, 8961.f, 9473.f, 9985.f, 10497.f, 11009.f, 11521.f, 12033.f, 12545.f, 13057.f, 13569.f, 14081.f, 14593.f, 15105.f, 15617.f, 16129.f, 16897.f, 17921.f, 18945.f, 19969.f, 20993.f, 22017.f, 23041.f, 24065.f, 25089.f, 26113.f, 27137.f, 28161.f, 29185.f, 30209.f, 31233.f, 32257.f, 33793.f, 35841.f, 37889.f, 39937.f, 41985.f, 44033.f, 46081.f, 48129.f, 50177.f, 52225.f, 54273.f, 56321.f, 58369.f, 60417.f, 62465.f, 64513.f, 67585.f, 71681.f, 75777.f, 79873.f, 83969.f, 88065.f, 92161.f, 96257.f, 100353.f, 104449.f, 108545.f, 112641.f, 116737.f, 120833.f, 124929.f,129025.f, 135169.f, 143361.f, 151553.f, 159745.f, 167937.f, 176129.f, 184321.f, 192513.f, 200705.f, 208897.f, 217089.f, 225281.f, 233473.f, 241665.f, 249857.f, 258049.f, 270337.f,286721.f,303105.f,319489.f,333873.f,352257.f,368641.f,385025.f, 401409.f,417793.f,434177.f,450561.f,466945.f,483329.f,499713.f, 0.f,1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f,10.f,11.f,12.f,13.f,14.f,15.f,16.f,17.f,18.f,19.f,20.f, 21.f,22.f,23.f,24.f,25.f,26.f,27.f,28.f,29.f,30.f,31.f,32.f,34.f,36.f,38.f,40.f,42.f,44.f, 46.f,48.f,50.f,52.f,54.f,56.f,58.f,60.f,62.f,64.f,67.f,71.f,75.f,79.f,83.f,87.f,91.f,95.f, 99.f,103.f,107.f,111.f,115.f,119.f,123.f,127.f,133.f,141.f,149.f,157.f,165.f,173.f, 181.f,189.f,197.f,205.f,213.f,221.f,229.f,237.f,245.f,253.f,265.f,281.f,297.f, 313.f,329.f,345.f,361.f,377.f,393.f,409.f,425.f,441.f,457.f,473.f,489.f,505.f, 529.f,561.f,593.f,625.f,657.f,689.f,721.f,753.f,785.f,817.f,849.f,881.f,913.f, 945.f,977.f,1009.f}; /* -------- Unpack IHD[] into their engineering values ---- */ for (i=0; i<3; i++) { s_temp = (short)r_.IHD[i] = (short)in_p_.IHD[i]; r_.IHD[i] = dcwSwapShort (s_temp); } for (i=3; i<8; i++) { s_temp = (short)r_.IHD[i+1] = (short)in_p_.IHD[i]; r_.IHD[i+1] = dcwSwapShort (s_temp); } r_.IHD[3] = dcwSwapLong(in_p_.IHD_Msec); /* -------- Unpack HEAD[] --------------------------------- */ for (i=0; i<2; i++) { temp = dcwSwapLong (in_p_.JHEAD[i]); r_.HEAD[i] = 0.01f * (float) (temp); } for (i=2; i<6; i++) { temp = dcwSwapLong (in_p_.JHEAD[i]); r_.HEAD[i] = (float) (temp); } temp = dcwSwapLong (in_p_.JHEAD[6]); r_.HEAD[6] = 0.01f * (float) (temp); temp = dcwSwapLong (in_p_.JHEAD[7]); r_.HEAD[7] = 0.01f * (float) (temp); for (i=8; i<12; i++) { temp = dcwSwapLong (in_p_.JHEAD[i]); r_.HEAD[i] = (float) (temp); } for (i=12; i<22; i++){ temp = dcwSwapLong (in_p_.JHEAD[i]); r_.HEAD[i] = 0.01f * (float) (temp); } r_.HEAD[22] = (float) (in_p_.Prog_Ver); /* -------- Unpack ISTAT_P[] ------------------------------ */ for (i=0; i<2; i++) { s_temp = dcwSwapShort (in_p_.ISTAT_P[i]); r_.ISTAT_P[i] = (long) (s_temp); } r_.ISTAT[0]= (r_.ISTAT_P[0] & 0x80) >> 7; r_.ISTAT[1]= (r_.ISTAT_P[0] & 0x40) >> 6; r_.ISTAT[2]= (r_.ISTAT_P[0] & 0x20) >> 5; r_.ISTAT[3]= (r_.ISTAT_P[0] & 0x10) >> 4; r_.ISTAT[4]= (r_.ISTAT_P[0] & 0x08) >> 3; r_.ISTAT[5]= (r_.ISTAT_P[0] & 0x6) >> 1; r_.ISTAT[6]= (r_.ISTAT_P[0] & 0x1); r_.ISTAT[7]=r_.ISTAT_P[1] & 0xFF; /* -------- Unpack HOUS[] --------------------------------- */ for (i=0; i<4; i++) { s_temp = dcwSwapShort (in_p_.JHOUS[i]); r_.HOUS[i] = ((float) (s_temp)) / 10.0f; } s_temp = dcwSwapShort (in_p_.JHOUS[4]); r_.HOUS[4] = (float) (s_temp); for (i=5; i<7; i++) { s_temp = dcwSwapShort (in_p_.JHOUS[i]); r_.HOUS[i] = ((float) (s_temp)) / 10.0f; } s_temp = dcwSwapShort (in_p_.JHOUS[7]); r_.HOUS[7] = ((float) (s_temp)) / 100.0f; for (i=8; i<12; i++) { s_temp = dcwSwapShort (in_p_.JHOUS[i]); r_.HOUS[i] = (float) (s_temp); } s_temp = dcwSwapShort (in_p_.JHOUS[12]); r_.HOUS[12] = ((float) (s_temp)) / 100.0f; for (i=13; i<15; i++) { s_temp = dcwSwapShort (in_p_.JHOUS[i]); r_.HOUS[i] = ((float) (s_temp)) / 10.0f; } /* -------- Unpack MEPI[] --------------------------------- */ for (i=0; i<2; i++) r_.MEPI[i] = (long) (ic[ (in_p_.Index_MEPI[i]) ]); /* -------- Unpack MEP[][] -------------------------------- */ for (i=0; i<4; i++) { for (j=0; j<19; j++) { r_.MEP[i][j] = (long) (ic[ (in_p_.Index_MEP[i][j]) ]); } } /* -------- Unpack IHEP[][] ------------------------------- */ for (i=0; i<2; i++) { for (j=0; j<11; j++) { r_.IHEP[i][j] = (long) (ic[ (in_p_.Index_IHEP[i][j]) ]); } } /* -------- Unpack TED[][] --------------------------------- */ for (i=0; i<4; i++) { for (j=0; j<5; j++) { r_.TED[i][j] = ic[ (in_p_.Index_TED[i][j]) ]; } r_.TED[i][5] = (float) (in_p_.Index_TED[i][5]); for (j=6; j<18; j=j+3) { r_.TED[i][j] = c2[ (in_p_.Index_TED[i][j]) ]; r_.TED[i][j+1] = ic[ (in_p_.Index_TED[i][j+1]) ]; r_.TED[i][j+2] = (float) (in_p_.Index_TED[i][j+2]); } /* -------- Unpack TEDFX[] --------------------------------- */ temp = dcwSwapLong (in_p_.JTEDFX[i]); r_.TEDFX[i] = ((float) (temp)) / 1000.0f; } /* End of for i=0;i<4 loop */ /* copy data to archive record which users are expecting --- */ for (i=0;i<9;i++) rec_->IHD[i] = r_.IHD[i]; for (i=0;i<23;i++) rec_->HEAD[i] = r_.HEAD[i]; for (i=0;i<8;i++) rec_->ISTAT[i] = r_.ISTAT[i]; for (i=0;i<15;i++) rec_->HOUS[i] = r_.HOUS[i]; for (i=0;i<2;i++) rec_->MEPI[i] = r_.MEPI[i]; for (i=0;i<4;i++) { for (j=0;j<19;j++) { rec_->MEP[i][j] = r_.MEP[i][j]; } } for (i=0;i<2;i++) { for (j=0;j<11;j++) { rec_->IHEP[i][j] = r_.IHEP[i][j]; } } for (i=0;i<4;i++) { for (j=0;j<18;j++) { rec_->TED[i][j] = r_.TED[i][j]; } } for (i=0;i<4;i++) rec_->TEDFX[i] = r_.TEDFX[i]; /* ---------- END ------------------------------------------ */ }