awips2/ncep/gov.noaa.nws.ncep.viz.rsc.ncgrid/dgdriv_c/dbgetrdata.c
Steve Harris 7f90924706 12.4.1-10 baseline
Former-commit-id: 7fa9dbd5fb [formerly 4bfbdad17d] [formerly 9f8cb727a5] [formerly 7fa9dbd5fb [formerly 4bfbdad17d] [formerly 9f8cb727a5] [formerly 8485b90ff8 [formerly 9f8cb727a5 [formerly bf53d06834caa780226121334ac1bcf0534c3f16]]]]
Former-commit-id: 8485b90ff8
Former-commit-id: 40aa780b3d [formerly 33a67cdd82] [formerly 73930fb29d0c1e91204e76e6ebfdbe757414f319 [formerly a28d70b5c5]]
Former-commit-id: a16a1b4dd44fc344ee709abbe262aeed58a8339b [formerly e5543a0e86]
Former-commit-id: 0c25458510
2012-05-01 18:06:13 -05:00

98 lines
4 KiB
C

#include "geminc.h"
#include "gemprm.h"
#include "dbcmn.h"
#include "imgdef.h"
void db_getRData ( char *dbHost, char *fileName, float *rdata, int *nword,
int *iret )
/************************************************************************
* *
* void db_getRData *
* *
* This function fills the imgData array by reading image data from *
* AWIPS II database given the location of the file on the server. *
* *
* void db_getRData ( char *dbHost, char *fileName, float *rdata, *
* int *nword, int *iret ) *
* *
* Input parameters: *
* *dbHost char Database host *
* *fileName char Name of the file on the server *
* *
* Output parameters: *
* *rdata float Data *
* *nword int size of rdata array *
* *iret int return code: *
* -1: data acquisition error *
* -2: binary data src unsupported *
* 0: normal *
** *
* Log: *
* *
* m.gamazaychikov/CWS 01/10 Created *
************************************************************************/
{
int chars_read = 0, ii, istmax, ier;
int fdatsize = 300000000;
int max_n;
int max_nlength = 20;
char fileAddress1[8] = "http://";
char fileAddress2[25] = ":8080/uEngineProducts/";
char fileAddress[100];
char popncmd[1024];
char *fBuffer;
char **starr;
FILE *read_fp;
/*---------------------------------------------------------------------*/
*iret = 0;
sprintf(fileAddress,"%s", fileAddress1);
strcat (fileAddress, dbHost);
strcat (fileAddress, fileAddress2);
strcat (fileAddress, fileName);
sprintf (popncmd, "%s %s", "curl -s", fileAddress);
if ( strcmp ( eSrc, "GRID") == 0 ) {
cst_numb (gDattim, &max_n, &ier);
/*
* Initialize the dataBuffer string, open the pipe,
* and read data from the pipe
*/
G_MALLOC ( fBuffer, char, fdatsize+1, "db_getRData:dataBuffer" );
memset (fBuffer, '\0', sizeof(fBuffer));
read_fp = popen(popncmd, "r");
if ( read_fp != NULL ) {
chars_read = fread(fBuffer, sizeof(char), fdatsize, read_fp);
while (chars_read > 0) {
fBuffer[chars_read - 1] = '\0';
chars_read = fread(fBuffer, sizeof(char), fdatsize, read_fp);
}
pclose(read_fp);
}
starr = (char **)malloc((size_t)max_n * sizeof(char *));
for( ii=0; ii < max_n; ii++ )
starr[ii] = (char *)malloc( max_nlength * sizeof(char));
cst_clst (fBuffer, ';', " ", max_n, max_nlength, starr, &istmax, &ier);
if ( istmax <= 1 ) {
*iret = -2;
return;
}
/*
* Convert the data values:
* 1. GRID - no conversion
*/
for ( ii = 0; ii < istmax; ii++ ) {
cst_crnm(starr[ii], &rdata[ii], &ier);
}
*nword = istmax;
for ( ii = 0; ii < max_n; ii++ ) free( starr[ii] );
if( starr ) free( (char **)starr );
G_FREE ( fBuffer, char );
}
else {
*iret = -1;
return;
}
return;
}