void rsdump ( int *iret ) /************************************************************************ * rsdump * * * * This function writes the contents of a raster image to a file. * * * * rsdump ( iret ) * * * * Output parameters: * * *iret int Return code * ** * * Log: * * E. Wehner/EAi 6/96 Created * * S. Jacobs/NCEP 7/97 Cleaned up header and global variables * * S. Jacobs/NCEP 7/97 Removed unnecessary include files * ***********************************************************************/ { FILE *fp; int ier; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; fp = cfl_wopn ( filnam, &ier ); if ( ( fp == NULL ) || ( ier < 0 ) ) { *iret = G_NOWROPN; return; } cfl_writ ( fp, msize, rasimg, &ier ); cfl_clos ( fp, &ier ); }
void pclear ( int *iret ) /************************************************************************ * PCLEAR * * * * This subroutine clears the PostScript device by advancing to a new * * page. * * * * PCLEAR ( IRET ) * * * * Output parameters: * * *IRET INT Return code * ** * * Log: * * A. Chang/EAI 2/94 * ***********************************************************************/ { char buff[88]; int lenb, ier; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Return if no file has been opened. */ if ( ( ! opnfil ) || ( ! psplot ) ) return ; /* * Force output to file. * Go to next page and increment counter in common. */ strcpy ( buff, " gsave showpage grestore\n" ); lenb = strlen ( buff ); cfl_writ ( flun, lenb, (unsigned char *)buff, &ier ); nnpage++; sprintf ( buff, "%%%%Page:%5d ?\n", nnpage ); lenb = strlen ( buff ); cfl_writ ( flun, lenb, (unsigned char *)buff, &ier ); }
FILE *spf_create ( char *filnam, int *hlen, int *iret ) /************************************************************************ * spf_create * * * * This function creates a new SPF file with an appropriate header. If * * the file suffix is not ".spf", it will be added. * * * * Note: If the tag value contains a "<", it must be preceeded by a * * backslash '\\' so as not to confuse it with the start of another tag.* * * * FILE *spf_create ( filnam, hlen, iret ) * * * * Input parameters: * * *filnam char file name with full path * * * * Output parameters: * * *hlen int Header length * * *iret int Return code * * 0 - Normal * * -3 - Failure to create SPF file * * Return parameters: * * *spf_create FILE File pointer * * * ** * * Log: * * J. Wu/GSC 6/01 create * * J. Wu/GSC 6/01 correct cfl_aopn to cfl_wopn * * J. Wu/SAIC 6/03 add comments about escaped '<' * * B. Yin/SAIC 3/04 changed css_gtim calling sequences * * T. Piper/SAIC 03/06 Added GROUP_PERMS_SPF logic and actions * ***********************************************************************/ { int ier, ierr, ipos, itype = 0; char outstr[1024], perms_prefs[16], curdat[20], *usernam; char filepart[MXFLSZ], pathpart[LLPATH]; char exn[] = "!\n", ex[] = "!", linf[] = "!----------------------------------------", linb[] = "----------------------------------------\n", str1[] = "This is a stored procedure file for nmap2.", str2[] = "Creation date:", str3[] = "Created by:", esp1[] = " Note: If the tag value contains a '<', it must be ", esp2[] = "preceeded by a backslash \n! '\\' so as not to ", esp3[] = "confuse it with the start of another tag."; FILE *fptr; mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; /*rw_rw_r*/ /*---------------------------------------------------------------------*/ *iret = G_NORMAL; fptr = (FILE *)NULL; /* * If the file suffix is not ".spf", add it. */ cfl_path ( filnam, pathpart, filepart, &ier ) ; cst_srch ( 0, (int)strlen(filepart), ".spf", filepart, &ipos, &ier ); if ( ier == -4 ) { strcat ( filnam, ".spf" ); } /* * Create the file for writing and add the header discription. */ fptr = cfl_wopn( filnam, &ier ); if ( fptr == NULL ) { *iret = -3; /* fail to create */ er_wmsg ( "CFL", &ier, filnam, &ierr, 3, strlen( filnam ) ); } else { ctb_pfstr ( "GROUP_PERMS_SPF", perms_prefs, &ier); if ( strcmp(perms_prefs, "TRUE") == 0 ) { chmod(filnam, mode); } /* * Write an appropriate header to the file. */ css_gtim( &itype, curdat, &ier ); usernam = getenv("LOGNAME"); sprintf( outstr, "%s%s%s%s%s%s %s\n%s%s %s\n%s%s%s%s%s \n%s%s %s\t%s\n%s%s %s\t\t%s\n%s%s%s%s%s%s", linf, linb, linf, linb, exn, ex, filnam, exn, ex, str1, exn, ex, esp1, esp2, esp3, exn, ex, str2, curdat, exn, ex, str3, usernam, exn, linf, linb, linf, linb, exn ); *hlen = (int)(strlen( outstr ) * sizeof( char )); cfl_writ( fptr, *hlen, (unsigned char*)outstr, &ier ); if ( ier < 0 ) { *iret = -3; /* fail to create */ er_wmsg ( "CFL", &ier, filnam, &ierr, 3, strlen( filnam ) ); fptr = (FILE *)NULL; } } return fptr; }
void cvg_writtca ( FILE *fptr, VG_DBStruct *el, int *iret ) /************************************************************************** * cvg_writtca * * * * This function writes a TCA element to file at the current location. * * * * cvg_writtca ( fptr, el, iret ) * * * * Input Parameters: * * *fptr FILE File pointer * * *el VG_DBStruct Pointer to a TCA element * * * * Output Parameters: * * * * *iret int Return code * * 0: Normal * * -6: No file has been opened * * -17: Failed to load TcaInfo * ** * * Log: * * B. Yin/SAIC 02/04 Created * * B. Yin/SAIC 05/04 Allocated memory for TCA string * * S. Gilbert/NCEP 12/05 Updated element hdr.recsz before * * writing out TCA element. * *************************************************************************/ { int ier, nbytes, one=1, temp; char *ptca; /*-----------------------------------------------------------------------*/ *iret = 0; if ( fptr == NULL ) { *iret = -6; return; } /* * Load the TcaInfo into a string */ nbytes = cvg_loadTcaFileInfo ( el->elem.tca.info, &ptca, &ier); if ( ier < 0 ) { *iret = -17; return; } /* * Update element header record size. Remember to swap * bytes on some machines. */ temp = nbytes + sizeof( VG_HdrStruct ); if ( MTMACH == MTULTX || MTMACH == MTALPH || MTMACH == MTLNUX ) ier = mv_swp4( &one, &temp, &(el->hdr.recsz) ); else el->hdr.recsz = temp; /* * Write out element header and TcaInfo string. */ cfl_writ( fptr, sizeof( VG_HdrStruct ), (unsigned char *)&el->hdr, &ier); cfl_writ( fptr, nbytes, (unsigned char *)ptca, &ier); free( ptca ); }
int main ( void ) /************************************************************************ * GDGRIB2 * * * * This program encodes a selected GEMPAK grid into a GRIB2 message. * * * * Command line: * * gdgrib2 * ** * * Log: * * S. Gilbert/NCEP 5/2005 Orig * * S. Gilbert/NCEP 3/2006 Replaced dg_clal with dg_nend * * T. Piper/SAIC 01/08 Added GD_INIT; removed from IN_BDTA * * B. Yin/ERT 09/15 Added bulk processing from table * ***********************************************************************/ { int respond, ret, ier, mode=1, done, skip, j; int g2len; /* Length of GRIB2 message */ unsigned char *g2msg; /* GRIB2 message */ char cur_gbfile[LLMXLN]=""; char chdr[22]; /* WMO Header */ FILE *gbfptr=0; GDG2_input input; /* user input variables */ GDG2_gemgrid gemgrid; /* GEMPAK grid and info */ /*---------------------------------------------------------------------*/ /* * Initialize TAE. */ ip_init ( &respond, &ret ); if ( ret == 0 ) { ip_idnt ( "GDGRIB2", &done, 7 ); /* * Initialize GEMPLT. */ gg_init ( &mode, &ret ); if ( ret == 0 ) { /* * Initialize grid library common area grdcmn.cmn */ gd_init ( &ier ); /* * Initialize the DG library */ dg_intl ( &ret ); done = 0; skip = 1; } else { done = 1; } } else { done = 1; } /* * Process next request, if user has one. */ while ( done == 0 ) { /* * Wait for user input, if not first time through this loop */ if ( skip == 0 ) ip_dynm( &done, &ret ); skip = 0; if ( done != 0 ) break; /* Exit out of interactive loop */ /* * Get user input info */ gdg2in( &input, &ret ); if ( ret != 0 ) { er_wmsg("GDGRIB2",&ret," ",&ier,7,1); continue; } else if ((strlen(input.g2conv) != (size_t)0) && (ret == 0)) { /* * Skip program prompt and get input from conversion table */ skip = 1; } if ( strlen(input.g2file) == (size_t)0 ) { ret=-28; er_wmsg("GDGRIB2",&ret," ",&ier,7,1); continue; } /* * Get requested grid */ gdgetgrid( &input, &gemgrid, &ret ); if ( ret != 0 ) { er_wmsg("GDGRIB2",&ret," ",&ier,7,1); continue; } /* * Make GRIB2 field */ gdmakeg2( &input, &gemgrid, &g2msg, &g2len, &ret ); if ( ret != 0 ) { er_wmsg("GDGRIB2",&ret," ",&ier,7,1); continue; } /* * Open GRIB2 file, if not already open. */ if ( strncmp(input.g2file, cur_gbfile, LLMXLN) != 0 ) { /* * If output GRIB file is different, must close previous one first */ if ( strlen(cur_gbfile) != (size_t)0 ) { cfl_clos( gbfptr, &ret); gbfptr=0; } /* * Open GRIB file */ gbfptr = cfl_aopn( input.g2file, &ret); if ( ret == 0 ) { strncpy( cur_gbfile, input.g2file, LLMXLN); } else { er_wmsg("CFL",&ret,input.g2file,&ier,7,strlen(input.g2file)); ret = -24; er_wmsg("GDGRIB2",&ret," ",&ier,7,1); gbfptr = 0; continue; } } /* * Write out WMO Header, if requested */ gdmakewmo( &input, &gemgrid, chdr, &ret ); if ( strlen(chdr) == (size_t)21 ) { cfl_writ( gbfptr, strlen(chdr), (unsigned char*)chdr, &ret ); } /* * Write out GRIB2 message. */ cfl_writ( gbfptr, g2len, g2msg, &ret ); if ( ret != 0 ) { er_wmsg("CFL",&ret,input.g2file,&ier,7,strlen(input.g2file)); ret = -25; er_wmsg("GDGRIB2",&ret," ",&ier,7,1); continue; } /* * Free no longer needed allocated space */ if ( gemgrid.grid != 0 ) free(gemgrid.grid); if ( g2msg != 0 ) free(g2msg); } /* * Clean up files */ dg_nend( &ret ); if ( gbfptr != 0 ) cfl_clos( gbfptr, &ret); /* * Exit the GEMPAK user interface */ ip_exit( &ret ); return(0); }
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); }
void dc_dlog ( char *messag, int *lenm, int *iret ) /************************************************************************ * dc_dlog * * * * This routine opens the decoder log file, writes the given message * * and closes the file. * * * * dc_dlog ( messag, lenm, iret ) * * * * Input parameters: * * *messag char Message to write to the log * * *lenm int Number of chars in the message * * * * Output parameters: * * *iret int Return code * * 0 = normal return * * -2 = error writing to log * * * ** * * Log: * * S. Jacobs/NMC 7/95 * * S. Jacobs/NCEP 6/96 Updated documentation; Removed check * * for log file not opened; Changed to use * * a FILE stream with CFL_WRIT * * S. Jacobs/NCEP 7/96 Added open and close of log file * * K. Tyle/GSC 1/97 Remove prog. name and dattim; remove * * loglev variable * * S. Jacobs/NCEP 2/01 Removed all references to ulog * ***********************************************************************/ { char mesg[DCMXLN+8], tstr[12]; int lens, ier; FILE *fplog; /*---------------------------------------------------------------------*/ *iret = 0; /* ** Start the output message with the process ID. */ cst_inch ( ipid, tstr, &ier ); strcpy ( mesg, "[" ); strcat ( mesg, tstr ); strcat ( mesg, "] " ); /* ** Concatenate the input message to the output string. */ strcat ( mesg, messag ); cst_lstr ( mesg, &lens, &ier ); /* ** Get the length of the message and add a Line Feed and ** a NULL to the end. */ if ( lens > (DCMXLN+8) - 2 ) { mesg [lens-1] = CHLF; mesg [lens] = CHNULL; } else { mesg [lens] = CHLF; mesg [++lens] = CHNULL; } /* ** Open the decoder log file. */ fplog = NULL; if ( dcdlog[0] == '-' ) { /* ** If the file name is "-", open standard error for logging. */ fplog = stderr; } else { /* ** Try to open the decoder log file. */ fplog = cfl_aopn ( dcdlog, &ier ); if ( ier != 0 ) { /* ** If there is an error opening the file, open standard ** error for real-time processing, otherwise write an ** error message to the LDM log. */ if ( irltim ) { fplog = stderr; } else { *iret = -3; return; } } } /* ** Write the message to the log file. */ cfl_writ ( fplog, lens, (unsigned char *)mesg, &ier ); if ( ier != 0 ) { *iret = -2; } /* ** Close the decoder log file. */ if ( fplog == stderr ) { /* ** If standard error is being used for logging, do nothing. */ } else if ( fplog != NULL ) { /* ** Otherwise, close the log file. */ cfl_clos ( fplog, &ier ); } }
void psltyp ( int *iltyp, int lpat[10][8], int *lpscal, int *iret ) /************************************************************************ * PSLTYP * * * * This subroutine sets the hardware line type. 8 * * * PSLTYP ( ILTYP, LPAT, LPSCAL, IRET ) * * * * Input parameters: * * *ILTYP INT Line type * * LPAT [10][8] INT Array of all line patterns * * *LPSCAL INT Line dash scale * * * * Output parameters: * * *IRET INT Return code * ** * * Log: * * S. Jacobs/NCEP 4/96 * ***********************************************************************/ { int jpatno, i, numpat, done, dash, ipattt, ihwpat[20], ihalf, lenb, ier; float psfac; char buff[80], ssss[7]; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Make sure that plot file is open. Put terminal in vector mode. */ if ( ! opnfil ) { psopen ( iret ); if ( *iret != G_NORMAL ) return; } psplot = G_TRUE; /* * Get pattern number (ones place) */ jpatno = *iltyp % 10; /* * Exit for solid line. */ if ( jpatno == 1 ) { strcpy ( buff, " [] 0 setdash\n" ); lenb = strlen ( buff ); cfl_writ ( flun, lenb, (unsigned char *)buff, &ier ); return; } /* * Get pattern size factor ( ones = 1, 10's = 0.5, * 20's = 1, 30's = 2, 40's = 3, ... ) */ psfac = ( *iltyp / 10 ) - 1; if ( G_DIFF(psfac, 0) ) psfac = 0.5; if ( psfac < 0 ) psfac = 1.0; /* psfac *= 4; */ numpat = -1; done = G_FALSE; dash = G_FALSE; i = 0; while ( ( i <= 7 ) && ( ! done ) ) { ipattt = lpat[jpatno][i] * psfac * *lpscal; if ( ipattt > 0 ) { numpat++; ihwpat [numpat] = ipattt; } else if ( ipattt == 0 ) { done = G_TRUE; } else if ( dash || ( i == 0 ) ) { ihalf = -ipattt / 2; ihwpat [numpat+1] = 2; ihwpat [numpat+2] = ihalf; numpat += 2; dash = G_TRUE; } else { ihalf = -ipattt / 2; ihwpat [numpat+1] = ihalf; ihwpat [numpat+2] = 2; ihwpat [numpat+3] = ihalf; numpat += 3; dash = G_TRUE; } i++; } strcpy ( buff, " [ " ); for ( i = 0; i <= numpat; i++ ) { sprintf ( ssss, "%6d ", ihwpat[i] ); strcat ( buff, ssss ); } strcat ( buff, "] 0 setdash\n" ); lenb = strlen ( buff ); cfl_writ ( flun, lenb, (unsigned char *)buff, &ier ); }
void cvg_writeD ( VG_DBStruct *el, int start, int numbytes, FILE *fp, int *iret ) /************************************************************************ * cvg_writeD * * * * This function writes an element record to an opened VG file. * * *WITHOUT* consideration of placement. This gives the option of using* * VG files without needing device transformations (which placement * * will need to get the meta data populated). * * NOTE: This is actually the original cvg_write, so the log has been * * kept from that version. * * * * cvg_writeD ( el, start, numbytes, fp, iret ) * * * * Input parameters: * * *el VG_DBStruct Pointer toVG record structure * * start int Offset to start VG record * * numbytes int Number of bytes to be written * * *fp FILE file pointer to VG file * * * * Output parameters: * * *iret int Return code * * -3 = seek to a bad location * * -17 = error writing to VG file * * -30 = invalid color(s) * * -47 = no proper file specified * * * ** * * Log: * * J. Wu/GSC 02/01 Created based on cvg_writelm() * * S. Jacobs/NCEP 2/01 Added machine type MTLNUX * * E. Safford/GSC 07/01 add frees for all error returns * * J. Wu/SAIC 10/02 use memcpy() to speed up performance * * T. Piper/SAIC 12/02 Only use tmp_el when necessary * * T. Piper/SAIC 12/02 Added -2 option for start * * T. Lee/SAIC 11/03 used cvgcmn.h * * J. Wu/SAIC 01/04 add cvg_writgfa for GFA_ELM * * B. Yin/SAIC 02/04 added cvg_writtca for TCA_ELM * * B. Yin/SAIC 05/04 copy entire el to tmp_el * * B. Yin/SAIC 07/04 Fixed a bug when grouping TCA * * E. Safford/SAIC 06/07 pass lower level cvg error code upward * ***********************************************************************/ { int ier; VG_DBStruct *tmp_el; Boolean cflError = False; /*---------------------------------------------------------------------*/ /* * Verify the file pointer. */ if ( fp == NULL ) { *iret = -47; return; } /* * Check the proper color settings. */ if ( el->hdr.maj_col < 0 || el->hdr.maj_col > 32 || el->hdr.maj_col < 0 || el->hdr.min_col > 32 ) { *iret = -30; return; } /* * Seek to the specified location. */ if ( start == -2 ) { ier = 0; } else if ( start == -1 ) { cfl_seek( fp, 0, SEEK_END, &ier ); } else { cfl_seek( fp, (long)start, SEEK_SET, &ier ); } if ( ier != 0 ) { *iret = -3; return; } *iret = G_NORMAL; /* * Swap bit order of VG elements if necessary. * Use tmp_el to avoid actually changing data in el when swapping. */ if ( MTMACH == MTULTX || MTMACH == MTALPH || MTMACH == MTLNUX ) { tmp_el = (VG_DBStruct *) malloc ( sizeof(VG_DBStruct) ); memcpy ( tmp_el, el, sizeof(VG_DBStruct) ); if ( numbytes == sizeof( VG_HdrStruct ) ) { cvg_swap( SWPHDR, G_FALSE, *tmp_el, tmp_el, &ier ); } else { cvg_swap( SWPALL, G_FALSE, *tmp_el, tmp_el, &ier ); } if ( el->hdr.vg_type == GFA_ELM ) { cvg_writgfa ( fp, tmp_el, &ier ); } else if ( ( el->hdr.vg_type == TCA_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtca ( fp, tmp_el, &ier ); } else if ( ( el->hdr.vg_type == TCERR_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtce ( fp, tmp_el, &ier ); } else if ( ( el->hdr.vg_type == TCTRK_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtct ( fp, tmp_el, &ier ); } else if ( ( el->hdr.vg_type == TCBKL_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtcb ( fp, tmp_el, &ier ); } else { cfl_writ( fp, numbytes, (unsigned char *)tmp_el, &ier); if( ier < 0 ) { cflError = True; } } free(tmp_el); } else { if ( el->hdr.vg_type == GFA_ELM ) { cvg_writgfa ( fp, el, &ier ); } else if ( ( el->hdr.vg_type == TCA_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtca ( fp, el, &ier ); } else if ( ( el->hdr.vg_type == TCERR_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtce ( fp, el, &ier ); } else if ( ( el->hdr.vg_type == TCTRK_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtct ( fp, el, &ier ); } else if ( ( el->hdr.vg_type == TCBKL_ELM ) && ( numbytes != sizeof( VG_HdrStruct ) ) ) { cvg_writtcb ( fp, el, &ier ); } else { cfl_writ( fp, numbytes, (unsigned char *)el, &ier); if( ier < 0 ) { cflError = True; } } } if ( ier < 0 ) { if( !cflError ) { *iret = ier; } else { *iret = -17; } } }
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 ); }
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); }