void NxmBusy_createBtns ( Widget rc ) /************************************************************************ * NxmBusy_createBtns * * * * This function creates the stop icon push_button. The parent widget * * is expected to be a Row Column widget. * * * * void NxmBusy_createBtns(rc) * * * * Input parameters: * * rc Widget parent RC widget ID * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * C. Lin/EAI 04/96 * * C. Lin/EAI 02/97 modified, move from NMAP to NXMLIB * * S. Wang/GSC 04/97 add auto-labels for stop/busy button * * S. Wang/GSC 10/97 add insensitive bits for stop button * * R. Tian/SAIC 01/03 add True flag to NxmBxmBtn_create(Multi)* * T. Piper/SAIC 07/03 removed the creation of the busy button * ***********************************************************************/ { char iconfile[256], ins_iconfile[256]; int iret; long ignore; struct bxmInfo stopbxm[2]; static char label_1[30]; /*---------------------------------------------------------------------*/ /* * create stop button */ cfl_inqr("stop.xbm", ICON_DIR, &ignore, iconfile, &iret); cfl_inqr("stpins.xbm", ICON_DIR, &ignore, ins_iconfile, &iret); strcpy( stopbxm[0].fgcolor, ICON_FGNAME ); strcpy( stopbxm[1].fgcolor, ICON_FGNAME ); strcpy( stopbxm[0].bgcolor, ICON_BGNAME ); strcpy( stopbxm[1].bgcolor, ICON_WORK_BGNAME ); stopbxm[0].sens_bits = iconfile; stopbxm[1].sens_bits = iconfile; stopbxm[0].insens_bits = ins_iconfile; stopbxm[1].insens_bits = NULL; strcpy( label_1, "stop action" ); _stopButton = NxmBxmBtn_createMulti( rc, "stopBtn", NULL, ICON_WIDTH, ICON_HEIGHT, stopbxm, 2, label_1, True, (XtCallbackProc)NxmBusy_pushbCb, 0, _stopPxm ); NxmBxmBtn_setPxm( _stopButton, (Pixmap)0, _stopPxm[0].insnstv ); }
int DoIt( char *in_file, int vg_class, int vg_type, int obj_type, int *match ) { int iret; int readpos; long in_size; char tmp_name[PATH_MAX]; VG_DBStruct el; readpos = 0; *match = 0; cfl_inqr(in_file, NULL, &in_size, tmp_name, &iret); while (!*match && !iret && (readpos < in_size)) { cvg_rdrec(in_file, readpos, &el, &iret); if (!iret) { readpos += el.hdr.recsz; *match = obj_match(&el, vg_class, vg_type, obj_type); } } return iret; }
void cvg_qkopen ( char *filnam, FILE **fptr, int *bytes_inFile, int *iret ) /************************************************************************ * cvg_qkopen * * * * This function opens a VG file. It differs from cvg_open in that * * only minimal error checking is done and no errors are reported. Any * * error detected will result in a iret value of -1. This routine is * * designed to be used on files previously opened by the more rigorous * * cvg_open. All files will be opened with write access. * * * * cvg_qkopen ( filnam, fptr, bytes_inFile, iret ) * * * * Input parameters: * * *filnam char VG filename * * * * Output parameters: * * **fptr FILE File pointer * * *bytes_inFile int number of bytes in file * * *iret int Return code * * 0 = normal * * -1 = error opening VG file * ** * * Log: * * E. Safford/GSC 10/98 copied from cvg_open * * S. Jacobs/NCEP 12/98 Fixed cast of NULL to int for LINUX * * T. Piper/GSC 3/99 Corrected prolog * * A. Hardy/GSC 1/01 changed fptr from int to FILE * * T. Lee/SAIC 11/03 used cvgcmn.h * * S. Jacobs/NCEP 3/06 Fixed 64bit long problem * ************************************************************************/ { int ier; char newfil[256]; long numbytes; /*---------------------------------------------------------------------*/ *iret = 0; /* Check to see if there is a file of the specified name, * open it if it is there. */ cfl_inqr(filnam, NULL, &numbytes, newfil, &ier); *bytes_inFile = (int) numbytes; *fptr = cfl_uopn(filnam, &ier); if (ier < 0) { *bytes_inFile = 0; *fptr = NULL; *iret = -1; } }
FILE *cfl_ropn ( char *filnam, char *defdir, int *iret ) /************************************************************************ * cfl_ropn * * * * This function opens a file for reading. * * * * The file is located by searching in the following order: * * * * 1. filnam (as given) * * 2. defdir/filnam * * * * FILE *cfl_ropn ( filnam, defdir, iret ) * * * * Input parameters: * * *filnam char File name * * *defdir char Default directory * * * * Output parameters: * * *iret int Return code * * *cfl_ropn FILE File pointer * ** * * G. Krueger/EAI 3/96 * * G. Krueger/EAI 8/96 Match with FL library * * S. Law/GSC 05/00 changed to use file size defines * ***********************************************************************/ { FILE *fptr; int ier; long lflen; char fullname[FILE_FULLSZ]; /*---------------------------------------------------------------------*/ *iret = 0; fptr = NULL; cfl_inqr ( filnam, defdir, &lflen, fullname, sizeof(fullname), iret ); if ( *iret == 0 ) { fptr = fopen ( fullname, "r" ); if ( fptr == NULL ) { cfl_iret ( errno, iret, &ier ); } } return fptr; }
int main ( int argc, char **argv ) /************************************************************************ * mdp * * * * This program generates the mesoscale discussion latlon pairings. * * Pairings will be written to a file whose filename is based on the * * input filename (filename extension, if exists, is replaced w/ "mdp").* * * * Example: * * mdp input_vgf_file.vgf * * Produces latlon pairings in the ASCII file * * output_vgf_file.mdp * * * * main(argc, argv) * * * * Input parameters: * * argc int number of parameters of command line * * argv char** parameter array of command line * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * D.W.Plummer/NCEP 6/02 * * D.W.Plummer/NCEP 8/02 Bug fix for lons > 99.995 and < 100.0 * * m.gamazaychikov/SAIC 3/03 Made mdp work only on scallop lines * * added WFOs and STATES to output text * * m.gamazaychikov/SAIC 3/03 Made mdp work on lines grouped or not * * grouped with WFOs and/or STATES * * Made MDP exit upon encountering first * * scallop line in VGF file * * Made changes to format of output text * * T. Piper/SAIC 12/05 Updated cst_wrap for CSC * * J. Wu/SAIC 04/06 Added parameter in cst_wrap * ***********************************************************************/ { int ii, ix, iy, pagflg, ier; int ilen, npts; char vg_class, vg_type; char blank[2]={' '}, errgrp[8], infile[128], ifname[128], outfile[128]; float x, y; long ifilesize; int ne1, more1, curpos1; char buffer[1024], str[20], *cptr; int wrtoutfg, wrtwfofg, wrtsttfg; int grpnumbr1, grpnumbr2; int lintyp, jj, narea, areatype; int ne2, more2, curpos2; char strwfo[480], strstt[480], bufferlat[1024]; VG_DBStruct el; FILE *ifptr, *ofptr; /*---------------------------------------------------------------------*/ /* * Check if number of input arguments is correct. */ if ( argc < 2 ) { pagflg = G_FALSE; strcpy ( errgrp, "MDP" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); exit (0); } /* * First input on command line is input vgf file name. */ strcpy ( infile, argv[1] ); cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier ); ifptr = (FILE *) cfl_ropn(ifname, "", &ier); if ( ier != 0 ) { printf("Error opening VGF file %s\n", infile ); exit (0); } /* * Output filename is input filename w/ "mdp" filename extension. */ strcpy ( outfile, infile ); cptr = strrchr( outfile, '.' ); if ( cptr != (char *)NULL ) { cptr[0] = '\0'; } strcat( outfile, ".mdp" ); /* * Loop through all the elements until a line is found. */ ne1 = 0; more1 = G_TRUE; curpos1 = 0; buffer[0] = '\0'; bufferlat[0] = '\0'; while ( ne1 < MAX_EDITABLE_ELEMS && more1 == G_TRUE ) { wrtoutfg = G_FALSE; wrtsttfg = G_FALSE; wrtwfofg = G_FALSE; cvg_rdrecnoc( ifname, ifptr, curpos1, &el, &ier ); if ( ier < 0 ) { more1 = G_FALSE; } else { curpos1 += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; grpnumbr1 = el.hdr.grpnum; if ( (int)vg_class == CLASS_LINES ) { /* * Open output file. */ ofptr = (FILE *)cfl_wopn ( outfile, &ier ); if ( ier != 0 ) { printf("Error opening/creating output file %s\n", outfile ); exit (0); } if ((int)vg_type == SPLN_ELM ) { /* * type of special line */ lintyp = el.elem.spl.info.spltyp; if (lintyp == 3 ) { /* * number of points in a line */ npts = el.elem.spl.info.numpts; /* * Format lats and lons into buffer. */ for ( ii = 0; ii < npts; ii++ ) { x = el.elem.spl.latlon[ii]; y = -el.elem.spl.latlon[ii+npts]; /* * Make sure lats and lons are rounded to 100ths of deg. */ x = ((int)(x*100)) / 100.0F; y = ((int)(y*100)) / 100.0F; if ( y >= 100.0F ) y -= 100.0F; ix = G_NINT(x*100.0F); iy = G_NINT(y*100.0F); sprintf( str, "%04d%04d ", ix, iy ); strcat ( bufferlat, str ); /* * this flag is here to ensure exit as soon * as a line is found */ more1 = G_FALSE; /* * this flag is here to ensure that lat-lon * pairs are written out even without wfo and states * grouped with it */ wrtoutfg = G_TRUE; } ne2 = 0; curpos2 = 0; more2 = G_TRUE; while ( ne2 < MAX_EDITABLE_ELEMS && more2 == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos2, &el, &ier ); if ( ier < 0 ) { more2 = G_FALSE; } else { curpos2 += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; grpnumbr2 = el.hdr.grpnum; if (grpnumbr2 == grpnumbr1 && grpnumbr2 != 0) { if ((int)vg_type == LIST_ELM ) { areatype = 0; areatype = el.elem.lst.info.subtyp; if (areatype == 3) { wrtwfofg = G_TRUE; narea = el.elem.lst.data.nitems; strwfo[0] = '\0'; strcat( strwfo, "ATTN...WFO..."); jj = 0; for (jj = 0; jj < narea; jj++) { strcpy (str, el.elem.lst.data.item[jj]); strcat (strwfo, str); strcat (strwfo, "..." ); if ((jj+1)%9 == 0) { strcat (strwfo, "\n"); } } strcat (strwfo, "\n"); } if (areatype == 4) { wrtsttfg = G_TRUE; narea = el.elem.lst.data.nitems; strstt[0] = '\0'; jj = 0; for (jj = 0; jj < narea; jj++) { strcpy (str, el.elem.lst.data.item[jj]); strcat (strstt, str); strcat (strstt, "Z000-" ); } strcat (strstt, "\n"); } } } } ne2++; } } } } } ne1++; /* * Write to output file. */ if (wrtoutfg == G_TRUE) { /* * Wrap bufferlat such that only 6 pairs of lat,lons on one line */ ilen = 55; cst_wrap( bufferlat, blank, &ilen, "\n", (char *)NULL, bufferlat, &ier ); if (wrtsttfg == G_TRUE) { /* * Wrap strstt such that only 7 STATE IDs on one line * and dump strstt into buffer for further output */ ilen = 49; cst_wrap( strstt, blank, &ilen, "\n", (char *)NULL, strstt, &ier ); strcat ( buffer, strstt ); strcat ( buffer, "\n"); } if (wrtwfofg == G_TRUE) { /* * Wrap strwfo such that only 9 WFOs on one line * and dump strswo into buffer for further output */ ilen = 67; cst_wrap( strwfo, blank, &ilen, "\n", (char *)NULL, strwfo, &ier ); strcat ( buffer, strwfo ); strcat ( buffer, "\n"); } strcat ( buffer, bufferlat); strcat ( buffer, "\n"); cfl_writ( ofptr, (int)strlen(buffer), (unsigned char *)buffer, &ier ); bufferlat[0] = '\0'; } } /* * If no line is found, close files and exit. */ cfl_clos ( ifptr, &ier ); cfl_clos ( ofptr, &ier ); return(0); }
Widget NxmVolcano_menuCreate ( Widget parent, Widget textwid, XtCallbackProc push_cb ) /************************************************************************ * NxmVolcano_menuCreate * * * * This function creates a volcano list menu. * * * * Widget NxmVolcano_menuCreate(parent, textwid, push_cb) * * * * Input parameters: * * parent Widget parent widget ID * * textwid Widget text field id on the left side * * (*push_cb)() void callback function for push btn * * * * Output parameters: * * NONE * * Return parameters: * * NxmVolcano_create Widget The menu bar widget * * * ** * * Log: * * H. Zeng/XTRIA 10/02 initial coding * * M. Li/SAIC 11/03 Re-arranged cascade button group * ***********************************************************************/ { Widget menub, menu, cascade, push_btn, vol_menu[24]; int toff = 5, menu_idx, ii, iret, nn; static Boolean first = TRUE; char *vol_list[] = {"AA-AM", "AN-AZ", "B", "CA-CH", "CI-CZ", "D-E", "F", "G", "H", "I-J", "KA-KH", "KI-KZ", "L", "MA-MC", "ME-MZ", "N", "O-P", "Q-R", "SA-SE", "SF-SZ", "TA-TH", "TI-TZ", "U", "V-Z" }; XmString xmstr; Pixel fg, bg; long btn_idx, ignore; char filename[256]; static Pixmap menu_pxm; /*---------------------------------------------------------------------*/ /* * If it is the first time NxmVolcano_menuCreate() be called, read * volcano info. from volcano.tbl. */ if ( _gotVolInfo == FALSE ) { NxmVolcano_rdInfo(); } /* * Create volcano menu bar and cascade button. */ menub = XmCreateMenuBar (parent, "tmbar", NULL, 0); XtVaSetValues (menub, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, textwid, XmNleftOffset, toff, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, toff, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, toff, XmNmarginHeight, 0, XmNmarginWidth, 0, XmNborderWidth, 0, XmNwidth, 5, XmNhighlightThickness, 1, XmNshadowThickness, 1, NULL); menu = XmCreatePulldownMenu (menub, "tmmenu", NULL, 0); cascade = XtVaCreateManagedWidget ("tmcascade", xmCascadeButtonWidgetClass, menub, XmNsubMenuId, menu, NULL); if (first) { first = FALSE; XtVaGetValues (parent, XmNforeground, &fg, XmNbackground, &bg, NULL); cfl_inqr ("menu_arrow.xbm", "$NAWIPS/icons/nmap", &ignore, filename, &iret); if (iret == 0) { menu_pxm = XmGetPixmap (XtScreen (parent), filename, fg, bg); } else { menu_pxm = XmUNSPECIFIED_PIXMAP; } } if (menu_pxm == (Pixmap)XmUNSPECIFIED_PIXMAP) { xmstr = XmStringCreateLocalized ("\\/"); XtVaSetValues (cascade, XmNlabelString, xmstr, NULL); XmStringFree (xmstr); } else { XtVaSetValues (cascade, XmNlabelType, XmPIXMAP, XmNlabelPixmap, menu_pxm, XmNmarginHeight, 0, XmNmarginWidth, 0, NULL); } /* * Create the first push button. */ btn_idx = 0; xmstr = XmStringCreateLocalized ("-Not_listed.__Enter_Name/Location-"); push_btn = XtVaCreateManagedWidget ("vol_list_button", xmPushButtonWidgetClass, menu, XmNlabelString, xmstr, XmNuserData, textwid, NULL); XmStringFree (xmstr); XtAddCallback ( push_btn, XmNactivateCallback, (XtCallbackProc)push_cb, (XtPointer)btn_idx ); btn_idx++; /* * Create cascade button group. */ nn = XtNumber(vol_list); for ( ii = 0; ii < nn; ii++ ) { xmstr = XmStringCreateLocalized (vol_list[ii]); vol_menu[ii] = XmCreatePulldownMenu (menu, "tmmenu", NULL, 0); XtVaCreateManagedWidget ("tmcascade", xmCascadeButtonWidgetClass, menu, XmNlabelString, xmstr, XmNsubMenuId, vol_menu[ii], NULL); XmStringFree (xmstr); } /* * Create the rest of volcano push buttons. */ for ( ii = 0; ii < _volNum; ii++ ) { /* * Check which cascade group the volcano station belongs to. */ if ( strcasecmp (_volTbl[ii].name, "AN") < 0 ) { menu_idx = 0; } else if ( strcasecmp (_volTbl[ii].name, "B") < 0 ) { menu_idx = 1; } else if ( strcasecmp (_volTbl[ii].name, "C") < 0 ) { menu_idx = 2; } else if ( strcasecmp (_volTbl[ii].name, "CI") < 0 ) { menu_idx = 3; } else if ( strcasecmp (_volTbl[ii].name, "D") < 0 ) { menu_idx = 4; } else if ( strcasecmp (_volTbl[ii].name, "F") < 0 ) { menu_idx = 5; } else if ( strcasecmp (_volTbl[ii].name, "G") < 0 ) { menu_idx = 6; } else if ( strcasecmp (_volTbl[ii].name, "H") < 0 ) { menu_idx = 7; } else if ( strcasecmp (_volTbl[ii].name, "I") < 0 ) { menu_idx = 8; } else if ( strcasecmp (_volTbl[ii].name, "K") < 0 ) { menu_idx = 9; } else if ( strcasecmp (_volTbl[ii].name, "KI") < 0 ) { menu_idx = 10; } else if ( strcasecmp (_volTbl[ii].name, "L") < 0 ) { menu_idx = 11; } else if ( strcasecmp (_volTbl[ii].name, "M") < 0 ) { menu_idx = 12; } else if ( strcasecmp (_volTbl[ii].name, "ME") < 0 ) { menu_idx = 13; } else if ( strcasecmp (_volTbl[ii].name, "N") < 0 ) { menu_idx = 14; } else if ( strcasecmp (_volTbl[ii].name, "O") < 0 ) { menu_idx = 15; } else if ( strcasecmp (_volTbl[ii].name, "Q") < 0 ) { menu_idx = 16; } else if ( strcasecmp (_volTbl[ii].name, "S") < 0 ) { menu_idx = 17; } else if ( strcasecmp (_volTbl[ii].name, "SF") < 0 ) { menu_idx = 18; } else if ( strcasecmp (_volTbl[ii].name, "T") < 0 ) { menu_idx = 19; } else if ( strcasecmp (_volTbl[ii].name, "TI") < 0 ) { menu_idx = 20; } else if ( strcasecmp (_volTbl[ii].name, "U") < 0 ) { menu_idx = 21; } else if ( strcasecmp (_volTbl[ii].name, "V") < 0 ) { menu_idx = 22; } else { menu_idx = 23; } xmstr = XmStringCreateLocalized (_volTbl[ii].name); push_btn = XtVaCreateManagedWidget ("vol_list_button", xmPushButtonWidgetClass, vol_menu[menu_idx], XmNlabelString, xmstr, XmNuserData, textwid, NULL); XmStringFree (xmstr); XtAddCallback ( push_btn, XmNactivateCallback, (XtCallbackProc)push_cb, (XtPointer)btn_idx ); btn_idx++; } XtManageChild(menub); return (menub); }
int main ( int argc, char **argv ) /************************************************************************ * mdp * * * * This program generates the mesoscale discussion latlon pairings. * * Pairings will be written to a file whose filename is based on the * * input filename (filename extension, if exists, is replaced w/ "mdp").* * * * Example: * * mdp input_vgf_file.vgf * * Produces latlon pairings in the ASCII file * * output_vgf_file.mdp * * * * main(argc, argv) * * * * Input parameters: * * argc int number of parameters of command line * * argv char** parameter array of command line * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * D.W.Plummer/NCEP 6/02 * * D.W.Plummer/NCEP 8/02 Bug fix for lons > 99.995 and < 100.0 * * G. Grosshans/SPC 11/02 Updated to decode multi-scalloped lines * * G. Grosshans/SPC 12/02 Updated to compute WFO/State * * S. Jacobs/NCEP 5/03 Clean up unused variables and headers * * G. Grosshans/SPC 10/03 Updated for precision * * T. Piper/SAIC 12/05 Updated cst_wrap for CSC * * J. Wu/SAIC 04/06 Added parameter in cst_wrap * * G. Grosshans/SPC 08/08 Updated for SCN 08-45 to add LAT...LON * * and list first point as last point * * to indicate a closed polygon. Add * * word wrapping for ATTN...WFO... * ***********************************************************************/ { int ii, ix, iy, ixfirst, iyfirst, pagflg, ne, ilen, npts, ier, iret, nitems, more, curpos; long ifilesize; float x, y, flat[MAXLISTITEMS], flon[MAXLISTITEMS]; char vg_class, vg_type, buffer[2048], bufferfinal[2048], bufferfinalwfo[2048],str[20], *cptr, errgrp[12], infile[128], ifname[128], outfile[128], info[2048], stpo[4], cstl_list[1000], cstl_liststate[1000], newLineStr[13]=" "; /* 13 spaces */ char blank[2]={' '}, device[13], dfilnam[73], pro[80]; int mode, istat, iunit, itype; float xsize, ysize, lllat, lllon, urlat, urlon, prjang1, prjang2, prjang3; VG_DBStruct el; FILE *ifptr, *ofptr; const int line_len = 66; /*---------------------------------------------------------------------*/ /* * Set defaults for gsdeva and gsmprj */ mode = 1; strcpy ( device, "GN" ); iunit = 1; strcpy ( dfilnam, "MDPSPC" ); itype = 1; xsize = 500.0F; ysize = 500.0F; lllat = 10.0F; lllon = -120.0F; urlat = 50.0F; urlon = -50.0F; strcpy ( pro, "str" ); prjang1 = 90.0F; prjang2 = -105.0F; prjang3 = 0.0F; cstl_list[0] = '\0'; cstl_liststate[0] = '\0'; in_bdta ( &ier ); ginitp ( &mode, &istat, &ier); gsdeva (device, &iunit, dfilnam, &itype, &xsize, &ysize, &iret, strlen(device), strlen(dfilnam)); gsmprj ( pro, &prjang1, &prjang2, &prjang3, &lllat, &lllon, &urlat, &urlon, &iret, strlen(pro)); clo_init ( &ier ); /* * Check if number of input arguments is correct. */ if ( argc < 2 ) { pagflg = G_FALSE; strcpy ( errgrp, "MDPSPC" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); gendp (&mode, &ier); exit (0); } /* * First input on command line is input vgf file name. */ strcpy ( infile, argv[1] ); cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier ); ifptr = (FILE *) cfl_ropn(ifname, "", &ier); if ( ier != 0 ) { printf("Error opening VGF file %s\n", infile ); gendp (&mode, &ier); exit (0); } /* * Output filename is input filename w/ "mdp" filename extension. */ strcpy ( outfile, infile ); cptr = strrchr( outfile, '.' ); if ( cptr != (char *)NULL ) { cptr[0] = '\0'; } strcat( outfile, ".mdp" ); /* * Loop through all the elements until a line is found. */ ne = 0; more = G_TRUE; curpos = 0; buffer[0] = '\0'; bufferfinal[0] = '\0'; bufferfinalwfo[0] = '\0'; strcat ( buffer, "LAT...LON " ); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else { curpos += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; if ( ( (int)vg_class == CLASS_LINES ) && ( el.hdr.vg_type == SPLN_ELM ) && ( (int)el.elem.spl.info.spltyp == 3 ) ) { /* * Open output file. */ ofptr = (FILE *)cfl_wopn ( outfile, &ier ); if ( ier != 0 ) { printf("Error opening/creating output file %s\n", outfile ); gendp (&mode, &ier); exit (0); } /* * Find FIPS bounded by the closed line */ npts = el.elem.spl.info.numpts; /* FIND WHAT STATES ARE IN MD AREA */ clo_binpoly ( "CNTY_BNDS", npts, el.elem.spl.latlon, &(el.elem.spl.latlon[npts]), &ier ); clo_tgltln ( "CNTY_BNDS", MAXLISTITEMS, &nitems, flat, flon, &ier); for ( ii = 0; ii < nitems; ii++ ) { clo_bginfo( "CNTY_BNDS", ii, info, &ier ); cst_gtag( "STATE", info, "?", stpo, &ier); if (strstr(cstl_liststate, stpo)==NULL) { strcat(cstl_liststate, stpo); strcat(cstl_liststate, " "); } } /* FIND WHAT WFOs ARE IN MD AREA */ clo_binpoly ( "CWA_BNDS", npts, el.elem.spl.latlon, &(el.elem.spl.latlon[el.elem.spl.info.numpts]), &ier ); clo_tgltln ( "CWA_BNDS", MAXLISTITEMS, &nitems, flat, flon, &ier); for ( ii = 0; ii < nitems; ii++ ) { clo_bginfo( "CWA_BNDS", ii, info, &ier ); cst_gtag( "WFO", info, "?", stpo, &ier); strcat(cstl_list, stpo); strcat(cstl_list, "..."); } /* * Format lats and lons into buffer. */ if ( (int)vg_type == LINE_ELM ) { npts = el.elem.lin.info.numpts; } else if ( (int)vg_type == SPLN_ELM ) { npts = el.elem.spl.info.numpts; } for ( ii = 0; ii < npts; ii++ ) { if ( (int)vg_type == LINE_ELM ) { x = el.elem.lin.latlon[ii]; y = -el.elem.lin.latlon[ii+npts]; } else if ( (int)vg_type == SPLN_ELM ) { x = el.elem.spl.latlon[ii]; y = -el.elem.spl.latlon[ii+npts]; } /* * Make sure lats and lons are rounded * to 100ths of deg. */ x = ((int)(x*100.0F)) / 100.0F; y = ((int)(y*100.0F)) / 100.0F; if ( y >= 100.0F ) y -= 100.0F; ix = G_NINT(x*100.0F); iy = G_NINT(y*100.0F); sprintf( str, "%04d%04d ", ix, iy ); strcat ( buffer, str ); if ( ii == 0 ) { ixfirst = ix; iyfirst = iy; } } /* * Repeat first lat/lon point as last lat/lon point * to indicate a closed polygon. */ sprintf( str, "%04d%04d ", ixfirst, iyfirst); strcat ( buffer, str ); sprintf( str, "\n\n" ); strcat ( buffer, str ); /* * Wrap buffer such that only 6 pairs of lat,lons * on one line. * ilen = 55; * cst_wrap( buffer, blank, &ilen, "\n", (char *)NULL, buffer, &ier ); */ ilen = 66; cst_wrap( buffer, blank, &ilen, "\n", newLineStr, buffer, &ier ); } } ne++; } /* * wrap the ATTN...WFO... line */ strcat ( bufferfinalwfo, "ATTN...WFO..." ); strcat ( bufferfinalwfo, cstl_list ); cst_wrap( bufferfinalwfo, "...", &line_len, "\n", (char *)NULL, bufferfinalwfo, &ier ); /* * build the output file string and add the ATTN...WFO... string */ strcat ( bufferfinal,"STATES=" ); strcat ( bufferfinal, cstl_liststate ); strcat ( bufferfinal, "\n\n" ); strcat ( bufferfinal, bufferfinalwfo ); /* strcat ( bufferfinal,"ATTN...WFO..." ); strcat ( bufferfinal, cstl_list ); */ strcat ( bufferfinal, "\n\n" ); strcat ( bufferfinal, buffer ); /* * Write to output file. */ cfl_writ ( ofptr, (int)strlen(bufferfinal), (unsigned char *)bufferfinal, &ier ); /* * close files and exit. */ cfl_clos ( ifptr, &ier ); cfl_clos ( ofptr, &ier ); gendp (&mode, &ier); return(0); }
void _getrpt ( srchinfo_t *srchinfo, char *report, int *iret ) /************************************************************************ * _getrpt * * * * This routine will retrieve the report for the requested location. * * * * _getrpt ( srchinfo, report, iret ) * * * * Input parameters: * * *srchinfo srchinfo_t Search info structure * * * * Output parameters: * * *report char Report * * *iret int Return code * * * * * ** * * Log: * * L. Williams/EAI 6/96 modified from srchb_fosdFndrepWW * * S. Jacobs/NCEP 12/98 Changed fclose to cfl_clos * * S. Chiswell/UCAR 04/01 Changed strchr to memchr * * R.Tian/SAIC 1/02 Avoid possible overflow report * * R. Tian/SAIC 04/02 Query file size before open it * ***********************************************************************/ { int rep_len; long flen; char dumyname[133]; char *iepos, *ispos, *text; /*---------------------------------------------------------------------*/ /* * Get the size of the new file. If the size is 0, skip it. */ cfl_inqr(srchinfo->file_info.filnam, NULL, &flen, dumyname, iret); if ( *iret != 0 || flen == 0 ) { report[0] = '\0'; *iret = -1; return; /* error in query file */ } srchinfo->file_info.file_len = (int)flen; /* * Open the new file. */ srchinfo->file_info.fptr = cfl_ropn( srchinfo->file_info.filnam, NULL, iret ); if ( *iret != 0 ) { report[0] = '\0'; *iret = -1; return; /* error in opening file */ } /* * Allocate enough space to hold the entire contents of the file. */ text = (char *) malloc((size_t)(srchinfo->file_info.file_len + 1) * sizeof(char) ); /* * Read the contents of the file into the TEXT string. */ if ( fread( text, (size_t)srchinfo->file_info.file_len, 1, srchinfo->file_info.fptr) != (size_t)1 ){ /* * reading error */ report[0] = '\0'; *iret = -1; free( text ); return; } /* * Copy the report from string text to string report */ ispos = &text[reportInfo[srchinfo->current].position]; iepos = memchr( &text[reportInfo[srchinfo->current].position], CHCTLC, (size_t)(srchinfo->file_info.file_len - reportInfo[srchinfo->current].position)); if ( iepos != NULL ) rep_len = G_MIN((iepos - ispos), (REPMAX - 1)); else rep_len = 0; strncpy( report, &text[reportInfo[srchinfo->current].position], (size_t)rep_len ); report[rep_len] = '\0'; free( text ); /* * Close the data file. */ if ( srchinfo->file_info.fptr != NULL ) { cfl_clos ( srchinfo->file_info.fptr, iret ); srchinfo->file_info.fptr = NULL; } }
void de_mbr1 ( const int *k, const char *infl, char *outfl, int *iret ) /************************************************************************ * de_mbr1 * * * * This subroutine parses a GDFILE entry to find and handle ensemble * * specifications. It is called from DG_NFIL. The routine turns an * * ensemble entry into a single entry that DG_NFIL can handle. * * * * de_mbr1 ( k, infl, outfl, iret ) * * * * Input parameters: * * *k const int GDFILE entry position number * * *infl const char Input file entry * * * * Output parameters: * * *outfl char* Output file replaces INFL * * *iret int Return code * * 0 = normal return * * -2 = grid file or template not * * exist * * * * Log: * * T. Lee/SAIC 12/04 * * T. Lee/SAIC 06/05 Parsed weight value * * R. Tian/SAIC 12/05 Translated from Fortran * * m.gamazaychikov/SAIC 04/06 Added idtmch flag to CTB_DTGET CS * * T. Piper/SAIC 04/07 Modified for cfl_scnt CSC * * F. J. Yen/NCEP 4/08 Added bin mins & mstrct to CTB_DTGET CSC* * S. Jacobs/NCEP 12/11 Fixed check if there is no table entry * * returned by ctb_dtget * ***********************************************************************/ { int index, nfarr, ic, is, iff, ir, ii, ino, ihb, mnb, iha, mna, mstrct, idtmch, nfile, istar, last, len, ier; long lens; char lsv[MXFLSZ], newfil[MXFLSZ], filnam[MXFLSZ], cycle[DTTMSZ], path[MXFLSZ], tmplt[MXFLSZ], dum[DTTMSZ], rplc[DTTMSZ], membr[17]; char *opnptr, *clsptr, *starp, *ptr, **farr, *def = " "; struct dirent **dnlist=NULL; /*----------------------------------------------------------------------*/ *iret = 0; outfl[0] = '\0'; /* * Check if INFL contains a curly-bracket enclosed ensemble spec. * If not, the first entry is not an ensemble grid. Do nothing. */ opnptr = strchr ( infl, '{' ); if ( ! opnptr ) { strcpy ( outfl, infl ); return; } /* * Save the string between curly brackets to ensspc (k). Get * the first element of the file(s). */ cst_opcl ( infl, opnptr, &clsptr, &ier ); if ( ier != 0 ) { *iret = -2; return; } for ( index = 0, ptr = opnptr + 1; ptr < clsptr; index++, ptr++ ) { _ensdiag.ensspc[*k-1][index] = *ptr; } _ensdiag.ensspc[*k-1][index] = '\0'; clsptr = strchr ( _ensdiag.ensspc[*k-1], ',' ); if ( ! clsptr ) { strcpy ( lsv, _ensdiag.ensspc[*k-1] ); } else { for ( index = 0, ptr = _ensdiag.ensspc[*k-1]; ptr < clsptr; index++, ptr++ ) { lsv[index] = *ptr; } lsv[index] = '\0'; } /* * If file name is not an alias, do nothing. */ cfl_inqr ( lsv, NULL, &lens, newfil, &ier ); if ( ier == 0 ) { strcpy ( outfl, lsv ); return; } /* * Get the template. If the template does not end with "*", * do nothing. */ farr = (char **)cmm_malloc2d ( 2, MXFLSZ, sizeof(char), &ier ); if ( strchr ( lsv, '%' ) ) { cst_clst ( lsv, '%', def, 2, MXFLSZ, farr, &nfarr, &ier ); strcpy ( lsv, farr[1] ); } cst_clst ( lsv, '|', def, 2, MXFLSZ, farr, &nfarr, &ier ); strcpy ( filnam, farr[0] ); strcpy ( cycle, farr[1] ); cmm_free2d ( (void **)farr, &ier ); ctb_dtget ( filnam, path, tmplt, &ic, &is, &iff, &ir, &ii, &ino, &ihb, &mnb, &iha, &mna, &mstrct, &idtmch, &ier ); if ( ier != 0 ) { strcpy ( outfl, lsv ); return; } else { starp = strchr ( tmplt, '*' ); istar = (int)( starp - tmplt ); if ( ! starp ) { strcpy ( outfl, lsv ); return; } } /* * If the template contains an "*", then it is an ensemble with * multiple members. The last member is the one sought. */ if ( strcmp ( cycle, def ) != 0 ) { cti_stan ( cycle, "YYMMDD/HHNN", dum, &ier ); if ( strstr ( tmplt, "YYYYMMDD" ) ) { strcpy ( rplc, "YY" ); strncat ( rplc, dum, 6 ); rplc[8] = '\0'; cst_rpst ( tmplt, "YYYYMMDD", rplc, tmplt, &ier ); } else { strncpy ( rplc, dum, 6 ); rplc[6] = '\0'; cst_rpst ( tmplt, "YYMMDD", rplc, tmplt, &ier ); } strncpy ( rplc, &dum[7], 2 ); rplc[2] = '\0'; cst_rpst ( tmplt, "HH", rplc, tmplt, &ier ); } /* * Retrieve the last member of the ensemble alias. */ cfl_scnt ( path, tmplt, -1, &dnlist, &nfile, &ier ); if ( nfile == 0 ) { *iret = -2; er_wmsg ( "DE", iret, " ", &ier, strlen("DE"), strlen(" ") ); return; } strcpy ( newfil, dnlist[0]->d_name ); for (ii=0;ii<nfile;ii++){ free(dnlist[ii]); } if ( dnlist != NULL ) free(dnlist); /* * Replace "*" in the template with member names. Note * that "*" may be embedded in the template. */ if ( *(starp+1) == '\0' ) { last = G_TRUE; } else { last = G_FALSE; } if ( last == G_TRUE ) { strcpy ( membr, &newfil[istar] ); } else { len = strlen ( newfil ) - strlen ( tmplt ) + 1; cst_ncpy ( membr, &newfil[istar], len, &ier ); } /* * Recombine the alias and last member with the cycle. */ strcpy ( outfl, filnam ); strcat ( outfl, ":" ); strcat ( outfl, membr ); if ( strcmp ( cycle, def ) != 0 ) { strcat ( outfl, "|" ); strcat ( outfl, cycle ); } return; }
int main ( int argc, char **argv ) /************************************************************************ * clipvgf * * * * This program clips elements in a VGF file based on a bounds * * specification. By default, a simple clipping algorithm is used * * where element points either inside or outside the polygon are kept * * or thrown away based on an input flag. Alternatively, an exact * * algorithm may be requested which clips precisely at the borders. * * * * The bound definition must be in the format: * * bound_name|<area_tag_name>area_tag_value * * and must be enclosed w/ quotes so the shell will ignore directives. * * * * Examples: * * clipvgf input.vgf "STATE_BNDS|<STATE>WY" keep output.vgf rough * * clipvgf input.vgf "STATE_BNDS|<STATE>WY" keep output.vgf exact * * Where "rough" uses the simple clipping algorithm and "exact" yields * * precise clipping at the bounds borders. * * * * The following element classes are not processed: * * CLASS_WATCHES, CLASS_TRACKS, CLASS_SIGMETS * * * * main(argc, argv) * * * * Input parameters: * * argc int number of parameters of command line * * argv char** parameter array of command line * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * D.W.Plummer/NCEP 2/02 * * D.W.Plummer/NCEP 5/02 Added exact clipping and label moving * * D.W.Plummer/NCEP 8/02 Account for text grouped with symbol * * D.W.Plummer/NCEP 8/02 Create output VGF, even if it is empty * * H. Zeng/XTRIA 02/03 converted CLASS_CIRCLE to CLASS LINES * * D.W.Plummer/NCEP 8/03 Bug fix - add pt to closed lines * * R. Tian/SAIC 11/04 Added clip jet element * * S. Danz/AWC 07/06 Update to new cvg_writef() parameter * * T. Piper/SAIC 03/07 Added ninout-- for closed line case * * L. Hinson/AWC 07/07 Added clip code for GFA elements * * L. Hinson/AWC 07/07 Add recalcGFAtLblArwLoc function * for GFA elements * * X.Guo/CWS 10/10 Bug fix - Low level graphic don't make * * it all the way north in central US * * L. Hinson/AWC 09/13 Fixed improperly clipped JET_ELM Barbs * * and hashes * ***********************************************************************/ { int ii, jj, ip, ibeg, iend, loc, ne, found, found_txt, joffset, kept, ier; int wrtflg, pagflg; int minpts, maxpts, npts, numpts, npoly; char vg_class, vg_type; char bnd[128], keep[32], bnd_name[64], bnd_tag[64]; char infile[128], ifname[128], outfile[128]; char *cptr; long ifilesize; int more, curpos; float flat, flon, filt, px[LLMXPT], py[LLMXPT]; float plat[LLMXPT], plon[LLMXPT], *ptrlat, *ptrlon; float tlat[LLMXPT], tlon[LLMXPT]; float fltmin, fltmax, flnmin, flnmax; int inout[LLMXPT], tinout[LLMXPT]; char device[8], dfilnam[128], pro[32]; float xsize, ysize, lllat, lllon, urlat, urlon; float prjang1, prjang2, prjang3; int mode, istat, iunit, itype; char errgrp[8]; int ninout; float xinout[LLMXPT], yinout[LLMXPT]; char precision[8]; int tltpts, nbarb, nhash; int tmaxpts, tnpts, tnclip; char hazList[ STD_STRLEN ]; VG_DBStruct el, el_t, el_q, el_lin; FILE *ifptr; int ninxarr, inxarr[100]; /*---------------------------------------------------------------------*/ /* * First check if number of input arguments is correct. */ if ( argc < 5 ) { pagflg = G_FALSE; strcpy ( errgrp, "CLIPVGF" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); exit (0); } /* * First input on command line is input vgf file name. */ strcpy ( infile, argv[1] ); wrtflg = 0; cvg_open ( infile, wrtflg, &(ifptr), &ier ); if ( ier != 0 ) { printf("Error opening VGF file %s\n", infile ); exit (0); } cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier ); /* * Second input on command line is bounds name. */ clo_init ( &ier ); strcpy ( bnd, argv[2] ); cptr = cst_split( bnd, '|', sizeof(bnd_name), bnd_name, &ier ); clo_bstype ( bnd_name, &ier ); if ( ier != 0 ) { printf("Error finding bounds type %s\n", bnd_name ); exit (0); } if ( cptr != (char *)NULL ) { strcpy ( bnd_tag, cptr ); clo_bstag ( bnd_tag, &ier ); } fltmin = -90.0F; fltmax = 90.0F; flnmin = -180.0F; flnmax = 180.0F; clo_bsarea ( &fltmin, &flnmin, &fltmax, &flnmax, &ier ); minpts = 3; maxpts = sizeof(px)/sizeof(float); filt = 0.0F; clo_bgnext ( &minpts, &maxpts, &filt, &npoly, px, py, &ier ); if ( ier < 0 ) { printf("Error retrieving bound area %s|%s\n", bnd_name, bnd_tag ); exit (0); } /* * Third input on command line is keep flag. */ strcpy ( keep, argv[3] ); /* * Fourth input on command line is output vgf file name; create it. */ strcpy ( outfile, argv[4] ); cvg_crvgf ( outfile, &ier ); /* * Fifth input on command line is clip precision = "rough" or "exact" */ if ( argv[5] != (char *)NULL ) strcpy ( precision, argv[5] ); else strcpy ( precision, "ROUGH" ); cst_lcuc ( precision, precision, &ier ); /* * All input checks out OK; set up GAREA and PROJ for inpoly. */ mode = 1; ginitp ( &mode, &istat, &ier ); strcpy ( device, "GN" ); iunit = 1; strcpy ( dfilnam, "CLIPVGF" ); itype = 1; xsize = 500.0F; ysize = 500.0F; gsdeva ( device, &iunit, dfilnam, &itype, &xsize, &ysize, &ier, strlen(device), strlen(dfilnam)); /* * Something more sophisticated may be needed here in the future * to set up a proper proj and garea based on the clip area. * For instance, the following definitions probably won't work * on a clipping bound equivalent to Antartica. */ lllat = 0.0F; lllon = -135.0F; urlat = 0.0F; urlon = 45.0F; strcpy ( pro, "str" ); prjang1 = 90.0F; prjang2 = -105.0F; prjang3 = 0.0F; gsmprj ( pro, &prjang1, &prjang2, &prjang3, &lllat, &lllon, &urlat, &urlon, &ier, strlen(pro)); /* * Loop through all the elements to set the range records. */ crg_init ( &ier ); ne = 0; more = G_TRUE; curpos = 0; ifptr = (FILE *) cfl_ropn(ifname, "", &ier); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc ( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else { crg_set ( &el, curpos, 1, &ier ); curpos += el.hdr.recsz; ne++; } } cfl_clos ( ifptr, &ier ); /* * Loop through all the elements. */ ne = 0; more = G_TRUE; curpos = 0; ifptr = (FILE *) cfl_ropn(ifname, "", &ier); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else if ( el.hdr.recsz > 0 ) { crg_gginx( el.hdr.grptyp, el.hdr.grpnum, sizeof(inxarr)/sizeof(inxarr[0]), inxarr, &ninxarr, &ier ); /* * Increment file pointer now because element hdrsz may change. */ curpos += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; switch ( (int)vg_class ) { case CLASS_SYMBOLS: case CLASS_TEXT: case CLASS_WINDS: case CLASS_COMSYM: case CLASS_MARKER: switch ( (int)vg_type ) { case TEXT_ELM: case TEXTC_ELM: flat = el.elem.txt.info.lat; flon = el.elem.txt.info.lon; break; case SPTX_ELM: flat = el.elem.spt.info.lat; flon = el.elem.spt.info.lon; break; case BARB_ELM: case ARROW_ELM: case DARR_ELM: case HASH_ELM: flat = el.elem.wnd.data.latlon[0]; flon = el.elem.wnd.data.latlon[1]; break; case WXSYM_ELM: case CTSYM_ELM: case ICSYM_ELM: case PTSYM_ELM: case PWSYM_ELM: case SKSYM_ELM: case SPSYM_ELM: case TBSYM_ELM: case MARK_ELM: case CMBSY_ELM: flat = el.elem.sym.data.latlon[0]; flon = el.elem.sym.data.latlon[1]; break; } npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { /* * Check if element is TEXT grouped with a SYMBOL. If this text was going * to be kept but it's symbol was going to be throw away, throw it away also. */ if ( (int)vg_class == CLASS_TEXT && (int)el.hdr.grptyp != 0 && ninxarr > 1 ) { found = G_FALSE; ii = 0; while ( ii < ninxarr && found == G_FALSE ) { crg_goffset ( inxarr[ii], &joffset, &ier ); cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier ); if ( el_q.hdr.vg_class == CLASS_SYMBOLS ) { found = G_TRUE; flat = el_q.elem.sym.data.latlon[0]; flon = el_q.elem.sym.data.latlon[1]; npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ((inout[0] == 1 && strcmp(keep,"keep") == 0) || (inout[0] == 0 && strcmp(keep,"keep") != 0)) { cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); kept = G_TRUE; } else { kept = G_FALSE; } } ii++; } if ( found == G_FALSE ) { cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); kept = G_TRUE; } } else { /* * non-TEXT -- keep it. */ cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); kept = G_TRUE; } } else { /* * Element is not to be kept. */ kept = G_FALSE; } /* * Check if element was kept and is a SYMBOL element grouped with TEXT; * make sure any text elements are saved off they were going to be thrown away. */ if ( kept == G_TRUE && (int)vg_class == CLASS_SYMBOLS && (int)el.hdr.grptyp != 0 && ninxarr > 1 ) { ii = 0; while ( ii < ninxarr ) { crg_goffset ( inxarr[ii], &joffset, &ier ); cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier ); if ( el_q.hdr.vg_class == CLASS_TEXT ) { el_t = el_q; switch ( (int)el_t.hdr.vg_type ) { case TEXT_ELM: case TEXTC_ELM: flat = el_t.elem.txt.info.lat; flon = el_t.elem.txt.info.lon; break; case SPTX_ELM: flat = el_t.elem.spt.info.lat; flon = el_t.elem.spt.info.lon; break; } npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ( ( kept == G_TRUE ) && ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) ) { } else { cvg_writef ( &el_t, -1, el_t.hdr.recsz, outfile, FALSE, &loc, &ier ); } } ii++; } } break; case CLASS_CIRCLE: case CLASS_LINES: case CLASS_FRONTS: /* * convert a circle element to a line element */ if ( vg_class == CLASS_CIRCLE ) { cvg_cir2lin ( &el, 10, &el_lin, &ier ); el = el_lin; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; } switch ( (int)vg_type ) { case LINE_ELM: npts = el.elem.lin.info.numpts; ptrlat = &(el.elem.lin.latlon[ 0]); ptrlon = &(el.elem.lin.latlon[npts]); break; case SPLN_ELM: npts = el.elem.spl.info.numpts; ptrlat = &(el.elem.spl.latlon[ 0]); ptrlon = &(el.elem.spl.latlon[npts]); break; case FRONT_ELM: npts = el.elem.frt.info.numpts; ptrlat = &(el.elem.frt.latlon[ 0]); ptrlon = &(el.elem.frt.latlon[npts]); break; } memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) ); memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) ); if ( el.hdr.closed == 1 ) { plat[npts] = plat[0]; plon[npts] = plon[0]; npts++; } if ( strcmp(precision,"EXACT") == 0 ) { clip_line ( npoly, px, py, npts, plat, plon, (int)el.hdr.closed, sizeof(xinout)/sizeof(float), &ninout, xinout, yinout, inout, &ier ); } else if ( strcmp(precision,"ROUGH") == 0 ) { cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier ); ninout = npts; memcpy ( xinout, plat, (size_t)ninout*sizeof(float) ); memcpy ( yinout, plon, (size_t)ninout*sizeof(float) ); } /* * If element is closed, and some points are to be kept and others are not, * then rotate the locations arrays such that a transition point is the first point. */ if ( el.hdr.closed == 1 ) { ip = 0; ninout--; while ( inout[ip] == inout[0] && ip < ninout ) ip++; if ( ip != ninout ) { if (( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( tlat, xinout, (size_t)ninout*sizeof(float) ); memcpy ( tlon, yinout, (size_t)ninout*sizeof(float) ); memcpy ( tinout, inout, (size_t)ninout*sizeof(float) ); for ( ii = 0; ii < ninout; ii++ ) { xinout[ii] = tlat[(ii+ip) % ninout]; yinout[ii] = tlon[(ii+ip) % ninout]; inout[ii] = tinout[(ii+ip) % ninout]; } } } } ip = 0; while ( ip < ninout ) { ibeg = ip; iend = ip; while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++; iend = ip - 1; numpts = iend - ibeg + 1; /* * If element is closed, and some points are to be kept and others are not, * then reset the closed flag. */ if ( el.hdr.closed == 1 && numpts != ninout ) el.hdr.closed = 0; if ( numpts > 1 ) { if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 ) ) { switch ( (int)vg_type ) { case LINE_ELM: el.elem.lin.info.numpts = numpts; ptrlat = &(el.elem.lin.latlon[ 0]); ptrlon = &(el.elem.lin.latlon[numpts]); el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) + sizeof(VG_HdrStruct) + sizeof(LineInfo) )); break; case SPLN_ELM: el.elem.spl.info.numpts = numpts; ptrlat = &(el.elem.spl.latlon[ 0]); ptrlon = &(el.elem.spl.latlon[numpts]); el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) + sizeof(VG_HdrStruct) + sizeof(SpLineInfo) )); break; case FRONT_ELM: el.elem.frt.info.numpts = numpts; ptrlat = &(el.elem.frt.latlon[ 0]); ptrlon = &(el.elem.frt.latlon[numpts]); el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) + sizeof(VG_HdrStruct) + sizeof(FrontInfo) )); break; } memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float)); memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float)); cvg_writef ( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); if ( (int)el.hdr.grptyp != 0 && ninxarr > 1 ) { found = G_FALSE; found_txt = G_FALSE; ii = 0; while ( ii < ninxarr && found == G_FALSE ) { crg_goffset ( inxarr[ii], &joffset, &ier ); cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier ); if ( el_q.hdr.vg_class == CLASS_TEXT ) { found_txt = G_TRUE; el_t = el_q; switch ( (int)el_t.hdr.vg_type ) { case TEXT_ELM: case TEXTC_ELM: flat = el_t.elem.txt.info.lat; flon = el_t.elem.txt.info.lon; break; case SPTX_ELM: flat = el_t.elem.spt.info.lat; flon = el_t.elem.spt.info.lon; break; } npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { found = G_TRUE; break; } } ii++; } if ( found == G_FALSE && ii == ninxarr && found_txt == G_TRUE ) { switch ( (int)vg_type ) { case LINE_ELM: flat = ( el.elem.lin.latlon[0] + el.elem.lin.latlon[1] ) / 2.0F; flon = ( el.elem.lin.latlon[numpts] + el.elem.lin.latlon[numpts+1] ) / 2.0F; break; case SPLN_ELM: flat = ( el.elem.spl.latlon[0] + el.elem.spl.latlon[1] ) / 2.0F; flon = ( el.elem.spl.latlon[numpts] + el.elem.spl.latlon[numpts+1] ) / 2.0F; break; case FRONT_ELM: flat = ( el.elem.frt.latlon[0] + el.elem.frt.latlon[1] ) / 2.0F; flon = ( el.elem.frt.latlon[numpts] + el.elem.frt.latlon[numpts+1] ) / 2.0F; break; } switch ( (int)el_t.hdr.vg_type ) { case TEXT_ELM: case TEXTC_ELM: el_t.elem.txt.info.lat = flat; el_t.elem.txt.info.lon = flon; break; case SPTX_ELM: el_t.elem.spt.info.lat = flat; el_t.elem.spt.info.lon = flon; break; } cvg_writef ( &el_t, -1, el_t.hdr.recsz, outfile, FALSE, &loc, &ier ); } } } } } break; case CLASS_MET: switch ( (int)vg_type ) { case JET_ELM: npts = tltpts = el.elem.jet.line.spl.info.numpts; ptrlat = &(el.elem.jet.line.spl.latlon[ 0]); ptrlon = &(el.elem.jet.line.spl.latlon[npts]); memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) ); memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) ); if ( strcmp(precision,"EXACT") == 0 ) { clip_line ( npoly, px, py, npts, plat, plon, (int)el.hdr.closed, sizeof(xinout)/sizeof(float), &ninout, xinout, yinout, inout, &ier ); } else if ( strcmp(precision,"ROUGH") == 0 ) { cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier ); ninout = npts; memcpy ( xinout, plat, (size_t)ninout*sizeof(float) ); memcpy ( yinout, plon, (size_t)ninout*sizeof(float) ); } ip = 0; while ( ip < ninout ) { ibeg = ip; iend = ip; while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++; iend = ip - 1; numpts = iend - ibeg + 1; if ( numpts > 1 ) { if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( &(el_t.hdr), &(el.hdr), sizeof(VG_HdrStruct) ); el_t.elem.jet.line.splcol = el.elem.jet.line.splcol; memcpy ( &(el_t.elem.jet.line.spl.info), &(el.elem.jet.line.spl.info), sizeof(SpLineInfo) ); el_t.elem.jet.line.spl.info.numpts = numpts; ptrlat = &(el_t.elem.jet.line.spl.latlon[ 0]); ptrlon = &(el_t.elem.jet.line.spl.latlon[numpts]); memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float)); memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float)); nbarb = 0; for ( ii = 0; ii < el.elem.jet.nbarb; ii++ ) { flat = el.elem.jet.barb[ii].wnd.data.latlon[0]; flon = el.elem.jet.barb[ii].wnd.data.latlon[1]; npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, tinout, &ier ); if (( tinout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( tinout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( &(el_t.elem.jet.barb[nbarb]), &(el.elem.jet.barb[ii]), sizeof(BarbAttr) ); nbarb++; } } el_t.elem.jet.nbarb = nbarb; nhash = 0; for ( ii = 0; ii < el.elem.jet.nhash; ii++ ) { flat = el.elem.jet.hash[ii].wnd.data.latlon[0]; flon = el.elem.jet.hash[ii].wnd.data.latlon[1]; npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, tinout, &ier ); if (( tinout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( tinout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( &(el_t.elem.jet.hash[nhash]), &(el.elem.jet.hash[ii]), sizeof(HashAttr) ); nhash++; } } el_t.elem.jet.nhash = nhash; cvg_writef ( &el_t, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); } } } break; case GFA_ELM: /* Get the Hazard Type... */ cvg_getFld ( &el, TAG_GFA_AREATYPE, hazList, &ier ); npts = el.elem.gfa.info.npts; ptrlat = &(el.elem.gfa.latlon[0]); ptrlon = &(el.elem.gfa.latlon[npts]); memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) ); memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) ); if ( el.hdr.closed == 1 ) { plat[npts] = plat[0]; plon[npts] = plon[0]; npts++; } if(strcmp(hazList,"FZLVL")==0) { /* Is this a Freezing Level? */ if ( strcmp(precision,"EXACT") == 0 ) { clip_line ( npoly, px, py, npts, plat, plon, (int)el.hdr.closed, sizeof(xinout)/sizeof(float), &ninout, xinout, yinout, inout, &ier ); } else if (strcmp(precision,"ROUGH") == 0 ) { cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier ); ninout = npts; memcpy ( xinout, plat, (size_t)ninout*sizeof(float) ); memcpy ( yinout, plon, (size_t)ninout*sizeof(float) ); } if ( el.hdr.closed == 1 ) { ip = 0; ninout--; while ( inout[ip] == inout[0] && ip < ninout ) ip++; if ( ip != ninout ) { if (( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( tlat, xinout, (size_t)ninout*sizeof(float) ); memcpy ( tlon, yinout, (size_t)ninout*sizeof(float) ); memcpy ( tinout, inout, (size_t)ninout*sizeof(float) ); for ( ii = 0; ii < ninout; ii++ ) { xinout[ii] = tlat[(ii+ip) % ninout]; yinout[ii] = tlon[(ii+ip) % ninout]; inout[ii] = tinout[(ii+ip) % ninout]; } } } } ip = 0; while ( ip < ninout ) { ibeg = ip; iend = ip; while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++; iend = ip - 1; numpts = iend - ibeg + 1; if (el.hdr.closed == 1 && numpts != ninout ) el.hdr.closed = 0; if ( numpts > 1 ) { if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 )) { el.elem.gfa.info.npts = numpts; ptrlat = &(el.elem.gfa.latlon[ 0]); ptrlon = &(el.elem.gfa.latlon[numpts]); memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float)); memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float)); /* Recompute Default Text Label & Arrow location */ recalcGFAtLblArwLoc( &el ); el.hdr.recsz = (int) (sizeof(VG_HdrStruct) + sizeof(int)*2 + sizeof(char)* STD_STRLEN * el.elem.gfa.info.nblocks ) + sizeof(float)*numpts*2; cvg_writef ( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); } } } } else { /* We have a GFA object (that's not a freezing level) to be clipped */ /* Use clo_clip to clip the GFA Polygon against the specified bounds area. The resulting number of clipped areas (tnclips), and max points (tmaxpts) is returned */ clo_clip(&npts, plat, plon, sys_M, bnd_name, bnd_tag, &tnclip, &tmaxpts, &ier); /* Foreach of the clipped areas, get the clipped area, and write it out to the VGF file */ for (ii = 0; ii < tnclip; ii++) { clo_clipget(&ii, &tnpts, tlat, tlon, &ier); el.elem.gfa.info.npts = tnpts; ptrlat = &(el.elem.gfa.latlon[ 0]); ptrlon = &(el.elem.gfa.latlon[tnpts]); /* Re-Initialize the latlon struct. */ for (jj =0; jj < MAXPTS*2; jj++) { el.elem.gfa.latlon[jj] = 0.00; } memcpy(ptrlat, &(tlat[0]), (size_t)tnpts*sizeof(float)); memcpy(ptrlon, &(tlon[0]), (size_t)tnpts*sizeof(float)); /* Recompute Default Text Label & Arrow location */ recalcGFAtLblArwLoc( &el ); el.hdr.recsz = (int) (sizeof(VG_HdrStruct) + sizeof(int)*2 + sizeof(char)* STD_STRLEN * el.elem.gfa.info.nblocks ) + sizeof(float)*tnpts*2; cvg_writef (&el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); } /* Free up memory left over from the clo routines */ clo_clipdone(&ier); } break; } break; } } ne++; } cfl_clos ( ifptr, &ier ); return(0); }
int main ( void ) /************************************************************************ * TESTCVQ * * * * This program tests the CGEMLIB "CVQ" functions. * * * ** * * Log: * * E. Wehner/EAi 6/97 Created * * E. Wehner/EAi 7/97 Fixed typecasting of group type * * E. Wehner/EAi 7/97 Added cvq_higrp. * * I. Durham/GSC 5/98 Changed underscore decl. to an include * * A. Hardy/SAIC 11/01 Added maxoff to cvq_scangrp * ***********************************************************************/ { int cont, iret, numsub, i, ier; int flag, level, elevel, ebuff; int eflag; int ingrp, maxoff; long size; char select[LLSCRN], filnam[LLSCRN]; char grp[4], path[133]; VG_DBStruct el; int vgstart; char gptyp; /* group type */ int gpnum; /* group number */ int members[10]; int fpos; int tgtyp; /* temporary group type */ /*---------------------------------------------------------------------*/ iret = 0; size = 0; cont = G_FALSE; flag = G_FALSE; eflag = G_FALSE; strcpy(grp, "CVQ"); level = 0; elevel = 2; ebuff = 0; in_bdta(&ier); er_stat(&elevel, &ebuff, &eflag, &ier); vgstart = 0; cvg_rdrec ( filnam, vgstart, &el, &iret ); while ( cont == G_FALSE ) { numsub = 0; printf ( "\n\n" ); printf (" 1 = CVQ_SCANGRP 2 = CVQ_GETGINF 3 = CVQ_NXTGNM\n"); printf (" 4 = CVQ_HIGP \n"); printf ( "\n" ); printf ( "Select a function number or type EXIT: " ); scanf ( " %s", select ); switch ( select[0] ) { case 'e': case 'E': cont = G_TRUE; break; default: numsub = atoi ( select ); break; } /*---------------------------------------------------------------------*/ switch (numsub) { /* * ---------------------------------------------------------- * CVQ_SCANGRP - retrieve the members of a group * ---------------------------------------------------------- */ case 1: printf ( "Enter the VG file name to scan:\n" ); scanf ( " %s", filnam ); printf( "Enter Group type to retrieve:\n"); scanf( " %i", &tgtyp); printf( "Enter Group number to retrieve: \n"); scanf( " %i", &gpnum); printf( "Enter maximum number of offsets to find: \n"); scanf( " %i", &maxoff); gptyp = (char)tgtyp; cvq_scangrp( filnam, gptyp, gpnum, maxoff, members, &ingrp, &iret); printf ( "\nCVQ_SCANGRP: iret = %d\n\n", iret ); printf(" Extracted %i elements in group: %i/%i \n", ingrp, gptyp, gpnum); for (i = 0; i< ingrp; i++) { /* read header */ cfl_inqr ( filnam, " ", &size, path, &ier ); if (members[i] < size) { cvg_rdrec ( filnam, members[i], &el, &iret ); cvg_dump ( el, el.hdr.recsz, el.hdr.recsz, flag, &iret ); } } er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; /* * ---------------------------------------------------------- * CVQ_GETGINF - Return group type and number from elem. * ---------------------------------------------------------- */ case 2: printf ( "Enter the VG file name to examine:\n" ); scanf ( " %s", filnam ); printf( "Enter file location of element in question:\n"); scanf( " %i", &fpos); cvq_getginf( filnam, fpos, &gptyp, &gpnum, &iret); printf ( "\nCVQ_GETGINF: iret = %d\n\n", iret ); printf(" Element is in group %c %i \n", gptyp, gpnum); er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; /* * ---------------------------------------------------------- * CVQ_NXTGNM - Get next group number used in file * ---------------------------------------------------------- */ case 3: printf ( "Enter the VG file name to examine:\n" ); scanf ( " %s", filnam ); printf( "Enter the group type to retrieve from:\n"); scanf( " %i", &tgtyp); gptyp = (char)tgtyp; printf( "Locate the next group number above: \n"); scanf( " %i", &gpnum); cvq_nxtgnm( filnam, gptyp, &gpnum, &iret); printf ( "\nCVQ_NXTGNM: iret = %d\n\n", iret ); printf(" The next group number of group type %c is %i \n", gptyp, gpnum); er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; /* * ---------------------------------------------------------- * CVQ_HIGP - Get highest group number used in file * ---------------------------------------------------------- */ case 4: printf ( "Enter the VG file name to examine:\n" ); scanf ( " %s", filnam ); cvq_higp( filnam, &gpnum, &iret); printf ( "\nCVQ_HIGP: iret = %d\n\n", iret ); printf(" The highest group number is %i \n", gpnum); er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; } } return 0; }
void cvg_valid ( char *filnam, int *iret ) /************************************************************************ * cvg_valid * * * * This function checks validity of a VG file. * * * * cvg_valid ( filnam, iret ) * * * * Input parameters: * * *filnam char VG filename * * * * Output parameters: * * *iret int Return code * * 1 = VG file does not exist * * 0 = normal * * -1 = error opening VG file * * -13 = error verifying vg file * * -25 = no filehead elm in file * * -47 = no file name specified * ** * * Log: * * T. Lee/SAIC 05/02 created * * T. Lee/SAIC 11/03 used cvgcmn.h * ***********************************************************************/ { int ier, flag, curpos; long maxbytes; VG_DBStruct el; char newfil[256]; FILE *fptr; /*---------------------------------------------------------------------*/ *iret = 0; fptr = NULL; /* * Check to see if there is a file of the specified name. */ if ( strlen (filnam) <= (size_t)0 ) { *iret = -47; return; } cfl_inqr(filnam, NULL, &maxbytes, newfil, &ier); if (ier < 0) { /* * if file does not exist retrun error code 1. */ *iret = 1; return; } /* * Open the file. */ fptr = cfl_ropn (newfil, NULL, &ier); if ( ( ier != 0 ) || ( fptr == NULL ) ) { /* open failed */ *iret = -1; return; } else { if ( maxbytes < (long)(sizeof(FileHeadType) + sizeof(VG_HdrStruct)) ) { *iret = -25; } else { /* * Check to see that the file is a valid VGF file... */ curpos = 0; cvg_rdhdr (newfil, fptr, curpos, (int)maxbytes, &el, &flag, &ier); if (ier != 0) { *iret = -13; } if (el.hdr.vg_type != FILEHEAD_ELM) { *iret = -25; } } cfl_clos ( fptr, &ier ); } }
void db_rdtr ( char *queryType, char *source, char *part, char *dattim, char *stid, char *dataUri, int *icnt, float *rdata, int *nword, int *iret ) /************************************************************************ * * * db_rdtr * * * * This function returns array of data values from the AWIPS II DB * * given certain data criteria. * * * * void db_rdtr ( char *queryType, char *source, char *part, * * char *dattim, char *stid, char *dataUri, int *icnt, * * float *rdata, int *nword, int *iret ) * * * * Input parameters: * * queryType char Type of query * * source char Source of data * * part char Part name * * dattim char The data time * * stid char Station ID * * dataUri char Data URI * * icnt int Number of stations (obsolete) * * * * Output parameters: * * rdata float Array of data values * * nword float Length of rdata array * * iret int Return code: * * 0 - normal return * * -1 - unable to get dataURI * * * ** * * Log: * * m.gamazaychikov/CWS 04/11 Created * ************************************************************************/ { int numberPayloadParts = 2; int payloadPartLength = 50; int bufferSize = 200000; char xsltFile[LLSCRN] = "response.xlt"; char xsltDir[LLSCRN] = "$NAWIPS/gempak/tables/xslt"; int ier, nbytes, ier1, nwrd, istmax, jj; long flen; char queryText[320], queryResult[bufferSize+1], xsltfile[FILE_FULLSZ]; char errStr[100], payload[100]; unsigned char* bigStr; char **starr; /*---------------------------------------------------------------------*/ /* * Initialization */ *iret = 0; queryText[0] = '\0'; queryResult[0] = '\0'; /* * Populate the query strings */ if (strcmp ( queryType, "gridDat" ) == 0 ) { if ( strcmp ( source, "GRID") == 0 ) { strcpy (eSrc, source); sprintf (eDistnctField, "%s", dataUri); sprintf (gDattim, "%s", dattim); eCount = 1; sprintf (eLibClass, "%s", "GempakGridLinkRequest"); } else { ier = -9; sprintf (errStr, "%s+", queryType); strcat (errStr, source); er_wmsg ( "DB", &ier, errStr, &ier1, 2, strlen(errStr) ); *iret = -1; return; } } else { ier = -8; er_wmsg ( "DB", &ier, queryType, &ier1, 2, strlen(queryType) ); *iret = -1; return; } /* * Get the query text */ db_getQueryText ( queryType, queryText, &ier); if ( ier !=0 ) { ier = -3; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); *iret = -1; return; } /* * Connect to database and get the query result */ db_runQuery ( queryText, queryResult, &ier); if ( ier !=0 ) { ier = -4; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); *iret = -1; return; } /* * Transform XML string to a string containing the name of the file * stored on the server side */ cfl_inqr(xsltFile, xsltDir, &flen, xsltfile, &ier); if ( ier !=0 ) { /* * XSLT file not found -> returning */ ier = -5; er_wmsg ( "DB", &ier, xsltFile, &ier1, 2, strlen(xsltFile) ); *iret = -1; return; } nbytes=xml_transform( queryResult, strlen(queryResult), xsltfile, &bigStr, &ier ); if ( ier !=0 || nbytes==0) { /* * XML Transform run unsuccessfully -> returning */ ier = -6; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); G_FREE( bigStr, unsigned char ); *iret = -1; return; } sprintf( payload, "%s", bigStr ); G_FREE( bigStr, unsigned char ); /* * Break the payload string into parts containing the dbHost and fileName */ starr = (char **)malloc((size_t)numberPayloadParts * sizeof(char *)); for( jj=0; jj < numberPayloadParts; jj++ ) starr[jj] = (char *)malloc( payloadPartLength * sizeof(char)); cst_clst (payload, '|', " ", numberPayloadParts, payloadPartLength, starr, &istmax, &ier); if ( ier !=0 || istmax != 2 ) { ier = -13; er_wmsg ( "DB", &ier, source, &ier1, 2, strlen(source) ); *iret = -1; for ( jj = 0; jj < numberPayloadParts; jj++ ) free( starr[jj] ); if( starr ) free( (char **)starr ); return; } /* * Get the data from the server side */ db_getRData(starr[0], starr[1], rdata, &nwrd, &ier); for ( jj = 0; jj < numberPayloadParts; jj++ ) free( starr[jj] ); if( starr ) free( (char **)starr ); *nword = nwrd; if ( ier !=0 ) { if ( ier == -1 ) { ier = -10; er_wmsg ( "DB", &ier, source, &ier1, 2, strlen(source) ); *iret = -1; return; } if ( ier == -2 ) { ier = -15; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); *iret = -1; return; } } return; }
void NxmCursor_createCursor ( int ref ) /************************************************************************ * NxmCursor_createCursor * * * * This function creates the cursor for a specific reference index * * * * void NxmCursor_createCursor(ref) * * * * Input parameters: * * ref int reference # of cursor * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * H. Zeng/EAI 04/00 initial coding * * H. Zeng/EAI 05/00 added incorrect info. handling * ***********************************************************************/ { int ii, x_hot, y_hot; int cursor_id = IMPVAL, iret1, iret2; long int no_use; unsigned int width, height; Pixmap cursor_pixmap, mask_pixmap; XColor fgcolr, bgcolr, ignore; char cursor_name[20], pix_name[25], cursor_file[128]; char cursor_mask[128], cursor_color[10]; char bg_color[] = "black", *ptr; Status status; /*---------------------------------------------------------------------*/ /* * Find cursor type and cursor color according to the reference #. */ strcpy(cursor_name, _currefTbl.currefs[ref].typ_name); strcpy(cursor_color, _currefTbl.currefs[ref].color); for(ii = 0; ii < _curtypTbl.ntyp; ii++) { if( strcmp(cursor_name,_curtypTbl.curtyps[ii].ext_name)==0 ) { strcpy(pix_name, _curtypTbl.curtyps[ii].int_name); cursor_id = _curtypTbl.curtyps[ii].id; break; } } /* * For garbage cursor_name */ if(cursor_id == IMPVAL) { switch(ref) { case 0: cursor_id = 132; break; case 1: cursor_id = 34; break; case 2: cursor_id = 0; break; default: cursor_id = 132; break; } } /* * Get foreground color and background color. */ fgcolr.flags = DoRed | DoBlue | DoGreen; status = XAllocNamedColor (NXMdisplay, NXMcmap, cursor_color, &fgcolr, &ignore); /* * For garbage cursor_color */ if(status == 0) { XAllocNamedColor (NXMdisplay, NXMcmap, "white", &fgcolr, &ignore); } bgcolr.flags = DoRed | DoBlue | DoGreen; XAllocNamedColor (NXMdisplay, NXMcmap, bg_color, &bgcolr, &ignore); /* * According to whether cursor_id is -1 or not, create * pixmap cursor or standard cursor. */ if( cursor_id != -1 ) { /* * create standard cursor */ if( _cursorRef[ref] != (Cursor)0 ) { XFreeCursor(NXMdisplay, _cursorRef[ref]); } _cursorRef[ref] = XCreateFontCursor(NXMdisplay, (Cardinal)cursor_id); XRecolorCursor (NXMdisplay, _cursorRef[ref], &fgcolr, &bgcolr); } else { strcat(pix_name, ".xbm"); cfl_inqr (pix_name, ICON_DIR, &no_use, cursor_file, &iret1 ); ptr = strstr(pix_name, ".xbm"); sprintf (ptr, "_mask.xbm"); cfl_inqr (pix_name, ICON_DIR, &no_use, cursor_mask, &iret2 ); if( (iret1 != 0) || (iret2 != 0) ) { /* * File not found ! */ fprintf(stderr, "\nPixmap file not found!\n"); fprintf(stderr, "Please check the cursor type table.\n\n"); switch(ref) { case 0: cfl_inqr ("lg_arrow.xbm", ICON_DIR, &no_use, cursor_file, &iret1 ); cfl_inqr ("lg_arrow_mask.xbm", ICON_DIR, &no_use, cursor_mask, &iret2 ); break; case 1: cfl_inqr ("lg_cross.xbm", ICON_DIR, &no_use, cursor_file, &iret1 ); cfl_inqr ("lg_cross_mask.xbm", ICON_DIR, &no_use, cursor_mask, &iret2 ); break; case 2: cfl_inqr ("lg_x.xbm", ICON_DIR, &no_use, cursor_file, &iret1 ); cfl_inqr ("lg_x_mask.xbm", ICON_DIR, &no_use, cursor_mask, &iret2 ); break; default: cfl_inqr ("lg_arrow.xbm", ICON_DIR, &no_use, cursor_file, &iret1 ); cfl_inqr ("lg_arrow_mask.xbm", ICON_DIR, &no_use, cursor_mask, &iret2 ); break; } } XReadBitmapFile(NXMdisplay, _bxmWin, cursor_mask, &width, &height, &mask_pixmap, &x_hot, &y_hot ); XReadBitmapFile(NXMdisplay, _bxmWin, cursor_file, &width, &height, &cursor_pixmap, &x_hot, &y_hot ); if( _cursorRef[ref] != (Cursor)0 ) { XFreeCursor(NXMdisplay, _cursorRef[ref]); } _cursorRef[ref] = XCreatePixmapCursor(NXMdisplay, cursor_pixmap, mask_pixmap, &fgcolr, &bgcolr, (Cardinal)x_hot, (Cardinal)y_hot ); XFreePixmap(NXMdisplay, mask_pixmap); XFreePixmap(NXMdisplay, cursor_pixmap); }/* the end of else part */ }
void cvg_load ( char *fname, Boolean selflag, Boolean wrtflg, Boolean plotflg, int layer, int icol, int *iret ) /************************************************************************ * cvg_load * * * * This function loads data from a VGF formatted file and converts * * encountered records to a set of actions that display the feature * * to an appropriate driver. The parameter icol controls whether the * * graphics will be plotted with the file-specified colors (icol=0) * * or whether the VGF file will be plotted monochrome (icol=other). * * * * void cvg_load ( fname, selflag, wrtflg, plotflg, layer, icol, iret ) * * * * Input parameters: * * *fname char Name of file to load * * selflag Boolean Are elements "selectable" * * wrtflg Boolean Write flag for file * * plotflg Boolean Display the elements or not * * layer int Layer the file contents will be * * assigned to * * icol int Plot color * * * * Output parameters: * * *iret int Return code * * 1 = elms in file exceeded * * (MAX_EDITABLE_ELEMS) * * -1 = error opening VG file * * -2 = error closing VG file * * -4 = error reading el hdr * * -5 = VG file is empty * ** * * Log: * * E. Wehner/EAi 10/96 Created * * D. Keiser/GSC 1/97 Clean up * * E. Wehner/EAi 2/97 Added selection flag. * * E. Wehner/EAi 5/97 Add double tier loading * * E. Wehner/EAi 5/97 Stop loading if > MAX_EDITABLE_ELEMS * * E. Wehner/EAi 5/97 Added refresh after displaying * * D. Keiser/GSC 5/97 Change cvg_dsply to cds_dspvg * * S. Jacobs/NCEP 6/97 Added write flag * * C. Lin/NCEP 6/97 Bug fix in calling cfl_ropn * * E. Wehner/EAi 6/97 Added check to not load header * * E. Wehner/EAi 7/97 Filled areas on all elements * * E. Wehner/EAi 8/97 Removed the graphics info record. * * E. Wehner/EAi 9/97 Allow NULL file name * * F. Yen/NCEP 1/98 Updated calls for crg library cleanup * * I. Durham/GSC 5/98 Changed underscore decl. to an include * * F. J. Yen/NCEP 5/98 Updated cds function names * * E. Safford/GSC 10/98 added display levels revised file reads * * T. Piper/GSC 10/98 Prolog update * * E. Safford/GSC 12/98 move display levels to pgprm.h * * S. Jacobs/NCEP 3/99 Added symbols to the last display level * * A. Hardy/GSC 1/01 changed fptr from int to FILE * * J. WU/SAIC 11/01 change prototype & add plotflg param * * J. WU/SAIC 12/01 add layer param to feed crg_set() * * J. WU/SAIC 12/01 locate displaying level with cvg_level * * T. Lee/SAIC 11/03 changed .DEFAULT.vgf to work_file * * T. Lee/SAIC 11/03 used cvgcmn.h * * M. Li/SAIC 08/04 Added time filter * * B. Yin/SAIC 08/04 Added code to free TCA memory * * B. Yin/SAIC 08/04 changed pgtca_freeBkpts to cvg_freeBkpts* * J. Wu/SAIC 10/04 free GFA block pointers * * S. Danz/AWC 03/06 Call autoplacement if enabled * * J. Wu/SAIC 06/06 call cvg_matchfilter * * M. Li/SAIC 03/07 Updated cvg_matchfilter * * m.gamazaychikov/SAIC 06/07 Add code to free TCB and TCT memory * ***********************************************************************/ { int curpos, ier, flag, el_level; long maxbytes; int ier1, loglev, ic, icx, ii, jj, kk, one=1; int elms[3][MAX_EDITABLE_ELEMS], lvl_cnt[LEVELS], total_elms; char newfil[LLPATH], reqfil[LLPATH], grp[4], dbgfile[LLPATH]; Boolean autopl_enabled; VG_DBStruct el; filter_t el_filter, timeMatched; Boolean filter_match, matchAny = False; FILE *fptr; CMDObjectSet nmap_metadata = NULL; PlacementSet nmap_placements = NULL; cvg_group_info *nmap_group_check = NULL; /*---------------------------------------------------------------------*/ ic = icol; icx = 256; if ( ic > icx || ic < 0 ) ic = 0; cds_scol ( ic, iret ); strcpy(grp, "CVG"); loglev = 0; *iret = 0; curpos = 0; maxbytes = 0; if (!fname) { strcpy(reqfil, work_file); } else { strcpy(reqfil, fname); } cvg_open(reqfil, (int)wrtflg, &fptr, &ier); if (( ier != 0 ) || ( fptr == NULL )) { *iret = -1; er_lmsg( &loglev, grp, &ier, reqfil, &ier1, strlen(grp),strlen(reqfil)); return; } cfl_inqr(reqfil, NULL, &maxbytes, newfil, &ier); if (ier < 0) { *iret = -1; er_lmsg( &loglev, grp, &ier, reqfil, &ier1, strlen(grp),strlen(reqfil)); return; } /* * Get each el.hdr and assign each elem offset to one of the levels. */ for (ii = 0; ii < 3; ii++) { lvl_cnt[ii] = 0; } /* * Scan the vg file and load the offsets of all non-deleted elements. * Stop loading at end of file or MAX_EDITABLE_ELEMS. */ total_elms = 0; while (((long)curpos < maxbytes) && (total_elms < MAX_EDITABLE_ELEMS)) { cvg_rdhdr(newfil, fptr, curpos, (int)maxbytes, &el, &flag, &ier); if (ier < 0 || el.hdr.recsz < 0 || el.hdr.recsz > 65536) { *iret = -4; return; } cvg_level( &el.hdr, &el_level, &ier ); if ( ier == 0 ) { elms[ el_level ] [ lvl_cnt[el_level]++ ] = curpos; total_elms++; } curpos += el.hdr.recsz; } if (total_elms >= MAX_EDITABLE_ELEMS) { *iret = 1; er_lmsg( &loglev, grp, &ier, newfil, &ier1, strlen(grp),strlen(reqfil)); } /* * Create the structures to manage the metadata and object placement * information. If there were structures already in place, hold them * aside as they were put there by product generation. */ ctb_pfbool( "ENABLE_AUTOPLACE", &autopl_enabled, &ier ); if (autopl_enabled) { if (cvg_metadata) { nmap_metadata = cvg_metadata; nmap_placements = cvg_placements; nmap_group_check = cvg_group_check; } cmd_osnew(&cvg_metadata, &ier); cap_psnew(&cvg_placements, &ier); G_CALLOC(cvg_group_check, cvg_group_info, one, "cvg_load: cvg_group_check"); /* * Fill in the structures with the information needed */ cvg_ld4place(fname, iret); /* * Ok, its all loaded, so place all the objects where they belong */ cap_psplace(cvg_placements, cvg_metadata, iret); ctb_pfstr("AUTOPLACE_DBG", dbgfile, &ier ); if (dbgfile[0] != '\0') { dump_objects(dbgfile, cvg_metadata, cvg_placements); } } /* * Now loop thru the levels and display the elements */ kk = 0; for (ii = 0; ii < LEVELS; ii++) { for (jj=0; jj<lvl_cnt[kk]; jj++) { curpos = elms[ii][jj]; cvg_rdhdr(newfil, fptr, curpos, (int)maxbytes, &el, &flag, &ier); cvg_rdele(&el, curpos, el.hdr.recsz, fptr, &ier); cvg_getElFilter ( &el, el_filter, &ier ); cvg_matchfilter ( el_filter, matchAny, &filter_match, timeMatched, &ier ); if (selflag) { crg_set(&el, curpos, layer, &ier); } if ( filter_match ) { cds_dspelm( &el, &ier); } /* * Free TCA/GFA/TCT/TCB memory */ if ( el.hdr.vg_type == TCA_ELM ) { cvg_freeBkpts ( &el ); } else if ( el.hdr.vg_type == GFA_ELM ) { cvg_freeElPtr ( &el ); } else if ( el.hdr.vg_type == TCTRK_ELM ) { cvg_freeTct ( &el ); } else if ( el.hdr.vg_type == TCBKL_ELM ) { cvg_freeTcb ( &el ); } } kk++; } cvg_clos(fptr, &ier); if ( ier != 0 ) *iret = -2; if ( plotflg ) geplot(&ier); ic = 0; cds_scol ( ic, iret ); /* * Free up the metadata and placement information now that we * are done plotting everything */ if (autopl_enabled) { cmd_osdel(cvg_metadata, iret); cap_psdel(cvg_placements, iret); G_FREE(cvg_group_check, cvg_group_info); /* * Put back the product generation metadata */ cvg_metadata = nmap_metadata; cvg_placements = nmap_placements; cvg_group_check = nmap_group_check; } return; }
void msdatt ( int *iunit, char *filnam, int *lenf, int *itype, float *xsize, float *ysize, int *ileft, int *ibot, int *iright, int *itop, int *iret ) /************************************************************************ * msdatt * * * * This subroutine is called to initialize the metafile attributes. * * * * msdatt ( iunit, filnam, lenf, itype, xsize, ysize, * * ileft, ibot, iright, itop, iret ) * * * * Input parameters: * * *iunit int Output type (Used for XW only) * * *filnam char Output metafile name * * *lenf int Length of file name * * *itype int Device color type * * *xsize float X size in pixels * * *ysize float Y size in pixels * * * * Output parameters: * * *ileft int Left device coordinate * * *ibot int Bottom device coordinate * * *iright int Right device coordinate * * *itop int Top device coordinate * * *iret int Return code * ** * * Log: * * S. Jacobs/NCEP 2/96 * * S. Jacobs/NCEP 5/96 Added new global variables for queries * * S. Jacobs/NCEP 2/97 Fixed check for same file name * * R. Tian/SAIC 4/02 Added init of ileft, ibot, iright, itop * * M. Li/SAIC 7/02 Added G_NINT * ***********************************************************************/ { int ier; char tmpfil[MAX_FNLEN]; int tmpxz, tmpyz; long flen; int nbin; FILE *fp; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * If the input length is greater than the maximum allowed, * return an error. */ if ( ( *lenf >= MAX_FNLEN ) || ( *lenf <= 0 ) ) { *iret = G_NOMETA; return; } /* * Copy the file name to a temporary variable and add a NULL. */ strncpy ( tmpfil, filnam, (size_t)*lenf ); tmpfil[*lenf] = CHNULL; /* * Compare the input file name to the current file name. If the * names are different, close the old file. Otherwise, do nothing. */ if ( strcmp ( curfil, tmpfil ) != 0 ) { mclose ( &ier ); /* * Set the current file name. */ strcpy ( curfil, tmpfil ); *iret = G_NEWWIN; /* * Set the global output and color scheme types. */ kctype = *itype; kunit = *iunit; /* * Check for the existence of the metafile. */ cfl_inqr(curfil, NULL, &flen, tmpfil, &ier); if ( ( ier == 0 ) && ( strcmp ( curfil, "Nmeta" ) != 0 ) ) { /* * Get frame size from the existing file */ if ( ( fp = cfl_ropn(curfil, NULL, &ier) ) == NULL ) { *iret = G_NOMETA; return; } cfl_read(fp, sizeof(nc_file_header), (unsigned char *)&meta_head, &nbin, &ier); if ( ier ) { *iret = G_NOMETA; cfl_clos(fp, &ier); return; } cfl_clos(fp, &ier); if ( meta_head.version == 2 ) { /* * Set the global CGM frame size */ fxsize = meta_head.fxsize; fysize = meta_head.fysize; /* * ileft = left device coordinate * ibot = bottom device coordinate * iright = right device coordinate * itop = top device coordinate */ *ileft = 0; *ibot = 0; *iright = (int)meta_head.fxsize; *itop = (int)meta_head.fysize; } } else { /* * The valid range of xsize and ysize is 0.1 ~ 1.0. If neither * value is 1.0, then set the larger value to be 1.0, and set the * smaller value to be the ratio of the smaller to the larger. */ tmpxz = G_NINT(*xsize * (float)XY_SCALE); tmpyz = G_NINT(*ysize * (float)XY_SCALE); tmpxz = (tmpxz < 0 || tmpxz > XY_SCALE) ? XY_SCALE : tmpxz; tmpyz = (tmpyz < 0 || tmpyz > XY_SCALE) ? XY_SCALE : tmpyz; if(tmpxz != XY_SCALE && tmpyz != XY_SCALE) { if(tmpxz > tmpyz) { tmpyz = G_NINT((((float)tmpyz)/(float)tmpxz)*(float)XY_SCALE); tmpxz = XY_SCALE; } else if(tmpxz < tmpyz) { tmpxz = G_NINT((((float)tmpxz)/(float)tmpyz)*(float)XY_SCALE); tmpyz = XY_SCALE; } else { tmpxz = XY_SCALE; tmpyz = XY_SCALE; } } tmpxz = (tmpxz < G_NINT(0.1F*(float)XY_SCALE)) ? G_NINT(0.1F*(float)XY_SCALE) : tmpxz; tmpyz = (tmpyz < G_NINT(0.1F*(float)XY_SCALE)) ? G_NINT(0.1F*(float)XY_SCALE) : tmpyz; /* * Set the global CGM frame size */ fxsize = (unsigned short)tmpxz; fysize = (unsigned short)tmpyz;; /* * ileft = left device coordinate * ibot = bottom device coordinate * iright = right device coordinate * itop = top device coordinate */ *ileft = 0; *ibot = 0; *iright = tmpxz; *itop = tmpyz; } } }
int main ( int argc, char **argv ) /************************************************************************ * VGF2TAG * * * * This program converts a file of pgen elements in <tag>value format * * into a standard VGF file. * * * ** * * Log: * * D.W.Plummer/NCEP 06/03 * * S. Jacobs/NCEP 5/05 Increased the size of the buffer * * S. Jacobs/NCEP 12/09 Changed cvg_rdrecnoc to cvg_rdjrecnoc * * S. Jacobs/NCEP 1/12 Changed cvg_jrdrecnoc to cvg_rdrecnoc * ***********************************************************************/ { int ne, more, ier; int wrtflg, curpos; VG_DBStruct el; char asfn[32], vgfn[128]; char comment[8]={"!\n"}, buffer[10000]; char infile[128], ifname[128]; long ifilesize; int nw; FILE *ifptr, *ofptr; /*---------------------------------------------------------------------*/ printf ( "Enter the VGF file name to convert from :\n" ); scanf ( " %s", vgfn ); printf ( "Enter the ASCII file name to write tags to :\n" ); scanf ( " %s", asfn ); wrtflg = 0; cvg_open ( vgfn, wrtflg, &(ifptr), &ier ); if ( ier != 0 ) { printf("Error opening VGF file %s\n", infile ); exit (0); } cfl_inqr ( vgfn, NULL, &ifilesize, ifname, &ier ); ofptr = cfl_wopn ( asfn, &ier ); nw = 0; ne = 0; more = G_TRUE; curpos = 0; ifptr = (FILE *) cfl_ropn(ifname, "", &ier); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else if ( el.hdr.recsz > 0 ) { curpos += el.hdr.recsz; cvg_v2t ( &el, buffer, &ier ); if ( ier == 0 ) { cfl_writ ( ofptr, (int)strlen("!\n"), (unsigned char*)comment, &ier ); strcat ( buffer, "\n" ); cfl_writ ( ofptr, (int)strlen(buffer), (unsigned char*)buffer, &ier ); if ( ier == 0 ) nw++; } } } printf("Number of elements encoded and written successfully = %d\n", nw ); return ( 0 ); }
void cvg_redraw ( char *fname, int *iret ) /************************************************************************ * cvg_redraw * * * * This function re-displays all records in a given VG file. If no file * * name is given, records in WORK_FILE will be redrawn. * * * * cvg_redraw ( fname, iret ) * * * * Input parameters: * * *fname char File name to redraw from * * * * Output parameters: * * *iret int Return code * * -1 = error opening VG file * * -2 = error closing VG file * ** * * Log: * * J. Wu/SAIC 12/01 modify from cvg_rfrsh() * * J. Wu/SAIC 02/02 add layering with cvg_drawLayer() * * J. Wu/SAIC 03/02 change loop max. from 2 to MAX_LAYERS * * J. Wu/SAIC 03/02 set proper color/fill mode for redraw * * E. Safford/SAIC 03/02 rm the display-on check for cur layer * * T. Lee/SAIC 11/03 added user directory to work_file * * T. Lee/SAIC 11/03 used cvgcmn.h * * S. Danz/AWC 08/06 Call cvg_rebuildplace to update placement * * before the redraw in case the device changed* ***********************************************************************/ { int ii, ier, icol, ifill, cur_layer; long maxbytes; char newfil[256], reqfil[256]; FILE *fp; /*---------------------------------------------------------------------*/ *iret = 0; cur_layer = pglayer_getCurLayer (); if (!fname) strcpy( reqfil, work_file ); else strcpy( reqfil, fname ); /* * Update the placement info */ cvg_rebuildplace(fname, &ier); /* * Open the specified file or WORK_FILE if it exists. */ cfl_inqr( reqfil, NULL, &maxbytes, newfil, &ier ); /* * If empty file just return, otherwise, attempt to open the file. * Report an error if applicable. */ if (maxbytes == 0) { return; } else { fp = (FILE *) cfl_ropn( newfil, NULL, &ier ); if ( ( ier != 0 ) || ( fp == NULL ) ) { *iret = -1; return; } } /* * Draw elements layer by layer except those on the current layer. */ for ( ii = 0; ii < MAX_LAYERS; ii++ ) { icol = 0; ifill = G_TRUE; /* * skip current layer, layers not in use or dsply_on is off. */ if ( ii == cur_layer || ( !pglayer_getInUse(ii) ) || ( !pglayer_getDsplOn(ii) ) ) { continue; } /* * Set required color & fill mode. */ if ( !pglayer_getDsplClr(ii) ) icol = pglayer_getMonoClr ( ii ); if ( !pglayer_getFill(ii) ) ifill = G_FALSE; cds_scol ( icol, iret ); cds_sfill ( &ifill, &ier ); /* * Draw elements. */ cvg_drawLayer ( fp, newfil, ii, (int)maxbytes, &ier ); } /* * Always draw elements on the current layer in full color & * fill mode if its dspl_on flag is on. */ icol = 0; ifill = G_TRUE; cds_scol ( icol, iret ); cds_sfill ( &ifill, &ier ); cvg_drawLayer ( fp, newfil, cur_layer, (int)maxbytes, &ier ); cfl_clos( fp, &ier ); if ( ier != 0 ) { *iret = -2; } geplot(&ier); }
int main ( void ) /************************************************************************ * TESTSPF * * * * This program tests the CGEMLIB "SPF" library functions. * * * ** * * Log: * * J. Wu/GSC 6/01 create * * H. Zeng/SAIC 9/04 spf_read() para. list change * ***********************************************************************/ { int cont, numsub, iret, nbytes, ier, eliblen, errlen; char select[LLSCRN], filnam[LLSCRN], newfil[FILE_FULLSZ]; char ans[LLSCRN], tag[LLSCRN], data[TAGDATA_BUF]; char errlib[3], errstr[2]; long lflen; FILE *filptr; /*---------------------------------------------------------------------*/ cont = G_TRUE; filptr = NULL; strcpy( errlib, "SPF" ); strcpy( errstr, " " ); eliblen = strlen( errlib ); errlen = strlen( errstr ); while ( cont == G_TRUE ) { printf ( "\n\n" ); printf ( " ? = Print HELP file\n\n"); printf ( " D - Dump a loaded SPF file\n\n"); printf ( " 1 = SPF_CREATE 2 = SPF_OPEN 3 = SPF_READ\n" ); printf ( " 4 = SPF_LOAD 5 = SPF_WRITE 6 = SPF_GTFLD\n" ); printf ( " 7 = SPF_CLNUP 8 = SPF_CLOSE \n" ); printf ( "\n" ); printf ( "Select a subroutine number or type EXIT: " ); scanf ( " %s", select ); numsub = 0; switch ( select[0] ) { case '?': printf ("\n *** HELP FILE ***\n\n"); printf (" D - Dump a loaded SPF file\n\n"); printf (" 1 = spf_create - Create an SPF file\n" ); printf (" 2 = spf_open - Open an SPF file\n" ); printf (" 3 = spf_read - Read an opened SPF into buffer\n" ); printf (" 4 = spf_load - Load an unopened SPF into buffer\n" ); printf (" 5 = spf_write - Write a tag/data pair to an SPF\n" ); printf (" 6 = spf_gtfld - Get data field associated with a tag\n" ); printf (" 7 = spf_clnup - Clean up SPF buffer\n" ); printf (" 8 = spf_close - Close an SPF file\n" ); printf ( "\n" ); break; case 'd': case 'D': if ( _spfBuffer != (char *)NULL ) { printf ( "\n%s\n", _spfBuffer ); } else { printf ( "\nPlease load the buffer first.\n" ); } break; case 'e': case 'E': cont = G_FALSE; break; default: numsub = atoi ( select ); break; } /*---------------------------------------------------------------------*/ if ( numsub == 1 ) { if ( filptr != NULL ) { printf ( "\nPlease close the opened file first.\n" ); } else { printf ( "Enter the file name:\n" ); scanf ( " %s", filnam ); cfl_inqr( filnam, NULL, &lflen, newfil, &ier ); if ( ier != 0 ) { strcat( filnam, ".spf" ); cfl_inqr( filnam, NULL, &lflen, newfil, &ier ); } if ( ier == 0 ) { printf ( "\nCan't create, file %s already exists!\n", newfil ); } else { nbytes = (int)lflen; filptr = (FILE *)spf_create ( filnam, &nbytes, &iret ); if ( iret == 0 ) { printf ( "\nSPF_CREATE: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, filnam, &ier, eliblen, strlen(filnam) ); } } } } /*---------------------------------------------------------------------*/ if ( numsub == 2 ) { if ( filptr != NULL ) { printf ( "\nPlease close the opened file first.\n" ); } else { printf ( "\nEnter the file name:\n" ); scanf ( " %s", filnam ); printf ( "Do you want to create it if the file doesn't exist?\n" ); scanf ( " %s", ans ); if ( ans[0] == 'y' || ans[0] == 'Y' ) { spf_open ( filnam, TRUE, &filptr, &nbytes, &iret ); } else { spf_open ( filnam, FALSE, &filptr, &nbytes, &iret ); } if ( iret == 0 ) { printf ( "\nSPF_OPEN: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, filnam, &ier, eliblen, strlen(filnam) ); } } } /*---------------------------------------------------------------------*/ if ( numsub == 3 ) { printf ( "Enter length in bytes:\n" ); scanf ( " %d", &nbytes ); spf_read ( filptr, filnam, nbytes, &iret ); if ( iret == 0 ) { printf ( "\nSPF_READ: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, errstr, &ier, eliblen, errlen ); } } /*---------------------------------------------------------------------*/ if ( numsub == 4 ) { if ( filptr != NULL ) { printf ( "\nPlease close the opened file first.\n" ); } else { printf ( "\nEnter the file name:\n" ); scanf ( " %s", filnam ); spf_load ( filnam, &iret ); if ( iret == 0 ) { printf ( "\nSPF_LOAD: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, filnam, &ier, eliblen, strlen(filnam) ); } } } /*---------------------------------------------------------------------*/ if ( numsub == 5 ) { printf ( "\nEnter the tag name:\n" ); scanf ( " %s", tag ); printf ( "Enter the data string:\n" ); scanf ( " %s", data ); spf_write ( filptr, tag, data, &iret ); if ( iret == 0 ) { printf ( "\nSPF_WRITE: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, errstr, &ier, eliblen, errlen ); } } /*---------------------------------------------------------------------*/ if ( numsub == 6 ) { printf ( "Enter the tag name:\n" ); scanf ( " %s", tag ); spf_gtfld ( tag, data, &iret ); if ( iret == 0 ) { printf ( "\nSPF_GTFLD: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, tag, &ier, eliblen, strlen(tag) ); } printf ( "\n Tag: %s \t Data: %s\n", tag, data ); } /*---------------------------------------------------------------------*/ if ( numsub == 7 ) { spf_clnup ( &iret ); if ( iret == 0 ) { printf ( "\nSPF_CLNUP: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, errstr, &ier, eliblen, errlen ); } } /*---------------------------------------------------------------------*/ if ( numsub == 8 ) { spf_close ( filptr, &iret ); filptr = NULL; if ( iret == 0 ) { printf ( "\nSPF_CLOSE: iret = %d\n\n", iret ); } else { er_wmsg ( errlib, &iret, errstr, &ier, eliblen, errlen ); } } /*---------------------------------------------------------------------*/ } if ( filptr != NULL ) fclose ( filptr ); return 0; }
void cfl_tinq ( char *table, char *type, long *flen, char *newfil, int *iret ) /************************************************************************ * cfl_tinq * * * * This function returns the path to a GEMPAK table file, if the table * * exists. * * * * The table is split into the path and filename, and the file is * * located by searching in the following order: * * * * 1. filename (local) * * 2. path/filename (table as given) * * 3. $NCDESK/type/filename * * 4. $NCSITE/type/filename * * 5. $GEMTBL/type/filename * * * * void cfl_tinq ( table, type, flen, newfil, iret ) * * * * Input parameters: * * *table char Table file name * * *type char File name type * * * * Output parameters: * * *flen long File size * * *newfil char Expanded file name * * *iret int Return code * ** * * S. Jacobs/NCEP 5/01 Copied from cfl_tbop * * S. Chiswell/Unidata 3/06 Modified for $LDM/etc * ***********************************************************************/ { int found; int lenp, lenf, lent, ier; long lfsize; char filepart[FILE_NAMESZ], pathpart[LLPATH]; char actualpath[LLPATH], pathfile[FILE_FULLSZ]; /*---------------------------------------------------------------------*/ *iret = 0; found = G_FALSE; newfil[0] = CHNULL; actualpath[0] = CHNULL; lfsize = 0; /* * Strip GEMTBL from beginning of the table file name if present. */ if ( strstr (table, "$GEMTBL/") == table ) { strcpy (pathfile, &table[8]); } else if ( strstr (table, "GEMTBL:") == table ) { strcpy (pathfile, &table[7]); } else { strcpy (pathfile, table); } /* * Extract the filename from the end of the path. */ cfl_path ( pathfile, pathpart, filepart, &ier ); cst_lstr ( pathpart, &lenp, &ier ); cst_lstr ( filepart, &lenf, &ier ); cst_lstr ( type, &lent, &ier ); /* * Check to see if the file is local. */ cfl_inqr (filepart, NULL, &lfsize, actualpath, iret ); if ( *iret == 0 ) { found = G_TRUE; } /* * Check to see if the file is in LDMHOME/etc. */ if ( found == G_FALSE) { cfl_inqr (filepart, LDM_ETC_PATH, &lfsize, actualpath, iret ); if ( *iret == 0 ) { found = G_TRUE; } } /* * Check to see if the file is down a path. */ if ( (found == G_FALSE) && ( lenp != 0 ) ) { cfl_inqr (filepart, pathpart, &lfsize, actualpath, iret ); if ( *iret == 0 ) { found = G_TRUE; } } /* * Check to see if the file exists in terms of type in NCDESK. */ if ( (found == G_FALSE) && (lent != 0) ) { strcpy (pathfile, "$NCDESK/"); strcat (pathfile, type); strcat (pathfile, "/"); strcat (pathfile, filepart); cfl_inqr (pathfile, type, &lfsize, actualpath, iret ); if ( *iret == 0 ) { found = G_TRUE; } } /* * Check to see if the file exists in terms of type in NCSITE. */ if ( (found == G_FALSE) && (lent != 0) ) { strcpy (pathfile, "$NCSITE/"); strcat (pathfile, type); strcat (pathfile, "/"); strcat (pathfile, filepart); cfl_inqr (pathfile, type, &lfsize, actualpath, iret ); if ( *iret == 0 ) { found = G_TRUE; } } /* * Check to see if the file exists in terms of type in GEMTBL. */ if ( (found == G_FALSE) && (lent != 0) ) { strcpy (pathfile, "$GEMTBL/"); strcat (pathfile, type); strcat (pathfile, "/"); strcat (pathfile, filepart); cfl_inqr (pathfile, type, &lfsize, actualpath, iret ); if ( *iret == 0 ) { found = G_TRUE; } } strcpy ( newfil, actualpath ); *flen = lfsize; }
int main ( int argc, char *argv[] ) /************************************************************************ * main * * * * Main program of shpcv. * * * * int main(argc, argv) * * * * Input parameters: * * argc int number of parameters of command line * * **argv char parameter array of command line * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * R. Tian/SAIC 3/04 Initial coding * * R. Tian/SAIC 2/05 Modified shp_mtyp * * T. Piper/SAIC 01/06 Call ip_help if inputs incorrect * * H. Zeng/SAIC 07/07 added calling to shp_rdException() * * S. Jacobs/NCEP 3/11 Added debug_flag and print statements * * S. Jacobs/NCEP 6/14 Moved split func to after dump output * ***********************************************************************/ { dbf_header dbfhdr; shx_record shxrec; shp_record *reclst, *newrec, *currec; shp_part *curprt; char dbfnam[MAXSHP][LLPATH], shxnam[MAXSHP][LLPATH], shpnam[MAXSHP][LLPATH]; FILE *dbffp, *shxfp, *shpfp; long flen; int ifld, nf, opt, rec, prt, file_code, nbin, ier; float ratio, clat, clon; int lfld, dump, rdpt, cbnd, ctbl, pagflg; int numrec, numfil, ii; int mode, istat, iunit, itype; unsigned long shp_fips; char device[8], proj[8], filnam[20], prognm[6]; float xsize, ysize, angle1, angle2, angle3, lllat, lllon, urlat, urlon; Boolean exception_found; /*---------------------------------------------------------------------*/ lfld = G_FALSE; dump = G_FALSE; rdpt = G_FALSE; cbnd = G_FALSE; ctbl = G_FALSE; pagflg = G_FALSE; strcpy ( prognm, "shpcv" ); debug_flag = G_TRUE; /*=================== Parse command line arguments ====================*/ while ( ( opt = getopt ( argc, argv, "r:btldh" ) ) != -1 ) { switch ( opt ) { case 'r': /* reduce points ratio */ ratio = atof ( optarg ); if ( ratio <= 0.0 ) { ratio = 0.01; } rdpt = G_TRUE; break; case 'b': /* create bound and bound info */ cbnd = G_TRUE; break; case 't': /* create station table */ ctbl = G_TRUE; break; case 'l': /* list fields */ lfld = G_TRUE; break; case 'd': /* dump the shape file */ dump = G_TRUE; break; case 'h': /* display help */ default: ip_help ( prognm, &pagflg, &ier, strlen(prognm) ); exit ( 0 ); break; } } if ( optind == argc || argc - optind > MAXSHP ) { ip_help ( prognm, &pagflg, &ier, strlen(prognm) ); exit ( -1 ); } /*======================== Read the shape file ========================*/ /* * Loop over input files. */ currec = NULL; numrec = 0; numfil = argc - optind; for ( nf = 0; nf < numfil; nf++ ) { /* * Get the input names and open them. */ if ( debug_flag ) { printf ( "File %d: %s\n", nf, argv[optind+nf] ); } strcpy ( dbfnam[nf], argv[optind+nf] ); strcat ( dbfnam[nf], ".dbf" ); strcpy ( shxnam[nf], argv[optind+nf] ); strcat ( shxnam[nf], ".shx" ); strcpy ( shpnam[nf], argv[optind+nf] ); strcat ( shpnam[nf], ".shp" ); cfl_inqr ( dbfnam[nf], NULL, &flen, dbfnam[nf], &ier ); dbffp = cfl_ropn ( dbfnam[nf], NULL, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s does not exist.\n", dbfnam[nf] ); exit ( -1 ); } cfl_inqr ( shxnam[nf], NULL, &flen, shxnam[nf], &ier ); shxfp = cfl_ropn ( shxnam[nf], NULL, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s does not exist.\n", shxnam[nf] ); exit ( -1 ); } cfl_inqr ( shpnam[nf], NULL, &flen, shpnam[nf], &ier ); shpfp = cfl_ropn ( shpnam[nf], NULL, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s does not exist.\n", shpnam[nf] ); exit ( -1 ); } /* * Detect platform endian. */ cfl_read ( shpfp, INTEGER_SIZE, (unsigned char *)&file_code, &nbin, &ier ); if ( file_code == 9994 ) { mch_endian = BIG; } else { mch_endian = LITTLE; } /* * Read database header. */ shp_rdbh ( dbffp, &dbfhdr, &ier ); numrec += dbfhdr.nrec; if ( lfld == G_TRUE ) { for ( ifld = 0; ifld < dbfhdr.nfld; ifld++ ) { printf ( "Field: %s\n", dbfhdr.dbflds[ifld].name ); } } else { /* * Read shape record and construct an internal list. */ for ( rec = 0; rec < dbfhdr.nrec; rec++ ) { /* * Read record field data. */ shp_rdbf ( dbffp, rec, &dbfhdr, &ier ); /* * Read record index. */ shp_rshx ( shxfp, rec, &shxrec, &ier ); /* * Read record data. */ shp_rshp ( shpfp, &dbfhdr, &shxrec, &newrec, &ier ); /* * Add the new record on record list. */ newrec->prvrec = currec; if ( currec != NULL ) { currec->nxtrec = newrec; } else { reclst = newrec; } currec = newrec; } } /* * Close up opened files. */ cfl_clos ( dbffp, &ier ); cfl_clos ( shxfp, &ier ); cfl_clos ( shpfp, &ier ); } if ( lfld == G_TRUE ) { shp_mfreeall ( ); exit ( 0 ); } /*======================== Read the shape exception table =============*/ _shpException = NULL; _numShpException = 0; shp_rdException ( &ier ); /*======================= Starting Post-Process =======================*/ /* * Dump shapefile records. */ if ( dump == G_TRUE ) { for ( rec = 0, currec = reclst; rec < numrec; rec++, currec = currec->nxtrec ) { shp_wfld ( stdout, currec, &ier ); shp_wrec ( stdout, currec, &ier ); } shp_mfreeall ( ); exit ( 0 ); } /* * Split record part if it has more than MAXOUT number of points * or it crosses the international dateline. */ shp_splt ( reclst, numrec, &ier ); /* * Detect the map type. */ shp_mtyp ( dbfnam, numfil, &ier ); if ( maptyp == 0 ) { fprintf ( stderr, "Unknown Map Type.\n" ); exit ( -1 ); } /* * Delete not used records. */ shp_drec ( &reclst, &numrec, &ier ); /* * Combine records that have the same key. */ shp_cmbn ( reclst, &numrec, &ier ); /* * Compute record centroid. */ mode = 1; iunit = itype = 1; xsize = ysize = 1.0F; strcpy ( device, "GN" ); strcpy ( filnam, "SHPCV" ); /* * Use North STR projection. */ strcpy ( proj, "STR" ); angle1 = 90.0F; angle2 = -90.0F; angle3 = 0.0F; lllat = -15.0F; lllon = -135.0F; urlat = -15.0F; urlon = -135.0F; ginitp ( &mode, &istat, &ier ); gsdeva ( device, &iunit, filnam, &itype, &xsize, &ysize, &ier, strlen(device), strlen(filnam) ); gsmprj ( proj, &angle1, &angle2, &angle3, &lllat, &lllon, &urlat, &urlon, &ier, strlen(proj) ); for ( currec = reclst, rec = 0; rec < numrec; rec++, currec = currec->nxtrec ) { /* * Get the shape fips code, check if there is a match in * Shape Exception Table. If yes, get manually set * clon&clat value from the table directly. */ if ( sscanf(currec->fields[3].data, "%lu", &shp_fips) == 1 ) { exception_found = FALSE; for ( ii = 0; ii < _numShpException; ii++ ) { if ( _shpException[ii].fips == shp_fips ) { currec->cenlat = _shpException[ii].clat; currec->cenlon = _shpException[ii].clon; exception_found = TRUE; break; } } if ( exception_found ) continue; } /* * Get the shape id, check if there is a match in * Shape Exception Table. If yes, get manually set * clon&clat value from the table directly. */ exception_found = FALSE; for ( ii = 0; ii < _numShpException; ii++ ) { if ( strcasecmp(currec->fields[0].data, _shpException[ii].id) == 0 ) { currec->cenlat = _shpException[ii].clat; currec->cenlon = _shpException[ii].clon; exception_found = TRUE; break; } } if ( exception_found ) continue; /* * Calculate clon&clat mathematically from an algorithm. */ shp_gctr ( currec, &clon, &clat, &ier ); if ( ier == 0 ) { currec->cenlat = clat; currec->cenlon = clon; } else { currec->cenlat = RMISSD; currec->cenlon = RMISSD; } } /* the end of for ( currec ... */ /* * Reduce number of points. */ if ( rdpt == G_TRUE ) { for ( rec = 0, currec = reclst; rec < numrec; rec++, currec = currec->nxtrec ) { for ( prt = 0, curprt = currec->shpart; prt < currec->numprt; prt++, curprt = curprt->nxtprt ) { shp_thin ( curprt, ratio, &ier ); } } } /* * Create station table. */ if ( ctbl == G_TRUE ) { shp_ctbl ( reclst, numrec, &ier ); } /* * Create bound and bound info. */ if ( cbnd == G_TRUE ) { shp_cbnd ( reclst, numrec, &ier ); } /* * Clean up. */ shp_mfreeall ( ); return 0; }
void crg_rebuild ( void ) /************************************************************************ * crg_rebuild * * * * This function rebuilds range records for all elem. in WORK_FILE. * * * * Note: the layer assignment is not affected by the rebuild - the * * existing layer values are kept unchanged in range records. * * They could only be changed by crg_set() or crg_setLayer(). * * * * void crg_rebuild ( void ) * * * * Input/output parameters: * * none * ** * * Log: * * J. Wu/SAIC 12/01 initial coding * * J. Wu/SAIC 12/01 replace crg_rdrec with crg_rdhdr/ele * * J. Wu/SAIC 12/01 Get VG file size with cfl_inqr() * * T. Lee/SAIC 11/03 added user directory to work_file * * T. Lee/SAIC 11/03 used cvg_getworkfile() * * B. Yin/SAIC 07/04 Added code to free TCA memory * * B. Yin/SAIC 08/04 changed pgtca_freeBkpts to cvg_freeBkpts* * J. Wu/SAIC 10/04 free GFA block pointers * * J. Wu/SAIC 07/07 skip records for GFA text boxes * ***********************************************************************/ { int ii, elnum, joffset, flag, ier; long maxbytes; char newfil[FILE_FULLSZ]; VG_DBStruct el; FILE *fp; /*---------------------------------------------------------------------*/ cfl_inqr( cvg_getworkfile(), NULL, &maxbytes, newfil, &ier); cvg_open( cvg_getworkfile(), TRUE, &fp, &ier ); if ( ( ier != 0 ) || ( fp == NULL ) ) { return; } for ( ii = 0; ii < MAX_EDITABLE_ELEMS; ii++) { joffset = range[ ii ].ioffset; if ( joffset >= 0 && !( crg_isauxrec( ii, &ier ) ) ) { crg_getinx( joffset, &elnum, &ier); cvg_rdhdr( cvg_getworkfile(), fp, joffset, (int)maxbytes, &el, &flag, &ier ); cvg_rdele( &el, joffset, el.hdr.recsz, fp, &ier ); if ( ier == 0 ) { crg_mkRange( &el, joffset, elnum, &ier ); } /* * Free TCA break point/GFA blocks memory */ if ( el.hdr.vg_type == TCA_ELM ) { cvg_freeBkpts ( &el ); } else if ( el.hdr.vg_type == GFA_ELM ) { cvg_freeElPtr ( &el ); } } } cvg_clos( fp, &ier ); }
void srchw_fosdScan ( srchinfo_t *srchinfo, int called_from, int *iret ) /************************************************************************ * srchw_fosdScan * * * * This routine will scan a file given a search structure and return * * the appropriate report. * * * * srchw_fosdScan ( srchinfo, called_from, iret ) * * * * Input parameters: * * *srchinfo srchinfo_t Search info structure * * called_from int Indicate from where it is called* * 1 - from user click * * 2 - from auto-update * * * * Output parameters: * * *iret int Return code * * -8 -- scandir failure * * -9 -- open file error * * * ** * * Log: * * L. Williams/EAI 10/95 * * D.Plummer/NCEP 12/95 Reorganize for fosd type W * * G. Krueger/EAI 3/96 CFL_SOPN -> CFL_ROPN * * L. Williams/EAI 6/96 Check for duplicate reports * * S. Jacobs/NCEP 12/98 Changed fclose to cfl_clos * * S. Danz/AWC 12/00 Updated call to dttm_cpy * * S. Danz/AWC 12/00 Remove NULL chars from report * * R. Tian/SAIC 04/02 Query file size before open it * * T. Piper/SAIC 05/02 Close last file opened before returning * * R. Tian/SAIC 11/03 Added called_from arg * * T. Piper/SAIC 01/04 Added check for -8 from dir_getflist * * T. Piper/SAIC 01/04 Added check on cfl_ropn * * E. Safford/SAIC 12/07 rm direct access to textW widget * ***********************************************************************/ { char *text, last_flg; char search_str[2]; static struct date_time_info _startd_save; static struct date_time_info _endd_save; int i, j, duplicate, ier; char nofile_msg[80]; long flen; char dumyname[133]; /* ------------------------------------------------------------------- */ repnum=0; /* * Scan the data directory for a list of valid files. */ if ( (srchinfo->idtyp != _idtyp_save) || (dttm_cmp(srchinfo->startd, _startd_save) != 0) || (dttm_cmp(srchinfo->endd, _endd_save) != 0) ) { _idtyp_save = srchinfo->idtyp; dttm_cpy(&_startd_save, srchinfo->startd); dttm_cpy(&_endd_save, srchinfo->endd); dir_getflist( nwxTable->dtyp_info, srchinfo->idtyp, srchinfo->startd, srchinfo->endd, &srchinfo->dir_info, iret ); if ( *iret == -8 ) { return; } else if ( *iret != 0 ) { /* * no matching data file */ *iret = -1; sprintf( nofile_msg, "No reports.\n\n" ); if ( called_from == 1 ) { pdata_setReportText( nofile_msg, &ier ); txtw_dsplyReport( &ier ); } stnList.nrptstn = 0; return; } } last_flg = 0; search_str[0] = CHCTLA; search_str[1] = '\0'; while ( !last_flg ) { /* * Get the next data file. */ dir_getnextf( &(srchinfo->dir_info), srchinfo->sflag, &(srchinfo->file_info), iret); if (srchinfo->sflag == 0) srchinfo->sflag = -1; if ( *iret == 3 ) last_flg = 1; if ( (*iret == 0) || (*iret == 3) ) { /* new file */ /* * Close the open file. */ if ( srchinfo->file_info.fptr != NULL ) { cfl_clos ( srchinfo->file_info.fptr, iret ); srchinfo->file_info.fptr = NULL; } /* * Get the size of the new file. If the size is 0, skip it. */ cfl_inqr(srchinfo->file_info.filnam, NULL, &flen, dumyname, iret); if ( *iret != 0 || flen == 0) { if ( last_flg ) { break; } else { continue; } } srchinfo->file_info.file_len = (int)flen; /* * Open the new file. */ srchinfo->file_info.fptr = cfl_ropn( srchinfo->file_info.filnam, NULL, iret ); if ( *iret != 0 ) { *iret = -9; return; } /* * Allocate enough space to hold the entire contents of the file. */ text = (char *) malloc((size_t)(srchinfo->file_info.file_len + 1) * sizeof(char) ); /* * Read the contents of the file into the TEXT string. */ if ( fread( text, (size_t)srchinfo->file_info.file_len, 1, srchinfo->file_info.fptr) != (size_t)1 ){ /* * reading error */ free ( text ); if ( last_flg ) { break; } else { continue; } } text[srchinfo->file_info.file_len] = '\0'; for (i=0; i<srchinfo->file_info.file_len; i++) { if (!text[i]) text[i] = ' '; } /* * Search the TEXT for the search string and report's position. */ srchw_fosdMarkrep( srchinfo, text, search_str, called_from, iret); /* * Free the allocated space */ free ( text ); } else break; } /* end while */ /* * Close the last open file. */ if ( srchinfo->file_info.fptr != NULL ) { cfl_clos ( srchinfo->file_info.fptr, iret ); srchinfo->file_info.fptr = NULL; } stnList.nrptstn = 0; for( i = 0 ; i < stnList.nreports; i++ ) { duplicate = G_FALSE; for( j=0; j < i; j++ ) { if( reportInfo[i].stnindex == reportInfo[j].stnindex ) { duplicate = G_TRUE; break; } } if( ! duplicate ) { stnList.rptstn[stnList.nrptstn] = reportInfo[i].stnindex; stnList.rptstnlat[stnList.nrptstn] = stnList.lat[reportInfo[i].stnindex]; stnList.rptstnlon[stnList.nrptstn] = stnList.lon[reportInfo[i].stnindex]; stnList.nrptstn++; } } }
void db_gtim ( char *queryType, char *source, char *qparms, char *times, int *ltimes, int *iret ) /************************************************************************ * * * db_gtim * * * * m.gamazaychikov/SAIC 11/08 Created * ************************************************************************/ { int bufferSize = 200000; char xsltFile[LLSCRN] = "response.xlt"; char xsltDir[LLSCRN] = "$NAWIPS/gempak/tables/xslt"; //char queryType[11] = "dbaseTime"; int ier, nbytes, ier1, ier2, iparm = 129, ierEvt; long flen; char queryText[320], queryResult[bufferSize+1], evtName[iparm-1]; char errStr[100], xsltfile[FILE_FULLSZ], parm[iparm-1]; unsigned char* bigStr; struct timeb t_start, t_query, t_run, t_xml, t_current; /*---------------------------------------------------------------------*/ ftime(&t_start); /* * Initialization */ *iret = 0; times[0] = '\0'; queryText[0] = '\0'; queryResult[0] = '\0'; db_getparm ( parm, &ier2, iparm); if ( ier2 != 0 ) { *iret = -1; return; } db_getevtname ( evtName, &ierEvt, iparm); /* * Populate the query strings */ if (strcmp ( queryType, "dbTime" ) == 0 ) { strcpy (eSrc, source); if ( strcmp ( source, "GRID") == 0 ) { sprintf (ePlugIn, "%s", parm); sprintf (eGrid, "%s", qparms); sprintf (eLibClass, "%s", "GempakCatalogTimeQuery"); if ( ierEvt == 0 ) { sprintf (gEventName, "%s", evtName); } } else if ( strcmp ( source, "METAR") == 0 ) { sprintf (ePlugIn, "%s", "obs"); sprintf (eLibClass, "%s", "NomTimeQuery"); } /* else if ( strcmp ( source, "BUFRUA") == 0 ) { sprintf (ePlugIn, "%s", "bufrua"); sprintf (eLibClass, "%s", "GempakCatalogTimeQuery"); } else if ( strcmp ( source, "SYNOP") == 0 ) { sprintf (ePlugIn, "%s", "sfcobs"); sprintf (eLibClass, "%s", "GempakCatalogTimeQuery"); } */ else { ier = -9; sprintf (errStr, "%s+", queryType); strcat (errStr, source); er_wmsg ( "DB", &ier, errStr, &ier1, 2, strlen(errStr) ); *iret = -1; return; } } else { ier = -8; er_wmsg ( "DB", &ier, queryType, &ier1, 2, strlen(queryType) ); *iret = -1; return; } /* * Get the query text */ ftime(&t_query); db_getQueryText ( queryType, queryText, &ier); ftime(&t_current); // printf("\t\t\t time spent in db_getQueryText: %d\n", (int) (1000.0 * (t_current.time - t_query.time) + (t_current.millitm - t_query.millitm))); if ( ier !=0 ) { /* * Query text not set -> returning */ ier = -3; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); *iret = -1; return; } /* * Connect to database and get the query result */ ftime(&t_run); db_runQuery ( queryText, queryResult, &ier); ftime(&t_current); // printf("\t\t\t time spent in db_runQuery: %d\n", (int) (1000.0 * (t_current.time - t_run.time) + (t_current.millitm - t_run.millitm))); if ( ier !=0 ) { ier = -4; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); *iret = -1; return; } /* * Transform XML string to a string containing list of header parameters */ cfl_inqr(xsltFile, xsltDir, &flen, xsltfile, &ier); if ( ier !=0 ) { /* * XSLT file not found -> returning */ ier = -5; er_wmsg ( "DB", &ier, xsltFile, &ier1, 2, strlen(xsltFile) ); *iret = -1; return; } ftime(&t_xml); nbytes=xml_transform( queryResult, strlen(queryResult), xsltfile, &bigStr, &ier ); ftime(&t_current); // printf("\t\t\t time spent in xml_transform: %d\n", (int) (1000.0 * (t_current.time - t_xml.time) + (t_current.millitm - t_xml.millitm))); if ( ier !=0 || nbytes==0) { /* * XML Transform run unsuccessfully -> returning */ ier = -6; er_wmsg ( "DB", &ier, NULL, &ier1, 2, 0 ); G_FREE( bigStr, unsigned char ); *iret = -1; return; } sprintf (times, "%s", bigStr); *ltimes = strlen(times); G_FREE( bigStr, unsigned char ); ftime(&t_current); // printf("\t\t time spent in db_gtim: %d\n", (int) (1000.0 * (t_current.time - t_start.time) + (t_current.millitm - t_start.millitm))); return; }
void nexr_list_lev ( char *filnam, int *lenfnam, char *radparm, int *lenparm, int *ier) { int i, nbin, iret; long flen, lofset = 20; char cfil[LLPATH], cprm[LLMXLN]; char stid[]="KFTG", callid[5]; Radar *radar=NULL; FILE *fp; *ier = 0; strncpy(cfil, filnam, *lenfnam); strncpy(cprm, radparm, *lenparm); cfil[*lenfnam] = '\0'; cprm[*lenparm] = '\0'; /* get actual file name to use in rsl call */ cfl_inqr ( cfil, NULL, &flen, cfil, &iret); RSL_select_fields(cprm, NULL); /* if ( cprm[0] == 'd' ) VINDEX = DZ_INDEX; else if ( cprm[0] == 's' ) VINDEX = SW_INDEX; else if ( cprm[0] == 'v' ) VINDEX = VR_INDEX; */ /* * see if we can get the station ID from bytes 21-24, otherwise, just use any ID */ fp = cfl_ropn ( cfil, NULL, &iret ); if ( iret != 0 ) { printf("failed to open %s\n",cfil); *ier = -1; return; } else { cfl_seek ( fp, lofset, SEEK_SET, &iret ); if ( iret != 0 ) { *ier = -1; cfl_clos ( fp, &iret ); return; } } cfl_read ( fp, 4, (unsigned char *)callid, &nbin, &iret ); cfl_clos ( fp, &iret ); if (( nbin < 4 )||(callid[0] < 'A')||(callid[0] > 'Z')) /* use a safe station ID....we aren't plotting lat/lon anyhow */ strcpy(callid,stid); else callid[4] = '\0'; /*RSL_radar_verbose_on();*/ RSL_read_these_sweeps("all", NULL); radar = RSL_wsr88d_to_radar(cfil, callid); /*RSL_radar_verbose_off();*/ if ( radar == NULL ) { printf("failed to open %s\n",cfil); *ier = -1; return; } for (i=0; i<radar->h.nvolumes; i++) { if (radar->v[i]) { printf("Volume %s: Sweeps available %d\n", cprm, radar->v[i]->h.nsweeps); print_header_for_volume(radar->v[i]); } } RSL_free_radar(radar); }
void cvg_open ( char *filnam, int wrtflg, FILE **fptr, int *iret ) /************************************************************************ * cvg_open * * * * This function opens a VG file. * * * * cvg_open ( filnam, wrtflg, fptr, iret ) * * * * Input parameters: * * *filnam char VG filename * * wrtflg int Write flag * * * * Output parameters: * * **fptr FILE File pointer * * *iret int Return code * * 2 = created vg file * * 0 = normal * * -1 = error opening VG file * * -13 = error verifying vg file * * -25 = no filehead elm in file * * -47 = no file name specified * ** * * Log: * * D. Keiser/GSC 1/97 Copied from UTF_OPEN * * E. Wehner/EAi 6/97 Create VGF if does not exist * * E. Wehner/EAi 7/97 Produce error msg on bad hdr * * E. Wehner/EAi 9/97 Handle null file name * * E. Safford/GSC 10/98 clean up & rework error mesgs * * A. Hardy/GSC 1/01 changed fptr from int to FILE * * E. Safford/SAIC 04/02 avoid cvg_rdhdr if bad filehead * * T. Lee/SAIC 11/03 used cvgcmn.h * * T. Piper/SAIC 09/06 Added wrtflg check after first cfl_inqr * ***********************************************************************/ { int ier, ier1, flag, curpos; long maxbytes; int err_log, dtl_log, dbg_log; VG_DBStruct el; char grp[4], newfil[256]; /*---------------------------------------------------------------------*/ *fptr = NULL; strcpy(grp, "CVG"); err_log = 0; dtl_log = 2; dbg_log = 4; *iret = 0; /* Check to see if there is a file of the specified name, * open it if it is there. */ if ( !filnam) { *iret = ier1 = -47; er_lmsg ( &dbg_log, grp, &ier1, filnam, &ier, strlen(grp), strlen(filnam) ); return; } cfl_inqr(filnam, NULL, &maxbytes, newfil, &ier); if ( ier < 0 && wrtflg == G_TRUE ) { /* * Attempt to create a vg file if specified file doesn't exist */ cvg_crvgf(filnam, &ier); if (ier == 0) { /* * Verify file was created */ cfl_inqr(filnam, NULL, &maxbytes, newfil, &ier); } if (ier != 0) { *iret = ier1 = -1; er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp), strlen(filnam) ); return; } else { /* * File was created successfully */ *iret = ier1 = 2; er_lmsg ( &dtl_log, grp, &ier1, filnam, &ier, strlen(grp), strlen(filnam) ); } } /* * Open file with either read, or read-write permissions */ if (wrtflg == G_TRUE) { *fptr = cfl_uopn(filnam, &ier); } else { *fptr = cfl_ropn(filnam, " ", &ier); } if (( ier != 0 ) || ( *fptr == NULL )) { /* open failed */ *iret = ier1 = -1; er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp), strlen(filnam) ); } else { if ( (size_t)maxbytes < (sizeof(FileHeadType) + sizeof(VG_HdrStruct)) ) { *iret = -25; } else { /* * Check to see that the file is a valid VGF file... */ curpos = 0; cvg_rdhdr(newfil, *fptr, curpos, (int)maxbytes, &el, &flag, &ier); if (ier != 0) { *iret = ier1 = -13; er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp), strlen(filnam) ); } if (el.hdr.vg_type != FILEHEAD_ELM) { *iret = ier1 = -25; er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp), strlen(filnam) ); } } } }
void spf_open ( char *filnam, Boolean crt, FILE **fptr, int *flen, int *iret ) /************************************************************************ * spf_open * * * * This function opens an SPF file for update. If the file doesn't * * exist and flag "crt" is TRUE, then it will be created. If the file * * suffix is not ".spf", it will be added. If the user has only read * * permission to the SPF file, it will be opened as "read-only". * * * * spf_open ( filnam, crt, fptr, flen, iret ) * * * * Input parameters: * * *filnam char File name with full path * * crt Boolean Flag, create a new file or not * * * * Output parameters: * * **fptr FILE Pointer to a file pointer * * *flen int File size * * *iret int Return code * * 1 - File opened as READ_ONLY * * 0 - Normal * * -1 - File does not exist * * -2 - File cannot be opened * * -3 - Failure to create SPF file * * * ** * * Log: * * J. Wu/GSC 6/01 create * * J. Wu/GSC 6/01 use cst_srch() * * J. Wu/GSC 7/01 allow access to read-only SPF files * * E. Safford/SAIC 02/06 fix cfl_inqr call, make 3rd param long * ***********************************************************************/ { int ipos, ier, ierr; char newfil[FILE_FULLSZ]; char filepart[MXFLSZ], pathpart[LLPATH]; long localFlen; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; *flen = 0; /* * Check if the file suffix is ".spf". If not, add it. */ cfl_path ( filnam, pathpart, filepart, &ier ) ; cst_srch ( 0, strlen(filepart), ".spf", filepart, &ipos, &ier ); if ( ier == -4 ) { strcat (filnam, ".spf"); } /* * Check the file status, if it exists, open it; otherwise, create * it if authorized. */ cfl_inqr( filnam, NULL, &localFlen, newfil, &ier ); *flen = ( int ) localFlen; if ( ier == 0 ) { *fptr = cfl_aopn( filnam, &ierr ); if ( *fptr == NULL ) { *fptr = cfl_ropn( filnam, NULL, &ierr ); if ( *fptr == NULL ) { *iret = -2; er_wmsg ( "CFL", &ierr, filnam, &ier, 3, strlen( filnam ) ); } else { *iret = 1; } } } else { *iret = -1; if ( crt == TRUE ) { *fptr = ( FILE *) spf_create( filnam, flen, iret ); } } }
void cvg_scangfa ( char *fname, int layer, int subtype, int areatype, char *tag, VG_DBStruct *el, int *selected, int *iret ) /************************************************************************ * cvg_scangfa * * * * This function scans a vector graphics file looking for a GFA element * * that matches the layer, subtype, area type (hazard) and tag input. * * The first matching record is returned in "el". Also, * * the element should match one of the active filters. * * * * cvg_scan ( fname, layer, subtype, areatype, tag, el, selected, iret )* * * * Input parameters: * * *fname char Name of file to scan from * * layer int layer to test against * * subtype int subtype to test against * * areatype int area type to test against * * tag char gfa tag to test against * * * * Output parameters: * * *el VG_DBStruct Pointer to VG record structure * * *selected int Offset to selected element * * *iret int Return code * * -1 = error opening VG file * * -2 = error closing VG file * * -6 = element not found * * -13 = error reading VG header * * -14 = error reading VG element * * * ** * * Log: * * J. Wu/SAIC 08/04 initial coding (modified from cvg_scan) * * J. Wu/SAIC 10/04 use cvg_getFld to access GFA attributes * * E. Safford/SAIC 07/05 replace seqnum param with tag * * J. Wu/SAIC 06/06 call cvg_matchfilter * * M. Li/SAIC 03/07 Updated cvg_matchfilter * ***********************************************************************/ { int ii, ier, el_layer, location; float llx,lly,urx,ury; long size; char newfil[133], reqfil[133], cclass, ctype, value[32]; FILE *fp; filter_t el_filter, timeMatched; Boolean filter_match, matchAny = False; /*---------------------------------------------------------------------*/ *iret = 0; *selected = -1; if ( !fname ) { strcpy ( reqfil, work_file ); } else { strcpy ( reqfil, fname ); } /* * Inquire the size of the VG file and open the file for update. */ cfl_inqr ( reqfil, NULL, &size, newfil, &ier ); fp = (FILE *) cfl_uopn ( newfil, &ier ); if ( (ier != 0) || (fp == NULL) ) { *iret = -1; return; } /* * Loop through all elements to find a match. */ for ( ii = 0; ii < MAX_EDITABLE_ELEMS; ii++ ) { crg_goffset ( ii, &location, &ier ); if ( location < 0 ) { continue; } crg_get ( ii, &el_layer, el_filter, &llx, &lly, &urx, &ury, &ier ); if ( ier >= 0 ) { crg_gtyp ( ii, &cclass, &ctype, &ier ); } if ( ier < 0 ) { continue; } /* * Match layer, class, vg type first. */ if ( (el_layer == layer) && (cclass == CLASS_MET) && (ctype == GFA_ELM) ) { /* * Then check if the element matches one of the filters. */ cvg_matchfilter ( el_filter, matchAny, &filter_match, timeMatched, &ier ); if ( !filter_match ) { continue; } /* * Read the element. */ cvg_rdrecnoc ( newfil, fp, location, el, iret ); if ( *iret != 0 ) { continue; } /* * Match the subtype, area type, and tag. */ cvg_getFld ( el, TAG_GFA_SUBTYPE, value, &ier ); if ( subtype == atoi(value) ) { cvg_getFld ( el, TAG_GFA_AREATYPE, value, &ier ); if ( areatype == atoi(value) ) { cvg_getFld ( el, TAG_GFA_TAG, value, &ier ); if( strcmp( tag, value ) == 0 ) { *selected = location; break; } } } } } /* * Check if there is an matching record found. */ if ( *selected < 0 ) { *iret = -6; } /* * Close the VG file. */ cfl_clos(fp, &ier); if ( ier != 0 ) *iret = -2; }
int main ( int argc, char *argv[] ) /************************************************************************ * sigavgf * * * * This program reads Significant Weather ASCII files and encodes the * * information into a VG file format. * * * * command line: * * sigavgf dattim hh * * dattim GEMPAK date/time string * * hh Valid time (hours) - must be 18 or 24 * ** * * Log: * * A. Hardy/SAIC 3/02 Created * * A. Hardy/SAIC 5/02 Added optional input file name; changed * * default input file name * * M. Li/SAIC 7/04 Removed grpch from sigajet * * M. Li/SAIC 9/04 Add idcent, chbase and chtop to cas_rdhdr* * M. Li/SAIC 1/05 Process SWM * * M. Li/SAIC 10/05 Checked for new format of jet info * ***********************************************************************/ { int ier, numerr, leverr, pagflg, grpid, iret; int itime[5], jtime[5], idcent; float chbase, chtop; int numtrp, rnum, lnum, hnum, membx, memhi, memlo; int memcld, memmcld, memfrt, memjet, memstm, memtur, memvlr; int numcld, nummcld, numfrt, numjet, numstm, numtur, numvlr; char fhour [3], fname[256], gtstr[12], grpch, chlvl[10]; char errgrp[8], cc[50], casgrp[4]; char path[256]; char newflvl[10]; long size; cloud_t *ptrc, *head, *ptr2; mcloud_t *ptrm, *headm, *ptr2m; jets_t *ptrj, *headj, *ptr2j; front_t *ptrf, *headf, *ptr2f; turb_t *ptrb, *headb, *ptr2b; storm_t *ptrs, *heads, *ptr2s; volrad_t *ptrv, *headv, *ptr2v; trop_t *ptrr, *headr, *ptr2r; trophi_t *ptrh, *headh, *ptr2h; troplo_t *ptrl, *headl, *ptr2l; Boolean readflg; FILE *ifpout; /*---------------------------------------------------------------------*/ iret = 0; leverr = 0; readflg = True; ifpout = NULL; strcpy ( errgrp, "SIGAVGF" ); strcpy ( casgrp, "CAS"); strcpy ( cc, " " ); rnum = lnum = hnum = 0; membx = memhi = memlo = 0; memcld = memmcld = memfrt = memjet = memstm = memtur = memvlr = 0; numcld = nummcld = numfrt = numjet = numstm = numtur = numvlr = 0; ptrc = NULL; ptrm = NULL; ptrj = NULL; ptrf = NULL; ptrb = NULL; ptrs = NULL; ptrv = NULL; ptrr = NULL; ptrh = NULL; ptrl = NULL; in_bdta ( &ier ); /* * If the forecast hour is not on the command line, print help * and exit. */ if ( argc < 3 ) { pagflg = G_FALSE; ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); numerr = -1; er_lmsg ( &leverr, errgrp, &numerr, cc, &ier, strlen(errgrp), strlen(cc) ); exit (1); } strcpy ( fhour, argv[2] ); if ( strcmp ( fhour, "24") != 0 ) { if ( strcmp ( fhour, "18") != 0 ) { numerr = -2; er_lmsg ( &leverr, errgrp, &numerr, fhour, &ier, strlen(errgrp), strlen(fhour) ); exit (1); } } /* * Check for input file. */ if ( argv[3] != NULL ) { strcpy ( fname, argv[3] ); } else { /* * If an input file is not specified, check for the existence of * either SIGWXHI.txt or SIGWXMID.txt. */ sprintf ( fname, "SIGWXHI.txt" ); cfl_inqr ( fname, NULL, &size, path, &ier ); if ( ier != 0 ) { sprintf ( fname, "SIGWXMID.txt" ); cfl_inqr ( fname, NULL, &size, path, &ier ); if ( ier != 0 ) { numerr = -3; er_lmsg ( &leverr, errgrp, &numerr, fname, &ier, strlen(errgrp), strlen(fname) ); exit (1); } } } ifpout = cas_open ( fname, readflg, &ier ); /* * If input ASCII file failed to open, exit program. */ if ( ier != 0 ) { numerr = -3; er_lmsg ( &leverr, errgrp, &numerr, fname, &ier, strlen(errgrp), strlen(fname) ); exit (1); } /* * Read in the input ASCII file into the CAS structures. */ cas_rdhdr ( ifpout, itime, jtime, &idcent, &chbase, &chtop, &ier ); rewind (ifpout); if ( G_ABS ( HI_BASE - chbase ) < 0.5F && G_ABS ( HI_TOP - chtop ) < 0.5F ) { strcpy ( chlvl, "SWH" ); cas_rdcld ( ifpout, &numcld, &ptrc, &memcld, &ier ); } else if ( G_ABS ( MID_BASE - chbase ) < 0.5F && G_ABS ( MID_TOP - chtop ) < 0.5F ) { strcpy ( chlvl, "SWM" ); cas_rdmcld ( ifpout, &nummcld, &ptrm, &memmcld, &ier ); } rewind (ifpout); cas_rdjets ( ifpout, &numjet, &ptrj, &memjet, &ier ); rewind (ifpout); cas_rdturb ( ifpout, &numtur, &ptrb, &memtur, &ier ); rewind (ifpout); cas_rdfrt ( ifpout, &numfrt, &ptrf, &memfrt, &ier); rewind (ifpout); cas_rdtrop ( ifpout, &numtrp, &ptrr, &membx, &rnum, &ptrl, &memlo, &lnum, &ptrh, &memhi, &hnum, &ier ); rewind (ifpout); cas_rdstm ( ifpout, &numstm, &ptrs, &memstm, &ier ); rewind (ifpout); cas_rdvlrd ( ifpout, &numvlr, &ptrv, &memvlr, &ier ); /* * Close input file. */ cas_clos ( ifpout, &ier ); /* * If ASCII file failed to close, write error message. */ if ( ier != 0 ) { numerr = -4; er_lmsg ( &leverr, casgrp, &numerr, fname, &ier, strlen(casgrp), strlen(fname) ); } /* * Initialize the group type table. */ ces_gtrtbl ( &iret ); /* * Call appropriate VG file encoding subroutines. * * Create cloud VG file. */ strcpy ( gtstr, "CLOUD"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; if ( strcmp ( chlvl, "SWH" ) == 0 ) { sigacld ( fhour, numcld, ptrc, itime, grpch, &ier ); } else { sigamcld ( fhour, nummcld, ptrm, itime, grpch, &ier ); } /* * Create jets VG file. */ ctb_rdprf ( "prefs.tbl", "config", "SIGWX_FLIGHT_LEVELS", newflvl, &ier ); sigajet ( fhour, numjet, ptrj, itime, chlvl, newflvl, &ier ); /* * Create turbulence VG file. */ strcpy ( gtstr, "TURB"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; sigatur ( fhour, numtur, ptrb, itime, grpch, chlvl, &ier ); /* * Create front VG file. */ strcpy ( gtstr, "FRONT"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; sigafrt ( fhour, numfrt, ptrf, itime, grpch, chlvl, &ier ); /* * Create tropopause VG file. */ sigatrp ( fhour, rnum, ptrr, hnum, ptrh, lnum, ptrl, itime, chlvl, &ier ); /* * Create symbol VG file. */ strcpy ( gtstr, "LABEL"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; sigavts ( fhour, numstm, ptrs, numvlr, ptrv, itime, grpch, chlvl, &ier ); /* * Free all created linked lists. */ /* Free cloud */ if ( memcld ) { head = ptrc; ptr2 = head -> next; while ( ptr2 != NULL ) { free (head); head = ptr2; ptr2 = ptr2 -> next; } free ( head ); } /* Free mcloud */ if ( memmcld ) { headm = ptrm; ptr2m = headm -> next; while ( ptr2m != NULL ) { free (headm); headm = ptr2m; ptr2m = ptr2m -> next; } free ( headm ); } /* Free jet */ if ( memjet ) { headj = ptrj; ptr2j = headj -> next; while ( ptr2j != NULL ) { free (headj); headj = ptr2j; ptr2j = ptr2j -> next; } free ( headj ); } /* Free turb */ if ( memtur ) { headb = ptrb; ptr2b = headb -> next; while ( ptr2b != NULL ) { free (headb); headb = ptr2b; ptr2b = ptr2b -> next; } free ( headb ); } /* Free front*/ if ( memfrt ) { headf = ptrf; ptr2f = headf -> next; while ( ptr2f != NULL ) { free (headf); headf = ptr2f; ptr2f = ptr2f -> next; } free ( headf ); } /* Free trop*/ if ( membx ) { headr = ptrr; ptr2r = headr -> next; while ( ptr2r != NULL ) { free ( headr ); headr = ptr2r; ptr2r = ptr2r -> next; } free ( headr ); } if ( memhi ) { headh = ptrh; ptr2h = headh -> next; while ( ptr2h != NULL ) { free ( headh ); headh = ptr2h; ptr2h = ptr2h -> next; } free ( headh ); } if ( memlo ) { headl = ptrl; ptr2l = headl -> next; while ( ptr2l != NULL ) { free ( headl ); headl = ptr2l; ptr2l = ptr2l -> next; } free ( headl ); } if ( memstm ) { heads = ptrs; ptr2s = heads -> next; while ( ptr2s != NULL ) { free ( heads ); heads = ptr2s; ptr2s = ptr2s -> next; } free ( heads ); } if ( memvlr ) { headv = ptrv; ptr2v = headv -> next; while ( ptr2v != NULL ) { free ( headv ); headv = ptr2v; ptr2v = ptr2v -> next; } free ( headv ); } return 0; }
int main(int argc, char *argv[], char *envp[]) { char clength[4]; char *block = (char *)malloc(8192), *oblock = (char *)malloc(262144); unsigned isize = 8192, osize=262144, olength; int length, go; int compress = 0; char *logfname = ""; int bzip2 = 1; int filter = 0; int fd; char stid[5]={0}; #define NUMEXP 1 int nexp = NUMEXP; char *prgnam = "DCNEXR2"; char *defprm = " "; char *defstn = " "; char *dfstn2 = " "; int idfadd=0; int idfmax=0; int ndfhr1=0; int ndfhr2=0; int idfwdh = 0; /* ** Do not change these variables. These variables are used by all ** decoders for getting the command line parameters. */ char parms[NUMEXP][DCMXLN], newfil[DCMXLN], curtim[DCMXLN]; int i, j, num, iret, ier; char stntbl[DCMXLN], stntb2[DCMXLN], prmfil[DCMXLN]; int iadstn, maxtim, nhours, txtflg, crcflg, iwndht; char errstr[DCMXLN]; extern int optind, opterr; extern char *optarg; int ch; long flen; if(atexit(cleanup) != 0) { printf("could not register exit routine\n"); } /* ** Initialize the output logs, set the time out and ** parse the command line parameters. dc_init calls in_bdta in 5.4.3+. */ /* * process some extra arguments "fC:" for this routine */ num = argc; i = 1; while ( i < num ) { if ( strcmp(argv[i], "-f") == 0 ) { num--; filter = 1; for ( j = i+1; j < argc; j++ ) argv[j-1] = argv[j]; continue; } if ( strcmp(argv[i], "-C") == 0 ) { /* optional compression specification for future use */ num-=2; for ( j = i+2; j < argc; j++ ) argv[j-2] = argv[j]; continue; } i++; } argc = num; dc_init ( prgnam, argc, argv, nexp, parms, &num, &iret ); /* ** Check for an initialization error. ** On an error, exit gracefully. */ if ( iret == -11 ) { fd = 1; } else if ( iret < 0 ) { sprintf ( errstr, "Error initializing\0" ); dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit ( &iret ); } else { char *cpos = strrchr(parms[0],'/'); if ( cpos == NULL ) sprintf(filnam,".%s\0",parms[0]); else { strncpy(filnam,parms[0],cpos - parms[0]+1); strncat(filnam,".",1); strcat(filnam,cpos+1); } cfl_inqr ( parms[0], NULL, &flen, newfil, &iret ); if(iret != 0) { filptr = parms[0]; strcpy(newfil,filnam); sprintf ( errstr, "new output file %s\0",newfil); dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); } if ((fd=mkdirs_open(newfil,O_WRONLY | O_CREAT, 0664)) == -1) { sprintf ( errstr, "Cannot open %s\0", newfil); iret = -10; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret ); } lseek(fd, 0, SEEK_END); } /* ** Set the decoder parameters to the command line entries or ** default values. */ dc_gopt ( defprm, defstn, dfstn2, idfadd, idfmax, ndfhr1, ndfhr2, idfwdh, prmfil, stntbl, stntb2, &iadstn, &maxtim, curtim, &nhours, &txtflg, &crcflg, &iwndht, &iret ); if(stntbl[0] != '\0') { strncat(stid,stntbl,4); sprintf ( errstr, "STID set to %s\0", stid ); dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); } /* * set up signal handlers */ go = 1; while (go) { /*bufread(0, (char *)(&length), 4, &i);*/ bufread(0, clength, 4, &i); if (i != 4) { if (i > 0) { sprintf ( errstr, "Short block length\0"); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); } else iret = 0; dc_exit(&iret); } if ( (memcmp(clength, "ARCH", 4)==0) || (memcmp(clength, "AR2V", 4)==0) ) { memcpy(block, clength, 4); bufread(0, block+4, 20, &i); if (i != 20) { sprintf ( errstr, "Missing header\0"); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret); } if ( stid[0] != 0 ) memcpy(block+20,stid,4); lseek(fd, 0, SEEK_SET); write(fd, block, 24); continue; } length = 0; for(i=0;i<4;i++) length = ( length << 8 ) + (unsigned char)clength[i]; if(length < 0) { sprintf ( errstr, "EOF %ld\0",length); iret = -9; dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); length = -length; go = 0; } if (length > isize) { isize = length; sprintf ( errstr, "Expanding input buffer to %d\0", isize); iret = -7; dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); if ((block = (char *)realloc(block, isize)) == NULL) { sprintf ( errstr, "Cannot allocate input buffer\0"); iret = -4; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret ); } } sprintf(errstr, "read block size %d\0",length); dc_wclg ( 4, "DCNEXR2", 0, errstr, &ier ); bufread(0, block, length, &i); if (i != length) { sprintf ( errstr, "Short block read\0"); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret ); } if (length > 10) { int error; tryagain: olength = osize; if (bzip2 == 1) #ifdef BZ_CONFIG_ERROR error = BZ2_bzBuffToBuffDecompress(oblock, &olength, /*error = bzBuffToBuffDecompress(oblock, &olength,*/ #else error = bzBuffToBuffDecompress(oblock, &olength, #endif block, length, 0, 0); if (error) { if (error == BZ_OUTBUFF_FULL) { osize += 262144; sprintf(errstr, "Expanding output buffer to %d\0", osize); iret = -7; dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); if ((oblock=(char*) realloc(oblock, osize)) == NULL) { sprintf(errstr, "Cannot allocate output buffer\0"); iret = -4; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit(&iret); } goto tryagain; } sprintf(errstr, "decompress error - %d\0", error); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret); } if (filter) { int i; for (i=0; i < olength; i += 2432) { struct packet *packet=(struct packet *) (oblock+i); if (packet->type != 2 || packet->rad_status != 28) write(fd, oblock+i, 2432); } } else write(fd, oblock, olength); } nbull++; }