*TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT * NOTE : I did't run this script to test it. Therefore there could be some * unnoticed bugs in the script. Mail me if you encounter some bugs * that you cant fix. * Contact: Martin V. Mathew, vmartinmathew@gamil.com *LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL 'reinit' infile1a='air.sig995.' infile1b='.nc' startYr=1948 noYrs=63 ;* total no of files to be read mnCnt=0; yrs=1 while(yrs<=noYrs) crntYr=startYr+yrs-1 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 1) Generating input file name & opening the file *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ infile1=infile1a%crntYr%infile1b say 'Opening input file '%infile1 'sdfopen 'infile1 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 2) Using 'q file' command to know details of time dimension in the file *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *ga-> q file *File 1 : * Descriptor: tauy_tropflux_1d_1979_2012.nc * Binary: tauy_tropflux_1d_1979_2012.nc * Type = Gridded * Xsize = 350 Ysize = 60 Zsize = 1 Tsize = 12266 Esize = 1 * Number of Variables = 1 * tauy 0 t,y,x meridional wind stress * Using intrinsic function to read information about maximum no of time from result of 'q file' * Refer http://grads.iges.org/grads/gadoc/script.html#functions anslin5=sublin(result,5) maxday=subwrd(anslin5,12) ; *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 3) Identifying start and end points of each month. * Note: I am assuming that your data is a daily data for a single station. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ days=1 strtMnT=days while(days<=maxday) 'set t 'days * Grads command 'q dim' is used to identify start and end points of each month *ga-> q dim *Default file number is: 1 *X is varying Lon = 30.5 to 379.5 X = 1 to 350 *Y is varying Lat = -29.5 to 29.5 Y = 1 to 60 *Z is fixed Lev = 0 Z = 1 *T is fixed Time = 11:59Z01JAN1979 T = 1 *E is fixed Ens = 1 E = 1 if days=1 'q dim' anslin5=sublin(result,5) prvM=substr(anslin5,31,3) else ;*if days=1 prvM=curM endif;*if days=1 'q dim' anslin5=sublin(result,5) curM=substr(anslin5,31,3) ;* Pls make necessary modification in the last two numbers ;* to make sure that they correspond to text showing month. ;* Numbers given here is valid for text JAN in the above eg if (prvM != curM) stopMnT=days-1 mnCnt=mnCnt+1 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 4) Variables 'strtMnT' & 'stopMnT' give the time indices showing start & stop of * each month. Now use grads functions 'max'& 'min' or 'amax' & 'amin' to identify * maximum value for data of each month. * http://www.iges.org/grads/gadoc/gadocindex.html *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Here I am using 'max' & 'min' assuming that there is only one station in the data. 'define minVal= min(temp, t= 'strtMnT', t= 'stopMnT) 'define maxVal= max(temp, t= 'strtMnT', t= 'stopMnT) 'd minVal'; MinVal1=subwrd(result,4); 'd maxVal'; MaxVal1=subwrd(result,4); * Saving the monthly maximum and minimum of data into a compound variable OutAry.mnCnt.1=crntYr ;* saving year OutAry.mnCnt.2=prvM ;* saving text showing months JAN, FEB, etc OutAry.mnCnt.3=MinVal1 ;* minimum value of the month OutAry.mnCnt.4=MaxVal1 ;* minimum value of the month strtMnT=stopMnT+1 endif ;*if (prvM != curM) days=days+1 endwhile ;*while(days<=maxday) yrs=yrs+1 'close 1' ;* closing file endwhile ;*while(yrs<=noYrs) * Computations for all years are completed. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 5) Writing the data in compound variable 'OutAry' to output file. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Please explore options to write output file. Probably following URL might be * helpful for you. * http://cookbooks.opengrads.org/index.php?title=Recipe-002:_Saving_GrADS_variable_data_to_a_text_file#Problem