Beispiel #1
0
void ensemble(unsigned char *pds, int mode) {

    int pdslen;
    unsigned char ctmp;
    char char_end;

    pdslen = PDS_LEN(pds);
    char_end = mode == 2 ? ' ' : ':';

    if ((PDS_Center(pds) == NMC || ncep_ens) && pdslen >= 45 && pds[40] == 1) {

	/* control run */

	if (pds[41] == 1) {
	    if (mode != 2) {
		printf("ens%c0:%c", pds[42] == 1 ? '+' : '-', char_end);
	    }
	    else {
		printf("%s-res_ens_control ", pds[42] == 1 ? "hi" : "low");
	    }
	}

	/* perturbation run */

	else if (pds[41] == 2 || pds[41] == 3) {
	    if (mode != 2) {
	        printf("ens%c%d%c", pds[41] == 3 ? '+' : '-', pds[42],char_end);
	    }
	    else {
		printf("ens_perturbation=%c%d ",pds[41] == 3 ? '+' : '-', 
		    pds[42]);
	    }
	}

	/* cluster mean */

	else if (pds[41] == 4) {
	    if (mode != 2) printf("cluster%c", char_end);
	    else printf("cluster(%d members) ",pds[60]);
	}


	/* ensemble mean */

	else if (pds[41] == 5) {
	    if (mode != 2) printf("ensemble%c", char_end);
	    else printf("ensemble(%d members) ",pds[60]);
	}

	/* other case .. debug code */

	else {
		printf("ens %d/%d/%d/%d%c", pds[41],pds[42],pds[43],pds[44],char_end);
	}


	if (pdslen >= 44) {
	    if (pds[43] == 1 && pds[41] >= 4) printf("mean%c", char_end);
	    else if (pds[43] == 2) printf("weighted mean%c",char_end);
	    else if (pds[43] == 3) printf("no bias%c",char_end);
	    else if (pds[43] == 4) printf("weighted mean no bias%c",char_end);
	    else if (pds[43] == 5) printf("weight%c",char_end);
	    else if (pds[43] == 6) printf("climate percentile%c",char_end);
	    else if (pds[43] == 7) printf("daily climate mean%c",char_end);
	    else if (pds[43] == 8) printf("daily climate std dev%c",char_end);
	    else if (pds[43] == 11) printf("std dev%c",char_end);
	    else if (pds[43] == 12) printf("norm std dev%c",char_end);
	    else if (pds[43] == 21) printf("max val%c",char_end);
	    else if (pds[43] == 22) printf("min val%c",char_end);
	}

	/* NCEP probability limits */

	if ((PDS_PARAM(pds) == 191 || PDS_PARAM(pds) == 192) && pdslen >= 47) {
	    ctmp = PDS_PARAM(pds);
	    PDS_PARAM(pds) = pds[45];
	    if (pds[46] == 1 && pdslen >= 51) {
		printf("prob(%s<%f)%c", k5toa(pds), ibm2flt(pds+47),char_end);
	    }
	    else if (pds[46] == 2 && pdslen >= 54) {
		printf("prob(%s>%f)%c", k5toa(pds), ibm2flt(pds+51), char_end);
	    }
	    else if (pds[46] == 3 && pdslen >= 54) {
		printf("prob(%f<%s<%f)%c", ibm2flt(pds+47), k5toa(pds), 
			ibm2flt(pds+51), char_end);
	    }
            PDS_PARAM(pds) = ctmp;
	}
    }
    /* ECMWF test should go here */
}
void	grib1name ( char *filename, int seqno,  char *data, char *ident )
{
unsigned char model_id,grid_id,parmid,vcordid,center,subcenter;
unsigned char dattim[6],ftim[4],level[2];
int CCYY,YYYY,MM,DD,HH,vtime;
time_t time1, time2;
struct tm tm1, tm2;
char prodtmp[255],prodid[255],levelstmp[255];
char *pos;
static char datyp[]="grib";
static int isinit=!0;

/* Initialize time zone information */
if(isinit)
   {
   isinit = 0;
   putenv("TZ=UTC0");
   tzset();
   }

	model_id = *((unsigned char *)data+13);
        grid_id = *((unsigned char *)data+14);
	center = *((unsigned char *)data+12);
        subcenter = *((unsigned char *)data+33);

        dattim[0] = *((unsigned char *)data+20);
        dattim[1] = *((unsigned char *)data+21);
        dattim[2] = *((unsigned char *)data+22);
        dattim[3] = *((unsigned char *)data+23);
        dattim[4] = *((unsigned char *)data+24);
        dattim[5] = *((unsigned char *)data+32);

        ftim[0] = *((unsigned char *)data+26);
        ftim[1] = *((unsigned char *)data+27);
        ftim[2] = *((unsigned char *)data+28);
        ftim[3] = *((unsigned char *)data+25);

        parmid = *((unsigned char *)data+16);
        vcordid = *((unsigned char *)data+17);
        level[0] = *((unsigned char *)data+18);
        level[1] = *((unsigned char *)data+19);

        if(dattim[0] > 0) dattim[5] = dattim[5] - 1; CCYY = dattim[5]*100 + dattim[0];
        vtime = verf_time((unsigned char *)data+8,&YYYY,&MM,&DD,&HH);

        tm1.tm_year    = CCYY - 1900; tm1.tm_mon     = dattim[1] - 1;
        tm1.tm_mday    = dattim[2]; tm1.tm_hour    = dattim[3];
        tm1.tm_min     = dattim[4]; tm1.tm_sec     = 0;
        tm1.tm_isdst   = -1; time1 = mktime(&tm1);

        tm2.tm_year    = YYYY - 1900; tm2.tm_mon     = MM - 1;
        tm2.tm_mday    = DD; tm2.tm_hour    = HH;
        tm2.tm_min     = 0; tm2.tm_sec     = 0;
        tm2.tm_isdst   = -1; time2 = mktime(&tm2);

        memset(prodtmp,0,255);
        memset(prodid,0,255);
        memset(levelstmp,0,255);

        sprintf(prodid,"%s\0",k5toa((unsigned char *)data+8));
        while((pos = strchr(prodid,' ')) != NULL) pos[0] = '_';

        sprintf(levelstmp,"%s\0",levels((int)vcordid,(int)level[0],(int)level[1]));
        while((pos = strchr(levelstmp,' ')) != NULL) pos[0] = '_';

        sprintf(prodtmp,"%s/%s/%s/#%03d/%04d%02d%02d%02d%02d/F%03d/%s/%s! %06d\0",datyp,
                s_pds_center(center,subcenter),s_pds_model(center,model_id),grid_id,
                CCYY,dattim[1],dattim[2],dattim[3],dattim[4],(time2 - time1)/3600,
                prodid,
                levelstmp,seqno
                /*(char *)PDStimes(ftim[2],ftim[0],ftim[1],ftim[3]),
                YYYY,MM,DD,HH*/);
        if(strlen(filename) < 253)
                {
                strcpy(ident,filename);
                strncat(ident," !",2);
                strncat(ident,prodtmp,253-strlen(filename));
                }
        else
		{
                strncpy(ident,filename,255);
		ident[255] = '\0';
		}
}