Saturday, January 31, 2009

Northeast monsoon area average (GrADS)

prompt 'Enter south boundary: '
pull s
prompt 'Enter north boundry: '
pull n
prompt 'Enter west boundary: '
pull w
prompt 'Enter east boundary: '
pull e

'!mkdir 'rain'_'s'_'n'_'w'_'e

yyyy=1951
while(yyyy<=2003)



'reinit'
'open rf_5103.ctl'
'set lat 10'
'set lon 75'

'set time 01Oct'yyyy' 31Dec'yyyy
'set grads off'
'define r=aave(rf,lon='w',lon='e',lat='s',lat='n')'
'd r'
'draw title Rain area ave 'w'e 'e'e 's'n 'n'n'
'printim rain_'s'_'n'_'w'_'e'/rain'yyyy'.jpg white'

yyyy=yyyy+1
endwhile

Friday, January 23, 2009

Indian ocean Dipole using grads

yyyy=1960
while(yyyy<=1979)

'reinit'
'open sst6079.ctl'

'set lat 10'
'set lon 75'

'set time 01Oct'yyyy' 31Dec'yyyy
'set grads off'
'define sste=aave(sst,lon=90,lon=110,lat=-10,lat=0)'
'd sste'
'define sstw=aave(sst,lon=50,lon=70,lat=-10,lat=10)'
'd sstw'
'define sstd=sstw-sste'
'd sstd'
'draw title sst control run'
'printim sst1/sst'yyyy'.jpg white'

yyyy=yyyy+1
endwhile


yyyy=1980
while(yyyy<=1998)

'reinit'
'open sst8098.ctl'

'set lat 10'
'set lon 75'

'set time 01Oct'yyyy' 31Dec'yyyy
'set grads off'
'define sste=aave(sst.2,lon=90,lon=110,lat=-10,lat=0)'
'd sste'
'define sstw=aave(sst.2,lon=50,lon=70,lat=-10,lat=10)'
'd sstw'
'define sstd=sstw-sste'
'd sstd'
'draw title sst control run'
'printim sst1/sst'yyyy'.jpg white'

yyyy=yyyy+1
endwhile

Tuesday, January 20, 2009

rain NE monsoon

yyyy=1951
while(yyyy<=2003)

'reinit'
'open rf_5103.ctl'
'set lat 10'
'set lon 75'

'set time 01Oct'yyyy' 31Dec'yyyy
'set grads off'
'define r=aave(rf,lon=70,lon=75,lat=8,lat=15)'
'd r'
'draw title Rain control run'
'printim rain1/rain'yyyy'.jpg white'

yyyy=yyyy+1
endwhile

Monday, January 12, 2009

Project topic

Topic:Intra seasonal variability of Northeast Monsoon and various physical parameters ditermining it.

Work Plan
1.Collecting daily dataof rainfall, SST, SLP, wind, etc.

2.Time series analysis of spacial average of precipitation over southern peninsular India. (Between 8N and 15N latitude, and between 74E and 80E longitude)

3. Determine the periodicity of intra-seasonal variability of rainfall during Northeast monsoon.

4. Cross examining and correlating the northeast monsoon rainfall variabilities with the parameters such as Indian ocean Sea surface temperature, Sea level pressure, wind speed, wind direction, cloud cover, over the tropical Indian Ocean and Southern peninsular India.

5. Identify if there is any other parameters which have its influence on the northeast monsoon precipitation.

6. The relationship of the periodicity of intra-seasonal variability of Northeast monsoon with various phenomenas such as

*Indian Ocean dipole
*Equatorial Indian Ocean Oscillation
*Global circulation pattern
*El-Nino Southern Oscillation
*Quasi Biennial Oscillation
*Madden Julian Oscillation
etc if time and resources are available.

7. The proposed study shall lead to a better understanding of Intra-seasonal variability Northeast monsoon and its dependence on various parameters and Global Meteorological Phenomenas

EPSS109

C Programming - File management in C


C Programming - File management in C

In this tutorial you will learn about C Programming - File management in C, File operation functions in C, Defining and opening a file, Closing a file, The getw and putw functions, The fprintf & fscanf functions, Random access to files and fseek function.



C supports a number of functions that have the ability to perform basic file operations, which include:
1. Naming a file
2. Opening a file
3. Reading from a file
4. Writing data into a file
5. Closing a file


  • Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two major problems
  • It becomes cumbersome and time consuming to handle large volumes of data through terminals.
  • The entire data is lost when either the program is terminated or computer is turned off therefore it is necessary to have more flexible approach where data can be stored on the disks and read whenever necessary, without destroying the data. This method employs the concept of files to store data.

File operation functions in C:

Function Name


Operation


fopen()


Creates a new file for use
Opens a new existing file for use


fclose


Closes a file which has been opened for use


getc()


Reads a character from a file


putc()


Writes a character to a file


fprintf()


Writes a set of data values to a file


fscanf()


Reads a set of data values from a file


getw()


Reads a integer from a file


putw()


Writes an integer to the file


fseek()


Sets the position to a desired point in the file


ftell()


Gives the current position in the file


rewind()


Sets the position to the begining of the file


Defining and opening a file:

If we want to store data in a file into the secondary memory, we must specify certain things about the file to the operating system. They include the fielname, data structure, purpose.


The general format of the function used for opening a file is


FILE *fp;
fp=fopen(“filename”,”mode”);

The first statement declares the variable fp as a pointer to the data type FILE. As stated earlier, File is a structure that is defined in the I/O Library. The second statement opens the file named filename and assigns an identifier to the FILE type pointer fp. This pointer, which contains all the information about the file, is subsequently used as a communication link between the system and the program.
The second statement also specifies the purpose of opening the file. The mode does this job.

R open the file for read only.
W open the file for writing only.
A open the file for appending data to it.

Consider the following statements:


FILE *p1, *p2;
p1=fopen(“data”,”r”);
p2=fopen(“results”,”w”);


In these statements the p1 and p2 are created and assigned to open the files data and results respectively the file data is opened for reading and result is opened for writing. In case the results file already exists, its contents are deleted and the files are opened as a new file. If data file does not exist error will occur.


Closing a file:

The input output library supports the function to close a file; it is in the following format.
fclose(file_pointer);

A file must be closed as soon as all operations on it have been completed. This would close the file associated with the file pointer.
Observe the following program.


….
FILE *p1 *p2;
p1=fopen (“Input”,”w”);
p2=fopen (“Output”,”r”);
….

fclose(p1);
fclose(p2)


The above program opens two files and closes them after all operations on them are completed, once a file is closed its file pointer can be reversed on other file.

The getc and putc functions are analogous to getchar and putchar functions and handle one character at a time. The putc function writes the character contained in character variable c to the file associated with the pointer fp1. ex putc(c,fp1); similarly getc function is used to read a character from a file that has been open in read mode. c=getc(fp2).


The program shown below displays use of a file operations. The data enter through the keyboard and the program writes it. Character by character, to the file input. The end of the data is indicated by entering an EOF character, which is control-z. the file input is closed at this signal.

#include<>
main()
{
file *f1;
printf(“Data input output”);
f1=fopen(“Input”,”w”); /*Open the file Input*/
while((c=getchar())!=EOF) /*get a character from key board*/
putc(c,f1); /*write a character to input*/
fclose(f1); /*close the file input*/
printf(“\nData output\n”);
f1=fopen(“INPUT”,”r”); /*Reopen the file input*/
while((c=getc(f1))!=EOF)
printf(“%c”,c);
fclose(f1);
}


The getw and putw functions:

These are integer-oriented functions. They are similar to get c and putc functions and are used to read and write integer values. These functions would be usefull when we deal with only integer data. The general forms of getw and putw are:


putw(integer,fp);
getw(fp);


/*Example program for using getw and putw functions*/
#include<>
main()
{
FILE *f1,*f2,*f3;
int number I;
printf(“Contents of the data file\n\n”);
f1=fopen(“DATA”,”W”);
for(I=1;I< 30;I++)
{
scanf(“%d”,&number);
if(number==-1)
break;
putw(number,f1);
}
fclose(f1);
f1=fopen(“DATA”,”r”);
f2=fopen(“ODD”,”w”);
f3=fopen(“EVEN”,”w”);
while((number=getw(f1))!=EOF)/* Read from data file*/
{
if(number%2==0)
putw(number,f3);/*Write to even file*/
else
putw(number,f2);/*write to odd file*/
}
fclose(f1);
fclose(f2);
fclose(f3);
f2=fopen(“ODD”,”r”);
f3=fopen(“EVEN”,”r”);
printf(“\n\nContents of the odd file\n\n”);
while(number=getw(f2))!=EOF)
printf(“%d%d”,number);
printf(“\n\nContents of the even file”);
while(number=getw(f3))!=EOF)
printf(“%d”,number);
fclose(f2);
fclose(f3);
}


The fprintf & fscanf functions:

The fprintf and scanf functions are identical to printf and scanf functions except that they work on files. The first argument of theses functions is a file pointer which specifies the file to be used. The general form of fprintf is


fprintf(fp,”control string”, list);


Where fp id a file pointer associated with a file that has been opened for writing. The control string is file output specifications list may include variable, constant and string.


fprintf(f1,%s%d%f”,name,age,7.5);


Here name is an array variable of type char and age is an int variable
The general format of fscanf is


fscanf(fp,”controlstring”,list);


This statement would cause the reading of items in the control string.

Example:

fscanf(f2,”5s%d”,item,&quantity”);


Like scanf, fscanf also returns the number of items that are successfully read.

/*Program to handle mixed data types*/
#include<>
main()
{
FILE *fp;
int num,qty,I;
float price,value;
char item[10],filename[10];
printf(“Input filename”);
scanf(“%s”,filename);
fp=fopen(filename,”w”);
printf(“Input inventory data\n\n”0;
printf(“Item namem number price quantity\n”);
for I=1;I< =3;I++)
{
fscanf(stdin,”%s%d%f%d”,item,&number,&price,&quality);
fprintf(fp,”%s%d%f%d”,itemnumber,price,quality);
}
fclose (fp);
fprintf(stdout,”\n\n”);
fp=fopen(filename,”r”);
printf(“Item name number price quantity value”);
for(I=1;I< =3;I++)
{
fscanf(fp,”%s%d%f%d”,item,&number,&prince,&quality);
value=price*quantity”);
fprintf(“stdout,”%s%d%f%d%d\n”,item,number,price,quantity,value);
}
fclose(fp);
}


Random access to files:

Sometimes it is required to access only a particular part of the and not the complete file. This can be accomplished by using the following function:


1 > fseek


fseek function:

The general format of fseek function is a s follows:


fseek(file pointer,offset, position);


This function is used to move the file position to a desired location within the file. Fileptr
is a pointer to the file concerned. Offset is a number or variable of type long, and position in an integer number. Offset specifies the number of positions (bytes) to be moved from the location specified bt the position. The position can take the 3 values.


Value Meaning
0 Beginning of the file
1 Current position
2 End of the file.

Saturday, January 3, 2009

GrADS code for drawing linegraph with monthly mean data

prompt 'Enter the keyword: '
pull key
'!mkdir linegr_'key
prompt 'Enter the Latitude: '
pull lat
prompt 'Enter the Longitude: '
pull lon
prompt 'Enter the number of Years: '
pull noy


y=1
while y< noy
strtime=1+12*(y-1)
endtime=12*y

'reinit'
'sdfopen monmeandata/'key'.mon.mean.nc'
'q file'
'set lat 'lat
'set lon 'lon
'set t 'strtime' 'endtime
'd 'key
'draw xlab Time'
'draw ylab 'key



'printim linegr_'key'/'y'.jpg white'

y=y+1
endwhile

GrADS code for a shaded contoured plot of Indian region

prompt 'Enter the keyword: '
pull key
'!mkdir scplot_'key
t=0
while t<30


'reinit'
'sdfopen monmeandata/'key'.mon.mean.nc'
'q file'
'set lat 0 40'
'set lon 60 100'
'set t 't
'set gxout shaded'
'd 'key
'cbarn'
'set gxout contour'
'd 'key
'draw xlab Longitude'
'draw ylab Latitude'



'printim scplot_'key'/'t'.jpg white'

t=t+1
endwhile

Friday, January 2, 2009

GrADS code for plot wind of Indian region

** Indian region *.'yyyy'.Jan
************************************

prompt 'Enter name for new folder: '
pull opf
'!mkdir 'opf
loop=y
while(loop=y)
prompt 'Enter level: '
pull lev

prompt 'Enter year: '
pull yyyy

prompt 'Enter month (three letters) : '
pull mmm


dd=1
while(dd<=31)

'reinit'
'sdfopen uwnd.'yyyy'.nc'
'q file'
'sdfopen vwnd.'yyyy'.nc'
'q file'
'set lat -15 40'
'set lon 40 120'
'set grads off'
'set time 'dd''mmm''yyyy''


'set lev 'lev

**********
'set gxout shaded'
'd uwnd'
'run cbarn'

'set gxout contour'
'd uwnd'

'draw title u wind m/s 'lev'mb\.'yyyy'.'mmm'.'dd''
'printim 'opf'/w.'lev'mb.uwnd.'yyyy'.'mmm'.'dd'.jpg white'

'c'
say 'Zonal Wind 'lev'mb\.'yyyy'.'mmm'.'dd' '
************

'set gxout shaded'
'd vwnd.2'
'run cbarn'

'set gxout contour'
'd vwnd.2'

'draw title v wind m/s 'lev'mb\.'yyyy'.'mmm'.'dd''
'printim 'opf'/w.'lev'mb.vwnd.'yyyy'.'mmm'.'dd'.jpg white'
'c'
say 'Meridional Wind 'lev'mb\.'yyyy'.'mmm'.'dd' '
************

'set gxout shaded'

'd mag(uwnd,vwnd.2)'
'cbarn'

'set gxout vector'
'd uwnd;vwnd.2'


'draw title wind speed m/s 'lev'mb\.'yyyy'.'mmm'.'dd''
'printim 'opf'/w.'lev'mb.wind.vtr.'yyyy'.'mmm'.'dd'.jpg white'
'c'
say 'Wind Vector 'lev'mb\.'yyyy'.'mmm'.'dd' '
*************
'set gxout stream'
'set ccolor 4'
'd uwnd;vwnd.2'

'draw title wind 'lev'mb\.'yyyy'.'mmm'.'dd''
'printim 'opf'/w.'lev'mb.wnd.strm.'yyyy'.'mmm'.'dd'.jpg white'
'c'
say 'Wind Streamline 'lev'mb\.'yyyy'.'mmm'.'dd' '

dd=dd+1
endwhile

prompt 'Do you want to plot another level: n for no, y for yes :'
pull loop
endwhile


*******************************

GrADS code for drawing Hoffmullers diagram

prompt 'Enter the keyword: '
pull key
'!mkdir hoff_'key
lat=0
while lat<90


'reinit'
'sdfopen monmeandata/'key'.mon.mean.nc'
'q file'
'set lat 'lat
'set lon 0 180'
'set t 1 12'
'd 'key
'draw xlab Longitude'
'draw ylab Time'



'printim hoff_'key'/'lat'.jpg white'

lat=lat+1
endwhile

GrADS code for creating new folder

prompt 'Enter name for new folder: '
pull name
'!mkdir 'name