#include #include /* Sample program to read the aerological data by Naoki Sato, June 11, 2001 revised by Naoki Sato, July 11, 2012 revised by Naoki Sato, January 14, 2015 revised by Naoki Sato, February 14, 2020 ======================================== Subroutine aerdt reads 'Aerological Data of Japan' from the data file. Output of subroutine aerdt ICHECK : The number which indicates whether data actually exist or not. 0: Not exist. 1: Exist. Output of subroutine aerdt p : Air pressure [hPa] iz : Geopotential height [m] t : Temperature [C] iu : Relative humidity [%] id : Wind direction [deg.] 0: N, 90: E. s : Wind speed [m/s] Input of subroutine aerdt ihh : Time [o'clock]. e.g. ihh = 1: 03:00 JST, 2: 09:00 JST, 3: 15:00 JST, 4: 21:00 JST. idd, imm, iyy : Date. e.g. idd = 15, imm = 8, iyy = 1995 : August 15, 1995. ihmax, idmax : The maximum values of ihh, idd and imm. ihmax, idmax and immax must be set as ihmax = 4 and idmax = 31. ilmax : The number of layers. ilmax must be set as ilmax = 26. nmax : The number of stations where you want to investigate the data. ista : Station No. e.g. ista = 47600 : Wajima. e.g. If you want to look into the data at Sapporo (47412), Wajima (47600) and Kagoshima (47827), set nmax and ista as follows. nmax = 3, ista[0] = 47412, ista[1] = 47600, ista[2] = 47827. In this sample program, nmax is set as nmax = 1, intending to look data at only one station. An example of the usage Assume that you want to know the temperatures at the 850 hPa at 0900 on August 15, 1995 at Sapporo (47412) and Wajima (47600). First, please assign the proper values to ihmax (=4), idmax (=31), and ilmax (=26), and set nmax as nx = 2. Then, please set the values of ista and iyy as ista[0] = 47412, ista[1] = 47600, imm = 8, iyy = 1995. After calling subroutine aerdt, you will get the values at the two stations as those of t[(2-1)+(15-1)*4+(5-1)*31*4+(1-1)*26*31*4] and t[(2-1)+(15-1)*4+(5-1)*31*4+(2-1)*26*31*4]. */ int aerdt( int ihx, int idx, int ilx, int nx, int *ista, int iyy, int imm, int imiss, float rmiss, int *icheck, float *p, int *iz, float *t, int *iu, int *id, float *s ); char *cmonth( int im ); int print( int ihmax, int idmax, int ilmax, int nmax, int *ista, int n, int iyy, int imm, int idd, int ihh, int imiss, float rmiss, int *icheck, float *p, int *iz, float *t, int *iu, int *id, float *s ); char *cmonth( int im ) { char *cmonth; if (im == 1) cmonth = "Jan."; if (im == 2) cmonth = "Feb."; if (im == 3) cmonth = "Mar."; if (im == 4) cmonth = "Apr."; if (im == 5) cmonth = "May "; if (im == 6) cmonth = "Jun."; if (im == 7) cmonth = "Jul."; if (im == 8) cmonth = "Aug."; if (im == 9) cmonth = "Sep."; if (im == 10) cmonth = "Oct."; if (im == 11) cmonth = "Nov."; if (im == 12) cmonth = "Dec."; return cmonth; } int print( int ihmax, int idmax, int ilmax, int nmax, int *ista, int n, int iyy, int imm, int idd, int ihh, int imiss, float rmiss, int *icheck, float *p, int *iz, float *t, int *iu, int *id, float *s ){ int ill, ip1, iz1, iu1, id1, irec; float rp1, rt1, rs1; char ch1[5], cs1[6]; FILE *fp; char c1[81], c2[81], c3[81], c4[81], c5[81]; if (icheck[(ihh-1)+(idd-1)*ihmax+(n-1)*idmax*ihmax] == 0){ printf( "%s\n", "Data not found." ); return 0; } fp = fopen( "output.txt", "w" ); if (fp == NULL){ printf( "%s\n", "Can not write data to file 'output.txt'." ); return 0; } if (ihh == 1){strcpy( ch1, "0300" );} if (ihh == 2){strcpy( ch1, "0900" );} if (ihh == 3){strcpy( ch1, "1500" );} if (ihh == 4){strcpy( ch1, "2100" );} fprintf( fp, " Station No. = %5d,\n", ista[n-1] ); fprintf( fp, " Time = %s, %s %2d, %4d\n", ch1, cmonth(imm), idd, iyy ); fprintf( fp, " Pres. GPH Temp. Hum. Dir. Speed\n" ); fprintf( fp, " hPa m C %% deg. m/s\n" ); for (ill=1; ill<=ilmax; ill++) { irec = (ihh-1)+(idd-1)*ihmax+(ill-1)*idmax*ihmax+(n-1)*ilmax*idmax*ihmax; if (p[irec] != rmiss){ rp1 = p[irec]; }else{ rp1 = 1.0e9; } if (p[irec] != rmiss){ ip1 = p[irec]+0.5; }else{ ip1 = 999999; } if (iz[irec] != imiss){ iz1 = iz[irec]; }else{ iz1 = 999999; } if (t[irec] != rmiss){ rt1 = t[irec]; }else{ rt1 = 1.0e9; } if (iu[irec] != imiss){ iu1 = iu[irec]; }else{ iu1 = 999999; } if (id[irec] != imiss){ id1 = id[irec]; }else{ id1 = 999999; } if (s[irec] != rmiss){ rs1 = s[irec]; }else{ rs1 = 1.0e9; } if (ill == 1){ if (iz[irec] != imiss){ strcpy( cs1, "Surf." ); }else{ strcpy( cs1, "*****" ); } fprintf( fp, " %6.1f %s %5.1f %3d %3d %5.1f\n", rp1, cs1, rt1, iu1, id1, rs1 ); }else{ /* fprintf( fp, " %4d %5d %5.1f %3d %3d %5.1f\n", ip1, iz1, rt1, iu1, id1, rs1 ); */ sprintf( c1, "*****" ); if (iz1 != 999999){sprintf( c1, "%5d", iz1 );} sprintf( c2, "*****" ); if (rt1 != 1.0e9){sprintf( c2, "%5.1f", rt1 );} sprintf( c3, "***" ); if (iu1 != 999999){sprintf( c3, "%3d", iu1 );} sprintf( c4, "***" ); if (id1 != 999999){sprintf( c4, "%3d", id1 );} sprintf( c5, "*****" ); if (rs1 != 1.0e9){sprintf( c5, "%5.1f", rs1 );} fprintf( fp, " %4d %s %s %s %s %s\n", ip1, c1, c2, c3, c4, c5 ); } } fclose( fp ); printf( "%s\n", "Output was written to file 'output.txt'." ); return 0; } int main( void ) { int ihmax=4, idmax=31, ilmax=26, nmax=1; static int ista[1],icheck[4*31*1], iz[24*31*26*1], iu[24*31*26*1], id[24*31*26*1]; static float p[24*31*26*1], t[24*31*26*1], s[24*31*26*1]; int ihh, idd, imm, iyy, status; int imiss = 999999; float rmiss = 1000000000.; printf( "%s\n", "Station No. ?" ); scanf( "%d", ista ); printf( "%s\n", "Year, Month, Day, Hour(3,9,15,21) ?" ); scanf( "%d,%d,%d, %d", &iyy, &imm, &idd, &ihh ); ihh = (ihh + 3) / 6; printf( "%s\n", "Reading data ..." ); status = aerdt( ihmax, idmax, ilmax, nmax, ista, iyy, imm, imiss, rmiss, icheck, p, iz, t, iu, id, s ); status = print( ihmax, idmax, ilmax, nmax, ista, 1, iyy, imm, idd, ihh, imiss, rmiss, icheck, p, iz, t, iu, id, s ); return 0; }