00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <unistd.h>
00019 #include <grass/Vect.h>
00020 #include <grass/gis.h>
00021
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024
00025 static char name_buf[1024];
00026 int check_coor ( struct Map_info *Map );
00027
00028
00029
00030
00031
00032
00033 int
00034 V1_open_old_nat ( struct Map_info *Map, int update)
00035 {
00036 char buf[1000];
00037
00038 G_debug (1, "V1_open_old_nat(): name = %s mapset = %s", Map->name, Map->mapset);
00039
00040 sprintf (buf, "%s/%s", GRASS_VECT_DIRECTORY, Map->name);
00041 dig_file_init ( &(Map->dig_fp) );
00042 if ( update )
00043 Map->dig_fp.file = G_fopen_modify (buf, GRASS_VECT_COOR_ELEMENT);
00044 else
00045 Map->dig_fp.file = G_fopen_old (buf, GRASS_VECT_COOR_ELEMENT, Map->mapset);
00046
00047 if ( Map->dig_fp.file == NULL ) return -1;
00048
00049 if ( !(dig__read_head (Map)) ) return (-1);
00050 check_coor ( Map );
00051
00052
00053 dig_init_portable ( &(Map->head.port), Map->head.port.byte_order );
00054
00055
00056 if ( !update )
00057 dig_file_load ( &(Map->dig_fp) );
00058
00059 return (0);
00060 }
00061
00062
00063
00064
00065
00066 int
00067 V1_open_new_nat (
00068 struct Map_info *Map,
00069 char *name,
00070 int with_z)
00071 {
00072 char buf[1000];
00073 struct stat info;
00074
00075 G_debug (1, "V1_open_new_nat(): name = %s", name);
00076
00077 sprintf (buf, "%s/%s", GRASS_VECT_DIRECTORY, name);
00078
00079
00080 Map->head.Version_Major = GV_COOR_VER_MAJOR;
00081 Map->head.Version_Minor = GV_COOR_VER_MINOR;
00082 Map->head.Back_Major = GV_COOR_EARLIEST_MAJOR;
00083 Map->head.Back_Minor = GV_COOR_EARLIEST_MINOR;
00084
00085
00086 dig_file_init ( &(Map->dig_fp) );
00087 Map->dig_fp.file = G_fopen_new (buf, GRASS_VECT_COOR_ELEMENT);
00088 if ( Map->dig_fp.file == NULL ) return (-1);
00089 fclose ( Map->dig_fp.file );
00090
00091 dig_file_init ( &(Map->dig_fp) );
00092 Map->dig_fp.file = G_fopen_modify (buf, GRASS_VECT_COOR_ELEMENT);
00093 if ( Map->dig_fp.file == NULL ) return (-1);
00094
00095
00096 G__file_name (name_buf, buf, GV_TOPO_ELEMENT, G_mapset ());
00097 if (stat (name_buf, &info) == 0)
00098 unlink (name_buf);
00099
00100 G__file_name (name_buf, buf, GRASS_VECT_COOR_ELEMENT, G_mapset ());
00101
00102 Map->head.size = 0;
00103 Map->head.head_size = GV_COOR_HEAD_SIZE;
00104 Vect__write_head (Map);
00105
00106
00107 dig_init_portable ( &(Map->head.port), dig__byte_order_out ());
00108
00109 if ( !(dig__write_head (Map)) ) return (-1);
00110
00111 return 0;
00112 }
00113
00114
00115 int check_coor ( struct Map_info *Map )
00116 {
00117 struct Coor_info CInfo;
00118 long dif;
00119
00120 Vect_coor_info ( Map, &CInfo);
00121 dif = CInfo.size - Map->head.size;
00122 G_debug ( 1, "coor size in head = %ld, real coor file size= %ld",
00123 Map->head.size, CInfo.size);
00124
00125 if ( dif > 0 ) {
00126 G_warning ( "coor files of vector '%s@%s' is larger than it should be "
00127 "(%ld bytes excess).", Map->name, Map->mapset, dif);
00128 } else if ( dif < 0 ) {
00129 G_warning ( "coor files of vector '%s@%s' is shorter than it should be "
00130 "(%ld bytes missing).", Map->name, Map->mapset, -dif);
00131 }
00132 return 1;
00133 }