/* sd_data_in.c All data comes in as location cards. Threre is a field description file, fdf, that names all these fields for reference by sd2rpl, which also eventually should guide Bill's data massaging code. Eventually, the .rpl file records should have a different agreed-upon field definition rfd (.rpl field description) for reference by the template, sd2rpl, and replicat. */ #include #include #include #include "sl_type.h" #include "sl_util.h" #include "sl_srvin.h" #include "sl_unit.h" #include "repldef.h" #include "coordcnv.h" FLOAT gflOrgLat = 0.0; FLOAT gflOrgLon = 0.0; #define TYPE_IIS 1 extern int argc; extern char *argv[]; char field_names[MAX_FIELDS][MAX_FIELD_NAME_LENGTH]; struct record { char *fields[25]; int heading; } records[20000]; int record_index = 0; struct heading { int stack; char *subheading; int first_record; int last_record; } headings[5000]; int heading_index = 0; read_data() { int i, j, k, len, string_index; int current_heading = 0; int record_index = 0; char data_f_name[20]; char buf[2*MAX_FIELD_NAME_LENGTH]; FILE *data_f_fd; read_fdf(); /* Read in only the data called for by .sd file info */ for (i=0;i MAX_FIELD_NAME_LENGTH) { printf("Name %s too long in fdf. Exiting.\n", buf); } strcpy(field_names[field_name_index++], buf); } } fclose(fdf_fd); } /* The following dummy function includes all the file work done in the original replre2. */ original_files() { short Repl_OK = FALSE; short Infmx_OK = FALSE; short Config_OK = FALSE; short Chunk_OK = FALSE; short Quad_OK = FALSE; short Level_OK = FALSE; short ViewSet_OK = FALSE; short RegionId_OK = FALSE; short Heading_OK = FALSE; short OrgLon_OK = FALSE; short OrgLat_OK = FALSE; short SrvData_OK = FALSE; short bad_arg = FALSE; short ret_val = 0; char ReplFile[256]; char InfmxFile[256]; char ConfigFile[256]; char ChunkIdxFile[256]; char QuadFile[256]; char SrvDataFile[256]; char XlnkIDFile[256]; char RegionId[256]; char Heading[256]; short Level = 0; char ViewSet = 0; FILE *fd_chunk; FILE *fd_quad; FILE *fd_qot; FILE *fd_infmx; FILE *fd_repl; FILE *fd_srv; FILE *fd_xlnkid; CONFIG_STRUCT ConfigInfo; CARDOFF_HANDLE_STRUCT CardOffHnd; char InLine[LINE_LENGTH]; short LocSoundFlag = FALSE; /* No sound for Germany */ short CardNum = 0; short LocCardCnt = 0; if (argc < 9) { printf ("Usage: %s -R -H -L -V \n", argv[0]); printf (" -I -F -C -D \n"); printf (" -S -X -Y -Q \n"); return (1); } while (--argc) { ++argv; switch (**argv) { case '-': switch (*((*argv)+1)) { case 'r': case 'R': if (--argc) { ++argv; strcpy(RegionId, *argv); RegionId_OK = 1; } break; case 'h': case 'H': if (--argc) { ++argv; strcpy(Heading, *argv); Heading_OK = 1; } break; case 'l': case 'L': if (--argc) { ++argv; Level = atoi(*argv); Level_OK = 1; } break; case 'v': case 'V': if (--argc) { ++argv; sscanf(*argv, "%c", &ViewSet); ViewSet_OK = 1; } break; case 'i': case 'I': if (--argc) { ++argv; strcpy(InfmxFile, *argv); Infmx_OK = 1; } break; case 'f': case 'F': if (--argc) { ++argv; strcpy(ConfigFile, *argv); Config_OK = 1; } break; case 'c': case 'C': if (--argc) { ++argv; strcpy(ChunkIdxFile, *argv); Chunk_OK = 1; } break; case 'q': case 'Q': if (--argc) { ++argv; strcpy(QuadFile, *argv); Quad_OK = 1; } break; case 'd': case 'D': if (--argc) { ++argv; strcpy(ReplFile, *argv); Repl_OK = 1; } break; case 's': case 'S': if (--argc) { ++argv; strcpy(SrvDataFile, *argv); SrvData_OK = 1; } break; case 'x': case 'X': if (--argc) { ++argv; gflOrgLon = atof(*argv); OrgLon_OK = 1; } break; case 'y': case 'Y': if (--argc) { ++argv; gflOrgLat = atof(*argv); OrgLat_OK = 1; } break; default: bad_arg = 1; break; } /* end switch */ break; default: bad_arg = 1; break; } /* end switch */ } /* end while */ if ( !Repl_OK || !Infmx_OK || !Config_OK || !Chunk_OK || !Level_OK || !ViewSet_OK || !RegionId_OK || !Heading_OK || !Quad_OK || !OrgLon_OK || !OrgLat_OK || !SrvData_OK || bad_arg ) { ret_val = 1; printf ("ERROR : Command line arguments not valid\n"); return(ret_val); } /* * Read configuration file and data file */ fd_infmx = fopen (InfmxFile, "r"); if (fd_infmx == NULL) { printf ("ERROR : Cannot open file '%s'. QUITTING\n", InfmxFile); exit(-1); } fd_repl = fopen (ReplFile, "w"); if (fd_repl == NULL) { printf ("ERROR : Cannot open file '%s'. QUITTING\n", ReplFile); exit(-1); } fd_chunk = fopen (ChunkIdxFile, "rb"); if (fd_chunk == NULL) { printf ("ERROR : Cannot open file '%s'. QUITTING\n", ChunkIdxFile); exit(-1); } fd_quad = fopen (QuadFile, "rb"); if (fd_quad == NULL) { printf ("ERROR : Cannot open file '%s'. QUITTING\n", QuadFile); exit(-1); } fd_qot = fopen ("FINDUNIT.TMP", "w+b"); if (fd_qot == NULL) { printf ("ERROR : Cannot open file 'FINDUNIT.TMP'. QUITTING\n"); exit (-1); } fd_srv = fopen (SrvDataFile, "a"); if ( fd_srv == NULL) { printf ("ERROR : Cannot open file '%s'. QUITTING\n", SrvDataFile); exit (-1); } sprintf ( XlnkIDFile, "%s.xid", RegionId ); fd_xlnkid = fopen (XlnkIDFile, "a+"); if ( fd_xlnkid == NULL) { printf ("ERROR : Cannot open file '%s'. QUITTING\n", XlnkIDFile); exit (-1); } /* * Build qot */ if (!BuildQOT(fd_chunk, fd_qot, Level, ViewSet)) { printf ("ERROR : Building QOT error. QUITTING\n"); exit (-1); } /* * Read configuration file */ Get_Heading_cfg (ConfigFile, &ConfigInfo, RegionId, Heading); /* * Go through data file once to assign card numbers and offset */ BuildCardOff (fd_infmx, &CardOffHnd); /* * Close all files */ fclose (fd_infmx); fclose (fd_repl); fclose (fd_chunk); fclose (fd_qot); fclose (fd_quad); fclose (fd_xlnkid); }