/* cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc Name : readump_nmc_data.c Usage : This program reads UARS NMC level 3 data files distributed from the GSFC DAAC. To run this program, type the program name followed by the metadata file name (*META extension). Example: readump_nmc_data CORR_ZNMC_STEMP_D0090.V0001_C01_META Description : This program first opens the metadata file (*.*META) to get the data file name (*.*PROD), and its physical record size. The data file is then opened, and its contents are read and dumped to the screen. Author : KE - JUN SUN Hughes_STX Date : February 2, 1994 Limitations : This program and the data it reads are designed for machines running a UNIX operating system, and having 32-bit architecture. IEEE floating point and/or integer values will not translate correctly on other machines! Notes : Since this program uses the metadata file (*.*META) to get the data file name (*.*PROD) and record size, both the data file and its corresponding metadata file must be in the same directory. Algorithm information : No calculation is performed in this program. Version : 0 To compile this progam : cc readump_nmc_data.c -o readump_nmc_data -lm executable code will be named readump_nmc_data ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc */ #include #include #include main(argc,argv) int argc; char *argv[]; { char buffer[30000]; char csfdu[90],cuarsh[300],corpar[50],blnk[17000]; char *prname; int data_type,sftype,yr,mn,day,hr,hemisp; int nrdata,numrec,irdata,numlat,numlon,i,j,*int4; float sfval,grid[65][65]; float prslvl, xlat0,xlon0,xltint,xlnint,*float4; char temp[50],*fname,type[4],cmt[81]; char str[80],data_file[180]; FILE *meta_ifp,*data_ifp; int rec_size,numb_par,index,n,j1,j2,ret; int col,row; float xi,xj; float nlatgrid[65][65],nlongrid[65][65]; float slatgrid[65][65],slongrid[65][65]; void w3fb05(); /* Open Meta data file first */ meta_ifp = fopen(argv[1],"r"); if (meta_ifp == NULL) { printf(" Can not open meta data file:%s \n",argv[1]); exit(); } for(i=0;i<10;i++) fgets(buffer,80,meta_ifp); /* get data file name from line 10 or from meta data file name */ strncpy(data_file,argv[1],(strlen(argv[1])-5)); strcat(data_file,"_PROD"); fgets(buffer,80,meta_ifp); fgets(buffer,80,meta_ifp); /* get record size from meta file */ strncpy(temp,&buffer[16],5); rec_size = atoi(temp); fclose(meta_ifp); data_ifp = fopen(data_file,"r"); /* open data file */ if (data_ifp == NULL) { printf(" Can not open data file %s\n",data_file); exit(0); } /* fill northern/southern lat/lon 65 by 65 grid */ for( row = -32;row < 33 ; row ++) { xj = (float)(row); for(col = -32;col < 33 ; col ++) { xi =(float)(col); w3fb05(xi,xj,381.0,80.0,&nlatgrid[row+32][col+32], &nlongrid[row+32][col+32]); if (nlongrid[row+32][col+32] >= 180.0) nlongrid[row+32][col+32] = 360.0 - nlongrid[row+32][col+32]; else nlongrid[row+32][col+32] = -nlongrid[row+32][col+32]; w3fb05(xi,xj,-381.0,260.0,&slatgrid[row+32][col+32], &slongrid[row+32][col+32]); if (slongrid[row+32][col+32] >= 180.0) slongrid[row+32][col+32] = 360.0 - slongrid[row+32][col+32]; else slongrid[row+32][col+32] = -slongrid[row+32][col+32]; } } printf("DATA WILL BE READ FROM CORRELATIVE FILE : \n"); printf("%s\n\n",data_file); printf(" ------------------------- \n"); printf(" SFDU INFORMATION FOR FILE \n"); printf(" ------------------------- \n"); memset(temp,' ',25); fread(csfdu,1,88,data_ifp); /* csfdu */ strncpy(temp,&csfdu[0],12); printf(" Tz_Field : %s\n",temp); memset(temp,' ',12); strncpy(temp,&csfdu[12],8); printf(" Lz_Field : %s\n",temp); strncpy(temp,&csfdu[20],12); printf(" Ti_Field : %s\n",temp); memset(temp,' ',12); strncpy(temp,&csfdu[32],8); printf(" Li_Field : %s\n",temp); strncpy(temp,&csfdu[40],48); printf(" Vi_Field : %s\n\n",temp); memset(temp,' ',49); printf(" -------------------------------- \n"); printf(" UARS HEADER INFORMATION FOR FILE \n"); printf(" -------------------------------- \n"); fread(cuarsh,1,292,data_ifp); /* cuarsh */ strncpy(temp,&cuarsh[0],4); printf(" Project_name : %s\n",temp); strncpy(temp,&cuarsh[4],20); printf(" UARS_PI : %s\n",temp); strncpy(temp,&cuarsh[24],20); printf(" UARS_CMI : %s\n",temp); memset(temp,' ',35); strncpy(temp,&cuarsh[44],8); printf(" Corr_Data_Class : %s\n",temp); strncpy(temp,&cuarsh[52],12); printf(" Instrument_Type : %s\n",temp); strncpy(temp,&cuarsh[64],12); printf(" Obs_Station_Id : %s\n",temp); strncpy(temp,&cuarsh[76],12); printf(" Corr_Data_FT_ID : %s\n",temp); strncpy(temp,&cuarsh[88],23); printf(" File_Start_Time : %s\n",temp); strncpy(temp,&cuarsh[111],23); printf(" File_Stop_Time : %s\n",temp); memset(temp,' ',35); strncpy(temp,&cuarsh[134],7); printf(" Maximum_Lat : %s\n",temp); strncpy(temp,&cuarsh[141],7); printf(" Minimum_Lat : %s\n",temp); strncpy(temp,&cuarsh[148],7); printf(" Maximum_Lon : %s\n",temp); strncpy(temp,&cuarsh[155],7); printf(" Minimum_Lon : %s\n",temp); strncpy(temp,&cuarsh[162],8); printf(" Maximum_Alt_Km : %s\n",temp); strncpy(temp,&cuarsh[170],8); printf(" Minimum_Alt_Km : %s\n",temp); strncpy(temp,&cuarsh[178],8); printf(" Maximum_Alt_Mb : %s\n",temp); strncpy(temp,&cuarsh[186],8); printf(" Minimum_Alt_Mb : %s\n",temp); memset(temp,' ',8); strncpy(temp,&cuarsh[194],6); printf(" Record_Size : %s\n",temp); strncpy(temp,&cuarsh[200],6); numrec = atoi(temp); printf(" Num_Rec_File : %6d\n",numrec); memset(temp,' ',6); strncpy(temp,&cuarsh[206],3); printf(" Data_Quality_1 : %s\n",temp); strncpy(temp,&cuarsh[209],3); printf(" Data_Quality_2 : %s\n",temp); strncpy(cmt,&cuarsh[212],80); printf(" User_Comments : %s\n\n",cmt); memset(temp,' ',45); fread(corpar,1,48,data_ifp); /* corpar */ strncpy(temp,&corpar[0],12); printf(" Corr_Param_1 : %s\n",temp); strncpy(temp,&corpar[12],12); printf(" Corr_Param_2 : %s\n",temp); strncpy(temp,&corpar[24],12); printf(" Corr_Param_3 : %s\n",temp); strncpy(temp,&corpar[36],12); printf(" Corr_Param_4 : %s\n",temp); memset(temp,' ',45); fread(blnk,1,16536,data_ifp); /* finish reading header */ /* nrdata = numrec - 1; */ irdata = 0; do { ret = fread(buffer,1,rec_size,data_ifp); if (ret > 0) { irdata ++; index = 0; printf("\n ----------------------------------- \n"); printf(" DATA RECORD NUMBER %8d\n",irdata); printf(" ----------------------------------- \n"); int4 = (int *)&buffer[0]; data_type = *int4; switch (data_type) { case 16: printf(" Data_Type : Temp \n"); break; case 1: printf(" Data_Type : Height \n"); break; case 88: printf(" Data_Type : Moisture \n"); break; case 48: printf(" Data_Type : uWind \n"); break; case 49: printf(" Data_Type : vWind \n"); break; } int4 = (int *)&buffer[4]; sftype = *int4; printf(" Surf_Type_1 : %14d\n",sftype); float4 = (float *)&buffer[8]; sfval = *float4; printf(" Surf_Value_1 : %6.1f mb\n",sfval); int4 = (int *)&buffer[20]; yr = *int4 + 1900; int4 = (int *)&buffer[24]; mn = *int4; int4 = (int *)&buffer[28]; day = *int4; int4 = (int *)&buffer[32]; hr = *int4; printf(" Year Month Day Hour : %d %d %d %d\n",yr,mn,day,hr); int4 = (int *)&buffer[36]; hemisp = *int4; if (hemisp == 27) printf(" Hemisphere : Northern\n"); else printf(" Hemisphere : Southern\n"); strncpy(temp,&buffer[40],23); printf(" Time_indicator : %s\n\n",temp); index = 64; row = 0; col = 0; for (i=0;i<4225;i++) { float4 = (float *)&buffer[index]; grid[row][col] = *float4; col++; if (col == 65) { col = 0; row++; } index += 4; } if (hemisp == 27) printf(" Northern Hemisphere NMC Grid Field Data "); else printf(" Southern Hemisphere NMC Grid Field Data "); switch (data_type) { case 16: printf(" TEMPERATURE (K)\n\n"); break; case 1: printf(" HEIGHT (m)\n\n"); break; case 88: printf(" MOISTURE (%%)\n\n"); break; case 48: printf(" U_WIND ( m/s )\n\n"); break; case 49: printf(" V_WIND ( m/s)\n\n"); break; } if (hemisp == 27) for(row=0;row<65;row++) for(col=0;col<65;col++) printf(" Lat : %10.4f Lon : %10.4f Data : %10.4f\n", nlatgrid[row][col],nlongrid[row][col],grid[row][col]); else for(row=0;row<65;row++) for(col=0;col<65;col++) printf(" Lat : %10.4f Lon : %10.4f Data : %10.4f\n", slatgrid[row][col],slongrid[row][col],grid[row][col]); /* northern or southern hemisphere */ } /* if ret > 0 */ } while (ret > 0); printf(" Total %d records \n",irdata); fclose(data_ifp); } /* ------------ this routine is given by CDHF2 --------- SUBROUTINE W3FB05(XI,XJ,XMESHL,ORIENT,ALAT,ALONG] C$$$ SUBPROGRAM DOCUMENTATION BLOCK C C SUBPROGRAM: W3FB05 GRID COORDINATES TO LATITUDE, LONGITUDE C AUTHOR: JONES,R.E. ORG: W345 DATE: 86-07-17 C C ABSTRACT: CONVERTS THE COORDINATES OF A LOCATION FROM THE GRID(I,J] C COORDINATE SYSTEM OVERLAID ON THE POLAR STEREOGRAPHIC MAP PROJEC- C TION TRUE AT 60 DEGREES N OR S LATITUDE TO THE NATURAL COORDINATE C SYSTEM OF LATITUDE/LONGITUDE ON THE EARTH. W3FB05 IS THE REVERSE C OF W3FB04. C C PROGRAM HISTORY LOG: C 86-07-17 R.E.JONES C 88-06-20 R.E.JONES CHANGE TO MICROSOFT FORTRAN 4.10 C 89-03-29 R.E.JONES CHANGE TO VAX-11 FORTRAN C C USAGE: CALL W3FB05 (XI, XJ, XMESHL, ORIENT, ALAT, ALONG] C C INPUT VARIABLES: C NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES C ------ --------- ----------------------------------------------- C XI ARG LIST I OF THE POINT RELATIVE TO THE NORTH OR S. POLE C XJ ARG LIST J OF THE POINT RELATIVE TO THE NORTH OR S. POLE C XMESHL ARG LIST MESH LENGTH OF GRID IN KM AT 60 DEGREES(<0 IF SH] C (190.5 LFM GRID, 381.0 NH PE GRID,-381.0 SH PE GRID] C ORIENT ARG LIST ORIENTATION WEST LONGITUDE OF THE GRID C (105.0 LFM GRID, 80.0 NH PE GRID, 260.0 SH PE GRID] C C OUTPUT VARIABLES: C NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES C ------ --------- ----------------------------------------------- C ALAT ARG LIST LATITUDE IN DEGREES (<0 IF SH] C ALONG ARG LIST WEST LONGITUDE IN DEGREES C C SUBPROGRAMS CALLED: C NAMES LIBRARY C ------------------------------------------------------- -------- C ASIN ATAN2 SYSLIB C C REMARKS: ALL PARAMETERS IN THE CALLING STATEMENT MUST BE C REAL. THE RANGE OF ALLOWABLE LATITUDES IS FROM A POLE TO C 30 DEGREES INTO THE OPPOSITE HEMISPHERE. C THE GRID USED IN THIS SUBROUTINE HAS ITS ORIGIN (I=0,J=0] C AT THE POLE, SO IF THE USER'S GRID HAS ITS ORIGIN AT A POINT C OTHER THAN A POLE, A TRANSLATION IS REQUIRED TO GET I AND J FOR C INPUT INTO W3FB05. THE SUBROUTINE GRID IS ORIENTED SO THAT C GRIDLINES OF I=CONSTANT ARE PARALLEL TO A WEST LONGITUDE SUP- C PLIED BY THE USER. THE EARTH'S RADIUS IS TAKEN TO BE 6371.2 KM. C C LANGUAGE: VAX-11 FORTRAN C MACHINE: VAX-11 730, 750, 780, 8600, ETC. C C FOR DETAILS OBTAIN WRITEUP FROM NMC/AD/SAB C C$$$ C */ void w3fb05(xi,xj,xmeshl,orient,alat,along) float xi,xj,xmeshl,orient,*alat,*along; { float degprd = 57.2957795; float earthr = 6371.2; float gi2,r2,angle; gi2 = pow(((1.86603 * earthr)/(xmeshl)),2); r2 = xi*xi + xj*xj; if (r2 == 0.0) { *along = 0.0; *alat = 90.0; if (xmeshl < 0.0) *alat = -*alat; return; } else { *alat = asin((gi2 - r2) / (gi2 + r2)) * degprd; angle = degprd * atan2(xj,xi); if (angle < 0.0) angle += 360.0; } if (xmeshl >= 0.0) *along = 270.0 + orient - angle; else { *along = angle + orient - 270.0; *alat = - *alat; } if (*along < 0.0) *along += 360.0; if (*along >= 360.0) *along -= 360.0; }