Mapper
create_rsel_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_rsel_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,ii,j,k,last_per;
26 int y,m,d,h;
27 int vy,vm,vd,vh;
28 int freezing_level;
29 int len,len_actual;
30 struct rsel_struct rsel[100];
31 
32  last_per=3+(4*(dur_toggle_item_set-1));
33 
34  /* load structure with fmap informaiton */
35  i=rsel_load(&rsel[0]);
36 
37  /* make sure that there are postable rsels */
38  ii=0;
39  if(i)
40  {
41  for(j=0;j<i;j++)
42  if(rsel[j].rfs_post)
43  ii=1;
44  }
45 
46  if(i && ii)
47  {
48  /* set time control */
49  adj_time(-6,tc.year,tc.month,tc.day,tc.hour,&y,&m,&d,&h);
50  if(tc.period==1) h=10;
51  if(tc.period==2) h=16;
52  if(tc.period==3) h=22;
53  if(tc.period==4) h=4;
54  /* mods are valid for the next 3 computational periods */
55  /* mods are valid for the current period only */
56  adj_time(0,y,m,d,h,&vy,&vm,&vd,&vh);
57  y=y%100;
58  vy=vy%100;
59 
60  /* create tmp filename */
61  sprintf(tmp_file,"rsel_fg.%d%d%d.%d%d%d",
62  tc.year,tc.month,tc.day,tc.hour,tc.minute,tc.second);
63 
64  if((fp = fopen (tmp_file, "w")))
65  {
66  strcpy(fg_last,"\0");
67  for(j=0;j<i;j++)
68  {
69  if(rsel[j].rfs_post)
70  {
71  if(strcmp(fg_last,rsel[j].fgroupid))
72  {
73  if(j)
74  fprintf(fp,"$\n");
75  for(k=0;k<fgroup_num;k++)
76  if(!strcmp(fg[k].id,rsel[j].fgroupid))
77  fprintf(fp,"$%s\n.TSCHNG "
78  "%02d%02d%02d%02dPST %02d%02d%02d%02dPST\n",
79  fg[k].desc,m,d,y,h,vm,vd,vy,vh);
80  }
81  strcpy(fg_last,rsel[j].fgroupid);
82 
83  sprintf(line,"%s ",rsel[j].segid);
84  *(line+8)='\0';
85  fprintf(fp,"%s ",line);
86 
87  sprintf(line,"%s ",rsel[j].ts_id);
88  *(line+8)='\0';
89  fprintf(fp,"%s ",line);
90 
91  sprintf(line,"%s ",rsel[j].ts_dt);
92  *(line+4)='\0';
93  fprintf(fp,"%s 6 ",line);
94 
95  for(k=0;k<=last_per;k++)
96  {
97  if(k<tc.period-1)
98  strcpy(line," ");
99  else
100  {
101  freezing_level=(int)(0.5+rsel[j].per[k].amt*1000.);
102  sprintf(line,"%5d",freezing_level);
103  }
104  fprintf(fp," %s",line);
105 
106  if(!((k+1)%4) && k != last_per)
107  fprintf(fp," &\n ");
108  }
109  fprintf(fp," %s\n",rsel[j].oper);
110  }
111  }
112 
113  fclose(fp);
114  if(remove)
115  {
116  if((fp = fopen (tmp_file, "r")))
117  {
118  len=10000;
119  if (!(text = XtMalloc ((unsigned)(len+1)))) /* +1 for NULL */
120  {
121  sprintf (line, "%s: XtMalloc(%ld) failed", len, tmp_file);
122  if(text_output)
123  XmTextFieldSetString (text_output, line);
124  return(0);
125  }
126  else
127  {
128  len_actual=fread (text, sizeof (char), len, fp);
129  text[len_actual] = 0; /* NULL-terminate */
130  if(text_edit);
131  XmTextSetString (text_edit, text);
132  sprintf (line, "Click 'Save as *' to store as '* File'");
133  if(text_output);
134  XmTextFieldSetString (text_output, line);
135  }
136  /* close and rm file */
137  fclose(fp);
138  sprintf(line,"rm %s",tmp_file);
139  system(line);
140  }
141  else
142  {
143  sprintf(line,"Couldn't open temp file %s",tmp_file);
144  if(text_output)
145  XmTextFieldSetString (text_output, line);
146  return(0);
147  }
148  }
149  }
150  else
151  {
152  sprintf(line,"Couldn't open temp file %s",tmp_file);
153  if(text_output)
154  XmTextFieldSetString (text_output, line);
155  return(0);
156  }
157  }
158  else
159  {
160  sprintf(line,"No Freezing Level forecasts in table fval to read.");
161  if(text_output)
162  XmTextFieldSetString (text_output, line);
163  return(0);
164  }
165 
166  return(1);
167 }
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
int create_rsel_file(int remove)
struct fgroup_info fg[20]
Widget text_edit
fgroup_num
Widget text_output
int dur_toggle_item_set
struct time_cntl tc
Widget text
Definition: display_rec.c:5
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
int rsel_load(struct rsel_struct *rsel)
Definition: rsel_load.c:38