Exemplo n.º 1
0
void da_getfilhdr ( int *iflno, char *fhdnam, int *mxword,
			float *rheadr, int *nword, int *iret )
/************************************************************************
 * da_getfilhdr								*
 *									*
 * This function reads the real values for the given file header from	*
 * a non-GEMPAK data source.						*
 *									*
 * da_getfilhdr ( iflno, fhdnam, mxword, rheadr, nword, iret )		*
 *									*
 * Input parameters:							*
 *	iflno		int*		GEMPAK file number		*
 *	fhdnam		char*		Name of the file header section	*
 *	mxword		int*		Maximum words to return		*
 *									*
 * Output parameters:							*
 *	rheadr		float*		File header			*
 *	nword		int*		Header length			*
 *	iret		int*		Return code			*
 **									*
 * S. Jacobs/NCEP	 6/13	Created					*
 * S. Jacobs/NCEP	12/13	Save NX and NY for later use		*
 ************************************************************************/
{
    int		ii, jj, gflnum, ier;
    char	arrlen[12], model[MXFLSZ];
    char	pyfile[MXFLSZ], pymeth[MXFLSZ];
/*---------------------------------------------------------------------*/
    *iret = 0;

    gflnum = *iflno - 1;

    for ( jj = 0; jj < common[gflnum].numfhdrs; jj++ ) {
	if ( strcmp ( common[gflnum].fhdrs[jj].name, fhdnam ) == 0 ) {
	    strcpy ( model, common[gflnum].fhdrs[jj].dbkey );
	    strcpy ( pyfile, common[gflnum].fhdrs[jj].pyfile );
	    strcpy ( pymeth, common[gflnum].fhdrs[jj].pymeth );
	    cst_inch ( common[gflnum].fhdrs[jj].length, arrlen, &ier );
	}
    }

    /* Set the arguments for input to the request script */
    danarg = 4;
    daargs = (char **) malloc ( danarg * sizeof(char *) );
    for ( ii = 0; ii < danarg; ii++ ) {
	daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
    }
    ii = 0;
    strcpy ( daargs[ii], common[gflnum].dbserver );	ii++;
    strcpy ( daargs[ii], common[gflnum].dbtable );	ii++;
    strcpy ( daargs[ii], model );		ii++;
    strcpy ( daargs[ii], arrlen );		ii++;

    /* Get the header data */
    /* Run the Python script to make the actual request */
    datype = DAFLOAT;
    da_runpy ( pyfile, pymeth, &ier );

    /* Assign the output array of floats */
    for ( ii = 0; ii < danumf; ii++ ) {
	rheadr[ii] = daoutf[ii];
    }
    *nword = danumf;

    /* If this is a grid navigation, save the number of points */
    if ( strcmp ( fhdnam, "NAVB" ) == 0 ) {
	dacmn.nx = rheadr[4];
	dacmn.ny = rheadr[5];
    }

    /* Free all allocated memory */
    for ( ii = 0 ; ii < danarg; ii++ ) {
	free ( daargs[ii] );
    }
    free ( daargs );
    free ( daoutf );
}
Exemplo n.º 2
0
int main (void)
/************************************************************************
 * TESTDA								*
 * 									*
 * This program tests the GEMLIB DA functions.				*
 * 									*
 ** 									*
 * Log:									*
 * S. Jacobs/NCEP	 5/13	Initial coding				*
 ***********************************************************************/
{
    int		cont, ier, iret, numsub, is, ie, ii;
    char	select[5];

    char	pyfile[MXFLSZ], pymeth[MXFLSZ];

/*---------------------------------------------------------------------*/
    in_bdta(&ier);

    cont = G_TRUE;

    while ( cont ) {
	printf ( "\n\n" );
	printf ( "  1 = DA_RUNPY for CHAR output\n" );
	printf ( "  2 = DA_RUNPY for INT output\n" );
	printf ( "  3 = DA_RUNPY for FLOAT output\n" );
	printf ( "\n" );
	printf ( "Select a subroutine number or type EXIT: " );
	ier = getinp ( 1, select, NULL, NULL, 4 );
	switch ( select[0] ) {
	    case 'e':
	    case 'E':
		cont = G_FALSE;
	    default:
		numsub = atoi ( select );
		break;
	}

/*---------------------------------------------------------------------*/
	if ( numsub == 1 ) {

	    printf ( "Enter the Python file name (without .py):\n" );
	    ier = getinp ( 1, pyfile, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the Python method name:\n" );
	    ier = getinp ( 1, pymeth, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the number of input strings:\n" );
	    ier = getinp ( 2, NULL, &danarg, NULL, STRSIZE );
	    if ( ier < 0 ) {
	       	break;
	    }

	    daargs = (char **) malloc ( danarg * sizeof(char *) );
	    for ( ii = 0; ii < danarg; ii++ ) {
		daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
		printf ( "Enter input string %d:\n", ii );
		ier = getinp ( 1, daargs[ii], NULL, NULL, STRSIZE );
		if ( ier < 0 ) {
		    break;
		}
	    }

	    datype = DACHAR;
	    da_runpy ( pyfile, pymeth, &iret );

	    printf ( "\nDA_RUNPY: iret = %d\n\n", iret );
	    if  ( iret >= 0 )  {
		printf ( "The length of result is: %ld\n", strlen(daoutc) );
		printf ( "The result is: %s\n\n", daoutc );

		free ( daoutc );
	    }
	    free ( daargs );
	}
/*---------------------------------------------------------------------*/
	if ( numsub == 2 ) {

	    printf ( "Enter the Python file name (without .py):\n" );
	    ier = getinp ( 1, pyfile, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the Python method name:\n" );
	    ier = getinp ( 1, pymeth, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the number of input strings:\n" );
	    ier = getinp ( 2, NULL, &danarg, NULL, STRSIZE );
	    if ( ier < 0 ) {
	       	break;
	    }

	    daargs = (char **) malloc ( danarg * sizeof(char *) );
	    for ( ii = 0; ii < danarg; ii++ ) {
		daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
		printf ( "Enter input string %d:\n", ii );
		ier = getinp ( 1, daargs[ii], NULL, NULL, STRSIZE );
		if ( ier < 0 ) {
		    break;
		}
	    }

	    datype = DAINT;
	    da_runpy ( pyfile, pymeth, &iret );

	    printf ( "\nDA_RUNPY: iret = %d\n\n", iret );
	    if  ( iret >= 0 )  {
		printf ( "The array size of result is: %d\n", danumi );
		printf ( "The result array is:\n" );
		is = 0;
		ie = G_MIN ( 8, danumi );
		while ( is < danumi ) {
		    for ( ii = is; ii < ie; ii++ ) {
			printf ( "%9d ", daouti[ii] );
		    }
		    printf ( "\n" );
		    is = ie;
		    ie = G_MIN ( is+8, danumi );
		}
		printf ( "\n" );

		free ( daouti );
	    }
	    free ( daargs );
	}
/*---------------------------------------------------------------------*/
	if ( numsub == 3 ) {

	    printf ( "Enter the Python file name (without .py):\n" );
	    ier = getinp ( 1, pyfile, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the Python method name:\n" );
	    ier = getinp ( 1, pymeth, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the number of input strings:\n" );
	    ier = getinp ( 2, NULL, &danarg, NULL, STRSIZE );
	    if ( ier < 0 ) {
	       	break;
	    }

	    daargs = (char **) malloc ( danarg * sizeof(char *) );
	    for ( ii = 0; ii < danarg; ii++ ) {
		daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
		printf ( "Enter input string %d:\n", ii );
		ier = getinp ( 1, daargs[ii], NULL, NULL, STRSIZE );
		if ( ier < 0 ) {
		    break;
		}
	    }

	    datype = DAFLOAT;
	    da_runpy ( pyfile, pymeth, &iret );

	    printf ( "\nDA_RUNPY: iret = %d\n\n", iret );

	    if  ( iret >= 0 )  {
		printf ( "The array size of result is: %d\n", danumf );
		printf ( "The result array is:\n" );
		is = 0;
		ie = G_MIN ( 8, danumf );
		while ( is < danumf ) {
		    for ( ii = is; ii < ie; ii++ ) {
			printf ( "%9.2f ", daoutf[ii] );
		    }
		    printf ( "\n" );
		    is = ie;
		    ie = G_MIN ( is+8, danumf );
		}
		printf ( "\n" );

		free ( daoutf );
	    }
	    free ( daargs );
	}

/*---------------------------------------------------------------------*/
    }

    return 0;
}