Mapper
create_fmap_file.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <X11/Xos.h>
5 #include <ctype.h>
6 #include "mm2rfs.h"
7 
8 #include <Xm/Text.h>
9 #include <Xm/TextF.h>
10 
11 extern struct time_cntl tc;
12 extern struct fgroup_info fg[20];
13 extern fgroup_num;
14 extern Widget text_edit;
15 extern Widget text_output;
16 extern int dur_toggle_item_set;
17 
18 int create_fmap_file(int remove)
19 {
20 FILE *fp;
21 char *text;
22 char fg_last[9];
23 char line[80];
24 char tmp_file[80];
25 int i,j,k,l,last_per;
26 int y,m,d,h,hx;
27 int len,len_actual;
28 int day;
29 float amt24;
30 struct fmap_struct fmap[100];
31 
32  if(dur_toggle_item_set==1) last_per=3;
33  if(dur_toggle_item_set==2) last_per=7;
34  if(dur_toggle_item_set>=3) last_per=11;
35 
36 
37  /* load structure with fmap informaiton */
38  i=fmap_load(&fmap[0]);
39  if(i)
40  {
41  /* set .FMAP6 time control */
42 
43  /* -8 hrs for ZULU > PST, then +2 to insure the correct day */
44  adj_time(-6,tc.year,tc.month,tc.day,tc.hour,&y,&m,&d,&h);
45  y=y%100;
46 
47  /* set PST ending time */
48  if(tc.period==1) h=10;
49  if(tc.period==2) h=16;
50  if(tc.period==3) h=22;
51  if(tc.period==4) h=4;
52 
53  /* create tmp filename */
54  sprintf(tmp_file,"fmap_fg.%d%d%d.%d%d%d",
55  tc.year,tc.month,tc.day,tc.hour,tc.minute,tc.second);
56 
57  if((fp = fopen (tmp_file, "w")))
58  {
59  strcpy(fg_last,"\0");
60  for(j=0;j<i;j++)
61  {
62  if(strcmp(fg_last,fmap[j].fgroupid))
63  {
64  if(j)
65  fprintf(fp,"ENDMOD\n\n");
66  for(k=0;k<fgroup_num;k++)
67  if(!strcmp(fg[k].id,fmap[j].fgroupid))
68  fprintf(fp,"$%s\nMOD\n.FMAP6 %02d%02d%02d%02dPST\n",
69  fg[k].desc,m,d,y,h);
70 
71  hx=h;
72  fprintf(fp,"$ ");
73  for(k=tc.period-1;k<=last_per;k++)
74  {
75  fprintf(fp," %02d ",hx);
76  if(k==3 || k==7) fprintf(fp," ");
77  hx=(hx+6)%24;
78  }
79  fprintf(fp,"\n");
80  }
81  strcpy(fg_last,fmap[j].fgroupid);
82  sprintf(line,"%s ",fmap[j].fmapid);
83  *(line+8)='\0';
84  fprintf(fp,"%s ",line);
85  for(k=tc.period-1;k<=last_per;k++)
86  {
87  fprintf(fp," %2.1f",fmap[j].per[k].amt);
88  if(k==3 || k==7) fprintf(fp," ");
89  }
90  fprintf(fp,"\n");
91  }
92  fprintf(fp,"ENDMOD\n\n");
93 
94  /* do .FMAP6 for days 4-7 if requested */
95  if(dur_toggle_item_set>=4)
96  {
97  adj_time(-6*(tc.period-1),
98  tc.year,tc.month,tc.day,tc.hour,&y,&m,&d,&h);
99  adj_time(48,y,m,d,h,&y,&m,&d,&h);
100  for(day=4;day<=dur_toggle_item_set;day++)
101  {
102  adj_time(24,y,m,d,h,&y,&m,&d,&h);
103  y=y%100;
104  h=10;
105  strcpy(fg_last,"\0");
106 
107  for(j=0;j<i;j++)
108  {
109  if(strcmp(fg_last,fmap[j].fgroupid))
110  {
111  if(j)
112  fprintf(fp,"ENDMOD\n\n");
113  for(k=0;k<fgroup_num;k++)
114  if(!strcmp(fg[k].id,fmap[j].fgroupid))
115  fprintf(fp,"$%s\nMOD\n.FMAP6 %02d%02d%02d%02dPST \n",
116  fg[k].desc,m,d,y,h);
117  fprintf(fp,"$ 10 16 22 04\n");
118  }
119  strcpy(fg_last,fmap[j].fgroupid);
120  sprintf(line,"%s ",fmap[j].fmapid);
121  *(line+10)='\0';
122  fprintf(fp,"%s",line);
123  for(l=0;l<4;l++)
124  fprintf(fp," %2.1f",fmap[j].per[l+4*(day-1)].amt);
125  fprintf(fp,"\n");
126  }
127  fprintf(fp,"ENDMOD\n\n");
128  }
129  }
130 
131  fclose(fp);
132  if(remove)
133  {
134  if((fp = fopen (tmp_file, "r")))
135  {
136  len=10000;
137  if (!(text = XtMalloc ((unsigned)(len+1)))) /* +1 for NULL */
138  {
139  sprintf (line, "%s: XtMalloc(%ld) failed", len, tmp_file);
140  if(text_output)
141  XmTextFieldSetString (text_output, line);
142  return(0);
143  }
144  else
145  {
146  len_actual=fread (text, sizeof (char), len, fp);
147  text[len_actual] = 0; /* NULL-terminate */
148  if(text_edit)
149  XmTextSetString (text_edit, text);
150  sprintf (line, "Click 'Save as *' to store as '* File'");
151  if(text_output)
152  XmTextFieldSetString (text_output, line);
153  }
154  /* close and rm file */
155  fclose(fp);
156  sprintf(line,"rm %s",tmp_file);
157  system(line);
158  }
159  else
160  {
161  sprintf(line,"Couldn't open temp file %s",tmp_file);
162  if(text_output)
163  XmTextFieldSetString (text_output, line);
164  return(0);
165  }
166  }
167  }
168  else
169  {
170  sprintf(line,"Couldn't open temp file %s",tmp_file);
171  if(text_output)
172  XmTextFieldSetString (text_output, line);
173  return(0);
174  }
175  }
176  else
177  {
178  sprintf(line,"No fmaps in table fmaqtrly to read.");
179  if(text_output)
180  XmTextFieldSetString (text_output, line);
181  return(0);
182  }
183 
184  return(1);
185 }
int adj_time(int adj, int y, int m, int d, int h, int *adj_y, int *adj_m, int *adj_d, int *adj_h)
Definition: adj_time.c:10
static int i
struct fgroup_info fg[20]
Widget text_edit
int create_fmap_file(int remove)
fgroup_num
Widget text_output
int dur_toggle_item_set
struct time_cntl tc
int day
Definition: display_data.c:26
Widget text
Definition: display_rec.c:5
int fmap_load(struct fmap_struct *fmap)
Definition: fmap_load.c:36
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
fp
Definition: make_NEXRAD.c:339
system(tarbuf)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
int j
Definition: mapp2h.h:48
int k
Definition: mapp2h.h:48